Issue 499: added ssh key import to AWSKeyPairClient

This commit is contained in:
Adrian Cole 2011-03-06 09:22:37 -05:00
parent d42f50e0c0
commit 9892fb1d1b
16 changed files with 763 additions and 188 deletions

View File

@ -36,7 +36,7 @@
<properties>
<test.aws-ec2.endpoint>https://ec2.us-east-1.amazonaws.com</test.aws-ec2.endpoint>
<test.aws-ec2.apiversion>2010-06-15</test.aws-ec2.apiversion>
<test.aws-ec2.apiversion>2010-11-15</test.aws-ec2.apiversion>
<test.aws-ec2.identity>${test.aws.identity}</test.aws-ec2.identity>
<test.aws-ec2.credential>${test.aws.credential}</test.aws-ec2.credential>
</properties>

View File

@ -21,6 +21,7 @@ package org.jclouds.aws.ec2;
import org.jclouds.aws.ec2.services.AWSAMIAsyncClient;
import org.jclouds.aws.ec2.services.AWSInstanceAsyncClient;
import org.jclouds.aws.ec2.services.AWSKeyPairAsyncClient;
import org.jclouds.aws.ec2.services.MonitoringAsyncClient;
import org.jclouds.aws.ec2.services.PlacementGroupAsyncClient;
import org.jclouds.ec2.EC2AsyncClient;
@ -32,7 +33,7 @@ import org.jclouds.rest.annotations.Delegate;
* @author Adrian Cole
*/
public interface AWSEC2AsyncClient extends EC2AsyncClient {
public final static String VERSION = "2010-06-15";
public final static String VERSION = "2010-11-15";
/**
* {@inheritDoc}
@ -60,4 +61,10 @@ public interface AWSEC2AsyncClient extends EC2AsyncClient {
@Delegate
MonitoringAsyncClient getMonitoringServices();
/**
* {@inheritDoc}
*/
@Delegate
@Override
AWSKeyPairAsyncClient getKeyPairServices();
}

View File

@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit;
import org.jclouds.aws.ec2.services.AWSAMIClient;
import org.jclouds.aws.ec2.services.AWSInstanceClient;
import org.jclouds.aws.ec2.services.AWSKeyPairClient;
import org.jclouds.aws.ec2.services.MonitoringClient;
import org.jclouds.aws.ec2.services.PlacementGroupClient;
import org.jclouds.concurrent.Timeout;
@ -63,4 +64,10 @@ public interface AWSEC2Client extends EC2Client {
@Delegate
MonitoringClient getMonitoringServices();
/**
* {@inheritDoc}
*/
@Delegate
@Override
AWSKeyPairClient getKeyPairServices();
}

View File

@ -31,6 +31,8 @@ import org.jclouds.aws.ec2.services.AWSAMIAsyncClient;
import org.jclouds.aws.ec2.services.AWSAMIClient;
import org.jclouds.aws.ec2.services.AWSInstanceAsyncClient;
import org.jclouds.aws.ec2.services.AWSInstanceClient;
import org.jclouds.aws.ec2.services.AWSKeyPairAsyncClient;
import org.jclouds.aws.ec2.services.AWSKeyPairClient;
import org.jclouds.aws.ec2.services.MonitoringAsyncClient;
import org.jclouds.aws.ec2.services.MonitoringClient;
import org.jclouds.aws.ec2.services.PlacementGroupAsyncClient;
@ -50,8 +52,6 @@ import org.jclouds.ec2.services.ElasticIPAddressAsyncClient;
import org.jclouds.ec2.services.ElasticIPAddressClient;
import org.jclouds.ec2.services.InstanceAsyncClient;
import org.jclouds.ec2.services.InstanceClient;
import org.jclouds.ec2.services.KeyPairAsyncClient;
import org.jclouds.ec2.services.KeyPairClient;
import org.jclouds.ec2.services.SecurityGroupAsyncClient;
import org.jclouds.ec2.services.SecurityGroupClient;
import org.jclouds.ec2.services.WindowsAsyncClient;
@ -75,7 +75,7 @@ public class AWSEC2RestClientModule extends EC2RestClientModule<AWSEC2Client, AW
.put(AWSAMIClient.class, AWSAMIAsyncClient.class)//
.put(ElasticIPAddressClient.class, ElasticIPAddressAsyncClient.class)//
.put(AWSInstanceClient.class, AWSInstanceAsyncClient.class)//
.put(KeyPairClient.class, KeyPairAsyncClient.class)//
.put(AWSKeyPairClient.class, AWSKeyPairAsyncClient.class)//
.put(SecurityGroupClient.class, SecurityGroupAsyncClient.class)//
.put(PlacementGroupClient.class, PlacementGroupAsyncClient.class)//
.put(MonitoringClient.class, MonitoringAsyncClient.class)//

View File

@ -0,0 +1,73 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.aws.ec2.functions;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.inject.Singleton;
import org.jclouds.crypto.CryptoStreams;
import com.google.common.base.Charsets;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
/**
* @see <a href=
* "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-ImportKeyPair.html"
* />
* @author Adrian Cole
*/
@Singleton
public class EncodedRSAPublicKeyToBase64 implements Function<Object, String> {
private static Predicate<Object> startsWith(String value) {
return new ToStringStartsWith(value);
}
private static final class ToStringStartsWith implements Predicate<Object> {
private final String value;
private ToStringStartsWith(String value) {
this.value = value;
}
@Override
public boolean apply(Object input) {
return input.toString().startsWith(value);
}
public String toString() {
return "toStringStartsWith(" + value + ")";
}
}
@SuppressWarnings("unchecked")
private static final Predicate<Object> ALLOWED_MARKERS = Predicates.or(startsWith("ssh-rsa"),
startsWith("-----BEGIN CERTIFICATE-----"), startsWith("---- BEGIN SSH2 PUBLIC KEY ----"));
@Override
public String apply(Object from) {
checkNotNull(from, "input");
checkArgument(ALLOWED_MARKERS.apply(from), "must be a ssh public key, conforming to %s ", ALLOWED_MARKERS);
return CryptoStreams.base64(from.toString().getBytes(Charsets.UTF_8));
}
}

View File

@ -0,0 +1,66 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.aws.ec2.services;
import static org.jclouds.aws.reference.FormParameters.ACTION;
import static org.jclouds.aws.reference.FormParameters.VERSION;
import javax.annotation.Nullable;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import org.jclouds.aws.ec2.AWSEC2AsyncClient;
import org.jclouds.aws.ec2.functions.EncodedRSAPublicKeyToBase64;
import org.jclouds.aws.filters.FormSigner;
import org.jclouds.ec2.domain.KeyPair;
import org.jclouds.ec2.services.KeyPairAsyncClient;
import org.jclouds.ec2.services.KeyPairClient;
import org.jclouds.ec2.xml.KeyPairResponseHandler;
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.FormParams;
import org.jclouds.rest.annotations.ParamParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.VirtualHost;
import org.jclouds.rest.annotations.XMLResponseParser;
import com.google.common.util.concurrent.ListenableFuture;
/**
* @author Adrian Cole
*/
@RequestFilters(FormSigner.class)
@FormParams(keys = VERSION, values = AWSEC2AsyncClient.VERSION)
@VirtualHost
public interface AWSKeyPairAsyncClient extends KeyPairAsyncClient {
/**
* @see KeyPairClient#importKeyPairInRegion
*/
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ImportKeyPair")
@XMLResponseParser(KeyPairResponseHandler.class)
ListenableFuture<KeyPair> importKeyPairInRegion(
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
@FormParam("KeyName") String keyName,
@FormParam("PublicKeyMaterial") @ParamParser(EncodedRSAPublicKeyToBase64.class) String publicKeyMaterial);
}

View File

@ -0,0 +1,71 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.aws.ec2.services;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.jclouds.concurrent.Timeout;
import org.jclouds.ec2.domain.KeyPair;
import org.jclouds.ec2.services.KeyPairClient;
/**
*
* @author Adrian Cole
*/
@Timeout(duration = 90, timeUnit = TimeUnit.SECONDS)
public interface AWSKeyPairClient extends KeyPairClient {
/**
* Imports the public key from an RSA key pair that you created with a third-party tool. Compare
* this with CreateKeyPair, in which AWS creates the key pair and gives the keys to you (AWS
* keeps a copy of the public key). With ImportKeyPair, you create the key pair and give AWS just
* the public key. The private key is never transferred between you and AWS.
*
* <p/>
* You can easily create an RSA key pair on Windows and Linux using the ssh-keygen command line
* tool (provided with the standard OpenSSH installation). Standard library support for RSA key
* pair creation is also available in Java, Ruby, Python, and many other programming languages.
*
* <p/>
* <h4>Supported Formats</h4>
* <ul>
* <li>OpenSSH public key format (e.g., the format in ~/.ssh/authorized_keys)</li>
* <li>Base64 encoded DER format</li>
* <li>SSH public key file format as specified in RFC4716</li>
* </ul>
* DSA keys are not supported. Make sure your key generator is set up to create RSA keys.
* <p/>
* Supported lengths: 1024, 2048, and 4096.
* <p/>
*
* @param region
* region to import the key into
* @param keyName
* A unique name for the key pair. Accepts alphanumeric characters, spaces, dashes, and
* underscores.
* @param publicKeyMaterial
* The public key
* @return imported key including fingerprint
*/
KeyPair importKeyPairInRegion(@Nullable String region, String keyName, String publicKeyMaterial);
}

View File

@ -29,10 +29,10 @@ import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import org.jclouds.aws.ec2.AWSEC2AsyncClient;
import org.jclouds.aws.ec2.domain.MonitoringState;
import org.jclouds.aws.ec2.xml.MonitoringStateHandler;
import org.jclouds.aws.filters.FormSigner;
import org.jclouds.ec2.EC2AsyncClient;
import org.jclouds.ec2.binders.BindInstanceIdsToIndexedFormParams;
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
import org.jclouds.rest.annotations.BinderParam;
@ -51,7 +51,7 @@ import com.google.common.util.concurrent.ListenableFuture;
* @author Adrian Cole
*/
@RequestFilters(FormSigner.class)
@FormParams(keys = VERSION, values = EC2AsyncClient.VERSION)
@FormParams(keys = VERSION, values = AWSEC2AsyncClient.VERSION)
@VirtualHost
public interface MonitoringAsyncClient {

View File

@ -29,10 +29,10 @@ import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import org.jclouds.aws.ec2.AWSEC2AsyncClient;
import org.jclouds.aws.ec2.domain.PlacementGroup;
import org.jclouds.aws.ec2.xml.DescribePlacementGroupsResponseHandler;
import org.jclouds.aws.filters.FormSigner;
import org.jclouds.ec2.EC2AsyncClient;
import org.jclouds.ec2.binders.BindGroupNamesToIndexedFormParams;
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
import org.jclouds.rest.annotations.BinderParam;
@ -54,7 +54,7 @@ import com.google.common.util.concurrent.ListenableFuture;
* @author Adrian Cole
*/
@RequestFilters(FormSigner.class)
@FormParams(keys = VERSION, values = EC2AsyncClient.VERSION)
@FormParams(keys = VERSION, values = AWSEC2AsyncClient.VERSION)
@VirtualHost
public interface PlacementGroupAsyncClient {

View File

@ -0,0 +1,28 @@
package org.jclouds.aws.ec2.functions;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import org.testng.annotations.Test;
/**
* Tests behavior of {@code EncodedRSAPublicKeyToBase64}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class EncodedRSAPublicKeyToBase64Test {
EncodedRSAPublicKeyToBase64 function = new EncodedRSAPublicKeyToBase64();
public void testAllowedMarkers() throws IOException {
assertEquals(function.apply("-----BEGIN CERTIFICATE-----"), "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0t");
assertEquals(function.apply("ssh-rsa"), "c3NoLXJzYQ==");
assertEquals(function.apply("---- BEGIN SSH2 PUBLIC KEY ----"), "LS0tLSBCRUdJTiBTU0gyIFBVQkxJQyBLRVkgLS0tLQ==");
}
@Test(expectedExceptions = IllegalArgumentException.class)
public void testDisallowedMarkersIllegalArgument() throws IOException {
function.apply("ssh-dsa");
}
}

View File

@ -58,13 +58,13 @@ public class AWSAMIAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSAMIAsync
public void testCreateImage() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSAMIAsyncClient.class.getMethod("createImageInRegion", String.class, String.class,
String.class, Array.newInstance(CreateImageOptions.class, 0).getClass());
String.class, Array.newInstance(CreateImageOptions.class, 0).getClass());
HttpRequest request = processor.createRequest(method, null, "name", "instanceId");
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request, "Version=2010-06-15&Action=CreateImage&InstanceId=instanceId&Name=name",
"application/x-www-form-urlencoded", false);
assertPayloadEquals(request, "Version=2010-11-15&Action=CreateImage&InstanceId=instanceId&Name=name",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
assertExceptionParserClassEquals(method, null);
@ -74,16 +74,16 @@ public class AWSAMIAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSAMIAsync
public void testCreateImageOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSAMIAsyncClient.class.getMethod("createImageInRegion", String.class, String.class,
String.class, Array.newInstance(CreateImageOptions.class, 0).getClass());
String.class, Array.newInstance(CreateImageOptions.class, 0).getClass());
HttpRequest request = processor.createRequest(method, null, "name", "instanceId", new CreateImageOptions()
.withDescription("description").noReboot());
.withDescription("description").noReboot());
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(
request,
"Version=2010-06-15&Action=CreateImage&InstanceId=instanceId&Name=name&Description=description&NoReboot=true",
"application/x-www-form-urlencoded", false);
request,
"Version=2010-11-15&Action=CreateImage&InstanceId=instanceId&Name=name&Description=description&NoReboot=true",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
@ -93,19 +93,19 @@ public class AWSAMIAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSAMIAsync
}
public void testDescribeImages() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSAMIAsyncClient.class.getMethod("describeImagesInRegion", String.class, Array.newInstance(
DescribeImagesOptions.class, 0).getClass());
Method method = AWSAMIAsyncClient.class.getMethod("describeImagesInRegion", String.class,
Array.newInstance(DescribeImagesOptions.class, 0).getClass());
HttpRequest request = processor.createRequest(method, (String) null);
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request, "Version=2010-06-15&Action=DescribeImages", "application/x-www-form-urlencoded",
false);
assertPayloadEquals(request, "Version=2010-11-15&Action=DescribeImages", "application/x-www-form-urlencoded",
false);
filter.filter(request);
assertPayloadEquals(
request,
"Action=DescribeImages&Signature=qE4vexSFJqS0UWK%2BccV3s%2BP9woL3M5HI5bTBoM7s%2FLY%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Version=2010-06-15&AWSAccessKeyId=identity",
"application/x-www-form-urlencoded", false);
request,
"Action=DescribeImages&Signature=1gIaOJ%2F0Wc8ZFl8GeinQzYAfD%2FOQCKLH32VLcOippGY%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Version=2010-11-15&AWSAccessKeyId=identity",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, DescribeImagesResponseHandler.class);
@ -115,17 +115,17 @@ public class AWSAMIAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSAMIAsync
}
public void testDescribeImagesOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSAMIAsyncClient.class.getMethod("describeImagesInRegion", String.class, Array.newInstance(
DescribeImagesOptions.class, 0).getClass());
HttpRequest request = processor.createRequest(method, null, executableBy("me").ownedBy("fred", "nancy").imageIds(
"1", "2"));
Method method = AWSAMIAsyncClient.class.getMethod("describeImagesInRegion", String.class,
Array.newInstance(DescribeImagesOptions.class, 0).getClass());
HttpRequest request = processor.createRequest(method, null,
executableBy("me").ownedBy("fred", "nancy").imageIds("1", "2"));
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(
request,
"Version=2010-06-15&Action=DescribeImages&ExecutableBy=me&Owner.1=fred&Owner.2=nancy&ImageId.1=1&ImageId.2=2",
"application/x-www-form-urlencoded", false);
request,
"Version=2010-11-15&Action=DescribeImages&ExecutableBy=me&Owner.1=fred&Owner.2=nancy&ImageId.1=1&ImageId.2=2",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, DescribeImagesResponseHandler.class);
@ -140,8 +140,8 @@ public class AWSAMIAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSAMIAsync
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request, "Version=2010-06-15&Action=DeregisterImage&ImageId=imageId",
"application/x-www-form-urlencoded", false);
assertPayloadEquals(request, "Version=2010-11-15&Action=DeregisterImage&ImageId=imageId",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
@ -152,13 +152,13 @@ public class AWSAMIAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSAMIAsync
public void testRegisterImageFromManifest() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSAMIAsyncClient.class.getMethod("registerImageFromManifestInRegion", String.class,
String.class, String.class, Array.newInstance(RegisterImageOptions.class, 0).getClass());
String.class, String.class, Array.newInstance(RegisterImageOptions.class, 0).getClass());
HttpRequest request = processor.createRequest(method, null, "name", "pathToManifest");
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request, "Version=2010-06-15&Action=RegisterImage&ImageLocation=pathToManifest&Name=name",
"application/x-www-form-urlencoded", false);
assertPayloadEquals(request, "Version=2010-11-15&Action=RegisterImage&ImageLocation=pathToManifest&Name=name",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
assertExceptionParserClassEquals(method, null);
@ -168,16 +168,15 @@ public class AWSAMIAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSAMIAsync
public void testRegisterImageFromManifestOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSAMIAsyncClient.class.getMethod("registerImageFromManifestInRegion", String.class,
String.class, String.class, Array.newInstance(RegisterImageOptions.class, 0).getClass());
HttpRequest request = processor.createRequest(method, null, "name", "pathToManifest", new RegisterImageOptions()
.withDescription("description"));
String.class, String.class, Array.newInstance(RegisterImageOptions.class, 0).getClass());
HttpRequest request = processor.createRequest(method, null, "name", "pathToManifest",
new RegisterImageOptions().withDescription("description"));
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(
request,
"Version=2010-06-15&Action=RegisterImage&ImageLocation=pathToManifest&Name=name&Description=description",
"application/x-www-form-urlencoded", false);
assertPayloadEquals(request,
"Version=2010-11-15&Action=RegisterImage&ImageLocation=pathToManifest&Name=name&Description=description",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
@ -188,15 +187,15 @@ public class AWSAMIAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSAMIAsync
public void testRegisterImageBackedByEBS() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSAMIAsyncClient.class.getMethod("registerUnixImageBackedByEbsInRegion", String.class,
String.class, String.class, Array.newInstance(RegisterImageBackedByEbsOptions.class, 0).getClass());
String.class, String.class, Array.newInstance(RegisterImageBackedByEbsOptions.class, 0).getClass());
HttpRequest request = processor.createRequest(method, null, "imageName", "snapshotId");
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(
request,
"Version=2010-06-15&Action=RegisterImage&RootDeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.0.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.0.Ebs.SnapshotId=snapshotId&Name=imageName",
"application/x-www-form-urlencoded", false);
request,
"Version=2010-11-15&Action=RegisterImage&RootDeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.0.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.0.Ebs.SnapshotId=snapshotId&Name=imageName",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
assertExceptionParserClassEquals(method, null);
@ -206,17 +205,22 @@ public class AWSAMIAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSAMIAsync
public void testRegisterImageBackedByEBSOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSAMIAsyncClient.class.getMethod("registerUnixImageBackedByEbsInRegion", String.class,
String.class, String.class, Array.newInstance(RegisterImageBackedByEbsOptions.class, 0).getClass());
HttpRequest request = processor.createRequest(method, null, "imageName", "snapshotId",
new RegisterImageBackedByEbsOptions().withDescription("description").addBlockDeviceFromSnapshot(
"/dev/device", null, "snapshot").addNewBlockDevice("/dev/newdevice", "newblock", 100));
String.class, String.class, Array.newInstance(RegisterImageBackedByEbsOptions.class, 0).getClass());
HttpRequest request = processor.createRequest(
method,
null,
"imageName",
"snapshotId",
new RegisterImageBackedByEbsOptions().withDescription("description")
.addBlockDeviceFromSnapshot("/dev/device", null, "snapshot")
.addNewBlockDevice("/dev/newdevice", "newblock", 100));
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(
request,
"Version=2010-06-15&Action=RegisterImage&RootDeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.0.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.0.Ebs.SnapshotId=snapshotId&Name=imageName&Description=description&BlockDeviceMapping.1.Ebs.DeleteOnTermination=false&BlockDeviceMapping.1.DeviceName=%2Fdev%2Fdevice&BlockDeviceMapping.1.Ebs.SnapshotId=snapshot&BlockDeviceMapping.2.Ebs.DeleteOnTermination=false&BlockDeviceMapping.2.DeviceName=%2Fdev%2Fnewdevice&BlockDeviceMapping.2.VirtualName=newblock&BlockDeviceMapping.2.Ebs.VolumeSize=100",
"application/x-www-form-urlencoded", false);
request,
"Version=2010-11-15&Action=RegisterImage&RootDeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.0.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.0.Ebs.SnapshotId=snapshotId&Name=imageName&Description=description&BlockDeviceMapping.1.Ebs.DeleteOnTermination=false&BlockDeviceMapping.1.DeviceName=%2Fdev%2Fdevice&BlockDeviceMapping.1.Ebs.SnapshotId=snapshot&BlockDeviceMapping.2.Ebs.DeleteOnTermination=false&BlockDeviceMapping.2.DeviceName=%2Fdev%2Fnewdevice&BlockDeviceMapping.2.VirtualName=newblock&BlockDeviceMapping.2.Ebs.VolumeSize=100",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
@ -232,8 +236,8 @@ public class AWSAMIAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSAMIAsync
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request,
"Version=2010-06-15&Action=DescribeImageAttribute&Attribute=productCodes&ImageId=imageId",
"application/x-www-form-urlencoded", false);
"Version=2010-11-15&Action=DescribeImageAttribute&Attribute=productCodes&ImageId=imageId",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, ProductCodesHandler.class);
@ -244,14 +248,14 @@ public class AWSAMIAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSAMIAsync
public void testGetBlockDeviceMappingsForImage() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSAMIAsyncClient.class.getMethod("getBlockDeviceMappingsForImageInRegion", String.class,
String.class);
String.class);
HttpRequest request = processor.createRequest(method, null, "imageId");
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request,
"Version=2010-06-15&Action=DescribeImageAttribute&Attribute=blockDeviceMapping&ImageId=imageId",
"application/x-www-form-urlencoded", false);
"Version=2010-11-15&Action=DescribeImageAttribute&Attribute=blockDeviceMapping&ImageId=imageId",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, BlockDeviceMappingHandler.class);
@ -262,14 +266,14 @@ public class AWSAMIAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSAMIAsync
public void testGetLaunchPermissionForImage() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSAMIAsyncClient.class.getMethod("getLaunchPermissionForImageInRegion", String.class,
String.class);
String.class);
HttpRequest request = processor.createRequest(method, null, "imageId");
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request,
"Version=2010-06-15&Action=DescribeImageAttribute&Attribute=launchPermission&ImageId=imageId",
"application/x-www-form-urlencoded", false);
"Version=2010-11-15&Action=DescribeImageAttribute&Attribute=launchPermission&ImageId=imageId",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, PermissionHandler.class);
@ -280,21 +284,21 @@ public class AWSAMIAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSAMIAsync
public void testAddLaunchPermissionsToImage() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSAMIAsyncClient.class.getMethod("addLaunchPermissionsToImageInRegion", String.class,
Iterable.class, Iterable.class, String.class);
HttpRequest request = processor.createRequest(method, null, ImmutableList.of("bob", "sue"), ImmutableList
.of("all"), "imageId");
Iterable.class, Iterable.class, String.class);
HttpRequest request = processor.createRequest(method, null, ImmutableList.of("bob", "sue"),
ImmutableList.of("all"), "imageId");
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(
request,
"Version=2010-06-15&Action=ModifyImageAttribute&OperationType=add&Attribute=launchPermission&ImageId=imageId&UserGroup.1=all&UserId.1=bob&UserId.2=sue",
"application/x-www-form-urlencoded", false);
request,
"Version=2010-11-15&Action=ModifyImageAttribute&OperationType=add&Attribute=launchPermission&ImageId=imageId&UserGroup.1=all&UserId.1=bob&UserId.2=sue",
"application/x-www-form-urlencoded", false);
filter.filter(request);
assertPayloadEquals(
request,
"Action=ModifyImageAttribute&Attribute=launchPermission&ImageId=imageId&OperationType=add&Signature=WZzNWOC1KHbuySvXEuLTiBA%2BVUfKpSBN2Lud6MrhlCQ%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&UserGroup.1=all&UserId.1=bob&UserId.2=sue&Version=2010-06-15&AWSAccessKeyId=identity",
"application/x-www-form-urlencoded", false);
request,
"Action=ModifyImageAttribute&Attribute=launchPermission&ImageId=imageId&OperationType=add&Signature=UvMbUlLld2h7MpNmuc9JSuOjDw4DS6PSNQVlBdBc%2FBQ%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&UserGroup.1=all&UserId.1=bob&UserId.2=sue&Version=2010-11-15&AWSAccessKeyId=identity",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
@ -305,16 +309,16 @@ public class AWSAMIAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSAMIAsync
public void testRemoveLaunchPermissionsFromImage() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSAMIAsyncClient.class.getMethod("removeLaunchPermissionsFromImageInRegion", String.class,
Iterable.class, Iterable.class, String.class);
HttpRequest request = processor.createRequest(method, null, ImmutableList.of("bob", "sue"), ImmutableList
.of("all"), "imageId");
Iterable.class, Iterable.class, String.class);
HttpRequest request = processor.createRequest(method, null, ImmutableList.of("bob", "sue"),
ImmutableList.of("all"), "imageId");
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(
request,
"Version=2010-06-15&Action=ModifyImageAttribute&OperationType=remove&Attribute=launchPermission&ImageId=imageId&UserGroup.1=all&UserId.1=bob&UserId.2=sue",
"application/x-www-form-urlencoded", false);
request,
"Version=2010-11-15&Action=ModifyImageAttribute&OperationType=remove&Attribute=launchPermission&ImageId=imageId&UserGroup.1=all&UserId.1=bob&UserId.2=sue",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
@ -324,14 +328,14 @@ public class AWSAMIAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSAMIAsync
public void testResetLaunchPermissionsOnImage() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSAMIAsyncClient.class.getMethod("resetLaunchPermissionsOnImageInRegion", String.class,
String.class);
String.class);
HttpRequest request = processor.createRequest(method, null, "imageId");
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request,
"Version=2010-06-15&Action=ResetImageAttribute&Attribute=launchPermission&ImageId=imageId",
"application/x-www-form-urlencoded", false);
"Version=2010-11-15&Action=ResetImageAttribute&Attribute=launchPermission&ImageId=imageId",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
@ -341,15 +345,15 @@ public class AWSAMIAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSAMIAsync
public void testAddProductCodesToImage() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSAMIAsyncClient.class.getMethod("addProductCodesToImageInRegion", String.class, Iterable.class,
String.class);
String.class);
HttpRequest request = processor.createRequest(method, null, ImmutableList.of("code1", "code2"), "imageId");
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(
request,
"Version=2010-06-15&Action=ModifyImageAttribute&OperationType=add&Attribute=productCodes&ImageId=imageId&ProductCode.1=code1&ProductCode.2=code2",
"application/x-www-form-urlencoded", false);
request,
"Version=2010-11-15&Action=ModifyImageAttribute&OperationType=add&Attribute=productCodes&ImageId=imageId&ProductCode.1=code1&ProductCode.2=code2",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
@ -360,15 +364,15 @@ public class AWSAMIAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSAMIAsync
public void testRemoveProductCodesFromImage() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSAMIAsyncClient.class.getMethod("removeProductCodesFromImageInRegion", String.class,
Iterable.class, String.class);
Iterable.class, String.class);
HttpRequest request = processor.createRequest(method, null, ImmutableList.of("code1", "code2"), "imageId");
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(
request,
"Version=2010-06-15&Action=ModifyImageAttribute&OperationType=remove&Attribute=productCodes&ImageId=imageId&ProductCode.1=code1&ProductCode.2=code2",
"application/x-www-form-urlencoded", false);
request,
"Version=2010-11-15&Action=ModifyImageAttribute&OperationType=remove&Attribute=productCodes&ImageId=imageId&ProductCode.1=code1&ProductCode.2=code2",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);

View File

@ -62,8 +62,8 @@ public class AWSInstanceAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSIns
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request, "Version=2010-06-15&Action=DescribeInstances", "application/x-www-form-urlencoded",
false);
assertPayloadEquals(request, "Version=2010-11-15&Action=DescribeInstances", "application/x-www-form-urlencoded",
false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, AWSDescribeInstancesResponseHandler.class);
@ -78,8 +78,8 @@ public class AWSInstanceAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSIns
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request, "Version=2010-06-15&Action=DescribeInstances&InstanceId.1=1&InstanceId.2=2",
"application/x-www-form-urlencoded", false);
assertPayloadEquals(request, "Version=2010-11-15&Action=DescribeInstances&InstanceId.1=1&InstanceId.2=2",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, AWSDescribeInstancesResponseHandler.class);
@ -90,13 +90,13 @@ public class AWSInstanceAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSIns
public void testTerminateInstances() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSInstanceAsyncClient.class.getMethod("terminateInstancesInRegion", String.class, Array
.newInstance(String.class, 0).getClass());
.newInstance(String.class, 0).getClass());
HttpRequest request = processor.createRequest(method, null, "1", "2");
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request, "Version=2010-06-15&Action=TerminateInstances&InstanceId.1=1&InstanceId.2=2",
"application/x-www-form-urlencoded", false);
assertPayloadEquals(request, "Version=2010-11-15&Action=TerminateInstances&InstanceId.1=1&InstanceId.2=2",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, InstanceStateChangeHandler.class);
@ -107,18 +107,18 @@ public class AWSInstanceAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSIns
public void testRunInstances() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSInstanceAsyncClient.class.getMethod("runInstancesInRegion", String.class, String.class,
String.class, int.class, int.class, Array.newInstance(RunInstancesOptions.class, 0).getClass());
String.class, int.class, int.class, Array.newInstance(RunInstancesOptions.class, 0).getClass());
HttpRequest request = processor.createRequest(method, null, null, "ami-voo", 1, 1);
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
try {
assertPayloadEquals(request, "Version=2010-06-15&Action=RunInstances&ImageId=ami-voo&MinCount=1&MaxCount=1",
"application/x-www-form-urlencoded", false);
assertPayloadEquals(request, "Version=2010-11-15&Action=RunInstances&ImageId=ami-voo&MinCount=1&MaxCount=1",
"application/x-www-form-urlencoded", false);
} catch (AssertionError e) {
// mvn 3.0 osx 10.6.5 somehow sorts differently
assertPayloadEquals(request, "Version=2010-06-15&Action=RunInstances&ImageId=ami-voo&MaxCount=1&MinCount=1",
"application/x-www-form-urlencoded", false);
assertPayloadEquals(request, "Version=2010-11-15&Action=RunInstances&ImageId=ami-voo&MaxCount=1&MinCount=1",
"application/x-www-form-urlencoded", false);
}
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, AWSRunInstancesResponseHandler.class);
@ -129,24 +129,30 @@ public class AWSInstanceAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSIns
public void testRunInstancesOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSInstanceAsyncClient.class.getMethod("runInstancesInRegion", String.class, String.class,
String.class, int.class, int.class, Array.newInstance(RunInstancesOptions.class, 0).getClass());
HttpRequest request = processor.createRequest(method, "us-east-1", "us-east-1a", "ami-voo",
1, 5, new AWSRunInstancesOptions().withKernelId("kernelId").enableMonitoring().withSecurityGroups(
"group1", "group2"));
String.class, int.class, int.class, Array.newInstance(RunInstancesOptions.class, 0).getClass());
HttpRequest request = processor.createRequest(
method,
"us-east-1",
"us-east-1a",
"ami-voo",
1,
5,
new AWSRunInstancesOptions().withKernelId("kernelId").enableMonitoring()
.withSecurityGroups("group1", "group2"));
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
try {
assertPayloadEquals(
request,
"Version=2010-06-15&Action=RunInstances&ImageId=ami-voo&MinCount=1&MaxCount=5&KernelId=kernelId&Monitoring.Enabled=true&SecurityGroup.1=group1&SecurityGroup.2=group2&Placement.AvailabilityZone=us-east-1a",
"application/x-www-form-urlencoded", false);
request,
"Version=2010-11-15&Action=RunInstances&ImageId=ami-voo&MinCount=1&MaxCount=5&KernelId=kernelId&Monitoring.Enabled=true&SecurityGroup.1=group1&SecurityGroup.2=group2&Placement.AvailabilityZone=us-east-1a",
"application/x-www-form-urlencoded", false);
} catch (AssertionError e) {
// mvn 3.0 osx 10.6.5 somehow sorts differently
assertPayloadEquals(
request,
"Version=2010-06-15&Action=RunInstances&ImageId=ami-voo&MaxCount=5&MinCount=1&KernelId=kernelId&Monitoring.Enabled=true&SecurityGroup.1=group1&SecurityGroup.2=group2&Placement.AvailabilityZone=us-east-1a",
"application/x-www-form-urlencoded", false);
request,
"Version=2010-11-15&Action=RunInstances&ImageId=ami-voo&MaxCount=5&MinCount=1&KernelId=kernelId&Monitoring.Enabled=true&SecurityGroup.1=group1&SecurityGroup.2=group2&Placement.AvailabilityZone=us-east-1a",
"application/x-www-form-urlencoded", false);
}
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, AWSRunInstancesResponseHandler.class);
@ -157,13 +163,13 @@ public class AWSInstanceAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSIns
public void testStopInstances() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSInstanceAsyncClient.class.getMethod("stopInstancesInRegion", String.class, boolean.class,
Array.newInstance(String.class, 0).getClass());
Array.newInstance(String.class, 0).getClass());
HttpRequest request = processor.createRequest(method, null, true, "1", "2");
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request, "Version=2010-06-15&Action=StopInstances&Force=true&InstanceId.1=1&InstanceId.2=2",
"application/x-www-form-urlencoded", false);
assertPayloadEquals(request, "Version=2010-11-15&Action=StopInstances&Force=true&InstanceId.1=1&InstanceId.2=2",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, InstanceStateChangeHandler.class);
@ -174,13 +180,13 @@ public class AWSInstanceAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSIns
public void testRebootInstances() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSInstanceAsyncClient.class.getMethod("rebootInstancesInRegion", String.class, Array
.newInstance(String.class, 0).getClass());
.newInstance(String.class, 0).getClass());
HttpRequest request = processor.createRequest(method, null, "1", "2");
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request, "Version=2010-06-15&Action=RebootInstances&InstanceId.1=1&InstanceId.2=2",
"application/x-www-form-urlencoded", false);
assertPayloadEquals(request, "Version=2010-11-15&Action=RebootInstances&InstanceId.1=1&InstanceId.2=2",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
@ -190,14 +196,14 @@ public class AWSInstanceAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSIns
}
public void testStartInstances() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSInstanceAsyncClient.class.getMethod("startInstancesInRegion", String.class, Array.newInstance(
String.class, 0).getClass());
Method method = AWSInstanceAsyncClient.class.getMethod("startInstancesInRegion", String.class,
Array.newInstance(String.class, 0).getClass());
HttpRequest request = processor.createRequest(method, null, "1", "2");
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request, "Version=2010-06-15&Action=StartInstances&InstanceId.1=1&InstanceId.2=2",
"application/x-www-form-urlencoded", false);
assertPayloadEquals(request, "Version=2010-11-15&Action=StartInstances&InstanceId.1=1&InstanceId.2=2",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, InstanceStateChangeHandler.class);
@ -208,14 +214,14 @@ public class AWSInstanceAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSIns
public void testGetUserDataForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSInstanceAsyncClient.class.getMethod("getUserDataForInstanceInRegion", String.class,
String.class);
String.class);
HttpRequest request = processor.createRequest(method, null, "1");
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request,
"Version=2010-06-15&Action=DescribeInstanceAttribute&Attribute=userData&InstanceId=1",
"application/x-www-form-urlencoded", false);
"Version=2010-11-15&Action=DescribeInstanceAttribute&Attribute=userData&InstanceId=1",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, UnencodeStringValueHandler.class);
@ -226,14 +232,14 @@ public class AWSInstanceAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSIns
public void testGetRootDeviceNameForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSInstanceAsyncClient.class.getMethod("getRootDeviceNameForInstanceInRegion", String.class,
String.class);
String.class);
HttpRequest request = processor.createRequest(method, null, "1");
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request,
"Version=2010-06-15&Action=DescribeInstanceAttribute&Attribute=rootDeviceName&InstanceId=1",
"application/x-www-form-urlencoded", false);
"Version=2010-11-15&Action=DescribeInstanceAttribute&Attribute=rootDeviceName&InstanceId=1",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, StringValueHandler.class);
@ -244,14 +250,14 @@ public class AWSInstanceAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSIns
public void testGetRamdiskForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSInstanceAsyncClient.class.getMethod("getRamdiskForInstanceInRegion", String.class,
String.class);
String.class);
HttpRequest request = processor.createRequest(method, null, "1");
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request,
"Version=2010-06-15&Action=DescribeInstanceAttribute&Attribute=ramdisk&InstanceId=1",
"application/x-www-form-urlencoded", false);
"Version=2010-11-15&Action=DescribeInstanceAttribute&Attribute=ramdisk&InstanceId=1",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, StringValueHandler.class);
@ -261,16 +267,16 @@ public class AWSInstanceAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSIns
}
public void testGetDisableApiTerminationForInstanceInRegion() throws SecurityException, NoSuchMethodException,
IOException {
IOException {
Method method = AWSInstanceAsyncClient.class.getMethod("isApiTerminationDisabledForInstanceInRegion",
String.class, String.class);
String.class, String.class);
HttpRequest request = processor.createRequest(method, null, "1");
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request,
"Version=2010-06-15&Action=DescribeInstanceAttribute&Attribute=disableApiTermination&InstanceId=1",
"application/x-www-form-urlencoded", false);
"Version=2010-11-15&Action=DescribeInstanceAttribute&Attribute=disableApiTermination&InstanceId=1",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, BooleanValueHandler.class);
@ -281,13 +287,13 @@ public class AWSInstanceAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSIns
public void testGetKernelForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSInstanceAsyncClient.class
.getMethod("getKernelForInstanceInRegion", String.class, String.class);
.getMethod("getKernelForInstanceInRegion", String.class, String.class);
HttpRequest request = processor.createRequest(method, null, "1");
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request, "Version=2010-06-15&Action=DescribeInstanceAttribute&Attribute=kernel&InstanceId=1",
"application/x-www-form-urlencoded", false);
assertPayloadEquals(request, "Version=2010-11-15&Action=DescribeInstanceAttribute&Attribute=kernel&InstanceId=1",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, StringValueHandler.class);
@ -298,14 +304,14 @@ public class AWSInstanceAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSIns
public void testGetInstanceTypeForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSInstanceAsyncClient.class.getMethod("getInstanceTypeForInstanceInRegion", String.class,
String.class);
String.class);
HttpRequest request = processor.createRequest(method, null, "1");
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request,
"Version=2010-06-15&Action=DescribeInstanceAttribute&Attribute=instanceType&InstanceId=1",
"application/x-www-form-urlencoded", false);
"Version=2010-11-15&Action=DescribeInstanceAttribute&Attribute=instanceType&InstanceId=1",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, InstanceTypeHandler.class);
@ -315,17 +321,17 @@ public class AWSInstanceAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSIns
}
public void testGetInstanceInitiatedShutdownBehaviorForInstanceInRegion() throws SecurityException,
NoSuchMethodException, IOException {
NoSuchMethodException, IOException {
Method method = AWSInstanceAsyncClient.class.getMethod("getInstanceInitiatedShutdownBehaviorForInstanceInRegion",
String.class, String.class);
String.class, String.class);
HttpRequest request = processor.createRequest(method, null, "1");
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(
request,
"Version=2010-06-15&Action=DescribeInstanceAttribute&Attribute=instanceInitiatedShutdownBehavior&InstanceId=1",
"application/x-www-form-urlencoded", false);
request,
"Version=2010-11-15&Action=DescribeInstanceAttribute&Attribute=instanceInitiatedShutdownBehavior&InstanceId=1",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, InstanceInitiatedShutdownBehaviorHandler.class);
@ -335,16 +341,16 @@ public class AWSInstanceAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSIns
}
public void testGetBlockDeviceMappingForInstanceInRegion() throws SecurityException, NoSuchMethodException,
IOException {
IOException {
Method method = AWSInstanceAsyncClient.class.getMethod("getBlockDeviceMappingForInstanceInRegion", String.class,
String.class);
String.class);
HttpRequest request = processor.createRequest(method, null, "1");
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request,
"Version=2010-06-15&Action=DescribeInstanceAttribute&Attribute=blockDeviceMapping&InstanceId=1",
"application/x-www-form-urlencoded", false);
"Version=2010-11-15&Action=DescribeInstanceAttribute&Attribute=blockDeviceMapping&InstanceId=1",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, BlockDeviceMappingHandler.class);
@ -355,19 +361,19 @@ public class AWSInstanceAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSIns
public void testSetUserDataForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSInstanceAsyncClient.class.getMethod("setUserDataForInstanceInRegion", String.class,
String.class, Array.newInstance(byte.class, 0).getClass());
String.class, Array.newInstance(byte.class, 0).getClass());
HttpRequest request = processor.createRequest(method, null, "1", "test".getBytes());
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request,
"Version=2010-06-15&Action=ModifyInstanceAttribute&Attribute=userData&Value=dGVzdA%3D%3D&InstanceId=1",
"application/x-www-form-urlencoded", false);
"Version=2010-11-15&Action=ModifyInstanceAttribute&Attribute=userData&Value=dGVzdA%3D%3D&InstanceId=1",
"application/x-www-form-urlencoded", false);
filter.filter(request);// ensure encoding worked properly
assertPayloadEquals(
request,
"Action=ModifyInstanceAttribute&Attribute=userData&InstanceId=1&Signature=LfUmzLM5DsACR5nQcEfGF5FPdznOwwhJ7tjhBWfHtGs%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Value=dGVzdA%3D%3D&Version=2010-06-15&AWSAccessKeyId=identity",
"application/x-www-form-urlencoded", false);
request,
"Action=ModifyInstanceAttribute&Attribute=userData&InstanceId=1&Signature=B15Bj0yiAMTwpHE%2B9LNNscM4fzFwv0t0adnYbFjgNDk%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Value=dGVzdA%3D%3D&Version=2010-11-15&AWSAccessKeyId=identity",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
@ -377,14 +383,14 @@ public class AWSInstanceAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSIns
public void testSetRamdiskForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSInstanceAsyncClient.class.getMethod("setRamdiskForInstanceInRegion", String.class,
String.class, String.class);
String.class, String.class);
HttpRequest request = processor.createRequest(method, null, "1", "test");
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request,
"Version=2010-06-15&Action=ModifyInstanceAttribute&Attribute=ramdisk&Value=test&InstanceId=1",
"application/x-www-form-urlencoded", false);
"Version=2010-11-15&Action=ModifyInstanceAttribute&Attribute=ramdisk&Value=test&InstanceId=1",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
@ -394,14 +400,14 @@ public class AWSInstanceAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSIns
public void testSetKernelForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSInstanceAsyncClient.class.getMethod("setKernelForInstanceInRegion", String.class,
String.class, String.class);
String.class, String.class);
HttpRequest request = processor.createRequest(method, null, "1", "test");
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request,
"Version=2010-06-15&Action=ModifyInstanceAttribute&Attribute=kernel&Value=test&InstanceId=1",
"application/x-www-form-urlencoded", false);
"Version=2010-11-15&Action=ModifyInstanceAttribute&Attribute=kernel&Value=test&InstanceId=1",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
@ -410,17 +416,17 @@ public class AWSInstanceAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSIns
}
public void testSetApiTerminationDisabledForInstanceInRegion() throws SecurityException, NoSuchMethodException,
IOException {
IOException {
Method method = AWSInstanceAsyncClient.class.getMethod("setApiTerminationDisabledForInstanceInRegion",
String.class, String.class, boolean.class);
String.class, String.class, boolean.class);
HttpRequest request = processor.createRequest(method, null, "1", true);
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(
request,
"Version=2010-06-15&Action=ModifyInstanceAttribute&Attribute=disableApiTermination&Value=true&InstanceId=1",
"application/x-www-form-urlencoded", false);
request,
"Version=2010-11-15&Action=ModifyInstanceAttribute&Attribute=disableApiTermination&Value=true&InstanceId=1",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
@ -431,14 +437,14 @@ public class AWSInstanceAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSIns
public void testSetInstanceTypeForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSInstanceAsyncClient.class.getMethod("setInstanceTypeForInstanceInRegion", String.class,
String.class, String.class);
String.class, String.class);
HttpRequest request = processor.createRequest(method, null, "1", InstanceType.C1_MEDIUM);
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request,
"Version=2010-06-15&Action=ModifyInstanceAttribute&Attribute=instanceType&Value=c1.medium&InstanceId=1",
"application/x-www-form-urlencoded", false);
"Version=2010-11-15&Action=ModifyInstanceAttribute&Attribute=instanceType&Value=c1.medium&InstanceId=1",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
@ -448,17 +454,17 @@ public class AWSInstanceAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSIns
}
public void testSetInstanceInitiatedShutdownBehaviorForInstanceInRegion() throws SecurityException,
NoSuchMethodException, IOException {
NoSuchMethodException, IOException {
Method method = AWSInstanceAsyncClient.class.getMethod("setInstanceInitiatedShutdownBehaviorForInstanceInRegion",
String.class, String.class, InstanceInitiatedShutdownBehavior.class);
String.class, String.class, InstanceInitiatedShutdownBehavior.class);
HttpRequest request = processor.createRequest(method, null, "1", InstanceInitiatedShutdownBehavior.TERMINATE);
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(
request,
"Version=2010-06-15&Action=ModifyInstanceAttribute&Attribute=instanceInitiatedShutdownBehavior&Value=terminate&InstanceId=1",
"application/x-www-form-urlencoded", false);
request,
"Version=2010-11-15&Action=ModifyInstanceAttribute&Attribute=instanceInitiatedShutdownBehavior&Value=terminate&InstanceId=1",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
@ -468,9 +474,9 @@ public class AWSInstanceAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSIns
}
public void testSetBlockDeviceMappingForInstanceInRegion() throws SecurityException, NoSuchMethodException,
IOException {
IOException {
Method method = AWSInstanceAsyncClient.class.getMethod("setBlockDeviceMappingForInstanceInRegion", String.class,
String.class, Map.class);
String.class, Map.class);
Map<String, BlockDevice> mapping = Maps.newLinkedHashMap();
mapping.put("/dev/sda1", new BlockDevice("vol-test1", true));
@ -479,14 +485,14 @@ public class AWSInstanceAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSIns
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(
request,
"Version=2010-06-15&Action=ModifyInstanceAttribute&InstanceId=1&BlockDeviceMapping.1.Ebs.VolumeId=vol-test1&BlockDeviceMapping.1.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.1.Ebs.DeleteOnTermination=true",
"application/x-www-form-urlencoded", false);
request,
"Version=2010-11-15&Action=ModifyInstanceAttribute&InstanceId=1&BlockDeviceMapping.1.Ebs.VolumeId=vol-test1&BlockDeviceMapping.1.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.1.Ebs.DeleteOnTermination=true",
"application/x-www-form-urlencoded", false);
filter.filter(request);// ensure encoding worked properly
assertPayloadEquals(
request,
"Action=ModifyInstanceAttribute&BlockDeviceMapping.1.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.1.Ebs.DeleteOnTermination=true&BlockDeviceMapping.1.Ebs.VolumeId=vol-test1&InstanceId=1&Signature=RwY8lVPHSQxQkd5efUKccHdSTkN4OxMIMFiYAe3rrUE%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Version=2010-06-15&AWSAccessKeyId=identity",
"application/x-www-form-urlencoded", false);
request,
"Action=ModifyInstanceAttribute&BlockDeviceMapping.1.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.1.Ebs.DeleteOnTermination=true&BlockDeviceMapping.1.Ebs.VolumeId=vol-test1&InstanceId=1&Signature=Cf8vx1IzPe%2FFYd7SRJBjztSOB3FQTW9yYtPxQ3OUHF0%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Version=2010-11-15&AWSAccessKeyId=identity",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);

View File

@ -0,0 +1,135 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.aws.ec2.services;
import java.io.IOException;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import org.jclouds.ec2.xml.DescribeKeyPairsResponseHandler;
import org.jclouds.ec2.xml.KeyPairResponseHandler;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReleasePayloadAndReturn;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code AWSKeyPairAsyncClient}
*
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
@Test(groups = "unit", testName = "AWSKeyPairAsyncClientTest")
public class AWSKeyPairAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSKeyPairAsyncClient> {
public void testCreateKeyPair() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSKeyPairAsyncClient.class.getMethod("createKeyPairInRegion", String.class, String.class);
HttpRequest request = processor.createRequest(method, null, "mykey");
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request, "Version=2010-11-15&Action=CreateKeyPair&KeyName=mykey",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, KeyPairResponseHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testImportKeyPair() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSKeyPairAsyncClient.class.getMethod("importKeyPairInRegion", String.class, String.class,
String.class);
HttpRequest request = processor.createRequest(method, null, "mykey", "ssh-rsa AA");
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request, "Version=2010-11-15&Action=ImportKeyPair&PublicKeyMaterial=c3NoLXJzYSBBQQ%3D%3D&KeyName=mykey",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, KeyPairResponseHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testDeleteKeyPair() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSKeyPairAsyncClient.class.getMethod("deleteKeyPairInRegion", String.class, String.class);
HttpRequest request = processor.createRequest(method, null, "mykey");
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request, "Version=2010-11-15&Action=DeleteKeyPair&KeyName=mykey",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testDescribeKeyPairs() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSKeyPairAsyncClient.class.getMethod("describeKeyPairsInRegion", String.class, Array
.newInstance(String.class, 0).getClass());
HttpRequest request = processor.createRequest(method, (String) null);
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request, "Version=2010-11-15&Action=DescribeKeyPairs", "application/x-www-form-urlencoded",
false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, DescribeKeyPairsResponseHandler.class);
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
checkFilters(request);
}
public void testDescribeKeyPairsArgs() throws SecurityException, NoSuchMethodException, IOException {
Method method = AWSKeyPairAsyncClient.class.getMethod("describeKeyPairsInRegion", String.class, Array
.newInstance(String.class, 0).getClass());
HttpRequest request = processor.createRequest(method, null, "1", "2");
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request, "Version=2010-11-15&Action=DescribeKeyPairs&KeyName.1=1&KeyName.2=2",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, DescribeKeyPairsResponseHandler.class);
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
checkFilters(request);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<AWSKeyPairAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<AWSKeyPairAsyncClient>>() {
};
}
}

View File

@ -0,0 +1,178 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.aws.ec2.services;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.SortedSet;
import org.jclouds.Constants;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.AWSEC2AsyncClient;
import org.jclouds.aws.ec2.AWSEC2Client;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.ComputeTestUtils;
import org.jclouds.ec2.domain.KeyPair;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rest.RestContext;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.google.inject.Module;
/**
* Tests behavior of {@code AWSKeyPairClient}
*
* @author Adrian Cole
*/
@Test(groups = "live", sequential = true)
public class AWSKeyPairClientLiveTest {
private AWSKeyPairClient client;
private RestContext<AWSEC2Client, AWSEC2AsyncClient> context;
protected String provider = "aws-ec2";
protected String identity;
protected String credential;
protected String endpoint;
protected String apiversion;
protected void setupCredentials() {
identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider
+ ".credential");
endpoint = System.getProperty("test." + provider + ".endpoint", null);
apiversion = System.getProperty("test." + provider + ".apiversion", null);
}
protected Properties setupProperties() {
Properties overrides = new Properties();
overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
overrides.setProperty(provider + ".identity", identity);
overrides.setProperty(provider + ".credential", credential);
if (endpoint != null)
overrides.setProperty(provider + ".endpoint", endpoint);
if (apiversion != null)
overrides.setProperty(provider + ".apiversion", apiversion);
return overrides;
}
@BeforeGroups(groups = { "live" })
public void setupClient() {
setupCredentials();
Properties overrides = setupProperties();
context = new ComputeServiceContextFactory().createContext(provider,
ImmutableSet.<Module> of(new Log4JLoggingModule()), overrides).getProviderSpecificContext();
client = context.getApi().getKeyPairServices();
}
@Test
void testDescribeAWSKeyPairs() {
for (String region : Region.DEFAULT_REGIONS) {
SortedSet<KeyPair> allResults = Sets.newTreeSet(client.describeKeyPairsInRegion(region));
assertNotNull(allResults);
if (allResults.size() >= 1) {
KeyPair pair = allResults.last();
SortedSet<KeyPair> result = Sets.newTreeSet(client.describeKeyPairsInRegion(region, pair.getKeyName()));
assertNotNull(result);
KeyPair compare = result.last();
assertEquals(compare, pair);
}
}
}
public static final String PREFIX = System.getProperty("user.name") + "-ec2";
@Test
void testCreateKeyPair() {
String keyName = PREFIX + "1";
cleanupKeyPair(keyName);
try {
KeyPair keyPair = client.createKeyPairInRegion(null, keyName);
checkKeyPair(keyName, keyPair);
assertNotNull(keyPair.getKeyMaterial());
} finally {
cleanupKeyPair(keyName);
}
}
protected void cleanupKeyPair(String keyName) {
try {
client.deleteKeyPairInRegion(null, keyName);
} catch (Exception e) {
}
client.deleteKeyPairInRegion(null, keyName);
}
@Test
void testImportKeyPair() throws FileNotFoundException, IOException {
String keyName = PREFIX + "2";
cleanupKeyPair(keyName);
Map<String, String> myKey = ComputeTestUtils.setupKeyPair();
try {
KeyPair keyPair = client.importKeyPairInRegion(null, keyName, myKey.get("public"));
checkKeyPair(keyName, keyPair);
// TODO generate correct fingerprint and check
// assertEquals(keyPair.getKeyFingerprint(),
// CryptoStreams.hex(CryptoStreams.md5(myKey.get("public").getBytes())));
// try again to see if there's an error
try {
client.importKeyPairInRegion(null, keyName, myKey.get("public"));
assert false;
} catch (IllegalStateException e) {
}
} finally {
cleanupKeyPair(keyName);
}
}
protected void checkKeyPair(String keyName, KeyPair keyPair) {
assertNotNull(keyPair);
assertNotNull(keyPair.getKeyFingerprint());
assertEquals(keyPair.getKeyName(), keyName);
Set<KeyPair> twoResults = Sets.newLinkedHashSet(client.describeKeyPairsInRegion(null, keyName));
assertNotNull(twoResults);
assertEquals(twoResults.size(), 1);
KeyPair listPair = twoResults.iterator().next();
assertEquals(listPair.getKeyName(), keyPair.getKeyName());
assertEquals(listPair.getKeyFingerprint(), keyPair.getKeyFingerprint());
}
@AfterTest
public void shutdown() {
context.close();
}
}

View File

@ -46,7 +46,7 @@ public class MonitoringAsyncClientTest extends BaseAWSEC2AsyncClientTest<Monitor
HttpRequest request = processor.createRequest(method, null, "instance1", "instance2");
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
String payload = "Version=2010-06-15&Action=UnmonitorInstances&InstanceId.0=instance1&InstanceId.1=instance2";
String payload = "Version=2010-11-15&Action=UnmonitorInstances&InstanceId.0=instance1&InstanceId.1=instance2";
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request, payload, "application/x-www-form-urlencoded", false);
@ -65,7 +65,7 @@ public class MonitoringAsyncClientTest extends BaseAWSEC2AsyncClientTest<Monitor
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request,
"Version=2010-06-15&Action=MonitorInstances&InstanceId.0=instance1&InstanceId.1=instance2",
"Version=2010-11-15&Action=MonitorInstances&InstanceId.0=instance1&InstanceId.1=instance2",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);

View File

@ -49,7 +49,7 @@ public class PlacementGroupAsyncClientTest extends BaseAWSEC2AsyncClientTest<Pla
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request, "Version=2010-06-15&Action=DeletePlacementGroup&GroupName=name",
assertPayloadEquals(request, "Version=2010-11-15&Action=DeletePlacementGroup&GroupName=name",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
@ -66,7 +66,7 @@ public class PlacementGroupAsyncClientTest extends BaseAWSEC2AsyncClientTest<Pla
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request, "Version=2010-06-15&Action=CreatePlacementGroup&Strategy=cluster&GroupName=name",
assertPayloadEquals(request, "Version=2010-11-15&Action=CreatePlacementGroup&Strategy=cluster&GroupName=name",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
@ -83,7 +83,7 @@ public class PlacementGroupAsyncClientTest extends BaseAWSEC2AsyncClientTest<Pla
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request, "Version=2010-06-15&Action=CreatePlacementGroup&Strategy=cluster&GroupName=name",
assertPayloadEquals(request, "Version=2010-11-15&Action=CreatePlacementGroup&Strategy=cluster&GroupName=name",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
@ -100,7 +100,7 @@ public class PlacementGroupAsyncClientTest extends BaseAWSEC2AsyncClientTest<Pla
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request, "Version=2010-06-15&Action=DescribePlacementGroups",
assertPayloadEquals(request, "Version=2010-11-15&Action=DescribePlacementGroups",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
@ -117,7 +117,7 @@ public class PlacementGroupAsyncClientTest extends BaseAWSEC2AsyncClientTest<Pla
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request, "Version=2010-06-15&Action=DescribePlacementGroups&GroupName.1=1&GroupName.2=2",
assertPayloadEquals(request, "Version=2010-11-15&Action=DescribePlacementGroups&GroupName.1=1&GroupName.2=2",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);