loosened dependency on the GeneratedHttpRequest class

This commit is contained in:
Adrian Cole 2010-07-02 16:47:46 -07:00
parent 9bac52d315
commit 85b5bd48f1
87 changed files with 2985 additions and 3194 deletions

View File

@ -40,6 +40,7 @@ import org.jclouds.blobstore.binders.BindBlobToMultipartFormTest;
import org.jclouds.blobstore.functions.ThrowContainerNotFoundOn404; import org.jclouds.blobstore.functions.ThrowContainerNotFoundOn404;
import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404; import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404;
import org.jclouds.date.TimeStamp; import org.jclouds.date.TimeStamp;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x; import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x;
@ -50,7 +51,6 @@ import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextFactory.ContextSpec; import org.jclouds.rest.RestContextFactory.ContextSpec;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -72,190 +72,182 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
public void testListDirectories() throws SecurityException, NoSuchMethodException, IOException { public void testListDirectories() throws SecurityException, NoSuchMethodException, IOException {
Method method = AtmosStorageAsyncClient.class.getMethod("listDirectories", Array.newInstance( Method method = AtmosStorageAsyncClient.class.getMethod("listDirectories", Array.newInstance(
ListOptions.class, 0).getClass()); ListOptions.class, 0).getClass());
GeneratedHttpRequest<AtmosStorageAsyncClient> httpMethod = processor.createRequest(method); HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"GET https://accesspoint.atmosonline.com/rest/namespace HTTP/1.1"); "GET https://accesspoint.atmosonline.com/rest/namespace HTTP/1.1");
assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + ": text/xml\n"); assertHeadersEqual(request, HttpHeaders.ACCEPT + ": text/xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, assertResponseParserClassEquals(method, request,
ParseDirectoryListFromContentAndHeaders.class); ParseDirectoryListFromContentAndHeaders.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testListDirectory() throws SecurityException, NoSuchMethodException, IOException { public void testListDirectory() throws SecurityException, NoSuchMethodException, IOException {
Method method = AtmosStorageAsyncClient.class.getMethod("listDirectory", String.class, Array Method method = AtmosStorageAsyncClient.class.getMethod("listDirectory", String.class, Array
.newInstance(ListOptions.class, 0).getClass()); .newInstance(ListOptions.class, 0).getClass());
GeneratedHttpRequest<AtmosStorageAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, "directory");
"directory");
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"GET https://accesspoint.atmosonline.com/rest/namespace/directory/ HTTP/1.1"); "GET https://accesspoint.atmosonline.com/rest/namespace/directory/ HTTP/1.1");
assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + ": text/xml\n"); assertHeadersEqual(request, HttpHeaders.ACCEPT + ": text/xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, assertResponseParserClassEquals(method, request,
ParseDirectoryListFromContentAndHeaders.class); ParseDirectoryListFromContentAndHeaders.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ThrowContainerNotFoundOn404.class); assertExceptionParserClassEquals(method, ThrowContainerNotFoundOn404.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testListDirectoriesOptions() throws SecurityException, NoSuchMethodException, public void testListDirectoriesOptions() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = AtmosStorageAsyncClient.class.getMethod("listDirectories", Array.newInstance( Method method = AtmosStorageAsyncClient.class.getMethod("listDirectories", Array.newInstance(
ListOptions.class, 0).getClass()); ListOptions.class, 0).getClass());
GeneratedHttpRequest<AtmosStorageAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, new ListOptions().limit(1)
new ListOptions().limit(1).token("asda")); .token("asda"));
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"GET https://accesspoint.atmosonline.com/rest/namespace HTTP/1.1"); "GET https://accesspoint.atmosonline.com/rest/namespace HTTP/1.1");
assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT assertHeadersEqual(request, HttpHeaders.ACCEPT
+ ": text/xml\nx-emc-limit: 1\nx-emc-token: asda\n"); + ": text/xml\nx-emc-limit: 1\nx-emc-token: asda\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, assertResponseParserClassEquals(method, request,
ParseDirectoryListFromContentAndHeaders.class); ParseDirectoryListFromContentAndHeaders.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testListDirectoryOptions() throws SecurityException, NoSuchMethodException, public void testListDirectoryOptions() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = AtmosStorageAsyncClient.class.getMethod("listDirectory", String.class, Array Method method = AtmosStorageAsyncClient.class.getMethod("listDirectory", String.class, Array
.newInstance(ListOptions.class, 0).getClass()); .newInstance(ListOptions.class, 0).getClass());
GeneratedHttpRequest<AtmosStorageAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, "directory", new ListOptions().limit(1)
"directory", new ListOptions().limit(1).token("asda")); .token("asda"));
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"GET https://accesspoint.atmosonline.com/rest/namespace/directory/ HTTP/1.1"); "GET https://accesspoint.atmosonline.com/rest/namespace/directory/ HTTP/1.1");
assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT assertHeadersEqual(request, HttpHeaders.ACCEPT
+ ": text/xml\nx-emc-limit: 1\nx-emc-token: asda\n"); + ": text/xml\nx-emc-limit: 1\nx-emc-token: asda\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, assertResponseParserClassEquals(method, request,
ParseDirectoryListFromContentAndHeaders.class); ParseDirectoryListFromContentAndHeaders.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ThrowContainerNotFoundOn404.class); assertExceptionParserClassEquals(method, ThrowContainerNotFoundOn404.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testCreateDirectory() throws SecurityException, NoSuchMethodException, IOException { public void testCreateDirectory() throws SecurityException, NoSuchMethodException, IOException {
Method method = AtmosStorageAsyncClient.class.getMethod("createDirectory", String.class); Method method = AtmosStorageAsyncClient.class.getMethod("createDirectory", String.class);
GeneratedHttpRequest<AtmosStorageAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, "dir");
"dir");
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"POST https://accesspoint.atmosonline.com/rest/namespace/dir/ HTTP/1.1"); "POST https://accesspoint.atmosonline.com/rest/namespace/dir/ HTTP/1.1");
assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + ": */*\n"); assertHeadersEqual(request, HttpHeaders.ACCEPT + ": */*\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, assertResponseParserClassEquals(method, request, ParseURIFromListOrLocationHeaderIf20x.class);
ParseURIFromListOrLocationHeaderIf20x.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnEndpointIfAlreadyExists.class); assertExceptionParserClassEquals(method, ReturnEndpointIfAlreadyExists.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testCreateFile() throws SecurityException, NoSuchMethodException, IOException { public void testCreateFile() throws SecurityException, NoSuchMethodException, IOException {
Method method = AtmosStorageAsyncClient.class.getMethod("createFile", String.class, Method method = AtmosStorageAsyncClient.class.getMethod("createFile", String.class,
AtmosObject.class); AtmosObject.class);
GeneratedHttpRequest<AtmosStorageAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, "dir", blobToObject
"dir", blobToObject.apply(BindBlobToMultipartFormTest.TEST_BLOB)); .apply(BindBlobToMultipartFormTest.TEST_BLOB));
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"POST https://accesspoint.atmosonline.com/rest/namespace/dir/hello HTTP/1.1"); "POST https://accesspoint.atmosonline.com/rest/namespace/dir/hello HTTP/1.1");
assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT assertHeadersEqual(request, HttpHeaders.ACCEPT
+ ": */*\nContent-Length: 5\nContent-Type: text/plain\n"); + ": */*\nContent-Length: 5\nContent-Type: text/plain\n");
assertPayloadEquals(httpMethod, "hello"); assertPayloadEquals(request, "hello");
assertResponseParserClassEquals(method, httpMethod, assertResponseParserClassEquals(method, request, ParseURIFromListOrLocationHeaderIf20x.class);
ParseURIFromListOrLocationHeaderIf20x.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testUpdateFile() throws SecurityException, NoSuchMethodException, IOException { public void testUpdateFile() throws SecurityException, NoSuchMethodException, IOException {
Method method = AtmosStorageAsyncClient.class.getMethod("updateFile", String.class, Method method = AtmosStorageAsyncClient.class.getMethod("updateFile", String.class,
AtmosObject.class); AtmosObject.class);
GeneratedHttpRequest<AtmosStorageAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, "dir", blobToObject
"dir", blobToObject.apply(BindBlobToMultipartFormTest.TEST_BLOB)); .apply(BindBlobToMultipartFormTest.TEST_BLOB));
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"PUT https://accesspoint.atmosonline.com/rest/namespace/dir/hello HTTP/1.1"); "PUT https://accesspoint.atmosonline.com/rest/namespace/dir/hello HTTP/1.1");
assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT assertHeadersEqual(request, HttpHeaders.ACCEPT
+ ": */*\nContent-Length: 5\nContent-Type: text/plain\n"); + ": */*\nContent-Length: 5\nContent-Type: text/plain\n");
assertPayloadEquals(httpMethod, "hello"); assertPayloadEquals(request, "hello");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ThrowKeyNotFoundOn404.class); assertExceptionParserClassEquals(method, ThrowKeyNotFoundOn404.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testReadFile() throws SecurityException, NoSuchMethodException, IOException { public void testReadFile() throws SecurityException, NoSuchMethodException, IOException {
Method method = AtmosStorageAsyncClient.class.getMethod("readFile", String.class, Array Method method = AtmosStorageAsyncClient.class.getMethod("readFile", String.class, Array
.newInstance(GetOptions.class, 0).getClass()); .newInstance(GetOptions.class, 0).getClass());
GeneratedHttpRequest<AtmosStorageAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, "dir/file");
"dir/file");
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"GET https://accesspoint.atmosonline.com/rest/namespace/dir/file HTTP/1.1"); "GET https://accesspoint.atmosonline.com/rest/namespace/dir/file HTTP/1.1");
assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + ": */*\n"); assertHeadersEqual(request, HttpHeaders.ACCEPT + ": */*\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, assertResponseParserClassEquals(method, request, ParseObjectFromHeadersAndHttpContent.class);
ParseObjectFromHeadersAndHttpContent.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testGetSystemMetadata() throws SecurityException, NoSuchMethodException, IOException { public void testGetSystemMetadata() throws SecurityException, NoSuchMethodException, IOException {
Method method = AtmosStorageAsyncClient.class.getMethod("getSystemMetadata", String.class); Method method = AtmosStorageAsyncClient.class.getMethod("getSystemMetadata", String.class);
GeneratedHttpRequest<AtmosStorageAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, "dir/file");
"dir/file");
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"HEAD https://accesspoint.atmosonline.com/rest/namespace/dir/file HTTP/1.1"); "HEAD https://accesspoint.atmosonline.com/rest/namespace/dir/file HTTP/1.1");
assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + ": */*\n"); assertHeadersEqual(request, HttpHeaders.ACCEPT + ": */*\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSystemMetadataFromHeaders.class); assertResponseParserClassEquals(method, request, ParseSystemMetadataFromHeaders.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testDeletePath() throws SecurityException, NoSuchMethodException, IOException { public void testDeletePath() throws SecurityException, NoSuchMethodException, IOException {
Method method = AtmosStorageAsyncClient.class.getMethod("deletePath", String.class); Method method = AtmosStorageAsyncClient.class.getMethod("deletePath", String.class);
GeneratedHttpRequest<AtmosStorageAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, "dir/file");
"dir/file");
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"DELETE https://accesspoint.atmosonline.com/rest/namespace/dir/file HTTP/1.1"); "DELETE https://accesspoint.atmosonline.com/rest/namespace/dir/file HTTP/1.1");
assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + ": */*\n"); assertHeadersEqual(request, HttpHeaders.ACCEPT + ": */*\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class); assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testNewObject() throws SecurityException, NoSuchMethodException, IOException { public void testNewObject() throws SecurityException, NoSuchMethodException, IOException {
@ -264,9 +256,9 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
} }
@Override @Override
protected void checkFilters(GeneratedHttpRequest<AtmosStorageAsyncClient> httpMethod) { protected void checkFilters(HttpRequest request) {
assertEquals(httpMethod.getFilters().size(), 1); assertEquals(request.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), SignRequest.class); assertEquals(request.getFilters().get(0).getClass(), SignRequest.class);
} }
@Override @Override

View File

@ -1,14 +1,32 @@
/**
*
* Copyright (C) 2009 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.binders; package org.jclouds.aws.ec2.binders;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.lang.String.format;
import static org.jclouds.http.HttpUtils.addFormParamTo;
import org.jclouds.aws.ec2.domain.BlockDeviceMapping; import org.jclouds.aws.ec2.domain.BlockDeviceMapping;
import org.jclouds.aws.ec2.domain.RunningInstance; import org.jclouds.aws.ec2.domain.RunningInstance;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder; import org.jclouds.rest.Binder;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.lang.String.format;
/** /**
* @author Oleksiy Yarmula * @author Oleksiy Yarmula
@ -19,30 +37,26 @@ public class BindBlockDeviceMappingToIndexedFormParams implements Binder {
private final String volumeIdPattern = "BlockDeviceMapping.%d.Ebs.VolumeId"; private final String volumeIdPattern = "BlockDeviceMapping.%d.Ebs.VolumeId";
private final String deleteOnTerminationPattern = "BlockDeviceMapping.%d.Ebs.DeleteOnTermination"; private final String deleteOnTerminationPattern = "BlockDeviceMapping.%d.Ebs.DeleteOnTermination";
@SuppressWarnings("unchecked")
public void bindToRequest(HttpRequest request, Object input) { public void bindToRequest(HttpRequest request, Object input) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest,
"this binder is only valid for GeneratedHttpRequests");
checkArgument(checkNotNull(input, "input") instanceof BlockDeviceMapping, checkArgument(checkNotNull(input, "input") instanceof BlockDeviceMapping,
"this binder is only valid for BlockDeviceMapping"); "this binder is only valid for BlockDeviceMapping");
BlockDeviceMapping blockDeviceMapping = (BlockDeviceMapping) input; BlockDeviceMapping blockDeviceMapping = (BlockDeviceMapping) input;
GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request;
int amazonOneBasedIndex = 1; //according to docs, counters must start with 1 int amazonOneBasedIndex = 1; // according to docs, counters must start with 1
for(String ebsBlockDeviceName : blockDeviceMapping.getEbsBlockDevices().keySet()) { for (String ebsBlockDeviceName : blockDeviceMapping.getEbsBlockDevices().keySet()) {
for(RunningInstance.EbsBlockDevice ebsBlockDevice : blockDeviceMapping.getEbsBlockDevices().get(ebsBlockDeviceName)) { for (RunningInstance.EbsBlockDevice ebsBlockDevice : blockDeviceMapping
.getEbsBlockDevices().get(ebsBlockDeviceName)) {
//not null by contract // not null by contract
generatedRequest.addFormParam(format(volumeIdPattern, amazonOneBasedIndex), addFormParamTo(request, format(volumeIdPattern, amazonOneBasedIndex), ebsBlockDevice
ebsBlockDevice.getVolumeId()); .getVolumeId());
if(ebsBlockDeviceName != null) { if (ebsBlockDeviceName != null) {
generatedRequest.addFormParam(format(deviceNamePattern, amazonOneBasedIndex), addFormParamTo(request, format(deviceNamePattern, amazonOneBasedIndex),
ebsBlockDeviceName); ebsBlockDeviceName);
} }
generatedRequest.addFormParam(format(deleteOnTerminationPattern, amazonOneBasedIndex), addFormParamTo(request, format(deleteOnTerminationPattern, amazonOneBasedIndex), String
String.valueOf(ebsBlockDevice.isDeleteOnTermination())); .valueOf(ebsBlockDevice.isDeleteOnTermination()));
amazonOneBasedIndex++; amazonOneBasedIndex++;
} }

View File

@ -18,15 +18,12 @@
*/ */
package org.jclouds.aws.ec2.binders; package org.jclouds.aws.ec2.binders;
import static com.google.common.base.Preconditions.checkArgument; import static org.jclouds.aws.ec2.util.EC2Utils.indexStringArrayToFormValuesWithPrefix;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.aws.ec2.util.EC2Utils;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder; import org.jclouds.rest.Binder;
import org.jclouds.rest.internal.GeneratedHttpRequest;
/** /**
* Binds the String [] to query parameters named with GroupName.index * Binds the String [] to query parameters named with GroupName.index
@ -36,11 +33,8 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
@Singleton @Singleton
public class BindGroupNameToIndexedFormParams implements Binder { public class BindGroupNameToIndexedFormParams implements Binder {
@SuppressWarnings("unchecked")
public void bindToRequest(HttpRequest request, Object input) { public void bindToRequest(HttpRequest request, Object input) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest, indexStringArrayToFormValuesWithPrefix(request, "GroupName", input);
"this binder is only valid for GeneratedHttpRequests!");
EC2Utils.indexStringArrayToFormValuesWithPrefix((GeneratedHttpRequest<?>) request, "GroupName", input);
} }
} }

View File

@ -18,15 +18,12 @@
*/ */
package org.jclouds.aws.ec2.binders; package org.jclouds.aws.ec2.binders;
import static com.google.common.base.Preconditions.checkArgument; import static org.jclouds.aws.ec2.util.EC2Utils.indexStringArrayToFormValuesWithPrefix;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.aws.ec2.util.EC2Utils;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder; import org.jclouds.rest.Binder;
import org.jclouds.rest.internal.GeneratedHttpRequest;
/** /**
* Binds the String [] to form parameters named with InstanceId.index * Binds the String [] to form parameters named with InstanceId.index
@ -36,11 +33,8 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
@Singleton @Singleton
public class BindInstanceIdsToIndexedFormParams implements Binder { public class BindInstanceIdsToIndexedFormParams implements Binder {
@SuppressWarnings("unchecked")
public void bindToRequest(HttpRequest request, Object input) { public void bindToRequest(HttpRequest request, Object input) {
checkArgument(checkNotNull(request, "input") instanceof GeneratedHttpRequest, indexStringArrayToFormValuesWithPrefix(request, "InstanceId", input);
"this binder is only valid for GeneratedHttpRequests!");
EC2Utils.indexStringArrayToFormValuesWithPrefix((GeneratedHttpRequest<?>) request, "InstanceId", input);
} }
} }

View File

@ -18,15 +18,12 @@
*/ */
package org.jclouds.aws.ec2.binders; package org.jclouds.aws.ec2.binders;
import static com.google.common.base.Preconditions.checkArgument; import static org.jclouds.aws.ec2.util.EC2Utils.indexStringArrayToFormValuesWithPrefix;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.aws.ec2.util.EC2Utils;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder; import org.jclouds.rest.Binder;
import org.jclouds.rest.internal.GeneratedHttpRequest;
/** /**
* Binds the String [] to query parameters named with KeyName.index * Binds the String [] to query parameters named with KeyName.index
@ -36,11 +33,8 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
@Singleton @Singleton
public class BindKeyNameToIndexedFormParams implements Binder { public class BindKeyNameToIndexedFormParams implements Binder {
@SuppressWarnings("unchecked")
public void bindToRequest(HttpRequest request, Object input) { public void bindToRequest(HttpRequest request, Object input) {
checkArgument(checkNotNull(request, "input") instanceof GeneratedHttpRequest, indexStringArrayToFormValuesWithPrefix(request, "KeyName", input);
"this binder is only valid for GeneratedHttpRequests!");
EC2Utils.indexStringArrayToFormValuesWithPrefix((GeneratedHttpRequest<?>) request, "KeyName", input);
} }
} }

View File

@ -18,15 +18,12 @@
*/ */
package org.jclouds.aws.ec2.binders; package org.jclouds.aws.ec2.binders;
import static com.google.common.base.Preconditions.checkArgument; import static org.jclouds.aws.ec2.util.EC2Utils.indexIterableToFormValuesWithPrefix;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.aws.ec2.util.EC2Utils;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder; import org.jclouds.rest.Binder;
import org.jclouds.rest.internal.GeneratedHttpRequest;
/** /**
* Binds the String [] to form parameters named with ProductCode.index * Binds the String [] to form parameters named with ProductCode.index
@ -36,11 +33,8 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
@Singleton @Singleton
public class BindProductCodesToIndexedFormParams implements Binder { public class BindProductCodesToIndexedFormParams implements Binder {
@SuppressWarnings("unchecked")
public void bindToRequest(HttpRequest request, Object input) { public void bindToRequest(HttpRequest request, Object input) {
checkArgument(checkNotNull(request, "input") instanceof GeneratedHttpRequest, indexIterableToFormValuesWithPrefix(request, "ProductCode", input);
"this binder is only valid for GeneratedHttpRequests!");
EC2Utils.indexIterableToFormValuesWithPrefix((GeneratedHttpRequest<?>) request, "ProductCode", input);
} }
} }

View File

@ -20,13 +20,12 @@ package org.jclouds.aws.ec2.binders;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.aws.ec2.util.EC2Utils.indexStringArrayToFormValuesWithPrefix;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.aws.ec2.util.EC2Utils;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder; import org.jclouds.rest.Binder;
import org.jclouds.rest.internal.GeneratedHttpRequest;
/** /**
* Binds the String [] to form parameters named with InstanceId.index * Binds the String [] to form parameters named with InstanceId.index
@ -36,15 +35,10 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
@Singleton @Singleton
public class BindPublicIpsToIndexedFormParams implements Binder { public class BindPublicIpsToIndexedFormParams implements Binder {
@SuppressWarnings("unchecked")
public void bindToRequest(HttpRequest request, Object input) { public void bindToRequest(HttpRequest request, Object input) {
checkArgument(checkNotNull(request, "input") instanceof GeneratedHttpRequest,
"this binder is only valid for GeneratedHttpRequests!");
checkArgument(checkNotNull(input, "input") instanceof String[], checkArgument(checkNotNull(input, "input") instanceof String[],
"this binder is only valid for String[] : " + input.getClass()); "this binder is only valid for String[] : " + input.getClass());
String[] addressStrings = (String[]) input; String[] addressStrings = (String[]) input;
EC2Utils.indexStringArrayToFormValuesWithPrefix((GeneratedHttpRequest<?>) request, indexStringArrayToFormValuesWithPrefix(request, "PublicIp", addressStrings);
"PublicIp", addressStrings);
} }
} }

View File

@ -20,13 +20,12 @@ package org.jclouds.aws.ec2.binders;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.aws.ec2.util.EC2Utils.indexIterableToFormValuesWithPrefix;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.aws.ec2.util.EC2Utils;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder; import org.jclouds.rest.Binder;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
@ -38,15 +37,11 @@ import com.google.common.collect.Iterables;
@Singleton @Singleton
public class BindUserGroupsToIndexedFormParams implements Binder { public class BindUserGroupsToIndexedFormParams implements Binder {
@SuppressWarnings("unchecked")
public void bindToRequest(HttpRequest request, Object input) { public void bindToRequest(HttpRequest request, Object input) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest,
"this binder is only valid for GeneratedHttpRequests!");
checkArgument(checkNotNull(input, "input") instanceof Iterable<?>, checkArgument(checkNotNull(input, "input") instanceof Iterable<?>,
"this binder is only valid for Iterable<?>: " + input.getClass()); "this binder is only valid for Iterable<?>: " + input.getClass());
checkValidUserGroup(input); checkValidUserGroup(input);
EC2Utils.indexIterableToFormValuesWithPrefix((GeneratedHttpRequest<?>) request, "UserGroup", indexIterableToFormValuesWithPrefix(request, "UserGroup", input);
input);
} }
private void checkValidUserGroup(Object input) { private void checkValidUserGroup(Object input) {

View File

@ -20,13 +20,13 @@ package org.jclouds.aws.ec2.binders;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.http.HttpUtils.addFormParamTo;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.aws.ec2.domain.UserIdGroupPair; import org.jclouds.aws.ec2.domain.UserIdGroupPair;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder; import org.jclouds.rest.Binder;
import org.jclouds.rest.internal.GeneratedHttpRequest;
/** /**
* Binds the String [] to query parameters named with GroupName.index * Binds the String [] to query parameters named with GroupName.index
@ -36,15 +36,11 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
@Singleton @Singleton
public class BindUserIdGroupPairToSourceSecurityGroupFormParams implements Binder { public class BindUserIdGroupPairToSourceSecurityGroupFormParams implements Binder {
@SuppressWarnings("unchecked")
public void bindToRequest(HttpRequest request, Object input) { public void bindToRequest(HttpRequest request, Object input) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest,
"this binder is only valid for GeneratedHttpRequests!");
checkArgument(checkNotNull(input, "input") instanceof UserIdGroupPair, checkArgument(checkNotNull(input, "input") instanceof UserIdGroupPair,
"this binder is only valid for UserIdGroupPair!"); "this binder is only valid for UserIdGroupPair!");
UserIdGroupPair pair = (UserIdGroupPair) input; UserIdGroupPair pair = (UserIdGroupPair) input;
GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request; addFormParamTo(request, "SourceSecurityGroupOwnerId", pair.getUserId());
generatedRequest.addFormParam("SourceSecurityGroupOwnerId", pair.getUserId()); addFormParamTo(request, "SourceSecurityGroupName", pair.getGroupName());
generatedRequest.addFormParam("SourceSecurityGroupName", pair.getGroupName());
} }
} }

View File

@ -18,15 +18,12 @@
*/ */
package org.jclouds.aws.ec2.binders; package org.jclouds.aws.ec2.binders;
import static com.google.common.base.Preconditions.checkArgument; import static org.jclouds.aws.ec2.util.EC2Utils.indexIterableToFormValuesWithPrefix;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.aws.ec2.util.EC2Utils;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder; import org.jclouds.rest.Binder;
import org.jclouds.rest.internal.GeneratedHttpRequest;
/** /**
* Binds the String [] to form parameters named with UserId.index * Binds the String [] to form parameters named with UserId.index
@ -35,13 +32,8 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
*/ */
@Singleton @Singleton
public class BindUserIdsToIndexedFormParams implements Binder { public class BindUserIdsToIndexedFormParams implements Binder {
@SuppressWarnings("unchecked")
public void bindToRequest(HttpRequest request, Object input) { public void bindToRequest(HttpRequest request, Object input) {
checkArgument(checkNotNull(request, "input") instanceof GeneratedHttpRequest, indexIterableToFormValuesWithPrefix(request, "UserId", input);
"this binder is only valid for GeneratedHttpRequests!");
EC2Utils.indexIterableToFormValuesWithPrefix((GeneratedHttpRequest<?>) request, "UserId",
input);
} }
} }

View File

@ -18,15 +18,12 @@
*/ */
package org.jclouds.aws.ec2.binders; package org.jclouds.aws.ec2.binders;
import static com.google.common.base.Preconditions.checkArgument; import static org.jclouds.aws.ec2.util.EC2Utils.indexStringArrayToFormValuesWithPrefix;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.aws.ec2.util.EC2Utils;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder; import org.jclouds.rest.Binder;
import org.jclouds.rest.internal.GeneratedHttpRequest;
/** /**
* Binds the String [] to form parameters named with VolumeId.index * Binds the String [] to form parameters named with VolumeId.index
@ -36,12 +33,8 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
@Singleton @Singleton
public class BindVolumeIdsToIndexedFormParams implements Binder { public class BindVolumeIdsToIndexedFormParams implements Binder {
@SuppressWarnings("unchecked")
public void bindToRequest(HttpRequest request, Object input) { public void bindToRequest(HttpRequest request, Object input) {
checkArgument(checkNotNull(request, "input") instanceof GeneratedHttpRequest, indexStringArrayToFormValuesWithPrefix(request, "VolumeId", input);
"this binder is only valid for GeneratedHttpRequests!");
EC2Utils.indexStringArrayToFormValuesWithPrefix((GeneratedHttpRequest<?>) request,
"VolumeId", input);
} }
} }

View File

@ -19,13 +19,12 @@
package org.jclouds.aws.ec2.binders; package org.jclouds.aws.ec2.binders;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.http.HttpUtils.addFormParamTo;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder; import org.jclouds.rest.Binder;
import org.jclouds.rest.internal.GeneratedHttpRequest;
/** /**
* Binds the AvailabilityZone to a form parameter if set. * Binds the AvailabilityZone to a form parameter if set.
@ -34,16 +33,10 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
*/ */
@Singleton @Singleton
public class IfNotNullBindAvailabilityZoneToFormParam implements Binder { public class IfNotNullBindAvailabilityZoneToFormParam implements Binder {
@SuppressWarnings("unchecked")
public void bindToRequest(HttpRequest request, Object input) { public void bindToRequest(HttpRequest request, Object input) {
if (input != null) { if (input != null) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest, checkArgument(input instanceof String, "this binder is only valid for AvailabilityZone!");
"this binder is only valid for GeneratedHttpRequests!"); addFormParamTo(request, "Placement.AvailabilityZone", (String) input);
checkArgument(input instanceof String,
"this binder is only valid for AvailabilityZone!");
((GeneratedHttpRequest<?>) request).addFormParam("Placement.AvailabilityZone",
(String) input);
} }
} }

View File

@ -20,6 +20,7 @@ package org.jclouds.aws.ec2.util;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.http.HttpUtils.addFormParamTo;
import java.util.Map; import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -33,6 +34,7 @@ import org.jclouds.aws.ec2.domain.RunningInstance;
import org.jclouds.aws.ec2.services.InstanceClient; import org.jclouds.aws.ec2.services.InstanceClient;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope; import org.jclouds.domain.LocationScope;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import com.google.common.base.Function; import com.google.common.base.Function;
@ -53,13 +55,14 @@ public class EC2Utils {
} }
} }
public static void indexStringArrayToFormValuesWithPrefix(GeneratedHttpRequest<?> request, public static void indexStringArrayToFormValuesWithPrefix(HttpRequest request, String prefix,
String prefix, Object input) { Object input) {
checkArgument(checkNotNull(input, "input") instanceof String[], checkArgument(checkNotNull(input, "input") instanceof String[],
"this binder is only valid for String[] : " + input.getClass()); "this binder is only valid for String[] : " + input.getClass());
String[] values = (String[]) input; String[] values = (String[]) input;
for (int i = 0; i < values.length; i++) { for (int i = 0; i < values.length; i++) {
request.addFormParam(prefix + "." + (i + 1), checkNotNull(values[i], prefix.toLowerCase() addFormParamTo(request, prefix + "." + (i + 1), checkNotNull(values[i], prefix
.toLowerCase()
+ "s[" + i + "]")); + "s[" + i + "]"));
} }
} }
@ -75,14 +78,14 @@ public class EC2Utils {
return parts; return parts;
} }
public static void indexIterableToFormValuesWithPrefix(GeneratedHttpRequest<?> request, public static void indexIterableToFormValuesWithPrefix(HttpRequest request, String prefix,
String prefix, Object input) { Object input) {
checkArgument(checkNotNull(input, "input") instanceof Iterable<?>, checkArgument(checkNotNull(input, "input") instanceof Iterable<?>,
"this binder is only valid for Iterable<?>: " + input.getClass()); "this binder is only valid for Iterable<?>: " + input.getClass());
Iterable<?> values = (Iterable<?>) input; Iterable<?> values = (Iterable<?>) input;
int i = 0; int i = 0;
for (Object o : values) { for (Object o : values) {
request.addFormParam(prefix + "." + (i++ + 1), checkNotNull(o.toString(), prefix addFormParamTo(request, prefix + "." + (i++ + 1), checkNotNull(o.toString(), prefix
.toLowerCase() .toLowerCase()
+ "s[" + i + "]")); + "s[" + i + "]"));
} }
@ -116,13 +119,13 @@ public class EC2Utils {
return null; return null;
} }
public static void indexStringArrayToFormValuesWithStringFormat(GeneratedHttpRequest<?> request, public static void indexStringArrayToFormValuesWithStringFormat(HttpRequest request,
String format, Object input) { String format, Object input) {
checkArgument(checkNotNull(input, "input") instanceof String[], checkArgument(checkNotNull(input, "input") instanceof String[],
"this binder is only valid for String[] : " + input.getClass()); "this binder is only valid for String[] : " + input.getClass());
String[] values = (String[]) input; String[] values = (String[]) input;
for (int i = 0; i < values.length; i++) { for (int i = 0; i < values.length; i++) {
request.addFormParam(String.format(format, (i + 1)), checkNotNull(values[i], format addFormParamTo(request, String.format(format, (i + 1)), checkNotNull(values[i], format
.toLowerCase() .toLowerCase()
+ "s[" + i + "]")); + "s[" + i + "]"));
} }

View File

@ -18,15 +18,12 @@
*/ */
package org.jclouds.aws.elb.binders; package org.jclouds.aws.elb.binders;
import static com.google.common.base.Preconditions.checkArgument; import static org.jclouds.aws.ec2.util.EC2Utils.indexStringArrayToFormValuesWithStringFormat;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.aws.ec2.util.EC2Utils;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder; import org.jclouds.rest.Binder;
import org.jclouds.rest.internal.GeneratedHttpRequest;
/** /**
* Binds the String [] to form parameters named with InstanceId.index * Binds the String [] to form parameters named with InstanceId.index
@ -36,11 +33,8 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
@Singleton @Singleton
public class BindELBInstanceIdsToIndexedFormParams implements Binder { public class BindELBInstanceIdsToIndexedFormParams implements Binder {
@SuppressWarnings("unchecked")
public void bindToRequest(HttpRequest request, Object input) { public void bindToRequest(HttpRequest request, Object input) {
checkArgument(checkNotNull(request, "input") instanceof GeneratedHttpRequest, indexStringArrayToFormValuesWithStringFormat(request, "Instances.member.%s.InstanceId", input);
"this binder is only valid for GeneratedHttpRequests!");
EC2Utils.indexStringArrayToFormValuesWithStringFormat((GeneratedHttpRequest<?>) request, "Instances.member.%s.InstanceId", input);
} }
} }

View File

@ -27,6 +27,9 @@ import static org.jclouds.aws.ec2.reference.EC2Parameters.SIGNATURE_METHOD;
import static org.jclouds.aws.ec2.reference.EC2Parameters.SIGNATURE_VERSION; import static org.jclouds.aws.ec2.reference.EC2Parameters.SIGNATURE_VERSION;
import static org.jclouds.aws.ec2.reference.EC2Parameters.TIMESTAMP; import static org.jclouds.aws.ec2.reference.EC2Parameters.TIMESTAMP;
import static org.jclouds.aws.ec2.reference.EC2Parameters.VERSION; import static org.jclouds.aws.ec2.reference.EC2Parameters.VERSION;
import static org.jclouds.http.HttpUtils.logRequest;
import static org.jclouds.http.HttpUtils.makeQueryLine;
import static org.jclouds.http.HttpUtils.parseQueryToMap;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
@ -46,12 +49,9 @@ import org.jclouds.encryption.EncryptionService;
import org.jclouds.http.HttpException; import org.jclouds.http.HttpException;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpRequestFilter; import org.jclouds.http.HttpRequestFilter;
import org.jclouds.http.HttpUtils;
import org.jclouds.http.internal.SignatureWire; import org.jclouds.http.internal.SignatureWire;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.rest.RequestSigner; import org.jclouds.rest.RequestSigner;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
@ -92,12 +92,11 @@ public class FormSigner implements HttpRequestFilter, RequestSigner {
this.encryptionService = encryptionService; this.encryptionService = encryptionService;
} }
public void filter(HttpRequest in) throws HttpException { public void filter(HttpRequest request) throws HttpException {
GeneratedHttpRequest<?> request = (GeneratedHttpRequest<?>) in;
checkNotNull(request.getFirstHeaderOrNull(HttpHeaders.HOST), checkNotNull(request.getFirstHeaderOrNull(HttpHeaders.HOST),
"request is not ready to sign; host not present"); "request is not ready to sign; host not present");
Multimap<String, String> decodedParams = RestAnnotationProcessor.parseQueryToMap(request Multimap<String, String> decodedParams = parseQueryToMap(request.getPayload().getRawContent()
.getPayload().getRawContent().toString()); .toString());
request.getHeaders().removeAll(HttpHeaders.CONTENT_LENGTH); request.getHeaders().removeAll(HttpHeaders.CONTENT_LENGTH);
addSigningParams(decodedParams); addSigningParams(decodedParams);
validateParams(decodedParams); validateParams(decodedParams);
@ -105,7 +104,7 @@ public class FormSigner implements HttpRequestFilter, RequestSigner {
String signature = sign(stringToSign); String signature = sign(stringToSign);
addSignature(decodedParams, signature); addSignature(decodedParams, signature);
setPayload(request, decodedParams); setPayload(request, decodedParams);
HttpUtils.logRequest(signatureLog, request, "<<"); logRequest(signatureLog, request, "<<");
} }
String[] sortForSigning(String queryLine) { String[] sortForSigning(String queryLine) {
@ -123,15 +122,12 @@ public class FormSigner implements HttpRequestFilter, RequestSigner {
return parts; return parts;
} }
void setPayload(GeneratedHttpRequest<?> request, Multimap<String, String> decodedParams) { void setPayload(HttpRequest request, Multimap<String, String> decodedParams) {
request.setPayload(RestAnnotationProcessor.makeQueryLine(decodedParams, request.setPayload(makeQueryLine(decodedParams, new Comparator<Map.Entry<String, String>>() {
new Comparator<Map.Entry<String, String>>() {
public int compare(Entry<String, String> o1, Entry<String, String> o2) { public int compare(Entry<String, String> o1, Entry<String, String> o2) {
if (o1.getKey().startsWith("Action") if (o1.getKey().startsWith("Action") || o2.getKey().startsWith("AWSAccessKeyId"))
|| o2.getKey().startsWith("AWSAccessKeyId"))
return -1; return -1;
if (o1.getKey().startsWith("AWSAccessKeyId") if (o1.getKey().startsWith("AWSAccessKeyId") || o2.getKey().startsWith("Action"))
|| o2.getKey().startsWith("Action"))
return 1; return 1;
return o1.getKey().compareTo(o2.getKey()); return o1.getKey().compareTo(o2.getKey());
} }
@ -166,7 +162,7 @@ public class FormSigner implements HttpRequestFilter, RequestSigner {
@VisibleForTesting @VisibleForTesting
public String createStringToSign(HttpRequest request, Multimap<String, String> decodedParams) { public String createStringToSign(HttpRequest request, Multimap<String, String> decodedParams) {
HttpUtils.logRequest(signatureLog, request, ">>"); logRequest(signatureLog, request, ">>");
StringBuilder stringToSign = new StringBuilder(); StringBuilder stringToSign = new StringBuilder();
// StringToSign = HTTPVerb + "\n" + // StringToSign = HTTPVerb + "\n" +
stringToSign.append(request.getMethod()).append("\n"); stringToSign.append(request.getMethod()).append("\n");
@ -184,8 +180,7 @@ public class FormSigner implements HttpRequestFilter, RequestSigner {
@VisibleForTesting @VisibleForTesting
String buildCanonicalizedString(Multimap<String, String> decodedParams) { String buildCanonicalizedString(Multimap<String, String> decodedParams) {
return RestAnnotationProcessor.makeQueryLine(decodedParams, return makeQueryLine(decodedParams, new Comparator<Map.Entry<String, String>>() {
new Comparator<Map.Entry<String, String>>() {
public int compare(Map.Entry<String, String> o1, Map.Entry<String, String> o2) { public int compare(Map.Entry<String, String> o1, Map.Entry<String, String> o2) {
if (o1.getKey().startsWith("AWSAccessKeyId")) if (o1.getKey().startsWith("AWSAccessKeyId"))
return -1; return -1;
@ -204,8 +199,8 @@ public class FormSigner implements HttpRequestFilter, RequestSigner {
} }
public String createStringToSign(HttpRequest input) { public String createStringToSign(HttpRequest input) {
return createStringToSign(input, RestAnnotationProcessor.parseQueryToMap(input.getPayload() return createStringToSign(input, parseQueryToMap(input.getPayload().getRawContent()
.getRawContent().toString())); .toString()));
} }
} }

View File

@ -18,8 +18,13 @@
*/ */
package org.jclouds.aws.handlers; package org.jclouds.aws.handlers;
import static org.jclouds.http.HttpUtils.changeSchemeHostAndPortTo;
import static org.jclouds.http.HttpUtils.changeToGETRequest;
import static org.jclouds.http.HttpUtils.closeClientButKeepContentStream;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Provider; import javax.inject.Provider;
import javax.inject.Singleton;
import javax.ws.rs.HttpMethod; import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriBuilder;
@ -29,7 +34,6 @@ import org.jclouds.aws.util.AWSUtils;
import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpException; import org.jclouds.http.HttpException;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpUtils;
import org.jclouds.http.handlers.BackoffLimitedRetryHandler; import org.jclouds.http.handlers.BackoffLimitedRetryHandler;
import org.jclouds.http.handlers.RedirectionRetryHandler; import org.jclouds.http.handlers.RedirectionRetryHandler;
@ -38,6 +42,7 @@ import org.jclouds.http.handlers.RedirectionRetryHandler;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton
public class AWSRedirectionRetryHandler extends RedirectionRetryHandler { public class AWSRedirectionRetryHandler extends RedirectionRetryHandler {
private final AWSUtils utils; private final AWSUtils utils;
@ -52,9 +57,9 @@ public class AWSRedirectionRetryHandler extends RedirectionRetryHandler {
public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) { public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) {
if (response.getFirstHeaderOrNull(HttpHeaders.LOCATION) == null if (response.getFirstHeaderOrNull(HttpHeaders.LOCATION) == null
&& (response.getStatusCode() == 301 || response.getStatusCode() == 307)) { && (response.getStatusCode() == 301 || response.getStatusCode() == 307)) {
byte[] content = HttpUtils.closeClientButKeepContentStream(response); byte[] content = closeClientButKeepContentStream(response);
if (command.getRequest().getMethod() == HttpMethod.HEAD) { if (command.getRequest().getMethod() == HttpMethod.HEAD) {
command.changeToGETRequest(); changeToGETRequest(command.getRequest());
return true; return true;
} else { } else {
command.incrementRedirectCount(); command.incrementRedirectCount();
@ -68,8 +73,9 @@ public class AWSRedirectionRetryHandler extends RedirectionRetryHandler {
// http://developer.amazonwebservices.com/connect/thread.jspa?messageID=72287&#72287 // http://developer.amazonwebservices.com/connect/thread.jspa?messageID=72287&#72287
return backoffHandler.shouldRetryRequest(command, response); return backoffHandler.shouldRetryRequest(command, response);
} else { } else {
command.changeSchemeHostAndPortTo(command.getRequest().getEndpoint() changeSchemeHostAndPortTo(command.getRequest(), command.getRequest()
.getScheme(), host, command.getRequest().getEndpoint().getPort()); .getEndpoint().getScheme(), host, command.getRequest().getEndpoint()
.getPort(), uriBuilderProvider.get());
} }
return true; return true;
} else { } else {

View File

@ -19,6 +19,7 @@
package org.jclouds.aws.s3.filters; package org.jclouds.aws.s3.filters;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.http.HttpUtils.logRequest;
import static org.jclouds.util.Patterns.NEWLINE_PATTERN; import static org.jclouds.util.Patterns.NEWLINE_PATTERN;
import java.util.Collection; import java.util.Collection;
@ -40,7 +41,6 @@ import org.jclouds.encryption.EncryptionService;
import org.jclouds.http.HttpException; import org.jclouds.http.HttpException;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpRequestFilter; import org.jclouds.http.HttpRequestFilter;
import org.jclouds.http.HttpUtils;
import org.jclouds.http.internal.SignatureWire; import org.jclouds.http.internal.SignatureWire;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.rest.RequestSigner; import org.jclouds.rest.RequestSigner;
@ -99,11 +99,11 @@ public class RequestAuthorizeSignature implements HttpRequestFilter, RequestSign
replaceDateHeader(request); replaceDateHeader(request);
String toSign = createStringToSign(request); String toSign = createStringToSign(request);
calculateAndReplaceAuthHeader(request, toSign); calculateAndReplaceAuthHeader(request, toSign);
HttpUtils.logRequest(signatureLog, request, "<<"); logRequest(signatureLog, request, "<<");
} }
public String createStringToSign(HttpRequest request) { public String createStringToSign(HttpRequest request) {
HttpUtils.logRequest(signatureLog, request, ">>"); logRequest(signatureLog, request, ">>");
StringBuilder buffer = new StringBuilder(); StringBuilder buffer = new StringBuilder();
// re-sign the request // re-sign the request
appendMethod(request, buffer); appendMethod(request, buffer);

View File

@ -4,7 +4,7 @@ import java.io.IOException;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import org.jclouds.aws.ec2.services.BaseEC2AsyncClientTest; import org.jclouds.aws.ec2.services.BaseEC2AsyncClientTest;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -61,7 +61,7 @@ public class EC2AsyncClientTest extends BaseEC2AsyncClientTest<EC2AsyncClient> {
} }
@Override @Override
protected void checkFilters(GeneratedHttpRequest<EC2AsyncClient> httpMethod) { protected void checkFilters(HttpRequest request) {
} }

View File

@ -33,9 +33,9 @@ import org.jclouds.aws.ec2.xml.DescribeImagesResponseHandler;
import org.jclouds.aws.ec2.xml.ImageIdHandler; import org.jclouds.aws.ec2.xml.ImageIdHandler;
import org.jclouds.aws.ec2.xml.PermissionHandler; import org.jclouds.aws.ec2.xml.PermissionHandler;
import org.jclouds.aws.ec2.xml.ProductCodesHandler; import org.jclouds.aws.ec2.xml.ProductCodesHandler;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -54,20 +54,19 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
Method method = AMIAsyncClient.class.getMethod("createImageInRegion", String.class, Method method = AMIAsyncClient.class.getMethod("createImageInRegion", String.class,
String.class, String.class, Array.newInstance(CreateImageOptions.class, 0) String.class, String.class, Array.newInstance(CreateImageOptions.class, 0)
.getClass()); .getClass());
GeneratedHttpRequest<AMIAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, "name", "instanceId");
"name", "instanceId");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 69\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 69\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=CreateImage&InstanceId=instanceId&Name=name"); "Version=2009-11-30&Action=CreateImage&InstanceId=instanceId&Name=name");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, ImageIdHandler.class); assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testCreateImageOptions() throws SecurityException, NoSuchMethodException, public void testCreateImageOptions() throws SecurityException, NoSuchMethodException,
@ -75,87 +74,84 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
Method method = AMIAsyncClient.class.getMethod("createImageInRegion", String.class, Method method = AMIAsyncClient.class.getMethod("createImageInRegion", String.class,
String.class, String.class, Array.newInstance(CreateImageOptions.class, 0) String.class, String.class, Array.newInstance(CreateImageOptions.class, 0)
.getClass()); .getClass());
GeneratedHttpRequest<AMIAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, "name", "instanceId",
"name", "instanceId", new CreateImageOptions().withDescription("description") new CreateImageOptions().withDescription("description").noReboot());
.noReboot());
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 107\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 107\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"Version=2009-11-30&Action=CreateImage&InstanceId=instanceId&Name=name&Description=description&NoReboot=true"); "Version=2009-11-30&Action=CreateImage&InstanceId=instanceId&Name=name&Description=description&NoReboot=true");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, ImageIdHandler.class); assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testDescribeImages() throws SecurityException, NoSuchMethodException, IOException { public void testDescribeImages() throws SecurityException, NoSuchMethodException, IOException {
Method method = AMIAsyncClient.class.getMethod("describeImagesInRegion", String.class, Array Method method = AMIAsyncClient.class.getMethod("describeImagesInRegion", String.class, Array
.newInstance(DescribeImagesOptions.class, 0).getClass()); .newInstance(DescribeImagesOptions.class, 0).getClass());
GeneratedHttpRequest<AMIAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, (String) null);
(String) null);
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 40\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 40\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, "Version=2009-11-30&Action=DescribeImages"); assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeImages");
filter.filter(httpMethod); filter.filter(request);
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"Action=DescribeImages&Signature=IYist5Mfzd44GO3%2BX8WJ4Ti%2BWe3UmrZQC10XdCkT5Fk%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Version=2009-11-30&AWSAccessKeyId=identity"); "Action=DescribeImages&Signature=IYist5Mfzd44GO3%2BX8WJ4Ti%2BWe3UmrZQC10XdCkT5Fk%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Version=2009-11-30&AWSAccessKeyId=identity");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, DescribeImagesResponseHandler.class); assertSaxResponseParserClassEquals(method, DescribeImagesResponseHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testDescribeImagesOptions() throws SecurityException, NoSuchMethodException, public void testDescribeImagesOptions() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = AMIAsyncClient.class.getMethod("describeImagesInRegion", String.class, Array Method method = AMIAsyncClient.class.getMethod("describeImagesInRegion", String.class, Array
.newInstance(DescribeImagesOptions.class, 0).getClass()); .newInstance(DescribeImagesOptions.class, 0).getClass());
GeneratedHttpRequest<AMIAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, executableBy("me").ownedBy(
executableBy("me").ownedBy("fred", "nancy").imageIds("1", "2")); "fred", "nancy").imageIds("1", "2"));
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 107\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 107\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"Version=2009-11-30&Action=DescribeImages&ExecutableBy=me&Owner.1=fred&Owner.2=nancy&ImageId.1=1&ImageId.2=2"); "Version=2009-11-30&Action=DescribeImages&ExecutableBy=me&Owner.1=fred&Owner.2=nancy&ImageId.1=1&ImageId.2=2");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, DescribeImagesResponseHandler.class); assertSaxResponseParserClassEquals(method, DescribeImagesResponseHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testDeregisterImage() throws SecurityException, NoSuchMethodException, IOException { public void testDeregisterImage() throws SecurityException, NoSuchMethodException, IOException {
Method method = AMIAsyncClient.class.getMethod("deregisterImageInRegion", String.class, Method method = AMIAsyncClient.class.getMethod("deregisterImageInRegion", String.class,
String.class); String.class);
GeneratedHttpRequest<AMIAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, "imageId");
"imageId");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 57\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 57\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, "Version=2009-11-30&Action=DeregisterImage&ImageId=imageId"); assertPayloadEquals(request, "Version=2009-11-30&Action=DeregisterImage&ImageId=imageId");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testRegisterImageFromManifest() throws SecurityException, NoSuchMethodException, public void testRegisterImageFromManifest() throws SecurityException, NoSuchMethodException,
@ -163,20 +159,19 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
Method method = AMIAsyncClient.class.getMethod("registerImageFromManifestInRegion", Method method = AMIAsyncClient.class.getMethod("registerImageFromManifestInRegion",
String.class, String.class, String.class, Array.newInstance( String.class, String.class, String.class, Array.newInstance(
RegisterImageOptions.class, 0).getClass()); RegisterImageOptions.class, 0).getClass());
GeneratedHttpRequest<AMIAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, "name", "pathToManifest");
"name", "pathToManifest");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 78\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 78\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=RegisterImage&ImageLocation=pathToManifest&Name=name"); "Version=2009-11-30&Action=RegisterImage&ImageLocation=pathToManifest&Name=name");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, ImageIdHandler.class); assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testRegisterImageFromManifestOptions() throws SecurityException, public void testRegisterImageFromManifestOptions() throws SecurityException,
@ -184,22 +179,22 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
Method method = AMIAsyncClient.class.getMethod("registerImageFromManifestInRegion", Method method = AMIAsyncClient.class.getMethod("registerImageFromManifestInRegion",
String.class, String.class, String.class, Array.newInstance( String.class, String.class, String.class, Array.newInstance(
RegisterImageOptions.class, 0).getClass()); RegisterImageOptions.class, 0).getClass());
GeneratedHttpRequest<AMIAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, "name", "pathToManifest",
"name", "pathToManifest", new RegisterImageOptions().withDescription("description")); new RegisterImageOptions().withDescription("description"));
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 102\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 102\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"Version=2009-11-30&Action=RegisterImage&ImageLocation=pathToManifest&Name=name&Description=description"); "Version=2009-11-30&Action=RegisterImage&ImageLocation=pathToManifest&Name=name&Description=description");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, ImageIdHandler.class); assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testRegisterImageBackedByEBS() throws SecurityException, NoSuchMethodException, public void testRegisterImageBackedByEBS() throws SecurityException, NoSuchMethodException,
@ -207,21 +202,20 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
Method method = AMIAsyncClient.class.getMethod("registerUnixImageBackedByEbsInRegion", Method method = AMIAsyncClient.class.getMethod("registerUnixImageBackedByEbsInRegion",
String.class, String.class, String.class, Array.newInstance( String.class, String.class, String.class, Array.newInstance(
RegisterImageBackedByEbsOptions.class, 0).getClass()); RegisterImageBackedByEbsOptions.class, 0).getClass());
GeneratedHttpRequest<AMIAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, "imageName", "snapshotId");
"imageName", "snapshotId");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 176\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 176\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"Version=2009-11-30&Action=RegisterImage&RootDeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.0.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.0.Ebs.SnapshotId=snapshotId&Name=imageName"); "Version=2009-11-30&Action=RegisterImage&RootDeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.0.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.0.Ebs.SnapshotId=snapshotId&Name=imageName");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, ImageIdHandler.class); assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testRegisterImageBackedByEBSOptions() throws SecurityException, public void testRegisterImageBackedByEBSOptions() throws SecurityException,
@ -229,198 +223,194 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
Method method = AMIAsyncClient.class.getMethod("registerUnixImageBackedByEbsInRegion", Method method = AMIAsyncClient.class.getMethod("registerUnixImageBackedByEbsInRegion",
String.class, String.class, String.class, Array.newInstance( String.class, String.class, String.class, Array.newInstance(
RegisterImageBackedByEbsOptions.class, 0).getClass()); RegisterImageBackedByEbsOptions.class, 0).getClass());
GeneratedHttpRequest<AMIAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, "imageName", "snapshotId",
"imageName", "snapshotId", new RegisterImageBackedByEbsOptions().withDescription( new RegisterImageBackedByEbsOptions().withDescription("description")
"description").addBlockDeviceFromSnapshot("/dev/device", null, "snapshot") .addBlockDeviceFromSnapshot("/dev/device", null, "snapshot")
.addNewBlockDevice("/dev/newdevice", "newblock", 100)); .addNewBlockDevice("/dev/newdevice", "newblock", 100));
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 528\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 528\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"Version=2009-11-30&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"); "Version=2009-11-30&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");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, ImageIdHandler.class); assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testGetProductCodesForImage() throws SecurityException, NoSuchMethodException, public void testGetProductCodesForImage() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = AMIAsyncClient.class.getMethod("getProductCodesForImageInRegion", Method method = AMIAsyncClient.class.getMethod("getProductCodesForImageInRegion",
String.class, String.class); String.class, String.class);
GeneratedHttpRequest<AMIAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, "imageId");
"imageId");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 87\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 87\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=DescribeImageAttribute&Attribute=productCodes&ImageId=imageId"); "Version=2009-11-30&Action=DescribeImageAttribute&Attribute=productCodes&ImageId=imageId");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, ProductCodesHandler.class); assertSaxResponseParserClassEquals(method, ProductCodesHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testGetBlockDeviceMappingsForImage() throws SecurityException, public void testGetBlockDeviceMappingsForImage() throws SecurityException,
NoSuchMethodException, IOException { NoSuchMethodException, IOException {
Method method = AMIAsyncClient.class.getMethod("getBlockDeviceMappingsForImageInRegion", Method method = AMIAsyncClient.class.getMethod("getBlockDeviceMappingsForImageInRegion",
String.class, String.class); String.class, String.class);
GeneratedHttpRequest<AMIAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, "imageId");
"imageId");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 93\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 93\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=DescribeImageAttribute&Attribute=blockDeviceMapping&ImageId=imageId"); "Version=2009-11-30&Action=DescribeImageAttribute&Attribute=blockDeviceMapping&ImageId=imageId");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, BlockDeviceMappingHandler.class); assertSaxResponseParserClassEquals(method, BlockDeviceMappingHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testGetLaunchPermissionForImage() throws SecurityException, NoSuchMethodException, public void testGetLaunchPermissionForImage() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = AMIAsyncClient.class.getMethod("getLaunchPermissionForImageInRegion", Method method = AMIAsyncClient.class.getMethod("getLaunchPermissionForImageInRegion",
String.class, String.class); String.class, String.class);
GeneratedHttpRequest<AMIAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, "imageId");
"imageId");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 91\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 91\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=DescribeImageAttribute&Attribute=launchPermission&ImageId=imageId"); "Version=2009-11-30&Action=DescribeImageAttribute&Attribute=launchPermission&ImageId=imageId");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, PermissionHandler.class); assertSaxResponseParserClassEquals(method, PermissionHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testAddLaunchPermissionsToImage() throws SecurityException, NoSuchMethodException, public void testAddLaunchPermissionsToImage() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = AMIAsyncClient.class.getMethod("addLaunchPermissionsToImageInRegion", Method method = AMIAsyncClient.class.getMethod("addLaunchPermissionsToImageInRegion",
String.class, Iterable.class, Iterable.class, String.class); String.class, Iterable.class, Iterable.class, String.class);
GeneratedHttpRequest<AMIAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, ImmutableList.of("bob", "sue"),
ImmutableList.of("bob", "sue"), ImmutableList.of("all"), "imageId"); ImmutableList.of("all"), "imageId");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 107\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 107\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"Version=2009-11-30&Action=ModifyImageAttribute&OperationType=add&Attribute=launchPermission&ImageId=imageId&UserGroup.1=all&UserId.1=bob&UserId.2=sue"); "Version=2009-11-30&Action=ModifyImageAttribute&OperationType=add&Attribute=launchPermission&ImageId=imageId&UserGroup.1=all&UserId.1=bob&UserId.2=sue");
filter.filter(httpMethod); filter.filter(request);
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"Action=ModifyImageAttribute&Attribute=launchPermission&ImageId=imageId&OperationType=add&Signature=Nf2oLuEQ%2BDgwhAxNt7Cdicjacz3PYTVR08%2BaGuXMfwU%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&UserGroup.1=all&UserId.1=bob&UserId.2=sue&Version=2009-11-30&AWSAccessKeyId=identity"); "Action=ModifyImageAttribute&Attribute=launchPermission&ImageId=imageId&OperationType=add&Signature=Nf2oLuEQ%2BDgwhAxNt7Cdicjacz3PYTVR08%2BaGuXMfwU%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&UserGroup.1=all&UserId.1=bob&UserId.2=sue&Version=2009-11-30&AWSAccessKeyId=identity");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testRemoveLaunchPermissionsFromImage() throws SecurityException, public void testRemoveLaunchPermissionsFromImage() throws SecurityException,
NoSuchMethodException, IOException { NoSuchMethodException, IOException {
Method method = AMIAsyncClient.class.getMethod("removeLaunchPermissionsFromImageInRegion", Method method = AMIAsyncClient.class.getMethod("removeLaunchPermissionsFromImageInRegion",
String.class, Iterable.class, Iterable.class, String.class); String.class, Iterable.class, Iterable.class, String.class);
GeneratedHttpRequest<AMIAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, ImmutableList.of("bob", "sue"),
ImmutableList.of("bob", "sue"), ImmutableList.of("all"), "imageId"); ImmutableList.of("all"), "imageId");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 110\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 110\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"Version=2009-11-30&Action=ModifyImageAttribute&OperationType=remove&Attribute=launchPermission&ImageId=imageId&UserGroup.1=all&UserId.1=bob&UserId.2=sue"); "Version=2009-11-30&Action=ModifyImageAttribute&OperationType=remove&Attribute=launchPermission&ImageId=imageId&UserGroup.1=all&UserId.1=bob&UserId.2=sue");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testResetLaunchPermissionsOnImage() throws SecurityException, NoSuchMethodException, public void testResetLaunchPermissionsOnImage() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = AMIAsyncClient.class.getMethod("resetLaunchPermissionsOnImageInRegion", Method method = AMIAsyncClient.class.getMethod("resetLaunchPermissionsOnImageInRegion",
String.class, String.class); String.class, String.class);
GeneratedHttpRequest<AMIAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, "imageId");
"imageId");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 88\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 88\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=ResetImageAttribute&Attribute=launchPermission&ImageId=imageId"); "Version=2009-11-30&Action=ResetImageAttribute&Attribute=launchPermission&ImageId=imageId");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testAddProductCodesToImage() throws SecurityException, NoSuchMethodException, public void testAddProductCodesToImage() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = AMIAsyncClient.class.getMethod("addProductCodesToImageInRegion", Method method = AMIAsyncClient.class.getMethod("addProductCodesToImageInRegion",
String.class, Iterable.class, String.class); String.class, Iterable.class, String.class);
GeneratedHttpRequest<AMIAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, ImmutableList
ImmutableList.of("code1", "code2"), "imageId"); .of("code1", "code2"), "imageId");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 103\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 103\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"Version=2009-11-30&Action=ModifyImageAttribute&OperationType=add&Attribute=productCodes&ImageId=imageId&ProductCode.1=code1&ProductCode.2=code2"); "Version=2009-11-30&Action=ModifyImageAttribute&OperationType=add&Attribute=productCodes&ImageId=imageId&ProductCode.1=code1&ProductCode.2=code2");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testRemoveProductCodesFromImage() throws SecurityException, NoSuchMethodException, public void testRemoveProductCodesFromImage() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = AMIAsyncClient.class.getMethod("removeProductCodesFromImageInRegion", Method method = AMIAsyncClient.class.getMethod("removeProductCodesFromImageInRegion",
String.class, Iterable.class, String.class); String.class, Iterable.class, String.class);
GeneratedHttpRequest<AMIAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, ImmutableList
ImmutableList.of("code1", "code2"), "imageId"); .of("code1", "code2"), "imageId");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 106\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 106\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"Version=2009-11-30&Action=ModifyImageAttribute&OperationType=remove&Attribute=productCodes&ImageId=imageId&ProductCode.1=code1&ProductCode.2=code2"); "Version=2009-11-30&Action=ModifyImageAttribute&OperationType=remove&Attribute=productCodes&ImageId=imageId&ProductCode.1=code1&ProductCode.2=code2");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
@Override @Override

View File

@ -31,8 +31,8 @@ import org.jclouds.aws.ec2.options.DescribeAvailabilityZonesOptions;
import org.jclouds.aws.ec2.options.DescribeRegionsOptions; import org.jclouds.aws.ec2.options.DescribeRegionsOptions;
import org.jclouds.aws.ec2.xml.DescribeAvailabilityZonesResponseHandler; import org.jclouds.aws.ec2.xml.DescribeAvailabilityZonesResponseHandler;
import org.jclouds.aws.ec2.xml.DescribeRegionsResponseHandler; import org.jclouds.aws.ec2.xml.DescribeRegionsResponseHandler;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -52,20 +52,19 @@ public class AvailabilityZoneAndRegionAsyncClientTest extends
Method method = AvailabilityZoneAndRegionAsyncClient.class.getMethod( Method method = AvailabilityZoneAndRegionAsyncClient.class.getMethod(
"describeAvailabilityZonesInRegion", String.class, Array.newInstance( "describeAvailabilityZonesInRegion", String.class, Array.newInstance(
DescribeAvailabilityZonesOptions.class, 0).getClass()); DescribeAvailabilityZonesOptions.class, 0).getClass());
GeneratedHttpRequest<AvailabilityZoneAndRegionAsyncClient> httpMethod = processor HttpRequest request = processor.createRequest(method, Region.US_WEST_1);
.createRequest(method, Region.US_WEST_1);
assertRequestLineEquals(httpMethod, "POST https://ec2.us-west-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-west-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 51\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-west-1.amazonaws.com\n"); "Content-Length: 51\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-west-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, "Version=2009-11-30&Action=DescribeAvailabilityZones"); assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeAvailabilityZones");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, DescribeAvailabilityZonesResponseHandler.class); assertSaxResponseParserClassEquals(method, DescribeAvailabilityZonesResponseHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testDescribeAvailabilityZonesOptions() throws SecurityException, public void testDescribeAvailabilityZonesOptions() throws SecurityException,
@ -73,62 +72,60 @@ public class AvailabilityZoneAndRegionAsyncClientTest extends
Method method = AvailabilityZoneAndRegionAsyncClient.class.getMethod( Method method = AvailabilityZoneAndRegionAsyncClient.class.getMethod(
"describeAvailabilityZonesInRegion", String.class, Array.newInstance( "describeAvailabilityZonesInRegion", String.class, Array.newInstance(
DescribeAvailabilityZonesOptions.class, 0).getClass()); DescribeAvailabilityZonesOptions.class, 0).getClass());
GeneratedHttpRequest<AvailabilityZoneAndRegionAsyncClient> httpMethod = processor HttpRequest request = processor.createRequest(method, Region.US_EAST_1, availabilityZones(
.createRequest(method, Region.US_EAST_1, availabilityZones(
AvailabilityZone.US_EAST_1A, AvailabilityZone.US_EAST_1B)); AvailabilityZone.US_EAST_1A, AvailabilityZone.US_EAST_1B));
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 95\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 95\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=DescribeAvailabilityZones&ZoneName.1=us-east-1a&ZoneName.2=us-east-1b"); "Version=2009-11-30&Action=DescribeAvailabilityZones&ZoneName.1=us-east-1a&ZoneName.2=us-east-1b");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, DescribeAvailabilityZonesResponseHandler.class); assertSaxResponseParserClassEquals(method, DescribeAvailabilityZonesResponseHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testDescribeRegions() throws SecurityException, NoSuchMethodException, IOException { public void testDescribeRegions() throws SecurityException, NoSuchMethodException, IOException {
Method method = AvailabilityZoneAndRegionAsyncClient.class.getMethod("describeRegions", Array Method method = AvailabilityZoneAndRegionAsyncClient.class.getMethod("describeRegions", Array
.newInstance(DescribeRegionsOptions.class, 0).getClass()); .newInstance(DescribeRegionsOptions.class, 0).getClass());
GeneratedHttpRequest<AvailabilityZoneAndRegionAsyncClient> httpMethod = processor HttpRequest request = processor.createRequest(method);
.createRequest(method);
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 41\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 41\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, "Version=2009-11-30&Action=DescribeRegions"); assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeRegions");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, DescribeRegionsResponseHandler.class); assertSaxResponseParserClassEquals(method, DescribeRegionsResponseHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testDescribeRegionsOptions() throws SecurityException, NoSuchMethodException, public void testDescribeRegionsOptions() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = AvailabilityZoneAndRegionAsyncClient.class.getMethod("describeRegions", Array Method method = AvailabilityZoneAndRegionAsyncClient.class.getMethod("describeRegions", Array
.newInstance(DescribeRegionsOptions.class, 0).getClass()); .newInstance(DescribeRegionsOptions.class, 0).getClass());
GeneratedHttpRequest<AvailabilityZoneAndRegionAsyncClient> httpMethod = processor HttpRequest request = processor.createRequest(method, regions(Region.US_EAST_1,
.createRequest(method, regions(Region.US_EAST_1, Region.US_WEST_1)); Region.US_WEST_1));
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 87\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 87\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=DescribeRegions&RegionName.1=us-east-1&RegionName.2=us-west-1"); "Version=2009-11-30&Action=DescribeRegions&RegionName.1=us-east-1&RegionName.2=us-west-1");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, DescribeRegionsResponseHandler.class); assertSaxResponseParserClassEquals(method, DescribeRegionsResponseHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
@Override @Override

View File

@ -34,12 +34,12 @@ import org.jclouds.aws.ec2.config.EC2RestClientModule;
import org.jclouds.aws.ec2.domain.AvailabilityZone; import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.aws.filters.FormSigner; import org.jclouds.aws.filters.FormSigner;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextFactory.ContextSpec; import org.jclouds.rest.RestContextFactory.ContextSpec;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
@ -80,9 +80,9 @@ public abstract class BaseEC2AsyncClientTest<T> extends RestClientTest<T> {
protected FormSigner filter; protected FormSigner filter;
@Override @Override
protected void checkFilters(GeneratedHttpRequest<T> httpMethod) { protected void checkFilters(HttpRequest request) {
assertEquals(httpMethod.getFilters().size(), 1); assertEquals(request.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), FormSigner.class); assertEquals(request.getFilters().get(0).getClass(), FormSigner.class);
} }
public BaseEC2AsyncClientTest() { public BaseEC2AsyncClientTest() {

View File

@ -36,9 +36,9 @@ import org.jclouds.aws.ec2.xml.DescribeSnapshotsResponseHandler;
import org.jclouds.aws.ec2.xml.DescribeVolumesResponseHandler; import org.jclouds.aws.ec2.xml.DescribeVolumesResponseHandler;
import org.jclouds.aws.ec2.xml.PermissionHandler; import org.jclouds.aws.ec2.xml.PermissionHandler;
import org.jclouds.aws.ec2.xml.SnapshotHandler; import org.jclouds.aws.ec2.xml.SnapshotHandler;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -57,158 +57,156 @@ public class ElasticBlockStoreAsyncClientTest extends
public void testCreateVolume() throws SecurityException, NoSuchMethodException, IOException { public void testCreateVolume() throws SecurityException, NoSuchMethodException, IOException {
Method method = ElasticBlockStoreAsyncClient.class.getMethod( Method method = ElasticBlockStoreAsyncClient.class.getMethod(
"createVolumeInAvailabilityZone", String.class, int.class); "createVolumeInAvailabilityZone", String.class, int.class);
GeneratedHttpRequest<ElasticBlockStoreAsyncClient> httpMethod = processor.createRequest( HttpRequest request = processor.createRequest(method, AvailabilityZone.US_EAST_1A, 20);
method, AvailabilityZone.US_EAST_1A, 20);
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 74\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 74\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=CreateVolume&AvailabilityZone=us-east-1a&Size=20"); "Version=2009-11-30&Action=CreateVolume&AvailabilityZone=us-east-1a&Size=20");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, CreateVolumeResponseHandler.class); assertSaxResponseParserClassEquals(method, CreateVolumeResponseHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testCreateVolumeFromSnapShot() throws SecurityException, NoSuchMethodException, public void testCreateVolumeFromSnapShot() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = ElasticBlockStoreAsyncClient.class.getMethod( Method method = ElasticBlockStoreAsyncClient.class.getMethod(
"createVolumeFromSnapshotInAvailabilityZone", String.class, String.class); "createVolumeFromSnapshotInAvailabilityZone", String.class, String.class);
GeneratedHttpRequest<ElasticBlockStoreAsyncClient> httpMethod = processor.createRequest( HttpRequest request = processor.createRequest(method, AvailabilityZone.US_EAST_1A,
method, AvailabilityZone.US_EAST_1A, "snapshotId"); "snapshotId");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 88\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 88\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=CreateVolume&AvailabilityZone=us-east-1a&SnapshotId=snapshotId"); "Version=2009-11-30&Action=CreateVolume&AvailabilityZone=us-east-1a&SnapshotId=snapshotId");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, CreateVolumeResponseHandler.class); assertSaxResponseParserClassEquals(method, CreateVolumeResponseHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testCreateVolumeFromSnapShotWithSize() throws SecurityException, public void testCreateVolumeFromSnapShotWithSize() throws SecurityException,
NoSuchMethodException, IOException { NoSuchMethodException, IOException {
Method method = ElasticBlockStoreAsyncClient.class.getMethod( Method method = ElasticBlockStoreAsyncClient.class.getMethod(
"createVolumeFromSnapshotInAvailabilityZone", String.class, int.class, String.class); "createVolumeFromSnapshotInAvailabilityZone", String.class, int.class, String.class);
GeneratedHttpRequest<ElasticBlockStoreAsyncClient> httpMethod = processor.createRequest( HttpRequest request = processor.createRequest(method, AvailabilityZone.US_EAST_1A, 15,
method, AvailabilityZone.US_EAST_1A, 15, "snapshotId"); "snapshotId");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 96\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 96\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=CreateVolume&AvailabilityZone=us-east-1a&SnapshotId=snapshotId&Size=15"); "Version=2009-11-30&Action=CreateVolume&AvailabilityZone=us-east-1a&SnapshotId=snapshotId&Size=15");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, CreateVolumeResponseHandler.class); assertSaxResponseParserClassEquals(method, CreateVolumeResponseHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testDeleteVolume() throws SecurityException, NoSuchMethodException, IOException { public void testDeleteVolume() throws SecurityException, NoSuchMethodException, IOException {
Method method = ElasticBlockStoreAsyncClient.class.getMethod("deleteVolumeInRegion", Method method = ElasticBlockStoreAsyncClient.class.getMethod("deleteVolumeInRegion",
String.class, String.class); String.class, String.class);
GeneratedHttpRequest<ElasticBlockStoreAsyncClient> httpMethod = processor.createRequest( HttpRequest request = processor.createRequest(method, null, "id");
method, null, "id");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(
request,
"Content-Length: 50\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 50\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, "Version=2009-11-30&Action=DeleteVolume&VolumeId=id"); assertPayloadEquals(request, "Version=2009-11-30&Action=DeleteVolume&VolumeId=id");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testDescribeVolumes() throws SecurityException, NoSuchMethodException, IOException { public void testDescribeVolumes() throws SecurityException, NoSuchMethodException, IOException {
Method method = ElasticBlockStoreAsyncClient.class.getMethod("describeVolumesInRegion", Method method = ElasticBlockStoreAsyncClient.class.getMethod("describeVolumesInRegion",
String.class, Array.newInstance(String.class, 0).getClass()); String.class, Array.newInstance(String.class, 0).getClass());
GeneratedHttpRequest<ElasticBlockStoreAsyncClient> httpMethod = processor.createRequest( HttpRequest request = processor.createRequest(method, (String) null);
method, (String) null);
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(
request,
"Content-Length: 41\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 41\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, "Version=2009-11-30&Action=DescribeVolumes"); assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeVolumes");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, DescribeVolumesResponseHandler.class); assertSaxResponseParserClassEquals(method, DescribeVolumesResponseHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testDescribeVolumesArgs() throws SecurityException, NoSuchMethodException, public void testDescribeVolumesArgs() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = ElasticBlockStoreAsyncClient.class.getMethod("describeVolumesInRegion", Method method = ElasticBlockStoreAsyncClient.class.getMethod("describeVolumesInRegion",
String.class, Array.newInstance(String.class, 0).getClass()); String.class, Array.newInstance(String.class, 0).getClass());
GeneratedHttpRequest<ElasticBlockStoreAsyncClient> httpMethod = processor.createRequest( HttpRequest request = processor.createRequest(method, null, "1", "2");
method, null, "1", "2");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(
request,
"Content-Length: 41\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 41\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=DescribeVolumes&VolumeId.1=1&VolumeId.2=2"); "Version=2009-11-30&Action=DescribeVolumes&VolumeId.1=1&VolumeId.2=2");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, DescribeVolumesResponseHandler.class); assertSaxResponseParserClassEquals(method, DescribeVolumesResponseHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testAttachVolume() throws SecurityException, NoSuchMethodException, IOException { public void testAttachVolume() throws SecurityException, NoSuchMethodException, IOException {
Method method = ElasticBlockStoreAsyncClient.class.getMethod("attachVolumeInRegion", Method method = ElasticBlockStoreAsyncClient.class.getMethod("attachVolumeInRegion",
String.class, String.class, String.class, String.class); String.class, String.class, String.class, String.class);
GeneratedHttpRequest<ElasticBlockStoreAsyncClient> httpMethod = processor.createRequest( HttpRequest request = processor.createRequest(method, null, "id", "instanceId", "/device");
method, null, "id", "instanceId", "/device");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(
request,
"Content-Length: 89\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 89\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=AttachVolume&InstanceId=instanceId&VolumeId=id&Device=%2Fdevice"); "Version=2009-11-30&Action=AttachVolume&InstanceId=instanceId&VolumeId=id&Device=%2Fdevice");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, AttachmentHandler.class); assertSaxResponseParserClassEquals(method, AttachmentHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testDetachVolume() throws SecurityException, NoSuchMethodException, IOException { public void testDetachVolume() throws SecurityException, NoSuchMethodException, IOException {
Method method = ElasticBlockStoreAsyncClient.class.getMethod("detachVolumeInRegion", Method method = ElasticBlockStoreAsyncClient.class.getMethod("detachVolumeInRegion",
String.class, String.class, boolean.class, Array.newInstance( String.class, String.class, boolean.class, Array.newInstance(
DetachVolumeOptions.class, 0).getClass()); DetachVolumeOptions.class, 0).getClass());
GeneratedHttpRequest<ElasticBlockStoreAsyncClient> httpMethod = processor.createRequest( HttpRequest request = processor.createRequest(method, null, "id", false);
method, null, "id", false);
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(
request,
"Content-Length: 62\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 62\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request, "Version=2009-11-30&Action=DetachVolume&Force=false&VolumeId=id");
"Version=2009-11-30&Action=DetachVolume&Force=false&VolumeId=id");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnVoidOnVolumeAvailable.class); assertExceptionParserClassEquals(method, ReturnVoidOnVolumeAvailable.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testDetachVolumeOptions() throws SecurityException, NoSuchMethodException, public void testDetachVolumeOptions() throws SecurityException, NoSuchMethodException,
@ -216,40 +214,41 @@ public class ElasticBlockStoreAsyncClientTest extends
Method method = ElasticBlockStoreAsyncClient.class.getMethod("detachVolumeInRegion", Method method = ElasticBlockStoreAsyncClient.class.getMethod("detachVolumeInRegion",
String.class, String.class, boolean.class, Array.newInstance( String.class, String.class, boolean.class, Array.newInstance(
DetachVolumeOptions.class, 0).getClass()); DetachVolumeOptions.class, 0).getClass());
GeneratedHttpRequest<ElasticBlockStoreAsyncClient> httpMethod = processor.createRequest( HttpRequest request = processor.createRequest(method, null, "id", true, fromInstance(
method, null, "id", true, fromInstance("instanceId").fromDevice("/device")); "instanceId").fromDevice("/device"));
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(
request,
"Content-Length: 100\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 100\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"Version=2009-11-30&Action=DetachVolume&Force=true&VolumeId=id&InstanceId=instanceId&Device=%2Fdevice"); "Version=2009-11-30&Action=DetachVolume&Force=true&VolumeId=id&InstanceId=instanceId&Device=%2Fdevice");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnVoidOnVolumeAvailable.class); assertExceptionParserClassEquals(method, ReturnVoidOnVolumeAvailable.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testCreateSnapshot() throws SecurityException, NoSuchMethodException, IOException { public void testCreateSnapshot() throws SecurityException, NoSuchMethodException, IOException {
Method method = ElasticBlockStoreAsyncClient.class.getMethod("createSnapshotInRegion", Method method = ElasticBlockStoreAsyncClient.class.getMethod("createSnapshotInRegion",
String.class, String.class, Array.newInstance(CreateSnapshotOptions.class, 0) String.class, String.class, Array.newInstance(CreateSnapshotOptions.class, 0)
.getClass()); .getClass());
GeneratedHttpRequest<ElasticBlockStoreAsyncClient> httpMethod = processor.createRequest( HttpRequest request = processor.createRequest(method, null, "volumeId");
method, null, "volumeId");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(
request,
"Content-Length: 58\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 58\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, "Version=2009-11-30&Action=CreateSnapshot&VolumeId=volumeId"); assertPayloadEquals(request, "Version=2009-11-30&Action=CreateSnapshot&VolumeId=volumeId");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, SnapshotHandler.class); assertSaxResponseParserClassEquals(method, SnapshotHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testCreateSnapshotOptions() throws SecurityException, NoSuchMethodException, public void testCreateSnapshotOptions() throws SecurityException, NoSuchMethodException,
@ -257,81 +256,82 @@ public class ElasticBlockStoreAsyncClientTest extends
Method method = ElasticBlockStoreAsyncClient.class.getMethod("createSnapshotInRegion", Method method = ElasticBlockStoreAsyncClient.class.getMethod("createSnapshotInRegion",
String.class, String.class, Array.newInstance(CreateSnapshotOptions.class, 0) String.class, String.class, Array.newInstance(CreateSnapshotOptions.class, 0)
.getClass()); .getClass());
GeneratedHttpRequest<ElasticBlockStoreAsyncClient> httpMethod = processor.createRequest( HttpRequest request = processor.createRequest(method, null, "volumeId",
method, null, "volumeId", CreateSnapshotOptions.Builder CreateSnapshotOptions.Builder.withDescription("description"));
.withDescription("description"));
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(
request,
"Content-Length: 82\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 82\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=CreateSnapshot&VolumeId=volumeId&Description=description"); "Version=2009-11-30&Action=CreateSnapshot&VolumeId=volumeId&Description=description");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, SnapshotHandler.class); assertSaxResponseParserClassEquals(method, SnapshotHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testDescribeSnapshots() throws SecurityException, NoSuchMethodException, IOException { public void testDescribeSnapshots() throws SecurityException, NoSuchMethodException, IOException {
Method method = ElasticBlockStoreAsyncClient.class.getMethod("describeSnapshotsInRegion", Method method = ElasticBlockStoreAsyncClient.class.getMethod("describeSnapshotsInRegion",
String.class, Array.newInstance(DescribeSnapshotsOptions.class, 0).getClass()); String.class, Array.newInstance(DescribeSnapshotsOptions.class, 0).getClass());
GeneratedHttpRequest<ElasticBlockStoreAsyncClient> httpMethod = processor.createRequest( HttpRequest request = processor.createRequest(method, (String) null);
method, (String) null);
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(
request,
"Content-Length: 43\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 43\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, "Version=2009-11-30&Action=DescribeSnapshots"); assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeSnapshots");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, DescribeSnapshotsResponseHandler.class); assertSaxResponseParserClassEquals(method, DescribeSnapshotsResponseHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testDescribeSnapshotsArgs() throws SecurityException, NoSuchMethodException, public void testDescribeSnapshotsArgs() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = ElasticBlockStoreAsyncClient.class.getMethod("describeSnapshotsInRegion", Method method = ElasticBlockStoreAsyncClient.class.getMethod("describeSnapshotsInRegion",
String.class, Array.newInstance(DescribeSnapshotsOptions.class, 0).getClass()); String.class, Array.newInstance(DescribeSnapshotsOptions.class, 0).getClass());
GeneratedHttpRequest<ElasticBlockStoreAsyncClient> httpMethod = processor.createRequest( HttpRequest request = processor.createRequest(method, null, ownedBy("o1", "o2").restorableBy(
method, null, ownedBy("o1", "o2").restorableBy("r1", "r2").snapshotIds("s1", "s2")); "r1", "r2").snapshotIds("s1", "s2"));
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(
request,
"Content-Length: 133\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 133\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"Version=2009-11-30&Action=DescribeSnapshots&Owner.1=o1&Owner.2=o2&RestorableBy.1=r1&RestorableBy.2=r2&SnapshotId.1=s1&SnapshotId.2=s2"); "Version=2009-11-30&Action=DescribeSnapshots&Owner.1=o1&Owner.2=o2&RestorableBy.1=r1&RestorableBy.2=r2&SnapshotId.1=s1&SnapshotId.2=s2");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, DescribeSnapshotsResponseHandler.class); assertSaxResponseParserClassEquals(method, DescribeSnapshotsResponseHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testGetCreateVolumePermissionForSnapshot() throws SecurityException, public void testGetCreateVolumePermissionForSnapshot() throws SecurityException,
NoSuchMethodException, IOException { NoSuchMethodException, IOException {
Method method = ElasticBlockStoreAsyncClient.class.getMethod( Method method = ElasticBlockStoreAsyncClient.class.getMethod(
"getCreateVolumePermissionForSnapshotInRegion", String.class, String.class); "getCreateVolumePermissionForSnapshotInRegion", String.class, String.class);
GeneratedHttpRequest<ElasticBlockStoreAsyncClient> httpMethod = processor.createRequest( HttpRequest request = processor.createRequest(method, null, "snapshotId");
method, null, "snapshotId");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(
request,
"Content-Length: 106\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 106\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"Version=2009-11-30&Action=DescribeSnapshotAttribute&Attribute=createVolumePermission&SnapshotId=snapshotId"); "Version=2009-11-30&Action=DescribeSnapshotAttribute&Attribute=createVolumePermission&SnapshotId=snapshotId");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, PermissionHandler.class); assertSaxResponseParserClassEquals(method, PermissionHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testAddCreateVolumePermissionsToSnapshot() throws SecurityException, public void testAddCreateVolumePermissionsToSnapshot() throws SecurityException,
@ -339,21 +339,22 @@ public class ElasticBlockStoreAsyncClientTest extends
Method method = ElasticBlockStoreAsyncClient.class.getMethod( Method method = ElasticBlockStoreAsyncClient.class.getMethod(
"addCreateVolumePermissionsToSnapshotInRegion", String.class, Iterable.class, "addCreateVolumePermissionsToSnapshotInRegion", String.class, Iterable.class,
Iterable.class, String.class); Iterable.class, String.class);
GeneratedHttpRequest<ElasticBlockStoreAsyncClient> httpMethod = processor.createRequest( HttpRequest request = processor.createRequest(method, null, ImmutableList.of("bob", "sue"),
method, null, ImmutableList.of("bob", "sue"), ImmutableList.of("all"), "snapshotId"); ImmutableList.of("all"), "snapshotId");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(
request,
"Content-Length: 122\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 122\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"Version=2009-11-30&Action=ModifySnapshotAttribute&OperationType=add&Attribute=createVolumePermission&SnapshotId=snapshotId&UserGroup.1=all&UserId.1=bob&UserId.2=sue"); "Version=2009-11-30&Action=ModifySnapshotAttribute&OperationType=add&Attribute=createVolumePermission&SnapshotId=snapshotId&UserGroup.1=all&UserId.1=bob&UserId.2=sue");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testRemoveCreateVolumePermissionsFromSnapshot() throws SecurityException, public void testRemoveCreateVolumePermissionsFromSnapshot() throws SecurityException,
@ -361,40 +362,41 @@ public class ElasticBlockStoreAsyncClientTest extends
Method method = ElasticBlockStoreAsyncClient.class.getMethod( Method method = ElasticBlockStoreAsyncClient.class.getMethod(
"removeCreateVolumePermissionsFromSnapshotInRegion", String.class, Iterable.class, "removeCreateVolumePermissionsFromSnapshotInRegion", String.class, Iterable.class,
Iterable.class, String.class); Iterable.class, String.class);
GeneratedHttpRequest<ElasticBlockStoreAsyncClient> httpMethod = processor.createRequest( HttpRequest request = processor.createRequest(method, null, ImmutableList.of("bob", "sue"),
method, null, ImmutableList.of("bob", "sue"), ImmutableList.of("all"), "snapshotId"); ImmutableList.of("all"), "snapshotId");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(
request,
"Content-Length: 125\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 125\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"Version=2009-11-30&Action=ModifySnapshotAttribute&OperationType=remove&Attribute=createVolumePermission&SnapshotId=snapshotId&UserGroup.1=all&UserId.1=bob&UserId.2=sue"); "Version=2009-11-30&Action=ModifySnapshotAttribute&OperationType=remove&Attribute=createVolumePermission&SnapshotId=snapshotId&UserGroup.1=all&UserId.1=bob&UserId.2=sue");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testResetCreateVolumePermissionsOnSnapshot() throws SecurityException, public void testResetCreateVolumePermissionsOnSnapshot() throws SecurityException,
NoSuchMethodException, IOException { NoSuchMethodException, IOException {
Method method = ElasticBlockStoreAsyncClient.class.getMethod( Method method = ElasticBlockStoreAsyncClient.class.getMethod(
"resetCreateVolumePermissionsOnSnapshotInRegion", String.class, String.class); "resetCreateVolumePermissionsOnSnapshotInRegion", String.class, String.class);
GeneratedHttpRequest<ElasticBlockStoreAsyncClient> httpMethod = processor.createRequest( HttpRequest request = processor.createRequest(method, null, "snapshotId");
method, null, "snapshotId");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(
request,
"Content-Length: 103\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 103\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"Version=2009-11-30&Action=ResetSnapshotAttribute&Attribute=createVolumePermission&SnapshotId=snapshotId"); "Version=2009-11-30&Action=ResetSnapshotAttribute&Attribute=createVolumePermission&SnapshotId=snapshotId");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
@Override @Override

View File

@ -24,9 +24,9 @@ import java.lang.reflect.Method;
import org.jclouds.aws.ec2.xml.AllocateAddressResponseHandler; import org.jclouds.aws.ec2.xml.AllocateAddressResponseHandler;
import org.jclouds.aws.ec2.xml.DescribeAddressesResponseHandler; import org.jclouds.aws.ec2.xml.DescribeAddressesResponseHandler;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -45,99 +45,94 @@ public class ElasticIPAddressAsyncClientTest extends
IOException { IOException {
Method method = ElasticIPAddressAsyncClient.class.getMethod("disassociateAddressInRegion", Method method = ElasticIPAddressAsyncClient.class.getMethod("disassociateAddressInRegion",
String.class, String.class); String.class, String.class);
GeneratedHttpRequest<ElasticIPAddressAsyncClient> httpMethod = processor.createRequest( HttpRequest request = processor.createRequest(method, null, "127.0.0.1");
method, null, "127.0.0.1");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 64\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 64\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=DisassociateAddress&PublicIp=127.0.0.1"); "Version=2009-11-30&Action=DisassociateAddress&PublicIp=127.0.0.1");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testAssociateAddress() throws SecurityException, NoSuchMethodException, IOException { public void testAssociateAddress() throws SecurityException, NoSuchMethodException, IOException {
Method method = ElasticIPAddressAsyncClient.class.getMethod("associateAddressInRegion", Method method = ElasticIPAddressAsyncClient.class.getMethod("associateAddressInRegion",
String.class, String.class, String.class); String.class, String.class, String.class);
GeneratedHttpRequest<ElasticIPAddressAsyncClient> httpMethod = processor.createRequest( HttpRequest request = processor.createRequest(method, null, "127.0.0.1", "me");
method, null, "127.0.0.1", "me");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 75\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 75\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=AssociateAddress&InstanceId=me&PublicIp=127.0.0.1"); "Version=2009-11-30&Action=AssociateAddress&InstanceId=me&PublicIp=127.0.0.1");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testReleaseAddress() throws SecurityException, NoSuchMethodException, IOException { public void testReleaseAddress() throws SecurityException, NoSuchMethodException, IOException {
Method method = ElasticIPAddressAsyncClient.class.getMethod("releaseAddressInRegion", Method method = ElasticIPAddressAsyncClient.class.getMethod("releaseAddressInRegion",
String.class, String.class); String.class, String.class);
GeneratedHttpRequest<ElasticIPAddressAsyncClient> httpMethod = processor.createRequest( HttpRequest request = processor.createRequest(method, null, "127.0.0.1");
method, null, "127.0.0.1");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 59\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 59\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, "Version=2009-11-30&Action=ReleaseAddress&PublicIp=127.0.0.1"); assertPayloadEquals(request, "Version=2009-11-30&Action=ReleaseAddress&PublicIp=127.0.0.1");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testDescribeAddresses() throws SecurityException, NoSuchMethodException, IOException { public void testDescribeAddresses() throws SecurityException, NoSuchMethodException, IOException {
Method method = ElasticIPAddressAsyncClient.class.getMethod("describeAddressesInRegion", Method method = ElasticIPAddressAsyncClient.class.getMethod("describeAddressesInRegion",
String.class, Array.newInstance(String.class, 0).getClass()); String.class, Array.newInstance(String.class, 0).getClass());
GeneratedHttpRequest<ElasticIPAddressAsyncClient> httpMethod = processor.createRequest( HttpRequest request = processor.createRequest(method, null, "127.0.0.1");
method, null, "127.0.0.1");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 43\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 43\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=DescribeAddresses&PublicIp.1=127.0.0.1"); "Version=2009-11-30&Action=DescribeAddresses&PublicIp.1=127.0.0.1");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, DescribeAddressesResponseHandler.class); assertSaxResponseParserClassEquals(method, DescribeAddressesResponseHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testAllocateAddress() throws SecurityException, NoSuchMethodException, IOException { public void testAllocateAddress() throws SecurityException, NoSuchMethodException, IOException {
Method method = ElasticIPAddressAsyncClient.class.getMethod("allocateAddressInRegion", Method method = ElasticIPAddressAsyncClient.class.getMethod("allocateAddressInRegion",
String.class); String.class);
GeneratedHttpRequest<ElasticIPAddressAsyncClient> httpMethod = processor.createRequest( HttpRequest request = processor.createRequest(method, (String) null);
method, (String) null);
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 41\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 41\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, "Version=2009-11-30&Action=AllocateAddress"); assertPayloadEquals(request, "Version=2009-11-30&Action=AllocateAddress");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, AllocateAddressResponseHandler.class); assertSaxResponseParserClassEquals(method, AllocateAddressResponseHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
@Override @Override

View File

@ -38,9 +38,9 @@ import org.jclouds.aws.ec2.xml.InstanceTypeHandler;
import org.jclouds.aws.ec2.xml.RunInstancesResponseHandler; import org.jclouds.aws.ec2.xml.RunInstancesResponseHandler;
import org.jclouds.aws.ec2.xml.StringValueHandler; import org.jclouds.aws.ec2.xml.StringValueHandler;
import org.jclouds.aws.ec2.xml.UnencodeStringValueHandler; import org.jclouds.aws.ec2.xml.UnencodeStringValueHandler;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -56,83 +56,79 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
public void testDescribeInstances() throws SecurityException, NoSuchMethodException, IOException { public void testDescribeInstances() throws SecurityException, NoSuchMethodException, IOException {
Method method = InstanceAsyncClient.class.getMethod("describeInstancesInRegion", Method method = InstanceAsyncClient.class.getMethod("describeInstancesInRegion",
String.class, Array.newInstance(String.class, 0).getClass()); String.class, Array.newInstance(String.class, 0).getClass());
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, (String) null);
(String) null);
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 43\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 43\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, "Version=2009-11-30&Action=DescribeInstances"); assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeInstances");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, DescribeInstancesResponseHandler.class); assertSaxResponseParserClassEquals(method, DescribeInstancesResponseHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testDescribeInstancesArgs() throws SecurityException, NoSuchMethodException, public void testDescribeInstancesArgs() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = InstanceAsyncClient.class.getMethod("describeInstancesInRegion", Method method = InstanceAsyncClient.class.getMethod("describeInstancesInRegion",
String.class, Array.newInstance(String.class, 0).getClass()); String.class, Array.newInstance(String.class, 0).getClass());
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, "1", "2");
"1", "2");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 43\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 43\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=DescribeInstances&InstanceId.1=1&InstanceId.2=2"); "Version=2009-11-30&Action=DescribeInstances&InstanceId.1=1&InstanceId.2=2");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, DescribeInstancesResponseHandler.class); assertSaxResponseParserClassEquals(method, DescribeInstancesResponseHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testTerminateInstances() throws SecurityException, NoSuchMethodException, public void testTerminateInstances() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = InstanceAsyncClient.class.getMethod("terminateInstancesInRegion", Method method = InstanceAsyncClient.class.getMethod("terminateInstancesInRegion",
String.class, Array.newInstance(String.class, 0).getClass()); String.class, Array.newInstance(String.class, 0).getClass());
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, "1", "2");
"1", "2");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 44\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 44\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=TerminateInstances&InstanceId.1=1&InstanceId.2=2"); "Version=2009-11-30&Action=TerminateInstances&InstanceId.1=1&InstanceId.2=2");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, InstanceStateChangeHandler.class); assertSaxResponseParserClassEquals(method, InstanceStateChangeHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testRunInstances() throws SecurityException, NoSuchMethodException, IOException { public void testRunInstances() throws SecurityException, NoSuchMethodException, IOException {
Method method = InstanceAsyncClient.class.getMethod("runInstancesInRegion", String.class, Method method = InstanceAsyncClient.class.getMethod("runInstancesInRegion", String.class,
String.class, String.class, int.class, int.class, Array.newInstance( String.class, String.class, int.class, int.class, Array.newInstance(
RunInstancesOptions.class, 0).getClass()); RunInstancesOptions.class, 0).getClass());
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, null, "ami-voo", 1, 1);
null, "ami-voo", 1, 1);
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 76\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 76\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=RunInstances&ImageId=ami-voo&MinCount=1&MaxCount=1"); "Version=2009-11-30&Action=RunInstances&ImageId=ami-voo&MinCount=1&MaxCount=1");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, RunInstancesResponseHandler.class); assertSaxResponseParserClassEquals(method, RunInstancesResponseHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testRunInstancesOptions() throws SecurityException, NoSuchMethodException, public void testRunInstancesOptions() throws SecurityException, NoSuchMethodException,
@ -140,210 +136,201 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
Method method = InstanceAsyncClient.class.getMethod("runInstancesInRegion", String.class, Method method = InstanceAsyncClient.class.getMethod("runInstancesInRegion", String.class,
String.class, String.class, int.class, int.class, Array.newInstance( String.class, String.class, int.class, int.class, Array.newInstance(
RunInstancesOptions.class, 0).getClass()); RunInstancesOptions.class, 0).getClass());
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, Region.EU_WEST_1,
Region.EU_WEST_1, AvailabilityZone.EU_WEST_1A, "ami-voo", 1, 5, AvailabilityZone.EU_WEST_1A, "ami-voo", 1, 5, new RunInstancesOptions()
new RunInstancesOptions().withKernelId("kernelId").enableMonitoring() .withKernelId("kernelId").enableMonitoring().withSecurityGroups("group1",
.withSecurityGroups("group1", "group2")); "group2"));
assertRequestLineEquals(httpMethod, "POST https://ec2.eu-west-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.eu-west-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 164\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.eu-west-1.amazonaws.com\n"); "Content-Length: 164\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.eu-west-1.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"Version=2009-11-30&Action=RunInstances&ImageId=ami-voo&MinCount=1&MaxCount=5&KernelId=kernelId&Monitoring.Enabled=true&SecurityGroup.1=group1&SecurityGroup.2=group2&Placement.AvailabilityZone=eu-west-1a"); "Version=2009-11-30&Action=RunInstances&ImageId=ami-voo&MinCount=1&MaxCount=5&KernelId=kernelId&Monitoring.Enabled=true&SecurityGroup.1=group1&SecurityGroup.2=group2&Placement.AvailabilityZone=eu-west-1a");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, RunInstancesResponseHandler.class); assertSaxResponseParserClassEquals(method, RunInstancesResponseHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testStopInstances() throws SecurityException, NoSuchMethodException, IOException { public void testStopInstances() throws SecurityException, NoSuchMethodException, IOException {
Method method = InstanceAsyncClient.class.getMethod("stopInstancesInRegion", String.class, Method method = InstanceAsyncClient.class.getMethod("stopInstancesInRegion", String.class,
boolean.class, Array.newInstance(String.class, 0).getClass()); boolean.class, Array.newInstance(String.class, 0).getClass());
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, true, "1", "2");
true, "1", "2");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 50\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 50\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=StopInstances&Force=true&InstanceId.1=1&InstanceId.2=2"); "Version=2009-11-30&Action=StopInstances&Force=true&InstanceId.1=1&InstanceId.2=2");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, InstanceStateChangeHandler.class); assertSaxResponseParserClassEquals(method, InstanceStateChangeHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testRebootInstances() throws SecurityException, NoSuchMethodException, IOException { public void testRebootInstances() throws SecurityException, NoSuchMethodException, IOException {
Method method = InstanceAsyncClient.class.getMethod("rebootInstancesInRegion", String.class, Method method = InstanceAsyncClient.class.getMethod("rebootInstancesInRegion", String.class,
Array.newInstance(String.class, 0).getClass()); Array.newInstance(String.class, 0).getClass());
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, "1", "2");
"1", "2");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 41\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 41\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=RebootInstances&InstanceId.1=1&InstanceId.2=2"); "Version=2009-11-30&Action=RebootInstances&InstanceId.1=1&InstanceId.2=2");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testStartInstances() throws SecurityException, NoSuchMethodException, IOException { public void testStartInstances() throws SecurityException, NoSuchMethodException, IOException {
Method method = InstanceAsyncClient.class.getMethod("startInstancesInRegion", String.class, Method method = InstanceAsyncClient.class.getMethod("startInstancesInRegion", String.class,
Array.newInstance(String.class, 0).getClass()); Array.newInstance(String.class, 0).getClass());
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, "1", "2");
"1", "2");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 40\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 40\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=StartInstances&InstanceId.1=1&InstanceId.2=2"); "Version=2009-11-30&Action=StartInstances&InstanceId.1=1&InstanceId.2=2");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, InstanceStateChangeHandler.class); assertSaxResponseParserClassEquals(method, InstanceStateChangeHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testGetUserDataForInstanceInRegion() throws SecurityException, public void testGetUserDataForInstanceInRegion() throws SecurityException,
NoSuchMethodException, IOException { NoSuchMethodException, IOException {
Method method = InstanceAsyncClient.class.getMethod("getUserDataForInstanceInRegion", Method method = InstanceAsyncClient.class.getMethod("getUserDataForInstanceInRegion",
String.class, String.class); String.class, String.class);
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, "1");
"1");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 83\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 83\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=userData&InstanceId=1"); "Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=userData&InstanceId=1");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, UnencodeStringValueHandler.class); assertSaxResponseParserClassEquals(method, UnencodeStringValueHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testGetRootDeviceNameForInstanceInRegion() throws SecurityException, public void testGetRootDeviceNameForInstanceInRegion() throws SecurityException,
NoSuchMethodException, IOException { NoSuchMethodException, IOException {
Method method = InstanceAsyncClient.class.getMethod("getRootDeviceNameForInstanceInRegion", Method method = InstanceAsyncClient.class.getMethod("getRootDeviceNameForInstanceInRegion",
String.class, String.class); String.class, String.class);
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, "1");
"1");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 89\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 89\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=rootDeviceName&InstanceId=1"); "Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=rootDeviceName&InstanceId=1");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, StringValueHandler.class); assertSaxResponseParserClassEquals(method, StringValueHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testGetRamdiskForInstanceInRegion() throws SecurityException, NoSuchMethodException, public void testGetRamdiskForInstanceInRegion() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = InstanceAsyncClient.class.getMethod("getRamdiskForInstanceInRegion", Method method = InstanceAsyncClient.class.getMethod("getRamdiskForInstanceInRegion",
String.class, String.class); String.class, String.class);
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, "1");
"1");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 82\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 82\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=ramdisk&InstanceId=1"); "Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=ramdisk&InstanceId=1");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, StringValueHandler.class); assertSaxResponseParserClassEquals(method, StringValueHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testGetDisableApiTerminationForInstanceInRegion() throws SecurityException, public void testGetDisableApiTerminationForInstanceInRegion() throws SecurityException,
NoSuchMethodException, IOException { NoSuchMethodException, IOException {
Method method = InstanceAsyncClient.class.getMethod( Method method = InstanceAsyncClient.class.getMethod(
"isApiTerminationDisabledForInstanceInRegion", String.class, String.class); "isApiTerminationDisabledForInstanceInRegion", String.class, String.class);
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, "1");
"1");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 96\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 96\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=disableApiTermination&InstanceId=1"); "Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=disableApiTermination&InstanceId=1");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, BooleanValueHandler.class); assertSaxResponseParserClassEquals(method, BooleanValueHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testGetKernelForInstanceInRegion() throws SecurityException, NoSuchMethodException, public void testGetKernelForInstanceInRegion() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = InstanceAsyncClient.class.getMethod("getKernelForInstanceInRegion", Method method = InstanceAsyncClient.class.getMethod("getKernelForInstanceInRegion",
String.class, String.class); String.class, String.class);
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, "1");
"1");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 81\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 81\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=kernel&InstanceId=1"); "Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=kernel&InstanceId=1");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, StringValueHandler.class); assertSaxResponseParserClassEquals(method, StringValueHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testGetInstanceTypeForInstanceInRegion() throws SecurityException, public void testGetInstanceTypeForInstanceInRegion() throws SecurityException,
NoSuchMethodException, IOException { NoSuchMethodException, IOException {
Method method = InstanceAsyncClient.class.getMethod("getInstanceTypeForInstanceInRegion", Method method = InstanceAsyncClient.class.getMethod("getInstanceTypeForInstanceInRegion",
String.class, String.class); String.class, String.class);
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, "1");
"1");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 87\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 87\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=instanceType&InstanceId=1"); "Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=instanceType&InstanceId=1");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, InstanceTypeHandler.class); assertSaxResponseParserClassEquals(method, InstanceTypeHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testGetInstanceInitiatedShutdownBehaviorForInstanceInRegion() public void testGetInstanceInitiatedShutdownBehaviorForInstanceInRegion()
@ -351,109 +338,104 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
Method method = InstanceAsyncClient.class.getMethod( Method method = InstanceAsyncClient.class.getMethod(
"getInstanceInitiatedShutdownBehaviorForInstanceInRegion", String.class, "getInstanceInitiatedShutdownBehaviorForInstanceInRegion", String.class,
String.class); String.class);
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, "1");
"1");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 108\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 108\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=instanceInitiatedShutdownBehavior&InstanceId=1"); "Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=instanceInitiatedShutdownBehavior&InstanceId=1");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, InstanceInitiatedShutdownBehaviorHandler.class); assertSaxResponseParserClassEquals(method, InstanceInitiatedShutdownBehaviorHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testGetBlockDeviceMappingForInstanceInRegion() throws SecurityException, public void testGetBlockDeviceMappingForInstanceInRegion() throws SecurityException,
NoSuchMethodException, IOException { NoSuchMethodException, IOException {
Method method = InstanceAsyncClient.class.getMethod( Method method = InstanceAsyncClient.class.getMethod(
"getBlockDeviceMappingForInstanceInRegion", String.class, String.class); "getBlockDeviceMappingForInstanceInRegion", String.class, String.class);
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, "1");
"1");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 93\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 93\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=blockDeviceMapping&InstanceId=1"); "Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=blockDeviceMapping&InstanceId=1");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, BlockDeviceMappingHandler.class); assertSaxResponseParserClassEquals(method, BlockDeviceMappingHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testSetUserDataForInstanceInRegion() throws SecurityException, public void testSetUserDataForInstanceInRegion() throws SecurityException,
NoSuchMethodException, IOException { NoSuchMethodException, IOException {
Method method = InstanceAsyncClient.class.getMethod("setUserDataForInstanceInRegion", Method method = InstanceAsyncClient.class.getMethod("setUserDataForInstanceInRegion",
String.class, String.class, Array.newInstance(byte.class, 0).getClass()); String.class, String.class, Array.newInstance(byte.class, 0).getClass());
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, "1", "test".getBytes());
"1", "test".getBytes());
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 100\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 100\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=userData&Value=dGVzdA%3D%3D&InstanceId=1"); "Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=userData&Value=dGVzdA%3D%3D&InstanceId=1");
filter.filter(httpMethod);// ensure encoding worked properly filter.filter(request);// ensure encoding worked properly
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"Action=ModifyInstanceAttribute&Attribute=userData&InstanceId=1&Signature=ch%2BpeYTRad241GAhjH9Wo2vKWlkgfNa3txM0lhPCBSM%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Value=dGVzdA%3D%3D&Version=2009-11-30&AWSAccessKeyId=identity"); "Action=ModifyInstanceAttribute&Attribute=userData&InstanceId=1&Signature=ch%2BpeYTRad241GAhjH9Wo2vKWlkgfNa3txM0lhPCBSM%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Value=dGVzdA%3D%3D&Version=2009-11-30&AWSAccessKeyId=identity");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testSetRamdiskForInstanceInRegion() throws SecurityException, NoSuchMethodException, public void testSetRamdiskForInstanceInRegion() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = InstanceAsyncClient.class.getMethod("setRamdiskForInstanceInRegion", Method method = InstanceAsyncClient.class.getMethod("setRamdiskForInstanceInRegion",
String.class, String.class, String.class); String.class, String.class, String.class);
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, "1", "test");
"1", "test");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 91\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 91\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=ramdisk&Value=test&InstanceId=1"); "Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=ramdisk&Value=test&InstanceId=1");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testSetKernelForInstanceInRegion() throws SecurityException, NoSuchMethodException, public void testSetKernelForInstanceInRegion() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = InstanceAsyncClient.class.getMethod("setKernelForInstanceInRegion", Method method = InstanceAsyncClient.class.getMethod("setKernelForInstanceInRegion",
String.class, String.class, String.class); String.class, String.class, String.class);
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, "1", "test");
"1", "test");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 90\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 90\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=kernel&Value=test&InstanceId=1"); "Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=kernel&Value=test&InstanceId=1");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testSetApiTerminationDisabledForInstanceInRegion() throws SecurityException, public void testSetApiTerminationDisabledForInstanceInRegion() throws SecurityException,
@ -461,44 +443,42 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
Method method = InstanceAsyncClient.class.getMethod( Method method = InstanceAsyncClient.class.getMethod(
"setApiTerminationDisabledForInstanceInRegion", String.class, String.class, "setApiTerminationDisabledForInstanceInRegion", String.class, String.class,
boolean.class); boolean.class);
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, "1", true);
"1", true);
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 105\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 105\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=disableApiTermination&Value=true&InstanceId=1"); "Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=disableApiTermination&Value=true&InstanceId=1");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testSetInstanceTypeForInstanceInRegion() throws SecurityException, public void testSetInstanceTypeForInstanceInRegion() throws SecurityException,
NoSuchMethodException, IOException { NoSuchMethodException, IOException {
Method method = InstanceAsyncClient.class.getMethod("setInstanceTypeForInstanceInRegion", Method method = InstanceAsyncClient.class.getMethod("setInstanceTypeForInstanceInRegion",
String.class, String.class, String.class); String.class, String.class, String.class);
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, "1", InstanceType.C1_MEDIUM);
"1", InstanceType.C1_MEDIUM);
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 101\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 101\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=instanceType&Value=c1.medium&InstanceId=1"); "Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=instanceType&Value=c1.medium&InstanceId=1");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testSetInstanceInitiatedShutdownBehaviorForInstanceInRegion() public void testSetInstanceInitiatedShutdownBehaviorForInstanceInRegion()
@ -506,22 +486,22 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
Method method = InstanceAsyncClient.class.getMethod( Method method = InstanceAsyncClient.class.getMethod(
"setInstanceInitiatedShutdownBehaviorForInstanceInRegion", String.class, "setInstanceInitiatedShutdownBehaviorForInstanceInRegion", String.class,
String.class, InstanceInitiatedShutdownBehavior.class); String.class, InstanceInitiatedShutdownBehavior.class);
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, "1",
"1", InstanceInitiatedShutdownBehavior.TERMINATE); InstanceInitiatedShutdownBehavior.TERMINATE);
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 122\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 122\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=instanceInitiatedShutdownBehavior&Value=terminate&InstanceId=1"); "Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=instanceInitiatedShutdownBehavior&Value=terminate&InstanceId=1");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testSetBlockDeviceMappingForInstanceInRegion() throws SecurityException, public void testSetBlockDeviceMappingForInstanceInRegion() throws SecurityException,
@ -533,25 +513,24 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
BlockDeviceMapping blockDeviceMapping = new BlockDeviceMapping(); BlockDeviceMapping blockDeviceMapping = new BlockDeviceMapping();
blockDeviceMapping.addEbsBlockDevice("/dev/sda1", new RunningInstance.EbsBlockDevice( blockDeviceMapping.addEbsBlockDevice("/dev/sda1", new RunningInstance.EbsBlockDevice(
"vol-test1", true)); "vol-test1", true));
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, "1", blockDeviceMapping);
"1", blockDeviceMapping);
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 62\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 62\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"Version=2009-11-30&Action=ModifyInstanceAttribute&InstanceId=1&BlockDeviceMapping.1.Ebs.VolumeId=vol-test1&BlockDeviceMapping.1.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.1.Ebs.DeleteOnTermination=true"); "Version=2009-11-30&Action=ModifyInstanceAttribute&InstanceId=1&BlockDeviceMapping.1.Ebs.VolumeId=vol-test1&BlockDeviceMapping.1.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.1.Ebs.DeleteOnTermination=true");
filter.filter(httpMethod);// ensure encoding worked properly filter.filter(request);// ensure encoding worked properly
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"Action=ModifyInstanceAttribute&BlockDeviceMapping.1.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.1.Ebs.DeleteOnTermination=true&BlockDeviceMapping.1.Ebs.VolumeId=vol-test1&InstanceId=1&Signature=QOd9dFUmgBAsz3b5rWOE2wWgoB85vmhsVM9yNO2s7cE%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Version=2009-11-30&AWSAccessKeyId=identity"); "Action=ModifyInstanceAttribute&BlockDeviceMapping.1.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.1.Ebs.DeleteOnTermination=true&BlockDeviceMapping.1.Ebs.VolumeId=vol-test1&InstanceId=1&Signature=QOd9dFUmgBAsz3b5rWOE2wWgoB85vmhsVM9yNO2s7cE%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Version=2009-11-30&AWSAccessKeyId=identity");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
@Override @Override

View File

@ -23,9 +23,9 @@ import java.lang.reflect.Array;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import org.jclouds.aws.ec2.xml.DescribeKeyPairsResponseHandler; import org.jclouds.aws.ec2.xml.DescribeKeyPairsResponseHandler;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -42,60 +42,57 @@ public class KeyPairAsyncClientTest extends BaseEC2AsyncClientTest<KeyPairAsyncC
public void testDeleteKeyPair() throws SecurityException, NoSuchMethodException, IOException { public void testDeleteKeyPair() throws SecurityException, NoSuchMethodException, IOException {
Method method = KeyPairAsyncClient.class.getMethod("deleteKeyPairInRegion", String.class, Method method = KeyPairAsyncClient.class.getMethod("deleteKeyPairInRegion", String.class,
String.class); String.class);
GeneratedHttpRequest<KeyPairAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, "mykey");
"mykey");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 53\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 53\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, "Version=2009-11-30&Action=DeleteKeyPair&KeyName=mykey"); assertPayloadEquals(request, "Version=2009-11-30&Action=DeleteKeyPair&KeyName=mykey");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testDescribeKeyPairs() throws SecurityException, NoSuchMethodException, IOException { public void testDescribeKeyPairs() throws SecurityException, NoSuchMethodException, IOException {
Method method = KeyPairAsyncClient.class.getMethod("describeKeyPairsInRegion", String.class, Method method = KeyPairAsyncClient.class.getMethod("describeKeyPairsInRegion", String.class,
Array.newInstance(String.class, 0).getClass()); Array.newInstance(String.class, 0).getClass());
GeneratedHttpRequest<KeyPairAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, (String) null);
(String) null);
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 42\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 42\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, "Version=2009-11-30&Action=DescribeKeyPairs"); assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeKeyPairs");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, DescribeKeyPairsResponseHandler.class); assertSaxResponseParserClassEquals(method, DescribeKeyPairsResponseHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testDescribeKeyPairsArgs() throws SecurityException, NoSuchMethodException, public void testDescribeKeyPairsArgs() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = KeyPairAsyncClient.class.getMethod("describeKeyPairsInRegion", String.class, Method method = KeyPairAsyncClient.class.getMethod("describeKeyPairsInRegion", String.class,
Array.newInstance(String.class, 0).getClass()); Array.newInstance(String.class, 0).getClass());
GeneratedHttpRequest<KeyPairAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, "1", "2");
"1", "2");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 42\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 42\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=DescribeKeyPairs&KeyName.1=1&KeyName.2=2"); "Version=2009-11-30&Action=DescribeKeyPairs&KeyName.1=1&KeyName.2=2");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, DescribeKeyPairsResponseHandler.class); assertSaxResponseParserClassEquals(method, DescribeKeyPairsResponseHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
@Override @Override

View File

@ -23,8 +23,8 @@ import java.lang.reflect.Array;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import org.jclouds.aws.ec2.xml.MonitoringStateHandler; import org.jclouds.aws.ec2.xml.MonitoringStateHandler;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -42,41 +42,39 @@ public class MonitoringAsyncClientTest extends BaseEC2AsyncClientTest<Monitoring
IOException { IOException {
Method method = MonitoringAsyncClient.class.getMethod("unmonitorInstancesInRegion", Method method = MonitoringAsyncClient.class.getMethod("unmonitorInstancesInRegion",
String.class, String.class, Array.newInstance(String.class, 0).getClass()); String.class, String.class, Array.newInstance(String.class, 0).getClass());
GeneratedHttpRequest<MonitoringAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, null, "instance1", "instance2");
null, "instance1", "instance2");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 67\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 67\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=UnmonitorInstances&InstanceId.0=instance1&InstanceId.1=instance2"); "Version=2009-11-30&Action=UnmonitorInstances&InstanceId.0=instance1&InstanceId.1=instance2");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, MonitoringStateHandler.class); assertSaxResponseParserClassEquals(method, MonitoringStateHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testMonitorInstances() throws SecurityException, NoSuchMethodException, IOException { public void testMonitorInstances() throws SecurityException, NoSuchMethodException, IOException {
Method method = MonitoringAsyncClient.class.getMethod("monitorInstancesInRegion", Method method = MonitoringAsyncClient.class.getMethod("monitorInstancesInRegion",
String.class, String.class, Array.newInstance(String.class, 0).getClass()); String.class, String.class, Array.newInstance(String.class, 0).getClass());
GeneratedHttpRequest<MonitoringAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, null, "instance1", "instance2");
null, "instance1", "instance2");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 65\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 65\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=MonitorInstances&InstanceId.0=instance1&InstanceId.1=instance2"); "Version=2009-11-30&Action=MonitorInstances&InstanceId.0=instance1&InstanceId.1=instance2");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, MonitoringStateHandler.class); assertSaxResponseParserClassEquals(method, MonitoringStateHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
@Override @Override

View File

@ -26,9 +26,9 @@ import org.jclouds.aws.ec2.domain.IpProtocol;
import org.jclouds.aws.ec2.domain.UserIdGroupPair; import org.jclouds.aws.ec2.domain.UserIdGroupPair;
import org.jclouds.aws.ec2.functions.ReturnVoidOnGroupNotFound; import org.jclouds.aws.ec2.functions.ReturnVoidOnGroupNotFound;
import org.jclouds.aws.ec2.xml.DescribeSecurityGroupsResponseHandler; import org.jclouds.aws.ec2.xml.DescribeSecurityGroupsResponseHandler;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -46,79 +46,78 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest<Securit
IOException { IOException {
Method method = SecurityGroupAsyncClient.class.getMethod("deleteSecurityGroupInRegion", Method method = SecurityGroupAsyncClient.class.getMethod("deleteSecurityGroupInRegion",
String.class, String.class); String.class, String.class);
GeneratedHttpRequest<SecurityGroupAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, null, "name");
null, "name");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(
request,
"Content-Length: 60\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 60\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request, "Version=2009-11-30&Action=DeleteSecurityGroup&GroupName=name");
"Version=2009-11-30&Action=DeleteSecurityGroup&GroupName=name");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnVoidOnGroupNotFound.class); assertExceptionParserClassEquals(method, ReturnVoidOnGroupNotFound.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testCreateSecurityGroup() throws SecurityException, NoSuchMethodException, public void testCreateSecurityGroup() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = SecurityGroupAsyncClient.class.getMethod("createSecurityGroupInRegion", Method method = SecurityGroupAsyncClient.class.getMethod("createSecurityGroupInRegion",
String.class, String.class, String.class); String.class, String.class, String.class);
GeneratedHttpRequest<SecurityGroupAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, null, "name", "description");
null, "name", "description");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(
request,
"Content-Length: 89\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 89\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=CreateSecurityGroup&GroupDescription=description&GroupName=name"); "Version=2009-11-30&Action=CreateSecurityGroup&GroupDescription=description&GroupName=name");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testDescribeSecurityGroups() throws SecurityException, NoSuchMethodException, public void testDescribeSecurityGroups() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = SecurityGroupAsyncClient.class.getMethod("describeSecurityGroupsInRegion", Method method = SecurityGroupAsyncClient.class.getMethod("describeSecurityGroupsInRegion",
String.class, Array.newInstance(String.class, 0).getClass()); String.class, Array.newInstance(String.class, 0).getClass());
GeneratedHttpRequest<SecurityGroupAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, (String) null);
(String) null);
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(
request,
"Content-Length: 48\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 48\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, "Version=2009-11-30&Action=DescribeSecurityGroups"); assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeSecurityGroups");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, DescribeSecurityGroupsResponseHandler.class); assertSaxResponseParserClassEquals(method, DescribeSecurityGroupsResponseHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testDescribeSecurityGroupsArgs() throws SecurityException, NoSuchMethodException, public void testDescribeSecurityGroupsArgs() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = SecurityGroupAsyncClient.class.getMethod("describeSecurityGroupsInRegion", Method method = SecurityGroupAsyncClient.class.getMethod("describeSecurityGroupsInRegion",
String.class, Array.newInstance(String.class, 0).getClass()); String.class, Array.newInstance(String.class, 0).getClass());
GeneratedHttpRequest<SecurityGroupAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, null, "1", "2");
null, "1", "2");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(
request,
"Content-Length: 48\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 48\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-11-30&Action=DescribeSecurityGroups&GroupName.1=1&GroupName.2=2"); "Version=2009-11-30&Action=DescribeSecurityGroups&GroupName.1=1&GroupName.2=2");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, DescribeSecurityGroupsResponseHandler.class); assertSaxResponseParserClassEquals(method, DescribeSecurityGroupsResponseHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testAuthorizeSecurityGroupIngressGroup() throws SecurityException, public void testAuthorizeSecurityGroupIngressGroup() throws SecurityException,
@ -126,21 +125,22 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest<Securit
Method method = SecurityGroupAsyncClient.class.getMethod( Method method = SecurityGroupAsyncClient.class.getMethod(
"authorizeSecurityGroupIngressInRegion", String.class, String.class, "authorizeSecurityGroupIngressInRegion", String.class, String.class,
UserIdGroupPair.class); UserIdGroupPair.class);
GeneratedHttpRequest<SecurityGroupAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, null, "group", new UserIdGroupPair(
null, "group", new UserIdGroupPair("sourceUser", "sourceGroup")); "sourceUser", "sourceGroup"));
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(
request,
"Content-Length: 71\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 71\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"Version=2009-11-30&Action=AuthorizeSecurityGroupIngress&GroupName=group&SourceSecurityGroupOwnerId=sourceUser&SourceSecurityGroupName=sourceGroup"); "Version=2009-11-30&Action=AuthorizeSecurityGroupIngress&GroupName=group&SourceSecurityGroupOwnerId=sourceUser&SourceSecurityGroupName=sourceGroup");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testAuthorizeSecurityGroupIngressCidr() throws SecurityException, public void testAuthorizeSecurityGroupIngressCidr() throws SecurityException,
@ -148,21 +148,22 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest<Securit
Method method = SecurityGroupAsyncClient.class.getMethod( Method method = SecurityGroupAsyncClient.class.getMethod(
"authorizeSecurityGroupIngressInRegion", String.class, String.class, "authorizeSecurityGroupIngressInRegion", String.class, String.class,
IpProtocol.class, int.class, int.class, String.class); IpProtocol.class, int.class, int.class, String.class);
GeneratedHttpRequest<SecurityGroupAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, null, "group", IpProtocol.TCP, 6000,
null, "group", IpProtocol.TCP, 6000, 7000, "0.0.0.0/0"); 7000, "0.0.0.0/0");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(
request,
"Content-Length: 131\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 131\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"Version=2009-11-30&Action=AuthorizeSecurityGroupIngress&CidrIp=0.0.0.0%2F0&IpProtocol=tcp&GroupName=group&FromPort=6000&ToPort=7000"); "Version=2009-11-30&Action=AuthorizeSecurityGroupIngress&CidrIp=0.0.0.0%2F0&IpProtocol=tcp&GroupName=group&FromPort=6000&ToPort=7000");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testRevokeSecurityGroupIngressGroup() throws SecurityException, public void testRevokeSecurityGroupIngressGroup() throws SecurityException,
@ -170,21 +171,22 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest<Securit
Method method = SecurityGroupAsyncClient.class.getMethod( Method method = SecurityGroupAsyncClient.class.getMethod(
"revokeSecurityGroupIngressInRegion", String.class, String.class, "revokeSecurityGroupIngressInRegion", String.class, String.class,
UserIdGroupPair.class); UserIdGroupPair.class);
GeneratedHttpRequest<SecurityGroupAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, null, "group", new UserIdGroupPair(
null, "group", new UserIdGroupPair("sourceUser", "sourceGroup")); "sourceUser", "sourceGroup"));
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(
request,
"Content-Length: 68\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 68\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"Version=2009-11-30&Action=RevokeSecurityGroupIngress&GroupName=group&SourceSecurityGroupOwnerId=sourceUser&SourceSecurityGroupName=sourceGroup"); "Version=2009-11-30&Action=RevokeSecurityGroupIngress&GroupName=group&SourceSecurityGroupOwnerId=sourceUser&SourceSecurityGroupName=sourceGroup");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testRevokeSecurityGroupIngressCidr() throws SecurityException, public void testRevokeSecurityGroupIngressCidr() throws SecurityException,
@ -192,21 +194,22 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest<Securit
Method method = SecurityGroupAsyncClient.class.getMethod( Method method = SecurityGroupAsyncClient.class.getMethod(
"revokeSecurityGroupIngressInRegion", String.class, String.class, IpProtocol.class, "revokeSecurityGroupIngressInRegion", String.class, String.class, IpProtocol.class,
int.class, int.class, String.class); int.class, int.class, String.class);
GeneratedHttpRequest<SecurityGroupAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, null, "group", IpProtocol.TCP, 6000,
null, "group", IpProtocol.TCP, 6000, 7000, "0.0.0.0/0"); 7000, "0.0.0.0/0");
assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(
request,
"Content-Length: 128\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); "Content-Length: 128\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"Version=2009-11-30&Action=RevokeSecurityGroupIngress&CidrIp=0.0.0.0%2F0&IpProtocol=tcp&GroupName=group&FromPort=6000&ToPort=7000"); "Version=2009-11-30&Action=RevokeSecurityGroupIngress&CidrIp=0.0.0.0%2F0&IpProtocol=tcp&GroupName=group&FromPort=6000&ToPort=7000");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
@Override @Override

View File

@ -28,17 +28,16 @@ import javax.inject.Named;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.aws.ec2.xml.RegisterInstancesWithLoadBalancerResponseHandler; import org.jclouds.aws.ec2.xml.RegisterInstancesWithLoadBalancerResponseHandler;
import org.jclouds.aws.elb.ELBAsyncClient;
import org.jclouds.aws.elb.config.ELBRestClientModule; import org.jclouds.aws.elb.config.ELBRestClientModule;
import org.jclouds.aws.filters.FormSigner; import org.jclouds.aws.filters.FormSigner;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextFactory.ContextSpec; import org.jclouds.rest.RestContextFactory.ContextSpec;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -55,28 +54,26 @@ public class ELBAsyncClientTest extends RestClientTest<ELBAsyncClient> {
public void testRegisterInstancesWithLoadBalancer() throws SecurityException, public void testRegisterInstancesWithLoadBalancer() throws SecurityException,
NoSuchMethodException, IOException { NoSuchMethodException, IOException {
Method method = ELBAsyncClient.class.getMethod( Method method = ELBAsyncClient.class.getMethod("registerInstancesWithLoadBalancerInRegion",
"registerInstancesWithLoadBalancerInRegion", String.class, String.class, String.class, String.class, String[].class);
String[].class);
GeneratedHttpRequest<ELBAsyncClient> httpMethod = processor.createRequest( HttpRequest request = processor.createRequest(method, null, "ReferenceAP1", "i-6055fa09");
method, null, "ReferenceAP1", "i-6055fa09");
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"POST https://elasticloadbalancing.us-east-1.amazonaws.com/ HTTP/1.1"); "POST https://elasticloadbalancing.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 89\nContent-Type: application/x-www-form-urlencoded\nHost: elasticloadbalancing.us-east-1.amazonaws.com\n"); "Content-Length: 89\nContent-Type: application/x-www-form-urlencoded\nHost: elasticloadbalancing.us-east-1.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"Version=2009-11-25&Action=RegisterInstancesWithLoadBalancer&LoadBalancerName=ReferenceAP1&Instances.member.1.InstanceId=i-6055fa09"); "Version=2009-11-25&Action=RegisterInstancesWithLoadBalancer&LoadBalancerName=ReferenceAP1&Instances.member.1.InstanceId=i-6055fa09");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, assertSaxResponseParserClassEquals(method,
RegisterInstancesWithLoadBalancerResponseHandler.class); RegisterInstancesWithLoadBalancerResponseHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
@Override @Override
@ -99,6 +96,7 @@ public class ELBAsyncClientTest extends RestClientTest<ELBAsyncClient> {
return "2009-11-08T15:54:08.897Z"; return "2009-11-08T15:54:08.897Z";
} }
} }
@Override @Override
protected Module createModule() { protected Module createModule() {
return new TestELBRestClientModule(); return new TestELBRestClientModule();
@ -111,9 +109,9 @@ public class ELBAsyncClientTest extends RestClientTest<ELBAsyncClient> {
} }
@Override @Override
protected void checkFilters(GeneratedHttpRequest<ELBAsyncClient> httpMethod) { protected void checkFilters(HttpRequest request) {
assertEquals(httpMethod.getFilters().size(), 1); assertEquals(request.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), FormSigner.class); assertEquals(request.getFilters().get(0).getClass(), FormSigner.class);
} }
} }

View File

@ -59,6 +59,7 @@ import org.jclouds.blobstore.functions.ReturnNullOnKeyNotFound;
import org.jclouds.blobstore.functions.ThrowContainerNotFoundOn404; import org.jclouds.blobstore.functions.ThrowContainerNotFoundOn404;
import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404; import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404;
import org.jclouds.date.TimeStamp; import org.jclouds.date.TimeStamp;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.http.functions.ParseETagHeader; import org.jclouds.http.functions.ParseETagHeader;
@ -70,7 +71,6 @@ import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextFactory.ContextSpec; import org.jclouds.rest.RestContextFactory.ContextSpec;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
@ -99,115 +99,112 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
public void testGetBucketLocation() throws SecurityException, NoSuchMethodException, IOException { public void testGetBucketLocation() throws SecurityException, NoSuchMethodException, IOException {
Method method = S3AsyncClient.class.getMethod("getBucketLocation", String.class); Method method = S3AsyncClient.class.getMethod("getBucketLocation", String.class);
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket"); HttpRequest request = processor.createRequest(method, "bucket");
assertRequestLineEquals(httpMethod, "GET https://bucket.s3.amazonaws.com/?location HTTP/1.1"); assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/?location HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n"); assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
filter.filter(httpMethod); filter.filter(request);
assertRequestLineEquals(httpMethod, "GET https://bucket.s3.amazonaws.com/?location HTTP/1.1"); assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/?location HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Authorization: AWS identity:2fFTeYJTDwiJmaAkKj732RjNbOg=\nDate: 2009-11-08T15:54:08.897Z\nHost: bucket.s3.amazonaws.com\n"); "Authorization: AWS identity:2fFTeYJTDwiJmaAkKj732RjNbOg=\nDate: 2009-11-08T15:54:08.897Z\nHost: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, LocationConstraintHandler.class); assertSaxResponseParserClassEquals(method, LocationConstraintHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testGetBucketPayer() throws SecurityException, NoSuchMethodException, IOException { public void testGetBucketPayer() throws SecurityException, NoSuchMethodException, IOException {
Method method = S3AsyncClient.class.getMethod("getBucketPayer", String.class); Method method = S3AsyncClient.class.getMethod("getBucketPayer", String.class);
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket"); HttpRequest request = processor.createRequest(method, "bucket");
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"GET https://bucket.s3.amazonaws.com/?requestPayment HTTP/1.1"); "GET https://bucket.s3.amazonaws.com/?requestPayment HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n"); assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, PayerHandler.class); assertSaxResponseParserClassEquals(method, PayerHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testSetBucketPayerOwner() throws SecurityException, NoSuchMethodException, public void testSetBucketPayerOwner() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = S3AsyncClient.class.getMethod("setBucketPayer", String.class, Payer.class); Method method = S3AsyncClient.class.getMethod("setBucketPayer", String.class, Payer.class);
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket", HttpRequest request = processor.createRequest(method, "bucket", Payer.BUCKET_OWNER);
Payer.BUCKET_OWNER);
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"PUT https://bucket.s3.amazonaws.com/?requestPayment HTTP/1.1"); "PUT https://bucket.s3.amazonaws.com/?requestPayment HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(request,
"Content-Length: 133\nContent-Type: text/xml\nHost: bucket.s3.amazonaws.com\n"); "Content-Length: 133\nContent-Type: text/xml\nHost: bucket.s3.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"<RequestPaymentConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Payer>BucketOwner</Payer></RequestPaymentConfiguration>"); "<RequestPaymentConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Payer>BucketOwner</Payer></RequestPaymentConfiguration>");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testSetBucketPayerRequester() throws SecurityException, NoSuchMethodException, public void testSetBucketPayerRequester() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = S3AsyncClient.class.getMethod("setBucketPayer", String.class, Payer.class); Method method = S3AsyncClient.class.getMethod("setBucketPayer", String.class, Payer.class);
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket", HttpRequest request = processor.createRequest(method, "bucket", Payer.REQUESTER);
Payer.REQUESTER);
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"PUT https://bucket.s3.amazonaws.com/?requestPayment HTTP/1.1"); "PUT https://bucket.s3.amazonaws.com/?requestPayment HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(request,
"Content-Length: 131\nContent-Type: text/xml\nHost: bucket.s3.amazonaws.com\n"); "Content-Length: 131\nContent-Type: text/xml\nHost: bucket.s3.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"<RequestPaymentConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Payer>Requester</Payer></RequestPaymentConfiguration>"); "<RequestPaymentConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Payer>Requester</Payer></RequestPaymentConfiguration>");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testListBucket() throws SecurityException, NoSuchMethodException, IOException { public void testListBucket() throws SecurityException, NoSuchMethodException, IOException {
Method method = S3AsyncClient.class.getMethod("listBucket", String.class, Array.newInstance( Method method = S3AsyncClient.class.getMethod("listBucket", String.class, Array.newInstance(
ListBucketOptions.class, 0).getClass()); ListBucketOptions.class, 0).getClass());
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket"); HttpRequest request = processor.createRequest(method, "bucket");
assertRequestLineEquals(httpMethod, "GET https://bucket.s3.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n"); assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, ListBucketHandler.class); assertSaxResponseParserClassEquals(method, ListBucketHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testBucketExists() throws SecurityException, NoSuchMethodException, IOException { public void testBucketExists() throws SecurityException, NoSuchMethodException, IOException {
Method method = S3AsyncClient.class.getMethod("bucketExists", String.class); Method method = S3AsyncClient.class.getMethod("bucketExists", String.class);
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket"); HttpRequest request = processor.createRequest(method, "bucket");
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request, "HEAD https://bucket.s3.amazonaws.com/?max-keys=0 HTTP/1.1");
"HEAD https://bucket.s3.amazonaws.com/?max-keys=0 HTTP/1.1"); assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n"); assertPayloadEquals(request, null);
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ReturnTrueIf2xx.class); assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnFalseOnContainerNotFound.class); assertExceptionParserClassEquals(method, ReturnFalseOnContainerNotFound.class);
checkFilters(httpMethod); checkFilters(request);
} }
@Test(expectedExceptions = IllegalArgumentException.class) @Test(expectedExceptions = IllegalArgumentException.class)
@ -226,154 +223,148 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
Method method = S3AsyncClient.class Method method = S3AsyncClient.class
.getMethod("copyObject", String.class, String.class, String.class, String.class, .getMethod("copyObject", String.class, String.class, String.class, String.class,
Array.newInstance(CopyObjectOptions.class, 0).getClass()); Array.newInstance(CopyObjectOptions.class, 0).getClass());
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, "sourceBucket", "sourceObject",
"sourceBucket", "sourceObject", "destinationbucket", "destinationObject"); "destinationbucket", "destinationObject");
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"PUT https://destinationbucket.s3.amazonaws.com/destinationObject HTTP/1.1"); "PUT https://destinationbucket.s3.amazonaws.com/destinationObject HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 0\nHost: destinationbucket.s3.amazonaws.com\nx-amz-copy-source: /sourceBucket/sourceObject\n"); "Content-Length: 0\nHost: destinationbucket.s3.amazonaws.com\nx-amz-copy-source: /sourceBucket/sourceObject\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, CopyObjectHandler.class); assertSaxResponseParserClassEquals(method, CopyObjectHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testDeleteBucketIfEmpty() throws SecurityException, NoSuchMethodException, public void testDeleteBucketIfEmpty() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = S3AsyncClient.class.getMethod("deleteBucketIfEmpty", String.class); Method method = S3AsyncClient.class.getMethod("deleteBucketIfEmpty", String.class);
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket"); HttpRequest request = processor.createRequest(method, "bucket");
assertRequestLineEquals(httpMethod, "DELETE https://bucket.s3.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "DELETE https://bucket.s3.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n"); assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ReturnTrueIf2xx.class); assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnTrueOn404OrNotFoundFalseIfNotEmpty.class); assertExceptionParserClassEquals(method, ReturnTrueOn404OrNotFoundFalseIfNotEmpty.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testDeleteObject() throws SecurityException, NoSuchMethodException, IOException { public void testDeleteObject() throws SecurityException, NoSuchMethodException, IOException {
Method method = S3AsyncClient.class.getMethod("deleteObject", String.class, String.class); Method method = S3AsyncClient.class.getMethod("deleteObject", String.class, String.class);
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket", HttpRequest request = processor.createRequest(method, "bucket", "object");
"object");
assertRequestLineEquals(httpMethod, "DELETE https://bucket.s3.amazonaws.com/object HTTP/1.1"); assertRequestLineEquals(request, "DELETE https://bucket.s3.amazonaws.com/object HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n"); assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class); assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testGetBucketACL() throws SecurityException, NoSuchMethodException, IOException { public void testGetBucketACL() throws SecurityException, NoSuchMethodException, IOException {
Method method = S3AsyncClient.class.getMethod("getBucketACL", String.class); Method method = S3AsyncClient.class.getMethod("getBucketACL", String.class);
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket"); HttpRequest request = processor.createRequest(method, "bucket");
assertRequestLineEquals(httpMethod, "GET https://bucket.s3.amazonaws.com/?acl HTTP/1.1"); assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/?acl HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n"); assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, AccessControlListHandler.class); assertSaxResponseParserClassEquals(method, AccessControlListHandler.class);
assertExceptionParserClassEquals(method, ThrowContainerNotFoundOn404.class); assertExceptionParserClassEquals(method, ThrowContainerNotFoundOn404.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testGetObject() throws ArrayIndexOutOfBoundsException, SecurityException, public void testGetObject() throws ArrayIndexOutOfBoundsException, SecurityException,
IllegalArgumentException, NoSuchMethodException, IOException { IllegalArgumentException, NoSuchMethodException, IOException {
Method method = S3AsyncClient.class.getMethod("getObject", String.class, String.class, Array Method method = S3AsyncClient.class.getMethod("getObject", String.class, String.class, Array
.newInstance(GetOptions.class, 0).getClass()); .newInstance(GetOptions.class, 0).getClass());
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket", HttpRequest request = processor.createRequest(method, "bucket", "object");
"object");
assertRequestLineEquals(httpMethod, "GET https://bucket.s3.amazonaws.com/object HTTP/1.1"); assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/object HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n"); assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, assertResponseParserClassEquals(method, request, ParseObjectFromHeadersAndHttpContent.class);
ParseObjectFromHeadersAndHttpContent.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnNullOnKeyNotFound.class); assertExceptionParserClassEquals(method, ReturnNullOnKeyNotFound.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testGetObjectACL() throws SecurityException, NoSuchMethodException, IOException { public void testGetObjectACL() throws SecurityException, NoSuchMethodException, IOException {
Method method = S3AsyncClient.class.getMethod("getObjectACL", String.class, String.class); Method method = S3AsyncClient.class.getMethod("getObjectACL", String.class, String.class);
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket", HttpRequest request = processor.createRequest(method, "bucket", "object");
"object");
assertRequestLineEquals(httpMethod, "GET https://bucket.s3.amazonaws.com/object?acl HTTP/1.1"); assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/object?acl HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n"); assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, AccessControlListHandler.class); assertSaxResponseParserClassEquals(method, AccessControlListHandler.class);
assertExceptionParserClassEquals(method, ThrowKeyNotFoundOn404.class); assertExceptionParserClassEquals(method, ThrowKeyNotFoundOn404.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testObjectExists() throws SecurityException, NoSuchMethodException, IOException { public void testObjectExists() throws SecurityException, NoSuchMethodException, IOException {
Method method = S3AsyncClient.class.getMethod("objectExists", String.class, String.class); Method method = S3AsyncClient.class.getMethod("objectExists", String.class, String.class);
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket", HttpRequest request = processor.createRequest(method, "bucket", "object");
"object");
assertRequestLineEquals(httpMethod, "HEAD https://bucket.s3.amazonaws.com/object HTTP/1.1"); assertRequestLineEquals(request, "HEAD https://bucket.s3.amazonaws.com/object HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n"); assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ReturnTrueIf2xx.class); assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnFalseOnKeyNotFound.class); assertExceptionParserClassEquals(method, ReturnFalseOnKeyNotFound.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testHeadObject() throws SecurityException, NoSuchMethodException, IOException { public void testHeadObject() throws SecurityException, NoSuchMethodException, IOException {
Method method = S3AsyncClient.class.getMethod("headObject", String.class, String.class); Method method = S3AsyncClient.class.getMethod("headObject", String.class, String.class);
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket", HttpRequest request = processor.createRequest(method, "bucket", "object");
"object");
assertRequestLineEquals(httpMethod, "HEAD https://bucket.s3.amazonaws.com/object HTTP/1.1"); assertRequestLineEquals(request, "HEAD https://bucket.s3.amazonaws.com/object HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n"); assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseObjectMetadataFromHeaders.class); assertResponseParserClassEquals(method, request, ParseObjectMetadataFromHeaders.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnNullOnKeyNotFound.class); assertExceptionParserClassEquals(method, ReturnNullOnKeyNotFound.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testListOwnedBuckets() throws SecurityException, NoSuchMethodException, IOException { public void testListOwnedBuckets() throws SecurityException, NoSuchMethodException, IOException {
Method method = S3AsyncClient.class.getMethod("listOwnedBuckets"); Method method = S3AsyncClient.class.getMethod("listOwnedBuckets");
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method); HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(httpMethod, "GET https://s3.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "GET https://s3.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: s3.amazonaws.com\n"); assertHeadersEqual(request, "Host: s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, ListAllMyBucketsHandler.class); assertSaxResponseParserClassEquals(method, ListAllMyBucketsHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testNewS3Object() throws SecurityException, NoSuchMethodException, IOException { public void testNewS3Object() throws SecurityException, NoSuchMethodException, IOException {
@ -384,60 +375,58 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
public void testPutBucketACL() throws SecurityException, NoSuchMethodException, IOException { public void testPutBucketACL() throws SecurityException, NoSuchMethodException, IOException {
Method method = S3AsyncClient.class.getMethod("putBucketACL", String.class, Method method = S3AsyncClient.class.getMethod("putBucketACL", String.class,
AccessControlList.class); AccessControlList.class);
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket", HttpRequest request = processor.createRequest(method, "bucket", AccessControlList
AccessControlList.fromCannedAccessPolicy(CannedAccessPolicy.PRIVATE, "1234")); .fromCannedAccessPolicy(CannedAccessPolicy.PRIVATE, "1234"));
assertRequestLineEquals(httpMethod, "PUT https://bucket.s3.amazonaws.com/?acl HTTP/1.1"); assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/?acl HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(request,
"Content-Length: 321\nContent-Type: text/xml\nHost: bucket.s3.amazonaws.com\n"); "Content-Length: 321\nContent-Type: text/xml\nHost: bucket.s3.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"<AccessControlPolicy xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Owner><ID>1234</ID></Owner><AccessControlList><Grant><Grantee xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"CanonicalUser\"><ID>1234</ID></Grantee><Permission>FULL_CONTROL</Permission></Grant></AccessControlList></AccessControlPolicy>"); "<AccessControlPolicy xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Owner><ID>1234</ID></Owner><AccessControlList><Grant><Grantee xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"CanonicalUser\"><ID>1234</ID></Grantee><Permission>FULL_CONTROL</Permission></Grant></AccessControlList></AccessControlPolicy>");
assertResponseParserClassEquals(method, httpMethod, ReturnTrueIf2xx.class); assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testPutBucketDefault() throws ArrayIndexOutOfBoundsException, SecurityException, public void testPutBucketDefault() throws ArrayIndexOutOfBoundsException, SecurityException,
IllegalArgumentException, NoSuchMethodException, IOException { IllegalArgumentException, NoSuchMethodException, IOException {
Method method = S3AsyncClient.class.getMethod("putBucketInRegion", String.class, Method method = S3AsyncClient.class.getMethod("putBucketInRegion", String.class,
String.class, Array.newInstance(PutBucketOptions.class, 0).getClass()); String.class, Array.newInstance(PutBucketOptions.class, 0).getClass());
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, (String) null, "bucket");
(String) null, "bucket");
assertRequestLineEquals(httpMethod, "PUT https://bucket.s3.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, "Content-Length: 0\nHost: bucket.s3.amazonaws.com\n"); assertHeadersEqual(request, "Content-Length: 0\nHost: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ReturnTrueIf2xx.class); assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnFalseIfBucketAlreadyOwnedByYou.class); assertExceptionParserClassEquals(method, ReturnFalseIfBucketAlreadyOwnedByYou.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testPutBucketEu() throws ArrayIndexOutOfBoundsException, SecurityException, public void testPutBucketEu() throws ArrayIndexOutOfBoundsException, SecurityException,
IllegalArgumentException, NoSuchMethodException, IOException { IllegalArgumentException, NoSuchMethodException, IOException {
Method method = S3AsyncClient.class.getMethod("putBucketInRegion", String.class, Method method = S3AsyncClient.class.getMethod("putBucketInRegion", String.class,
String.class, Array.newInstance(PutBucketOptions.class, 0).getClass()); String.class, Array.newInstance(PutBucketOptions.class, 0).getClass());
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "EU", HttpRequest request = processor.createRequest(method, "EU", "bucket");
"bucket");
assertRequestLineEquals(httpMethod, "PUT https://bucket.s3.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(request,
"Content-Length: 98\nContent-Type: application/unknown\nHost: bucket.s3.amazonaws.com\n"); "Content-Length: 98\nContent-Type: application/unknown\nHost: bucket.s3.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"<CreateBucketConfiguration><LocationConstraint>EU</LocationConstraint></CreateBucketConfiguration>"); "<CreateBucketConfiguration><LocationConstraint>EU</LocationConstraint></CreateBucketConfiguration>");
assertResponseParserClassEquals(method, httpMethod, ReturnTrueIf2xx.class); assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnFalseIfBucketAlreadyOwnedByYou.class); assertExceptionParserClassEquals(method, ReturnFalseIfBucketAlreadyOwnedByYou.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testPutObject() throws ArrayIndexOutOfBoundsException, SecurityException, public void testPutObject() throws ArrayIndexOutOfBoundsException, SecurityException,
@ -445,102 +434,102 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
Method method = S3AsyncClient.class.getMethod("putObject", String.class, S3Object.class, Method method = S3AsyncClient.class.getMethod("putObject", String.class, S3Object.class,
Array.newInstance(PutObjectOptions.class, 0).getClass()); Array.newInstance(PutObjectOptions.class, 0).getClass());
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket", HttpRequest request = processor.createRequest(method, "bucket", blobToS3Object
blobToS3Object.apply(BindBlobToMultipartFormTest.TEST_BLOB)); .apply(BindBlobToMultipartFormTest.TEST_BLOB));
assertRequestLineEquals(httpMethod, "PUT https://bucket.s3.amazonaws.com/hello HTTP/1.1"); assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/hello HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(request,
"Content-Length: 5\nContent-Type: text/plain\nHost: bucket.s3.amazonaws.com\n"); "Content-Length: 5\nContent-Type: text/plain\nHost: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, "hello"); assertPayloadEquals(request, "hello");
assertResponseParserClassEquals(method, httpMethod, ParseETagHeader.class); assertResponseParserClassEquals(method, request, ParseETagHeader.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testPutObjectACL() throws SecurityException, NoSuchMethodException, IOException { public void testPutObjectACL() throws SecurityException, NoSuchMethodException, IOException {
Method method = S3AsyncClient.class.getMethod("putObjectACL", String.class, String.class, Method method = S3AsyncClient.class.getMethod("putObjectACL", String.class, String.class,
AccessControlList.class); AccessControlList.class);
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket", HttpRequest request = processor.createRequest(method, "bucket", "key", AccessControlList
"key", AccessControlList.fromCannedAccessPolicy(CannedAccessPolicy.PRIVATE, "1234")); .fromCannedAccessPolicy(CannedAccessPolicy.PRIVATE, "1234"));
assertRequestLineEquals(httpMethod, "PUT https://bucket.s3.amazonaws.com/key?acl HTTP/1.1"); assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/key?acl HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(request,
"Content-Length: 321\nContent-Type: text/xml\nHost: bucket.s3.amazonaws.com\n"); "Content-Length: 321\nContent-Type: text/xml\nHost: bucket.s3.amazonaws.com\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"<AccessControlPolicy xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Owner><ID>1234</ID></Owner><AccessControlList><Grant><Grantee xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"CanonicalUser\"><ID>1234</ID></Grantee><Permission>FULL_CONTROL</Permission></Grant></AccessControlList></AccessControlPolicy>"); "<AccessControlPolicy xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Owner><ID>1234</ID></Owner><AccessControlList><Grant><Grantee xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"CanonicalUser\"><ID>1234</ID></Grantee><Permission>FULL_CONTROL</Permission></Grant></AccessControlList></AccessControlPolicy>");
assertResponseParserClassEquals(method, httpMethod, ReturnTrueIf2xx.class); assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testGetBucketLogging() throws SecurityException, NoSuchMethodException, IOException { public void testGetBucketLogging() throws SecurityException, NoSuchMethodException, IOException {
Method method = S3AsyncClient.class.getMethod("getBucketLogging", String.class); Method method = S3AsyncClient.class.getMethod("getBucketLogging", String.class);
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket"); HttpRequest request = processor.createRequest(method, "bucket");
assertRequestLineEquals(httpMethod, "GET https://bucket.s3.amazonaws.com/?logging HTTP/1.1"); assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/?logging HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n"); assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, BucketLoggingHandler.class); assertSaxResponseParserClassEquals(method, BucketLoggingHandler.class);
assertExceptionParserClassEquals(method, ThrowContainerNotFoundOn404.class); assertExceptionParserClassEquals(method, ThrowContainerNotFoundOn404.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testDisableBucketLogging() throws SecurityException, NoSuchMethodException, public void testDisableBucketLogging() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = S3AsyncClient.class.getMethod("disableBucketLogging", String.class); Method method = S3AsyncClient.class.getMethod("disableBucketLogging", String.class);
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket"); HttpRequest request = processor.createRequest(method, "bucket");
assertRequestLineEquals(httpMethod, "PUT https://bucket.s3.amazonaws.com/?logging HTTP/1.1"); assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/?logging HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(request,
"Content-Length: 70\nContent-Type: text/xml\nHost: bucket.s3.amazonaws.com\n"); "Content-Length: 70\nContent-Type: text/xml\nHost: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"<BucketLoggingStatus xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"/>"); "<BucketLoggingStatus xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"/>");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testEnableBucketLoggingOwner() throws SecurityException, NoSuchMethodException, public void testEnableBucketLoggingOwner() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = S3AsyncClient.class.getMethod("enableBucketLogging", String.class, Method method = S3AsyncClient.class.getMethod("enableBucketLogging", String.class,
BucketLogging.class); BucketLogging.class);
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket", HttpRequest request = processor.createRequest(method, "bucket", new BucketLogging("mylogs",
new BucketLogging("mylogs", "access_log-", ImmutableSet.<Grant> of(new Grant( "access_log-", ImmutableSet.<Grant> of(new Grant(new EmailAddressGrantee(
new EmailAddressGrantee("adrian@jclouds.org"), Permission.FULL_CONTROL)))); "adrian@jclouds.org"), Permission.FULL_CONTROL))));
assertRequestLineEquals(httpMethod, "PUT https://bucket.s3.amazonaws.com/?logging HTTP/1.1"); assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/?logging HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(request,
"Content-Length: 433\nContent-Type: text/xml\nHost: bucket.s3.amazonaws.com\n"); "Content-Length: 433\nContent-Type: text/xml\nHost: bucket.s3.amazonaws.com\n");
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream( assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream(
"/s3/bucket_logging.xml"))); "/s3/bucket_logging.xml")));
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
BlobToObject blobToS3Object; BlobToObject blobToS3Object;
RequestAuthorizeSignature filter; RequestAuthorizeSignature filter;
@Override @Override
protected void checkFilters(GeneratedHttpRequest<S3AsyncClient> httpMethod) { protected void checkFilters(HttpRequest request) {
assertEquals(httpMethod.getFilters().size(), 1); assertEquals(request.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), RequestAuthorizeSignature.class); assertEquals(request.getFilters().get(0).getClass(), RequestAuthorizeSignature.class);
} }
@Override @Override

View File

@ -38,12 +38,12 @@ import org.jclouds.aws.sqs.options.ListQueuesOptions;
import org.jclouds.aws.sqs.xml.RegexListQueuesResponseHandler; import org.jclouds.aws.sqs.xml.RegexListQueuesResponseHandler;
import org.jclouds.aws.sqs.xml.RegexQueueHandler; import org.jclouds.aws.sqs.xml.RegexQueueHandler;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextFactory.ContextSpec; import org.jclouds.rest.RestContextFactory.ContextSpec;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -78,81 +78,79 @@ public class SQSAsyncClientTest extends RestClientTest<SQSAsyncClient> {
IOException { IOException {
Method method = SQSAsyncClient.class.getMethod("listQueuesInRegion", String.class, Array Method method = SQSAsyncClient.class.getMethod("listQueuesInRegion", String.class, Array
.newInstance(ListQueuesOptions.class, 0).getClass()); .newInstance(ListQueuesOptions.class, 0).getClass());
GeneratedHttpRequest<SQSAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, (String) null);
(String) null);
assertRequestLineEquals(httpMethod, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 36\nContent-Type: application/x-www-form-urlencoded\nHost: sqs.us-east-1.amazonaws.com\n"); "Content-Length: 36\nContent-Type: application/x-www-form-urlencoded\nHost: sqs.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, "Version=2009-02-01&Action=ListQueues"); assertPayloadEquals(request, "Version=2009-02-01&Action=ListQueues");
assertResponseParserClassEquals(method, httpMethod, RegexListQueuesResponseHandler.class); assertResponseParserClassEquals(method, request, RegexListQueuesResponseHandler.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testListQueuesInRegionOptions() throws SecurityException, NoSuchMethodException, public void testListQueuesInRegionOptions() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = SQSAsyncClient.class.getMethod("listQueuesInRegion", String.class, Array Method method = SQSAsyncClient.class.getMethod("listQueuesInRegion", String.class, Array
.newInstance(ListQueuesOptions.class, 0).getClass()); .newInstance(ListQueuesOptions.class, 0).getClass());
GeneratedHttpRequest<SQSAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, ListQueuesOptions.Builder
ListQueuesOptions.Builder.queuePrefix("prefix")); .queuePrefix("prefix"));
assertRequestLineEquals(httpMethod, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 59\nContent-Type: application/x-www-form-urlencoded\nHost: sqs.us-east-1.amazonaws.com\n"); "Content-Length: 59\nContent-Type: application/x-www-form-urlencoded\nHost: sqs.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, "Version=2009-02-01&Action=ListQueues&QueueNamePrefix=prefix"); assertPayloadEquals(request, "Version=2009-02-01&Action=ListQueues&QueueNamePrefix=prefix");
assertResponseParserClassEquals(method, httpMethod, RegexListQueuesResponseHandler.class); assertResponseParserClassEquals(method, request, RegexListQueuesResponseHandler.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testCreateQueueInRegion() throws SecurityException, NoSuchMethodException, public void testCreateQueueInRegion() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = SQSAsyncClient.class.getMethod("createQueueInRegion", String.class, Method method = SQSAsyncClient.class.getMethod("createQueueInRegion", String.class,
String.class, Array.newInstance(CreateQueueOptions.class, 0).getClass()); String.class, Array.newInstance(CreateQueueOptions.class, 0).getClass());
GeneratedHttpRequest<SQSAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, "queueName");
"queueName");
assertRequestLineEquals(httpMethod, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 57\nContent-Type: application/x-www-form-urlencoded\nHost: sqs.us-east-1.amazonaws.com\n"); "Content-Length: 57\nContent-Type: application/x-www-form-urlencoded\nHost: sqs.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, "Version=2009-02-01&Action=CreateQueue&QueueName=queueName"); assertPayloadEquals(request, "Version=2009-02-01&Action=CreateQueue&QueueName=queueName");
assertResponseParserClassEquals(method, httpMethod, RegexQueueHandler.class); assertResponseParserClassEquals(method, request, RegexQueueHandler.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testCreateQueueInRegionOptions() throws SecurityException, NoSuchMethodException, public void testCreateQueueInRegionOptions() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = SQSAsyncClient.class.getMethod("createQueueInRegion", String.class, Method method = SQSAsyncClient.class.getMethod("createQueueInRegion", String.class,
String.class, Array.newInstance(CreateQueueOptions.class, 0).getClass()); String.class, Array.newInstance(CreateQueueOptions.class, 0).getClass());
GeneratedHttpRequest<SQSAsyncClient> httpMethod = processor.createRequest(method, null, HttpRequest request = processor.createRequest(method, null, "queueName",
"queueName", CreateQueueOptions.Builder.defaultVisibilityTimeout(45)); CreateQueueOptions.Builder.defaultVisibilityTimeout(45));
assertRequestLineEquals(httpMethod, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(request, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Content-Length: 85\nContent-Type: application/x-www-form-urlencoded\nHost: sqs.us-east-1.amazonaws.com\n"); "Content-Length: 85\nContent-Type: application/x-www-form-urlencoded\nHost: sqs.us-east-1.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(request,
"Version=2009-02-01&Action=CreateQueue&QueueName=queueName&DefaultVisibilityTimeout=45"); "Version=2009-02-01&Action=CreateQueue&QueueName=queueName&DefaultVisibilityTimeout=45");
assertResponseParserClassEquals(method, httpMethod, RegexQueueHandler.class); assertResponseParserClassEquals(method, request, RegexQueueHandler.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testAllRegions() throws SecurityException, NoSuchMethodException, IOException { public void testAllRegions() throws SecurityException, NoSuchMethodException, IOException {
@ -164,9 +162,9 @@ public class SQSAsyncClientTest extends RestClientTest<SQSAsyncClient> {
} }
@Override @Override
protected void checkFilters(GeneratedHttpRequest<SQSAsyncClient> httpMethod) { protected void checkFilters(HttpRequest request) {
assertEquals(httpMethod.getFilters().size(), 1); assertEquals(request.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), FormSigner.class); assertEquals(request.getFilters().get(0).getClass(), FormSigner.class);
} }
@Override @Override

View File

@ -38,6 +38,7 @@ import org.jclouds.azure.storage.blob.options.ListBlobsOptions;
import org.jclouds.azure.storage.filters.SharedKeyLiteAuthentication; import org.jclouds.azure.storage.filters.SharedKeyLiteAuthentication;
import org.jclouds.azure.storage.options.ListOptions; import org.jclouds.azure.storage.options.ListOptions;
import org.jclouds.blobstore.functions.ReturnNullOnContainerNotFound; import org.jclouds.blobstore.functions.ReturnNullOnContainerNotFound;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReturnTrueIf2xx; import org.jclouds.http.functions.ReturnTrueIf2xx;
@ -47,7 +48,6 @@ import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextFactory.ContextSpec; import org.jclouds.rest.RestContextFactory.ContextSpec;
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -67,16 +67,15 @@ public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClien
Method method = AzureBlobAsyncClient.class.getMethod("listContainers", Array.newInstance( Method method = AzureBlobAsyncClient.class.getMethod("listContainers", Array.newInstance(
ListOptions.class, 0).getClass()); ListOptions.class, 0).getClass());
GeneratedHttpRequest<AzureBlobAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, new Object[] {});
new Object[] {}); assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
assertEquals(httpMethod.getEndpoint().getHost(), "identity.blob.core.windows.net"); assertEquals(request.getEndpoint().getPath(), "/");
assertEquals(httpMethod.getEndpoint().getPath(), "/"); assertEquals(request.getEndpoint().getQuery(), "comp=list");
assertEquals(httpMethod.getEndpoint().getQuery(), "comp=list"); assertEquals(request.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getMethod(), HttpMethod.GET); assertEquals(request.getHeaders().size(), 1);
assertEquals(httpMethod.getHeaders().size(), 1); assertEquals(request.getHeaders().get("x-ms-version"), Collections
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
.singletonList("2009-09-19")); .singletonList("2009-09-19"));
assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseSax.class); assertEquals(processor.createResponseParser(method, request).getClass(), ParseSax.class);
// TODO check generic type of response parser // TODO check generic type of response parser
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
@ -87,19 +86,19 @@ public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClien
Method method = AzureBlobAsyncClient.class.getMethod("listContainers", Array.newInstance( Method method = AzureBlobAsyncClient.class.getMethod("listContainers", Array.newInstance(
ListOptions.class, 0).getClass()); ListOptions.class, 0).getClass());
GeneratedHttpRequest<AzureBlobAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, new Object[] { maxResults(1).marker(
new Object[] { maxResults(1).marker("marker").prefix("prefix") }); "marker").prefix("prefix") });
assertEquals(httpMethod.getEndpoint().getHost(), "identity.blob.core.windows.net"); assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
assertEquals(httpMethod.getEndpoint().getPath(), "/"); assertEquals(request.getEndpoint().getPath(), "/");
assert httpMethod.getEndpoint().getQuery().contains("comp=list"); assert request.getEndpoint().getQuery().contains("comp=list");
assert httpMethod.getEndpoint().getQuery().contains("marker=marker"); assert request.getEndpoint().getQuery().contains("marker=marker");
assert httpMethod.getEndpoint().getQuery().contains("maxresults=1"); assert request.getEndpoint().getQuery().contains("maxresults=1");
assert httpMethod.getEndpoint().getQuery().contains("prefix=prefix"); assert request.getEndpoint().getQuery().contains("prefix=prefix");
assertEquals(httpMethod.getMethod(), HttpMethod.GET); assertEquals(request.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 1); assertEquals(request.getHeaders().size(), 1);
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections assertEquals(request.getHeaders().get("x-ms-version"), Collections
.singletonList("2009-09-19")); .singletonList("2009-09-19"));
assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseSax.class); assertEquals(processor.createResponseParser(method, request).getClass(), ParseSax.class);
// TODO check generic type of response parser // TODO check generic type of response parser
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
@ -110,17 +109,16 @@ public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClien
Method method = AzureBlobAsyncClient.class.getMethod("createContainer", String.class, Array Method method = AzureBlobAsyncClient.class.getMethod("createContainer", String.class, Array
.newInstance(CreateContainerOptions.class, 0).getClass()); .newInstance(CreateContainerOptions.class, 0).getClass());
GeneratedHttpRequest<AzureBlobAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, new Object[] { "container" });
new Object[] { "container" }); assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
assertEquals(httpMethod.getEndpoint().getHost(), "identity.blob.core.windows.net"); assertEquals(request.getEndpoint().getPath(), "/container");
assertEquals(httpMethod.getEndpoint().getPath(), "/container"); assertEquals(request.getEndpoint().getQuery(), "restype=container");
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container"); assertEquals(request.getMethod(), HttpMethod.PUT);
assertEquals(httpMethod.getMethod(), HttpMethod.PUT); assertEquals(request.getHeaders().size(), 2);
assertEquals(httpMethod.getHeaders().size(), 2); assertEquals(request.getHeaders().get("x-ms-version"), Collections
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
.singletonList("2009-09-19")); .singletonList("2009-09-19"));
assertEquals(httpMethod.getHeaders().get("Content-Length"), Collections.singletonList("0")); assertEquals(request.getHeaders().get("Content-Length"), Collections.singletonList("0"));
assertEquals(processor.createResponseParser(method, httpMethod).getClass(), assertEquals(processor.createResponseParser(method, request).getClass(),
ReturnTrueIf2xx.class); ReturnTrueIf2xx.class);
// TODO check generic type of response parser // TODO check generic type of response parser
assertEquals(processor assertEquals(processor
@ -131,16 +129,15 @@ public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClien
public void testDeleteContainer() throws SecurityException, NoSuchMethodException { public void testDeleteContainer() throws SecurityException, NoSuchMethodException {
Method method = AzureBlobAsyncClient.class.getMethod("deleteContainer", String.class); Method method = AzureBlobAsyncClient.class.getMethod("deleteContainer", String.class);
GeneratedHttpRequest<AzureBlobAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, new Object[] { "container" });
new Object[] { "container" }); assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
assertEquals(httpMethod.getEndpoint().getHost(), "identity.blob.core.windows.net"); assertEquals(request.getEndpoint().getPath(), "/container");
assertEquals(httpMethod.getEndpoint().getPath(), "/container"); assertEquals(request.getEndpoint().getQuery(), "restype=container");
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container"); assertEquals(request.getMethod(), HttpMethod.DELETE);
assertEquals(httpMethod.getMethod(), HttpMethod.DELETE); assertEquals(request.getHeaders().size(), 1);
assertEquals(httpMethod.getHeaders().size(), 1); assertEquals(request.getHeaders().get("x-ms-version"), Collections
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
.singletonList("2009-09-19")); .singletonList("2009-09-19"));
assertEquals(processor.createResponseParser(method, httpMethod).getClass(), assertEquals(processor.createResponseParser(method, request).getClass(),
CloseContentAndReturn.class); CloseContentAndReturn.class);
// TODO check generic type of response parser // TODO check generic type of response parser
assertEquals(processor assertEquals(processor
@ -152,21 +149,20 @@ public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClien
Method method = AzureBlobAsyncClient.class.getMethod("createContainer", String.class, Array Method method = AzureBlobAsyncClient.class.getMethod("createContainer", String.class, Array
.newInstance(CreateContainerOptions.class, 0).getClass()); .newInstance(CreateContainerOptions.class, 0).getClass());
GeneratedHttpRequest<AzureBlobAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, new Object[] { "container",
new Object[] { "container",
withPublicAcl().withMetadata(ImmutableMultimap.of("foo", "bar")) }); withPublicAcl().withMetadata(ImmutableMultimap.of("foo", "bar")) });
assertEquals(httpMethod.getEndpoint().getHost(), "identity.blob.core.windows.net"); assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
assertEquals(httpMethod.getEndpoint().getPath(), "/container"); assertEquals(request.getEndpoint().getPath(), "/container");
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container"); assertEquals(request.getEndpoint().getQuery(), "restype=container");
assertEquals(httpMethod.getMethod(), HttpMethod.PUT); assertEquals(request.getMethod(), HttpMethod.PUT);
assertEquals(httpMethod.getHeaders().size(), 4); assertEquals(request.getHeaders().size(), 4);
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections assertEquals(request.getHeaders().get("x-ms-version"), Collections
.singletonList("2009-09-19")); .singletonList("2009-09-19"));
assertEquals(httpMethod.getHeaders().get("x-ms-meta-foo"), Collections.singletonList("bar")); assertEquals(request.getHeaders().get("x-ms-meta-foo"), Collections.singletonList("bar"));
assertEquals(httpMethod.getHeaders().get("x-ms-prop-publicaccess"), Collections assertEquals(request.getHeaders().get("x-ms-prop-publicaccess"), Collections
.singletonList("true")); .singletonList("true"));
assertEquals(httpMethod.getHeaders().get("Content-Length"), Collections.singletonList("0")); assertEquals(request.getHeaders().get("Content-Length"), Collections.singletonList("0"));
assertEquals(processor.createResponseParser(method, httpMethod).getClass(), assertEquals(processor.createResponseParser(method, request).getClass(),
ReturnTrueIf2xx.class); ReturnTrueIf2xx.class);
// TODO check generic type of response parser // TODO check generic type of response parser
assertEquals(processor assertEquals(processor
@ -178,17 +174,16 @@ public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClien
Method method = AzureBlobAsyncClient.class.getMethod("createRootContainer", Array Method method = AzureBlobAsyncClient.class.getMethod("createRootContainer", Array
.newInstance(CreateContainerOptions.class, 0).getClass()); .newInstance(CreateContainerOptions.class, 0).getClass());
GeneratedHttpRequest<AzureBlobAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, new Object[] {});
new Object[] {}); assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
assertEquals(httpMethod.getEndpoint().getHost(), "identity.blob.core.windows.net"); assertEquals(request.getEndpoint().getPath(), "/$root");
assertEquals(httpMethod.getEndpoint().getPath(), "/$root"); assertEquals(request.getEndpoint().getQuery(), "restype=container");
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container"); assertEquals(request.getMethod(), HttpMethod.PUT);
assertEquals(httpMethod.getMethod(), HttpMethod.PUT); assertEquals(request.getHeaders().size(), 2);
assertEquals(httpMethod.getHeaders().size(), 2); assertEquals(request.getHeaders().get("x-ms-version"), Collections
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
.singletonList("2009-09-19")); .singletonList("2009-09-19"));
assertEquals(httpMethod.getHeaders().get("Content-Length"), Collections.singletonList("0")); assertEquals(request.getHeaders().get("Content-Length"), Collections.singletonList("0"));
assertEquals(processor.createResponseParser(method, httpMethod).getClass(), assertEquals(processor.createResponseParser(method, request).getClass(),
ReturnTrueIf2xx.class); ReturnTrueIf2xx.class);
// TODO check generic type of response parser // TODO check generic type of response parser
assertEquals(processor assertEquals(processor
@ -199,16 +194,15 @@ public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClien
public void testDeleteRootContainer() throws SecurityException, NoSuchMethodException { public void testDeleteRootContainer() throws SecurityException, NoSuchMethodException {
Method method = AzureBlobAsyncClient.class.getMethod("deleteRootContainer"); Method method = AzureBlobAsyncClient.class.getMethod("deleteRootContainer");
GeneratedHttpRequest<AzureBlobAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, new Object[] {});
new Object[] {}); assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
assertEquals(httpMethod.getEndpoint().getHost(), "identity.blob.core.windows.net"); assertEquals(request.getEndpoint().getPath(), "/$root");
assertEquals(httpMethod.getEndpoint().getPath(), "/$root"); assertEquals(request.getEndpoint().getQuery(), "restype=container");
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container"); assertEquals(request.getMethod(), HttpMethod.DELETE);
assertEquals(httpMethod.getMethod(), HttpMethod.DELETE); assertEquals(request.getHeaders().size(), 1);
assertEquals(httpMethod.getHeaders().size(), 1); assertEquals(request.getHeaders().get("x-ms-version"), Collections
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
.singletonList("2009-09-19")); .singletonList("2009-09-19"));
assertEquals(processor.createResponseParser(method, httpMethod).getClass(), assertEquals(processor.createResponseParser(method, request).getClass(),
CloseContentAndReturn.class); CloseContentAndReturn.class);
// TODO check generic type of response parser // TODO check generic type of response parser
assertEquals(processor assertEquals(processor
@ -220,20 +214,20 @@ public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClien
Method method = AzureBlobAsyncClient.class.getMethod("createRootContainer", Array Method method = AzureBlobAsyncClient.class.getMethod("createRootContainer", Array
.newInstance(CreateContainerOptions.class, 0).getClass()); .newInstance(CreateContainerOptions.class, 0).getClass());
GeneratedHttpRequest<AzureBlobAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, new Object[] { withPublicAcl()
new Object[] { withPublicAcl().withMetadata(ImmutableMultimap.of("foo", "bar")) }); .withMetadata(ImmutableMultimap.of("foo", "bar")) });
assertEquals(httpMethod.getEndpoint().getHost(), "identity.blob.core.windows.net"); assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
assertEquals(httpMethod.getEndpoint().getPath(), "/$root"); assertEquals(request.getEndpoint().getPath(), "/$root");
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container"); assertEquals(request.getEndpoint().getQuery(), "restype=container");
assertEquals(httpMethod.getMethod(), HttpMethod.PUT); assertEquals(request.getMethod(), HttpMethod.PUT);
assertEquals(httpMethod.getHeaders().size(), 4); assertEquals(request.getHeaders().size(), 4);
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections assertEquals(request.getHeaders().get("x-ms-version"), Collections
.singletonList("2009-09-19")); .singletonList("2009-09-19"));
assertEquals(httpMethod.getHeaders().get("x-ms-meta-foo"), Collections.singletonList("bar")); assertEquals(request.getHeaders().get("x-ms-meta-foo"), Collections.singletonList("bar"));
assertEquals(httpMethod.getHeaders().get("x-ms-prop-publicaccess"), Collections assertEquals(request.getHeaders().get("x-ms-prop-publicaccess"), Collections
.singletonList("true")); .singletonList("true"));
assertEquals(httpMethod.getHeaders().get("Content-Length"), Collections.singletonList("0")); assertEquals(request.getHeaders().get("Content-Length"), Collections.singletonList("0"));
assertEquals(processor.createResponseParser(method, httpMethod).getClass(), assertEquals(processor.createResponseParser(method, request).getClass(),
ReturnTrueIf2xx.class); ReturnTrueIf2xx.class);
// TODO check generic type of response parser // TODO check generic type of response parser
assertEquals(processor assertEquals(processor
@ -245,16 +239,15 @@ public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClien
Method method = AzureBlobAsyncClient.class.getMethod("listBlobs", String.class, Array Method method = AzureBlobAsyncClient.class.getMethod("listBlobs", String.class, Array
.newInstance(ListBlobsOptions.class, 0).getClass()); .newInstance(ListBlobsOptions.class, 0).getClass());
GeneratedHttpRequest<AzureBlobAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, new Object[] { "container" });
new Object[] { "container" }); assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
assertEquals(httpMethod.getEndpoint().getHost(), "identity.blob.core.windows.net"); assertEquals(request.getEndpoint().getPath(), "/container");
assertEquals(httpMethod.getEndpoint().getPath(), "/container"); assertEquals(request.getEndpoint().getQuery(), "restype=container&comp=list");
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container&comp=list"); assertEquals(request.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getMethod(), HttpMethod.GET); assertEquals(request.getHeaders().size(), 1);
assertEquals(httpMethod.getHeaders().size(), 1); assertEquals(request.getHeaders().get("x-ms-version"), Collections
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
.singletonList("2009-09-19")); .singletonList("2009-09-19"));
assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseSax.class); assertEquals(processor.createResponseParser(method, request).getClass(), ParseSax.class);
// TODO check generic type of response parser // TODO check generic type of response parser
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
@ -265,16 +258,15 @@ public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClien
Method method = AzureBlobAsyncClient.class.getMethod("listBlobs", Array.newInstance( Method method = AzureBlobAsyncClient.class.getMethod("listBlobs", Array.newInstance(
ListBlobsOptions.class, 0).getClass()); ListBlobsOptions.class, 0).getClass());
GeneratedHttpRequest<AzureBlobAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, new Object[] {});
new Object[] {}); assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
assertEquals(httpMethod.getEndpoint().getHost(), "identity.blob.core.windows.net"); assertEquals(request.getEndpoint().getPath(), "/$root");
assertEquals(httpMethod.getEndpoint().getPath(), "/$root"); assertEquals(request.getEndpoint().getQuery(), "restype=container&comp=list");
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container&comp=list"); assertEquals(request.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getMethod(), HttpMethod.GET); assertEquals(request.getHeaders().size(), 1);
assertEquals(httpMethod.getHeaders().size(), 1); assertEquals(request.getHeaders().get("x-ms-version"), Collections
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
.singletonList("2009-09-19")); .singletonList("2009-09-19"));
assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseSax.class); assertEquals(processor.createResponseParser(method, request).getClass(), ParseSax.class);
// TODO check generic type of response parser // TODO check generic type of response parser
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
@ -284,16 +276,15 @@ public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClien
public void testContainerProperties() throws SecurityException, NoSuchMethodException { public void testContainerProperties() throws SecurityException, NoSuchMethodException {
Method method = AzureBlobAsyncClient.class.getMethod("getContainerProperties", String.class); Method method = AzureBlobAsyncClient.class.getMethod("getContainerProperties", String.class);
GeneratedHttpRequest<AzureBlobAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, new Object[] { "container" });
new Object[] { "container" }); assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
assertEquals(httpMethod.getEndpoint().getHost(), "identity.blob.core.windows.net"); assertEquals(request.getEndpoint().getPath(), "/container");
assertEquals(httpMethod.getEndpoint().getPath(), "/container"); assertEquals(request.getEndpoint().getQuery(), "restype=container");
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container"); assertEquals(request.getMethod(), HttpMethod.HEAD);
assertEquals(httpMethod.getMethod(), HttpMethod.HEAD); assertEquals(request.getHeaders().size(), 1);
assertEquals(httpMethod.getHeaders().size(), 1); assertEquals(request.getHeaders().get("x-ms-version"), Collections
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
.singletonList("2009-09-19")); .singletonList("2009-09-19"));
assertEquals(processor.createResponseParser(method, httpMethod).getClass(), assertEquals(processor.createResponseParser(method, request).getClass(),
ParseContainerPropertiesFromHeaders.class); ParseContainerPropertiesFromHeaders.class);
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
@ -304,20 +295,20 @@ public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClien
Method method = AzureBlobAsyncClient.class.getMethod("setResourceMetadata", String.class, Method method = AzureBlobAsyncClient.class.getMethod("setResourceMetadata", String.class,
Map.class); Map.class);
GeneratedHttpRequest<AzureBlobAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, new Object[] { "container",
new Object[] { "container", ImmutableMap.of("key", "value") }); ImmutableMap.of("key", "value") });
assertEquals(httpMethod.getEndpoint().getHost(), "identity.blob.core.windows.net"); assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
assertEquals(httpMethod.getEndpoint().getPath(), "/container"); assertEquals(request.getEndpoint().getPath(), "/container");
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container&comp=metadata"); assertEquals(request.getEndpoint().getQuery(), "restype=container&comp=metadata");
assertEquals(httpMethod.getMethod(), HttpMethod.PUT); assertEquals(request.getMethod(), HttpMethod.PUT);
assertEquals(httpMethod.getHeaders().size(), 3); assertEquals(request.getHeaders().size(), 3);
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections
.singletonList("0")); .singletonList("0"));
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections assertEquals(request.getHeaders().get("x-ms-version"), Collections
.singletonList("2009-09-19")); .singletonList("2009-09-19"));
assertEquals(httpMethod.getHeaders().get("x-ms-meta-key"), Collections.singletonList("value")); assertEquals(request.getHeaders().get("x-ms-meta-key"), Collections.singletonList("value"));
assertEquals(processor.createResponseParser(method, httpMethod).getClass(), assertEquals(processor.createResponseParser(method, request).getClass(),
CloseContentAndReturn.class); CloseContentAndReturn.class);
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
@ -327,20 +318,20 @@ public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClien
public void testSetBlobMetadata() throws SecurityException, NoSuchMethodException { public void testSetBlobMetadata() throws SecurityException, NoSuchMethodException {
Method method = AzureBlobAsyncClient.class.getMethod("setBlobMetadata", String.class, Method method = AzureBlobAsyncClient.class.getMethod("setBlobMetadata", String.class,
String.class, Map.class); String.class, Map.class);
GeneratedHttpRequest<AzureBlobAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, new Object[] { "container", "blob",
new Object[] { "container", "blob", ImmutableMap.of("key", "value") }); ImmutableMap.of("key", "value") });
assertEquals(httpMethod.getEndpoint().getHost(), "identity.blob.core.windows.net"); assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
assertEquals(httpMethod.getEndpoint().getPath(), "/container/blob"); assertEquals(request.getEndpoint().getPath(), "/container/blob");
assertEquals(httpMethod.getEndpoint().getQuery(), "comp=metadata"); assertEquals(request.getEndpoint().getQuery(), "comp=metadata");
assertEquals(httpMethod.getMethod(), HttpMethod.PUT); assertEquals(request.getMethod(), HttpMethod.PUT);
assertEquals(httpMethod.getHeaders().size(), 3); assertEquals(request.getHeaders().size(), 3);
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections assertEquals(request.getHeaders().get("x-ms-version"), Collections
.singletonList("2009-09-19")); .singletonList("2009-09-19"));
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections
.singletonList("0")); .singletonList("0"));
assertEquals(httpMethod.getHeaders().get("x-ms-meta-key"), Collections.singletonList("value")); assertEquals(request.getHeaders().get("x-ms-meta-key"), Collections.singletonList("value"));
assertEquals(processor.createResponseParser(method, httpMethod).getClass(), assertEquals(processor.createResponseParser(method, request).getClass(),
CloseContentAndReturn.class); CloseContentAndReturn.class);
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
@ -348,9 +339,9 @@ public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClien
} }
@Override @Override
protected void checkFilters(GeneratedHttpRequest<AzureBlobAsyncClient> httpMethod) { protected void checkFilters(HttpRequest request) {
assertEquals(httpMethod.getFilters().size(), 1); assertEquals(request.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class); assertEquals(request.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class);
} }
@Override @Override

View File

@ -35,13 +35,13 @@ import org.jclouds.azure.storage.queue.options.GetOptions;
import org.jclouds.azure.storage.queue.options.PutMessageOptions; import org.jclouds.azure.storage.queue.options.PutMessageOptions;
import org.jclouds.azure.storage.queue.xml.AccountNameEnumerationResultsHandler; import org.jclouds.azure.storage.queue.xml.AccountNameEnumerationResultsHandler;
import org.jclouds.azure.storage.queue.xml.QueueMessagesListHandler; import org.jclouds.azure.storage.queue.xml.QueueMessagesListHandler;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReturnTrueIf2xx; import org.jclouds.http.functions.ReturnTrueIf2xx;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextFactory.ContextSpec; import org.jclouds.rest.RestContextFactory.ContextSpec;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -59,91 +59,88 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
public void testGetMessages() throws SecurityException, NoSuchMethodException, IOException { public void testGetMessages() throws SecurityException, NoSuchMethodException, IOException {
Method method = AzureQueueAsyncClient.class.getMethod("getMessages", String.class, Method method = AzureQueueAsyncClient.class.getMethod("getMessages", String.class,
GetOptions[].class); GetOptions[].class);
GeneratedHttpRequest<AzureQueueAsyncClient> httpRequest = processor.createRequest(method, HttpRequest request = processor.createRequest(method, "myqueue");
"myqueue");
assertRequestLineEquals(httpRequest, assertRequestLineEquals(request,
"GET https://identity.queue.core.windows.net/myqueue/messages HTTP/1.1"); "GET https://identity.queue.core.windows.net/myqueue/messages HTTP/1.1");
assertHeadersEqual(httpRequest, "x-ms-version: 2009-09-19\n"); assertHeadersEqual(request, "x-ms-version: 2009-09-19\n");
assertPayloadEquals(httpRequest, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpRequest, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, QueueMessagesListHandler.class); assertSaxResponseParserClassEquals(method, QueueMessagesListHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest); checkFilters(request);
} }
public void testGetMessagesOptions() throws SecurityException, NoSuchMethodException, public void testGetMessagesOptions() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = AzureQueueAsyncClient.class.getMethod("getMessages", String.class, Method method = AzureQueueAsyncClient.class.getMethod("getMessages", String.class,
GetOptions[].class); GetOptions[].class);
GeneratedHttpRequest<AzureQueueAsyncClient> httpRequest = processor.createRequest(method, HttpRequest request = processor.createRequest(method, "myqueue", maxMessages(1)
"myqueue", maxMessages(1).visibilityTimeout(30)); .visibilityTimeout(30));
assertRequestLineEquals( assertRequestLineEquals(
httpRequest, request,
"GET https://identity.queue.core.windows.net/myqueue/messages?numofmessages=1&visibilitytimeout=30 HTTP/1.1"); "GET https://identity.queue.core.windows.net/myqueue/messages?numofmessages=1&visibilitytimeout=30 HTTP/1.1");
assertHeadersEqual(httpRequest, "x-ms-version: 2009-09-19\n"); assertHeadersEqual(request, "x-ms-version: 2009-09-19\n");
assertPayloadEquals(httpRequest, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpRequest, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, QueueMessagesListHandler.class); assertSaxResponseParserClassEquals(method, QueueMessagesListHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest); checkFilters(request);
} }
public void testListQueues() throws SecurityException, NoSuchMethodException, IOException { public void testListQueues() throws SecurityException, NoSuchMethodException, IOException {
Method method = AzureQueueAsyncClient.class.getMethod("listQueues", ListOptions[].class); Method method = AzureQueueAsyncClient.class.getMethod("listQueues", ListOptions[].class);
GeneratedHttpRequest<AzureQueueAsyncClient> httpRequest = processor.createRequest(method); HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(httpRequest, assertRequestLineEquals(request,
"GET https://identity.queue.core.windows.net/?comp=list HTTP/1.1"); "GET https://identity.queue.core.windows.net/?comp=list HTTP/1.1");
assertHeadersEqual(httpRequest, "x-ms-version: 2009-09-19\n"); assertHeadersEqual(request, "x-ms-version: 2009-09-19\n");
assertPayloadEquals(httpRequest, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpRequest, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, AccountNameEnumerationResultsHandler.class); assertSaxResponseParserClassEquals(method, AccountNameEnumerationResultsHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest); checkFilters(request);
} }
public void testListQueuesOptions() throws SecurityException, NoSuchMethodException, IOException { public void testListQueuesOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = AzureQueueAsyncClient.class.getMethod("listQueues", ListOptions[].class); Method method = AzureQueueAsyncClient.class.getMethod("listQueues", ListOptions[].class);
GeneratedHttpRequest<AzureQueueAsyncClient> httpRequest = processor.createRequest(method, HttpRequest request = processor.createRequest(method, maxResults(1).marker("marker").prefix(
maxResults(1).marker("marker").prefix("prefix")); "prefix"));
assertRequestLineEquals( assertRequestLineEquals(
httpRequest, request,
"GET https://identity.queue.core.windows.net/?comp=list&maxresults=1&marker=marker&prefix=prefix HTTP/1.1"); "GET https://identity.queue.core.windows.net/?comp=list&maxresults=1&marker=marker&prefix=prefix HTTP/1.1");
assertHeadersEqual(httpRequest, "x-ms-version: 2009-09-19\n"); assertHeadersEqual(request, "x-ms-version: 2009-09-19\n");
assertPayloadEquals(httpRequest, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpRequest, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, AccountNameEnumerationResultsHandler.class); assertSaxResponseParserClassEquals(method, AccountNameEnumerationResultsHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest); checkFilters(request);
} }
public void testCreateQueue() throws SecurityException, NoSuchMethodException, IOException { public void testCreateQueue() throws SecurityException, NoSuchMethodException, IOException {
Method method = AzureQueueAsyncClient.class.getMethod("createQueue", String.class, Method method = AzureQueueAsyncClient.class.getMethod("createQueue", String.class,
CreateOptions[].class); CreateOptions[].class);
GeneratedHttpRequest<AzureQueueAsyncClient> httpRequest = processor.createRequest(method, HttpRequest request = processor.createRequest(method, "queue");
"queue");
assertRequestLineEquals(httpRequest, assertRequestLineEquals(request, "PUT https://identity.queue.core.windows.net/queue HTTP/1.1");
"PUT https://identity.queue.core.windows.net/queue HTTP/1.1"); assertHeadersEqual(request, "Content-Length: 0\nx-ms-version: 2009-09-19\n");
assertHeadersEqual(httpRequest, "Content-Length: 0\nx-ms-version: 2009-09-19\n"); assertPayloadEquals(request, null);
assertPayloadEquals(httpRequest, null);
assertResponseParserClassEquals(method, httpRequest, ReturnTrueIf2xx.class); assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest); checkFilters(request);
} }
public void testCreateQueueOptions() throws SecurityException, NoSuchMethodException, public void testCreateQueueOptions() throws SecurityException, NoSuchMethodException,
@ -151,38 +148,36 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
Method method = AzureQueueAsyncClient.class.getMethod("createQueue", String.class, Method method = AzureQueueAsyncClient.class.getMethod("createQueue", String.class,
CreateOptions[].class); CreateOptions[].class);
GeneratedHttpRequest<AzureQueueAsyncClient> httpRequest = processor.createRequest(method, HttpRequest request = processor.createRequest(method, "queue", withMetadata(ImmutableMultimap
"queue", withMetadata(ImmutableMultimap.of("foo", "bar"))); .of("foo", "bar")));
assertRequestLineEquals(httpRequest, assertRequestLineEquals(request, "PUT https://identity.queue.core.windows.net/queue HTTP/1.1");
"PUT https://identity.queue.core.windows.net/queue HTTP/1.1"); assertHeadersEqual(request,
assertHeadersEqual(httpRequest,
"Content-Length: 0\nx-ms-meta-foo: bar\nx-ms-version: 2009-09-19\n"); "Content-Length: 0\nx-ms-meta-foo: bar\nx-ms-version: 2009-09-19\n");
assertPayloadEquals(httpRequest, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpRequest, ReturnTrueIf2xx.class); assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest); checkFilters(request);
} }
public void testDeleteQueue() throws SecurityException, NoSuchMethodException, IOException { public void testDeleteQueue() throws SecurityException, NoSuchMethodException, IOException {
Method method = AzureQueueAsyncClient.class.getMethod("deleteQueue", String.class); Method method = AzureQueueAsyncClient.class.getMethod("deleteQueue", String.class);
GeneratedHttpRequest<AzureQueueAsyncClient> httpRequest = processor.createRequest(method, HttpRequest request = processor.createRequest(method, "queue");
"queue");
assertRequestLineEquals(httpRequest, assertRequestLineEquals(request,
"DELETE https://identity.queue.core.windows.net/queue HTTP/1.1"); "DELETE https://identity.queue.core.windows.net/queue HTTP/1.1");
assertHeadersEqual(httpRequest, "x-ms-version: 2009-09-19\n"); assertHeadersEqual(request, "x-ms-version: 2009-09-19\n");
assertPayloadEquals(httpRequest, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpRequest, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest); checkFilters(request);
} }
@ -190,66 +185,63 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
Method method = AzureQueueAsyncClient.class.getMethod("putMessage", String.class, Method method = AzureQueueAsyncClient.class.getMethod("putMessage", String.class,
String.class, PutMessageOptions[].class); String.class, PutMessageOptions[].class);
GeneratedHttpRequest<AzureQueueAsyncClient> httpRequest = processor.createRequest(method, HttpRequest request = processor.createRequest(method, "queue", "message");
"queue", "message");
assertRequestLineEquals(httpRequest, assertRequestLineEquals(request,
"POST https://identity.queue.core.windows.net/queue/messages HTTP/1.1"); "POST https://identity.queue.core.windows.net/queue/messages HTTP/1.1");
assertHeadersEqual(httpRequest, assertHeadersEqual(request,
"Content-Length: 63\nContent-Type: application/unknown\nx-ms-version: 2009-09-19\n"); "Content-Length: 63\nContent-Type: application/unknown\nx-ms-version: 2009-09-19\n");
assertPayloadEquals(httpRequest, assertPayloadEquals(request,
"<QueueMessage><MessageText>message</MessageText></QueueMessage>"); "<QueueMessage><MessageText>message</MessageText></QueueMessage>");
assertResponseParserClassEquals(method, httpRequest, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest); checkFilters(request);
} }
public void testPutMessageOptions() throws SecurityException, NoSuchMethodException, IOException { public void testPutMessageOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = AzureQueueAsyncClient.class.getMethod("putMessage", String.class, Method method = AzureQueueAsyncClient.class.getMethod("putMessage", String.class,
String.class, PutMessageOptions[].class); String.class, PutMessageOptions[].class);
GeneratedHttpRequest<AzureQueueAsyncClient> httpRequest = processor.createRequest(method, HttpRequest request = processor.createRequest(method, "queue", "message", withTTL(3));
"queue", "message", withTTL(3));
assertRequestLineEquals(httpRequest, assertRequestLineEquals(request,
"POST https://identity.queue.core.windows.net/queue/messages?messagettl=3 HTTP/1.1"); "POST https://identity.queue.core.windows.net/queue/messages?messagettl=3 HTTP/1.1");
assertHeadersEqual(httpRequest, assertHeadersEqual(request,
"Content-Length: 63\nContent-Type: application/unknown\nx-ms-version: 2009-09-19\n"); "Content-Length: 63\nContent-Type: application/unknown\nx-ms-version: 2009-09-19\n");
assertPayloadEquals(httpRequest, assertPayloadEquals(request,
"<QueueMessage><MessageText>message</MessageText></QueueMessage>"); "<QueueMessage><MessageText>message</MessageText></QueueMessage>");
assertResponseParserClassEquals(method, httpRequest, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest); checkFilters(request);
} }
public void testClearMessages() throws SecurityException, NoSuchMethodException, IOException { public void testClearMessages() throws SecurityException, NoSuchMethodException, IOException {
Method method = AzureQueueAsyncClient.class.getMethod("clearMessages", String.class); Method method = AzureQueueAsyncClient.class.getMethod("clearMessages", String.class);
GeneratedHttpRequest<AzureQueueAsyncClient> httpRequest = processor.createRequest(method, HttpRequest request = processor.createRequest(method, "queue");
"queue");
assertRequestLineEquals(httpRequest, assertRequestLineEquals(request,
"DELETE https://identity.queue.core.windows.net/queue/messages HTTP/1.1"); "DELETE https://identity.queue.core.windows.net/queue/messages HTTP/1.1");
assertHeadersEqual(httpRequest, "x-ms-version: 2009-09-19\n"); assertHeadersEqual(request, "x-ms-version: 2009-09-19\n");
assertPayloadEquals(httpRequest, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpRequest, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest); checkFilters(request);
} }
@Override @Override
protected void checkFilters(GeneratedHttpRequest<AzureQueueAsyncClient> httpMethod) { protected void checkFilters(HttpRequest request) {
assertEquals(httpMethod.getFilters().size(), 1); assertEquals(request.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class); assertEquals(request.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class);
} }
@Override @Override

View File

@ -111,8 +111,7 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore {
ConcurrentMap<String, Location> containerToLocation, ConcurrentMap<String, Location> containerToLocation,
HttpGetOptionsListToGetOptions httpGetOptionsConverter, HttpGetOptionsListToGetOptions httpGetOptionsConverter,
IfDirectoryReturnNameStrategy ifDirectoryReturnName, Blob.Factory blobFactory, IfDirectoryReturnNameStrategy ifDirectoryReturnName, Blob.Factory blobFactory,
BlobUtils blobUtils, BlobUtils blobUtils, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service,
Location defaultLocation, Set<Location> locations) { Location defaultLocation, Set<Location> locations) {
super(context, blobUtils, service, defaultLocation, locations); super(context, blobUtils, service, defaultLocation, locations);
this.blobFactory = blobFactory; this.blobFactory = blobFactory;
@ -446,12 +445,6 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore {
return false; return false;
} }
public void changeSchemeHostAndPortTo(String scheme, String host, int port) {
}
public void changeToGETRequest() {
}
public Exception getException() { public Exception getException() {
return null; return null;
} }
@ -472,9 +465,6 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore {
} }
@Override
public void changePathTo(String newPath) {
}
}, response); }, response);
} }

View File

@ -29,6 +29,7 @@ import static org.testng.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.http.functions.ReturnStringIf200; import org.jclouds.http.functions.ReturnStringIf200;
@ -51,7 +52,6 @@ import com.google.inject.TypeLiteral;
@Test(groups = "unit", testName = "boxdotnet.BoxDotNetAsyncClientTest") @Test(groups = "unit", testName = "boxdotnet.BoxDotNetAsyncClientTest")
public class BoxDotNetAsyncClientTest extends RestClientTest<BoxDotNetAsyncClient> { public class BoxDotNetAsyncClientTest extends RestClientTest<BoxDotNetAsyncClient> {
public void testList() throws SecurityException, NoSuchMethodException, IOException { public void testList() throws SecurityException, NoSuchMethodException, IOException {
Method method = BoxDotNetAsyncClient.class.getMethod("list"); Method method = BoxDotNetAsyncClient.class.getMethod("list");
GeneratedHttpRequest<BoxDotNetAsyncClient> httpRequest = processor.createRequest(method); GeneratedHttpRequest<BoxDotNetAsyncClient> httpRequest = processor.createRequest(method);
@ -66,7 +66,8 @@ public class BoxDotNetAsyncClientTest extends RestClientTest<BoxDotNetAsyncClien
assertRequestLineEquals(httpRequest, "GET https://www.box.net/api/1.0/rest/items HTTP/1.1"); assertRequestLineEquals(httpRequest, "GET https://www.box.net/api/1.0/rest/items HTTP/1.1");
// for example, using basic authentication, we should get "only one" header // for example, using basic authentication, we should get "only one" header
assertHeadersEqual(httpRequest, "Accept: application/json\nAuthorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\n"); assertHeadersEqual(httpRequest,
"Accept: application/json\nAuthorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\n");
assertPayloadEquals(httpRequest, null); assertPayloadEquals(httpRequest, null);
// TODO: insert expected response class, which probably extends ParseJson // TODO: insert expected response class, which probably extends ParseJson
@ -98,8 +99,7 @@ public class BoxDotNetAsyncClientTest extends RestClientTest<BoxDotNetAsyncClien
public void testDelete() throws SecurityException, NoSuchMethodException, IOException { public void testDelete() throws SecurityException, NoSuchMethodException, IOException {
Method method = BoxDotNetAsyncClient.class.getMethod("delete", long.class); Method method = BoxDotNetAsyncClient.class.getMethod("delete", long.class);
GeneratedHttpRequest<BoxDotNetAsyncClient> httpRequest = processor.createRequest( GeneratedHttpRequest<BoxDotNetAsyncClient> httpRequest = processor.createRequest(method, 1);
method, 1);
assertRequestLineEquals(httpRequest, assertRequestLineEquals(httpRequest,
"DELETE https://www.box.net/api/1.0/rest/items/1 HTTP/1.1"); "DELETE https://www.box.net/api/1.0/rest/items/1 HTTP/1.1");
@ -113,10 +113,11 @@ public class BoxDotNetAsyncClientTest extends RestClientTest<BoxDotNetAsyncClien
checkFilters(httpRequest); checkFilters(httpRequest);
} }
@Override @Override
protected void checkFilters(GeneratedHttpRequest<BoxDotNetAsyncClient> httpRequest) { protected void checkFilters(HttpRequest request) {
assertEquals(httpRequest.getFilters().size(), 1); assertEquals(request.getFilters().size(), 1);
assertEquals(httpRequest.getFilters().get(0).getClass(), BasicAuthentication.class); assertEquals(request.getFilters().get(0).getClass(), BasicAuthentication.class);
} }
@Override @Override
@ -127,7 +128,7 @@ public class BoxDotNetAsyncClientTest extends RestClientTest<BoxDotNetAsyncClien
@Override @Override
public ContextSpec<BoxDotNetClient, BoxDotNetAsyncClient> createContextSpec() { public ContextSpec<BoxDotNetClient, BoxDotNetAsyncClient> createContextSpec() {
return contextSpec("boxdotnet", "https://www.box.net/api/1.0/rest", "1.0", "identity", "credential", return contextSpec("boxdotnet", "https://www.box.net/api/1.0/rest", "1.0", "identity",
BoxDotNetClient.class, BoxDotNetAsyncClient.class); "credential", BoxDotNetClient.class, BoxDotNetAsyncClient.class);
} }
} }

View File

@ -121,10 +121,10 @@ public class SignedHeaderAuth implements HttpRequestFilter {
} }
} }
public String createStringToSign(String httpMethod, String hashedPath, String contentHash, public String createStringToSign(String request, String hashedPath, String contentHash,
String timestamp) { String timestamp) {
return new StringBuilder().append("Method:").append(httpMethod).append("\n").append( return new StringBuilder().append("Method:").append(request).append("\n").append(
"Hashed Path:").append(hashedPath).append("\n").append("X-Ops-Content-Hash:") "Hashed Path:").append(hashedPath).append("\n").append("X-Ops-Content-Hash:")
.append(contentHash).append("\n").append("X-Ops-Timestamp:").append(timestamp) .append(contentHash).append("\n").append("X-Ops-Timestamp:").append(timestamp)
.append("\n").append("X-Ops-UserId:").append(userId).toString(); .append("\n").append("X-Ops-UserId:").append(userId).toString();

View File

@ -39,6 +39,7 @@ import org.jclouds.chef.functions.ParseKeyFromJson;
import org.jclouds.chef.functions.ParseKeySetFromJson; import org.jclouds.chef.functions.ParseKeySetFromJson;
import org.jclouds.chef.functions.ParseSandboxFromJson; import org.jclouds.chef.functions.ParseSandboxFromJson;
import org.jclouds.date.TimeStamp; import org.jclouds.date.TimeStamp;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.http.functions.ReturnStringIf200; import org.jclouds.http.functions.ReturnStringIf200;
@ -67,18 +68,14 @@ import com.google.inject.TypeLiteral;
@Test(groups = "unit", testName = "chef.ChefAsyncClientTest") @Test(groups = "unit", testName = "chef.ChefAsyncClientTest")
public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> { public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
public void testGetUploadUrisForContent() throws SecurityException, public void testGetUploadUrisForContent() throws SecurityException, NoSuchMethodException,
NoSuchMethodException, IOException { IOException {
Method method = ChefAsyncClient.class.getMethod( Method method = ChefAsyncClient.class.getMethod("getUploadUrisForContent", Set.class);
"getUploadUrisForContent", Set.class); GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method,
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor ImmutableSet.of("0189e76ccc476701d6b374e5a1a27347",
.createRequest(method, ImmutableSet.of( "0c5ecd7788cf4f6c7de2a57193897a6c", "1dda05ed139664f1f89b9dec482b77c0"));
"0189e76ccc476701d6b374e5a1a27347",
"0c5ecd7788cf4f6c7de2a57193897a6c",
"1dda05ed139664f1f89b9dec482b77c0"));
assertRequestLineEquals(httpRequest, assertRequestLineEquals(httpRequest, "POST http://localhost:4000/sandboxes HTTP/1.1");
"POST http://localhost:4000/sandboxes HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpRequest, httpRequest,
"Accept: application/json\nContent-Length: 135\nContent-Type: application/json\nX-Chef-Version: 0.9.0\n"); "Accept: application/json\nContent-Length: 135\nContent-Type: application/json\nX-Chef-Version: 0.9.0\n");
@ -86,8 +83,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
httpRequest, httpRequest,
"{\"checksums\":{\"0189e76ccc476701d6b374e5a1a27347\":null,\"0c5ecd7788cf4f6c7de2a57193897a6c\":null,\"1dda05ed139664f1f89b9dec482b77c0\":null}}"); "{\"checksums\":{\"0189e76ccc476701d6b374e5a1a27347\":null,\"0c5ecd7788cf4f6c7de2a57193897a6c\":null,\"1dda05ed139664f1f89b9dec482b77c0\":null}}");
assertResponseParserClassEquals(method, httpRequest, assertResponseParserClassEquals(method, httpRequest, ParseSandboxFromJson.class);
ParseSandboxFromJson.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -95,20 +91,16 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
} }
public void testGetCookbook() throws SecurityException, public void testGetCookbook() throws SecurityException, NoSuchMethodException, IOException {
NoSuchMethodException, IOException { Method method = ChefAsyncClient.class.getMethod("getCookbook", String.class, String.class);
Method method = ChefAsyncClient.class.getMethod("getCookbook", GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method,
String.class, String.class); "cookbook", "1.0.0");
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor
.createRequest(method, "cookbook", "1.0.0");
assertRequestLineEquals(httpRequest, assertRequestLineEquals(httpRequest,
"GET http://localhost:4000/cookbooks/cookbook/1.0.0 HTTP/1.1"); "GET http://localhost:4000/cookbooks/cookbook/1.0.0 HTTP/1.1");
assertHeadersEqual(httpRequest, assertHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.0\n");
"Accept: application/json\nX-Chef-Version: 0.9.0\n");
assertPayloadEquals(httpRequest, null); assertPayloadEquals(httpRequest, null);
assertResponseParserClassEquals(method, httpRequest, assertResponseParserClassEquals(method, httpRequest, ParseCookbookFromJson.class);
ParseCookbookFromJson.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
@ -116,20 +108,16 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
} }
public void testDeleteCookbook() throws SecurityException, public void testDeleteCookbook() throws SecurityException, NoSuchMethodException, IOException {
NoSuchMethodException, IOException { Method method = ChefAsyncClient.class.getMethod("deleteCookbook", String.class, String.class);
Method method = ChefAsyncClient.class.getMethod("deleteCookbook", GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method,
String.class, String.class); "cookbook", "1.0.0");
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor
.createRequest(method, "cookbook", "1.0.0");
assertRequestLineEquals(httpRequest, assertRequestLineEquals(httpRequest,
"DELETE http://localhost:4000/cookbooks/cookbook/1.0.0 HTTP/1.1"); "DELETE http://localhost:4000/cookbooks/cookbook/1.0.0 HTTP/1.1");
assertHeadersEqual(httpRequest, assertHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.0\n");
"Accept: application/json\nX-Chef-Version: 0.9.0\n");
assertPayloadEquals(httpRequest, null); assertPayloadEquals(httpRequest, null);
assertResponseParserClassEquals(method, httpRequest, assertResponseParserClassEquals(method, httpRequest, CloseContentAndReturn.class);
CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class); assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
@ -137,12 +125,11 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
} }
public void testUpdateCookbook() throws SecurityException, public void testUpdateCookbook() throws SecurityException, NoSuchMethodException, IOException {
NoSuchMethodException, IOException { Method method = ChefAsyncClient.class.getMethod("updateCookbook", String.class, String.class,
Method method = ChefAsyncClient.class.getMethod("updateCookbook", Cookbook.class);
String.class, String.class, Cookbook.class); GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method,
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor "cookbook", "1.0.1", new Cookbook());
.createRequest(method, "cookbook", "1.0.1", new Cookbook());
assertRequestLineEquals(httpRequest, assertRequestLineEquals(httpRequest,
"PUT http://localhost:4000/cookbooks/cookbook/1.0.1 HTTP/1.1"); "PUT http://localhost:4000/cookbooks/cookbook/1.0.1 HTTP/1.1");
@ -153,8 +140,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
httpRequest, httpRequest,
"{\"definitions\":[],\"attributes\":[],\"files\":[],\"providers\":[],\"resources\":[],\"templates\":[],\"libraries\":[],\"recipes\":[],\"root_files\":[]}"); "{\"definitions\":[],\"attributes\":[],\"files\":[],\"providers\":[],\"resources\":[],\"templates\":[],\"libraries\":[],\"recipes\":[],\"root_files\":[]}");
assertResponseParserClassEquals(method, httpRequest, assertResponseParserClassEquals(method, httpRequest, CloseContentAndReturn.class);
CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -162,20 +148,15 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
} }
public void testListCookbooks() throws SecurityException, public void testListCookbooks() throws SecurityException, NoSuchMethodException, IOException {
NoSuchMethodException, IOException {
Method method = ChefAsyncClient.class.getMethod("listCookbooks"); Method method = ChefAsyncClient.class.getMethod("listCookbooks");
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method);
.createRequest(method);
assertRequestLineEquals(httpRequest, assertRequestLineEquals(httpRequest, "GET http://localhost:4000/cookbooks HTTP/1.1");
"GET http://localhost:4000/cookbooks HTTP/1.1"); assertHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.0\n");
assertHeadersEqual(httpRequest,
"Accept: application/json\nX-Chef-Version: 0.9.0\n");
assertPayloadEquals(httpRequest, null); assertPayloadEquals(httpRequest, null);
assertResponseParserClassEquals(method, httpRequest, assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class);
ParseKeySetFromJson.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -183,20 +164,14 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
} }
public void testClientExists() throws SecurityException, public void testClientExists() throws SecurityException, NoSuchMethodException, IOException {
NoSuchMethodException, IOException { Method method = ChefAsyncClient.class.getMethod("clientExists", String.class);
Method method = ChefAsyncClient.class.getMethod("clientExists", GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, "client");
String.class); assertRequestLineEquals(httpRequest, "HEAD http://localhost:4000/clients/client HTTP/1.1");
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor assertHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.0\n");
.createRequest(method, "client");
assertRequestLineEquals(httpRequest,
"HEAD http://localhost:4000/clients/client HTTP/1.1");
assertHeadersEqual(httpRequest,
"Accept: application/json\nX-Chef-Version: 0.9.0\n");
assertPayloadEquals(httpRequest, null); assertPayloadEquals(httpRequest, null);
assertResponseParserClassEquals(method, httpRequest, assertResponseParserClassEquals(method, httpRequest, ReturnTrueIf2xx.class);
ReturnTrueIf2xx.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnFalseOnNotFoundOr404.class); assertExceptionParserClassEquals(method, ReturnFalseOnNotFoundOr404.class);
@ -204,20 +179,14 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
} }
public void testDeleteClient() throws SecurityException, public void testDeleteClient() throws SecurityException, NoSuchMethodException, IOException {
NoSuchMethodException, IOException { Method method = ChefAsyncClient.class.getMethod("deleteClient", String.class);
Method method = ChefAsyncClient.class.getMethod("deleteClient", GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, "client");
String.class); assertRequestLineEquals(httpRequest, "DELETE http://localhost:4000/clients/client HTTP/1.1");
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor assertHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.0\n");
.createRequest(method, "client");
assertRequestLineEquals(httpRequest,
"DELETE http://localhost:4000/clients/client HTTP/1.1");
assertHeadersEqual(httpRequest,
"Accept: application/json\nX-Chef-Version: 0.9.0\n");
assertPayloadEquals(httpRequest, null); assertPayloadEquals(httpRequest, null);
assertResponseParserClassEquals(method, httpRequest, assertResponseParserClassEquals(method, httpRequest, ReturnStringIf200.class);
ReturnStringIf200.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
@ -225,22 +194,17 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
} }
public void testGenerateKeyForClient() throws SecurityException, public void testGenerateKeyForClient() throws SecurityException, NoSuchMethodException,
NoSuchMethodException, IOException { IOException {
Method method = ChefAsyncClient.class.getMethod("generateKeyForClient", Method method = ChefAsyncClient.class.getMethod("generateKeyForClient", String.class);
String.class); GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, "client");
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor assertRequestLineEquals(httpRequest, "PUT http://localhost:4000/clients/client HTTP/1.1");
.createRequest(method, "client");
assertRequestLineEquals(httpRequest,
"PUT http://localhost:4000/clients/client HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpRequest, httpRequest,
"Accept: application/json\nContent-Length: 44\nContent-Type: application/json\nX-Chef-Version: 0.9.0\n"); "Accept: application/json\nContent-Length: 44\nContent-Type: application/json\nX-Chef-Version: 0.9.0\n");
assertPayloadEquals(httpRequest, assertPayloadEquals(httpRequest, "{\"clientname\":\"client\", \"private_key\": true}");
"{\"clientname\":\"client\", \"private_key\": true}");
assertResponseParserClassEquals(method, httpRequest, assertResponseParserClassEquals(method, httpRequest, ParseKeyFromJson.class);
ParseKeyFromJson.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -248,22 +212,17 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
} }
public void testCreateClient() throws SecurityException, public void testCreateClient() throws SecurityException, NoSuchMethodException, IOException {
NoSuchMethodException, IOException { Method method = ChefAsyncClient.class.getMethod("createClient", String.class);
Method method = ChefAsyncClient.class.getMethod("createClient", GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, "client");
String.class);
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor
.createRequest(method, "client");
assertRequestLineEquals(httpRequest, assertRequestLineEquals(httpRequest, "POST http://localhost:4000/clients HTTP/1.1");
"POST http://localhost:4000/clients HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpRequest, httpRequest,
"Accept: application/json\nContent-Length: 23\nContent-Type: application/json\nX-Chef-Version: 0.9.0\n"); "Accept: application/json\nContent-Length: 23\nContent-Type: application/json\nX-Chef-Version: 0.9.0\n");
assertPayloadEquals(httpRequest, "{\"clientname\":\"client\"}"); assertPayloadEquals(httpRequest, "{\"clientname\":\"client\"}");
assertResponseParserClassEquals(method, httpRequest, assertResponseParserClassEquals(method, httpRequest, ParseKeyFromJson.class);
ParseKeyFromJson.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -271,20 +230,15 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
} }
public void testListClients() throws SecurityException, public void testListClients() throws SecurityException, NoSuchMethodException, IOException {
NoSuchMethodException, IOException {
Method method = ChefAsyncClient.class.getMethod("listClients"); Method method = ChefAsyncClient.class.getMethod("listClients");
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method);
.createRequest(method);
assertRequestLineEquals(httpRequest, assertRequestLineEquals(httpRequest, "GET http://localhost:4000/clients HTTP/1.1");
"GET http://localhost:4000/clients HTTP/1.1"); assertHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.0\n");
assertHeadersEqual(httpRequest,
"Accept: application/json\nX-Chef-Version: 0.9.0\n");
assertPayloadEquals(httpRequest, null); assertPayloadEquals(httpRequest, null);
assertResponseParserClassEquals(method, httpRequest, assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class);
ParseKeySetFromJson.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -293,10 +247,9 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
} }
@Override @Override
protected void checkFilters(GeneratedHttpRequest<ChefAsyncClient> httpRequest) { protected void checkFilters(HttpRequest request) {
assertEquals(httpRequest.getFilters().size(), 1); assertEquals(request.getFilters().size(), 1);
assertEquals(httpRequest.getFilters().get(0).getClass(), assertEquals(request.getFilters().get(0).getClass(), SignedHeaderAuth.class);
SignedHeaderAuth.class);
} }
@Override @Override

View File

@ -32,14 +32,17 @@ import java.util.Properties;
import java.util.Set; import java.util.Set;
import org.jclouds.chef.domain.Cookbook; import org.jclouds.chef.domain.Cookbook;
import org.jclouds.chef.domain.Resource;
import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory;
import org.jclouds.util.Utils;
import org.testng.annotations.AfterClass; import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.io.Files; import com.google.common.io.Files;
import com.google.inject.Module; import com.google.inject.Module;
@ -52,8 +55,6 @@ import com.google.inject.Module;
@Test(groups = "live", testName = "chef.ChefClientLiveTest") @Test(groups = "live", testName = "chef.ChefClientLiveTest")
public class ChefClientLiveTest { public class ChefClientLiveTest {
private static final String COOKBOOK_NAME = "brew";
private static final String COOKBOOK_URI = "https://s3.amazonaws.com/opscode-community/cookbook_versions/tarballs/195/original/runit.tar.gz";
private RestContext<ChefClient, ChefAsyncClient> validatorConnection; private RestContext<ChefClient, ChefAsyncClient> validatorConnection;
private RestContext<ChefClient, ChefAsyncClient> clientConnection; private RestContext<ChefClient, ChefAsyncClient> clientConnection;
private RestContext<ChefClient, ChefAsyncClient> adminConnection; private RestContext<ChefClient, ChefAsyncClient> adminConnection;
@ -62,48 +63,40 @@ public class ChefClientLiveTest {
private String endpoint; private String endpoint;
private String validator; private String validator;
private String user; private String user;
private byte[] cookbookContent;
private File cookbookFile;
public static final String PREFIX = System.getProperty("user.name") public static final String PREFIX = System.getProperty("user.name") + "-jcloudstest";
+ "-jcloudstest";
@BeforeClass(groups = { "live" }) @BeforeClass(groups = { "live" })
public void setupClient() throws IOException { public void setupClient() throws IOException {
endpoint = checkNotNull(System.getProperty("jclouds.test.endpoint"), endpoint = checkNotNull(System.getProperty("jclouds.test.endpoint"), "jclouds.test.endpoint");
"jclouds.test.endpoint");
validator = System.getProperty("jclouds.test.validator"); validator = System.getProperty("jclouds.test.validator");
if (validator == null || validator.equals("")) if (validator == null || validator.equals(""))
validator = "chef-validator"; validator = "chef-validator";
String validatorKey = System.getProperty("jclouds.test.validator.key"); String validatorKey = System.getProperty("jclouds.test.validator.key");
if (validatorKey == null || validatorKey.equals("")) if (validatorKey == null || validatorKey.equals(""))
validatorKey = System.getProperty("user.home") validatorKey = System.getProperty("user.home") + "/.chef/validation.pem";
+ "/.chef/validation.pem"; user = checkNotNull(System.getProperty("jclouds.test.identity"), "jclouds.test.identity");
user = checkNotNull(System.getProperty("jclouds.test.identity"),
"jclouds.test.identity");
String keyfile = System.getProperty("jclouds.test.credential"); String keyfile = System.getProperty("jclouds.test.credential");
if (keyfile == null || keyfile.equals("")) if (keyfile == null || keyfile.equals(""))
keyfile = System.getProperty("user.home") + "/.chef/" + user + ".pem"; keyfile = System.getProperty("user.home") + "/.chef/" + user + ".pem";
validatorConnection = createConnection(validator, Files.toString( validatorConnection = createConnection(validator, Files.toString(new File(validatorKey),
new File(validatorKey), Charsets.UTF_8)); Charsets.UTF_8));
adminConnection = createConnection(user, Files.toString( adminConnection = createConnection(user, Files.toString(new File(keyfile), Charsets.UTF_8));
new File(keyfile), Charsets.UTF_8));
} }
private RestContext<ChefClient, ChefAsyncClient> createConnection( private RestContext<ChefClient, ChefAsyncClient> createConnection(String identity, String key)
String identity, String key) throws IOException { throws IOException {
Properties props = new Properties(); Properties props = new Properties();
props.setProperty("chef.endpoint", endpoint); props.setProperty("chef.endpoint", endpoint);
return new RestContextFactory().createContext("chef", identity, key, return new RestContextFactory().createContext("chef", identity, key, ImmutableSet
ImmutableSet.<Module> of(new Log4JLoggingModule()), props); .<Module> of(new Log4JLoggingModule()), props);
} }
@Test @Test
public void testListClients() throws Exception { public void testListClients() throws Exception {
Set<String> clients = validatorConnection.getApi().listClients(); Set<String> clients = validatorConnection.getApi().listClients();
assertNotNull(clients); assertNotNull(clients);
assert clients.contains(validator) : "validator: " + validator assert clients.contains(validator) : "validator: " + validator + " not in: " + clients;
+ " not in: " + clients;
} }
@Test(dependsOnMethods = "testListClients") @Test(dependsOnMethods = "testListClients")
@ -133,22 +126,30 @@ public class ChefClientLiveTest {
@Test @Test
public void testListCookbooks() throws Exception { public void testListCookbooks() throws Exception {
for (String cookbook : adminConnection.getApi().listCookbooks()) for (String cookbook : adminConnection.getApi().listCookbooks())
for (String version : adminConnection.getApi().getVersionsOfCookbook( for (String version : adminConnection.getApi().getVersionsOfCookbook(cookbook)) {
cookbook)) {
System.err.printf("%s/%s:%n", cookbook, version); System.err.printf("%s/%s:%n", cookbook, version);
System.err.printf("%s%n", adminConnection.getApi().getCookbook( Cookbook cookbookO = adminConnection.getApi().getCookbook(cookbook, version);
cookbook, version)); for (Resource resource : ImmutableList.<Resource> builder().addAll(
cookbookO.getDefinitions()).addAll(cookbookO.getFiles()).addAll(
cookbookO.getLibraries()).addAll(cookbookO.getProviders()).addAll(
cookbookO.getRecipes()).addAll(cookbookO.getResources()).addAll(
cookbookO.getRootFiles()).addAll(cookbookO.getTemplates()).build()) {
try {
Utils.toStringAndClose(adminConnection.utils().http().get(resource.getUrl()));
} catch (NullPointerException e) {
assert false : "resource not found: " + resource;
}
System.err.printf("resource %s ok%n", resource.getName());
}
} }
} }
@Test(dependsOnMethods = "testListCookbooks") @Test(dependsOnMethods = "testListCookbooks")
public void testUpdateCookbook() throws Exception { public void testUpdateCookbook() throws Exception {
for (String cookbook : adminConnection.getApi().listCookbooks()) for (String cookbook : adminConnection.getApi().listCookbooks())
for (String version : adminConnection.getApi().getVersionsOfCookbook( for (String version : adminConnection.getApi().getVersionsOfCookbook(cookbook)) {
cookbook)) {
System.err.printf("%s/%s:%n", cookbook, version); System.err.printf("%s/%s:%n", cookbook, version);
Cookbook cook = adminConnection.getApi().getCookbook(cookbook, Cookbook cook = adminConnection.getApi().getCookbook(cookbook, version);
version);
adminConnection.getApi().updateCookbook(cookbook, version, cook); adminConnection.getApi().updateCookbook(cookbook, version, cook);
} }
@ -157,11 +158,9 @@ public class ChefClientLiveTest {
@Test(dependsOnMethods = "testUpdateCookbook") @Test(dependsOnMethods = "testUpdateCookbook")
public void testCreateCookbook() throws Exception { public void testCreateCookbook() throws Exception {
for (String cookbook : adminConnection.getApi().listCookbooks()) for (String cookbook : adminConnection.getApi().listCookbooks())
for (String version : adminConnection.getApi().getVersionsOfCookbook( for (String version : adminConnection.getApi().getVersionsOfCookbook(cookbook)) {
cookbook)) {
System.err.printf("%s/%s:%n", cookbook, version); System.err.printf("%s/%s:%n", cookbook, version);
Cookbook cook = adminConnection.getApi().getCookbook(cookbook, Cookbook cook = adminConnection.getApi().getCookbook(cookbook, version);
version);
adminConnection.getApi().deleteCookbook(cookbook, version); adminConnection.getApi().deleteCookbook(cookbook, version);
assert adminConnection.getApi().getCookbook(cookbook, version) == null : cookbook assert adminConnection.getApi().getCookbook(cookbook, version) == null : cookbook
+ version; + version;

View File

@ -45,23 +45,6 @@ public interface HttpCommand {
*/ */
boolean isReplayable(); boolean isReplayable();
/**
* change the destination of the current http command. typically used in handling redirects.
*
* @param string
*/
void changeSchemeHostAndPortTo(String scheme, String host, int port);
/**
* change method from GET to HEAD. typically used in handling redirects.
*/
void changeToGETRequest();
/**
* change the path of the service. typically used in handling redirects.
*/
void changePathTo(String newPath);
/** /**
* increment the current failure count. * increment the current failure count.
* *

View File

@ -24,6 +24,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import java.io.File; import java.io.File;
import java.io.InputStream; import java.io.InputStream;
import java.net.URI; import java.net.URI;
import java.util.Arrays;
import java.util.List; import java.util.List;
import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.HttpHeaders;
@ -44,6 +45,7 @@ public class HttpRequest extends HttpMessage {
private String method; private String method;
private URI endpoint; private URI endpoint;
private Payload payload; private Payload payload;
private char[] skips;
/** /**
* *
@ -53,10 +55,15 @@ public class HttpRequest extends HttpMessage {
* If the request is HEAD, this may change to GET due to redirects * If the request is HEAD, this may change to GET due to redirects
*/ */
public HttpRequest(String method, URI endpoint) { public HttpRequest(String method, URI endpoint) {
this(method, endpoint, new char[] {});
}
public HttpRequest(String method, URI endpoint, char[] skips) {
this.setMethod(checkNotNull(method, "method")); this.setMethod(checkNotNull(method, "method"));
this.setEndpoint(checkNotNull(endpoint, "endpoint")); this.setEndpoint(checkNotNull(endpoint, "endpoint"));
checkArgument(endpoint.getHost() != null, String.format("endpoint.getHost() is null for %s", checkArgument(endpoint.getHost() != null, String.format("endpoint.getHost() is null for %s",
endpoint)); endpoint));
this.skips = skips;
} }
/** /**
@ -132,6 +139,17 @@ public class HttpRequest extends HttpMessage {
} }
} }
/**
* characters to skip encoding on.
*/
public char[] getSkips() {
return skips;
}
public void setSkips(char[] skips) {
this.skips = skips;
}
public URI getEndpoint() { public URI getEndpoint() {
return endpoint; return endpoint;
} }
@ -167,11 +185,12 @@ public class HttpRequest extends HttpMessage {
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = super.hashCode();
result = prime * result + ((endpoint == null) ? 0 : endpoint.hashCode()); result = prime * result + ((endpoint == null) ? 0 : endpoint.hashCode());
result = prime * result + ((method == null) ? 0 : method.hashCode()); result = prime * result + ((method == null) ? 0 : method.hashCode());
result = prime * result + ((payload == null) ? 0 : payload.hashCode()); result = prime * result + ((payload == null) ? 0 : payload.hashCode());
result = prime * result + ((requestFilters == null) ? 0 : requestFilters.hashCode()); result = prime * result + ((requestFilters == null) ? 0 : requestFilters.hashCode());
result = prime * result + Arrays.hashCode(skips);
return result; return result;
} }
@ -179,7 +198,7 @@ public class HttpRequest extends HttpMessage {
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj)
return true; return true;
if (obj == null) if (!super.equals(obj))
return false; return false;
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
@ -204,12 +223,14 @@ public class HttpRequest extends HttpMessage {
return false; return false;
} else if (!requestFilters.equals(other.requestFilters)) } else if (!requestFilters.equals(other.requestFilters))
return false; return false;
if (!Arrays.equals(skips, other.skips))
return false;
return true; return true;
} }
@Override @Override
public String toString() { public String toString() {
return "[method=" + method + ", endpoint=" + endpoint + ", headers=" + headers return "[method=" + method + ", endpoint=" + endpoint + ", headers=" + headers + "]";
+ "]";
} }
} }

View File

@ -19,6 +19,8 @@
package org.jclouds.http; package org.jclouds.http;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import static com.google.common.io.ByteStreams.toByteArray;
import static java.util.Collections.singletonList;
import static org.jclouds.util.Patterns.CHAR_TO_ENCODED_PATTERN; import static org.jclouds.util.Patterns.CHAR_TO_ENCODED_PATTERN;
import static org.jclouds.util.Patterns.PATTERN_THAT_BREAKS_URI; import static org.jclouds.util.Patterns.PATTERN_THAT_BREAKS_URI;
import static org.jclouds.util.Patterns.PLUS_PATTERN; import static org.jclouds.util.Patterns.PLUS_PATTERN;
@ -35,11 +37,21 @@ import java.io.UnsupportedEncodingException;
import java.net.URI; import java.net.URI;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.SortedSet;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import javax.annotation.Nullable;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
@ -48,17 +60,20 @@ import org.jclouds.util.Utils;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import com.google.common.collect.SortedSetMultimap; import com.google.common.collect.SortedSetMultimap;
import com.google.common.collect.TreeMultimap; import com.google.common.collect.TreeMultimap;
import com.google.common.io.ByteStreams;
import com.google.common.io.Closeables; import com.google.common.io.Closeables;
import com.google.inject.Inject; import com.google.inject.Inject;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton
public class HttpUtils { public class HttpUtils {
@Inject(optional = true) @Inject(optional = true)
@Named(Constants.PROPERTY_RELAX_HOSTNAME) @Named(Constants.PROPERTY_RELAX_HOSTNAME)
@ -201,7 +216,7 @@ public class HttpUtils {
public static void consumeContent(HttpResponse response) { public static void consumeContent(HttpResponse response) {
if (response.getContent() != null) { if (response.getContent() != null) {
try { try {
ByteStreams.toByteArray(response.getContent()); toByteArray(response.getContent());
} catch (IOException e) { } catch (IOException e) {
Throwables.propagate(e); Throwables.propagate(e);
} finally { } finally {
@ -216,7 +231,7 @@ public class HttpUtils {
public static byte[] closeClientButKeepContentStream(HttpResponse response) { public static byte[] closeClientButKeepContentStream(HttpResponse response) {
if (response.getContent() != null) { if (response.getContent() != null) {
try { try {
byte[] data = ByteStreams.toByteArray(response.getContent()); byte[] data = toByteArray(response.getContent());
response.setContent(new ByteArrayInputStream(data)); response.setContent(new ByteArrayInputStream(data));
return data; return data;
} catch (IOException e) { } catch (IOException e) {
@ -250,14 +265,14 @@ public class HttpUtils {
/** /**
* Used to extract the URI and authentication data from a String. Note that the java URI class * Used to extract the URI and authentication data from a String. Note that the java URI class
* breaks, if there are special characters like '/' present. Otherwise, we wouldn't need this * breaks, if there are special characters like '/' present. Otherwise, we wouldn't need this
* class, and we could simply use URI.create("uri").getUserData(); Also, URI breaks if there * class, and we could simply use URI.create("uri").getUserData(); Also, URI breaks if there are
* are curly braces. * curly braces.
* *
*/ */
public static URI createUri(String uriPath) { public static URI createUri(String uriPath) {
List<String> onQuery = Lists.newArrayList(Splitter.on('?').split(uriPath)); List<String> onQuery = Lists.newArrayList(Splitter.on('?').split(uriPath));
if (onQuery.size() == 2){ if (onQuery.size() == 2) {
onQuery.add(urlEncode(onQuery.remove(1), '=','&')); onQuery.add(urlEncode(onQuery.remove(1), '=', '&'));
uriPath = Joiner.on('?').join(onQuery); uriPath = Joiner.on('?').join(onQuery);
} }
if (uriPath.indexOf('@') != 1) { if (uriPath.indexOf('@') != 1) {
@ -341,4 +356,132 @@ public class HttpUtils {
return buffer.toString(); return buffer.toString();
} }
/**
* change the destination of the current http command. typically used in handling redirects.
*
* @param string
*/
public static void changeSchemeHostAndPortTo(HttpRequest request, String scheme, String host,
int port, UriBuilder builder) {
builder.uri(request.getEndpoint());
builder.scheme(scheme);
builder.host(host);
builder.port(port);
request.setEndpoint(builder.build());
request.getHeaders().replaceValues(HttpHeaders.HOST, singletonList(host));
}
/**
* change the path of the service. typically used in handling redirects.
*/
public static void changePathTo(HttpRequest request, String newPath, UriBuilder builder) {
builder.uri(request.getEndpoint());
builder.replacePath(newPath);
request.setEndpoint(builder.build());
}
/**
* change method from GET to HEAD. typically used in handling redirects.
*/
public static void changeToGETRequest(HttpRequest request) {
request.setMethod(HttpMethod.GET);
}
public static void addQueryParamTo(HttpRequest request, String key, Object value,
UriBuilder builder) {
addQueryParamTo(request, key, ImmutableSet.<Object> of(value), builder, request.getSkips());
}
public static void addQueryParamTo(HttpRequest request, String key, Iterable<?> values,
UriBuilder builder) {
addQueryParamTo(request, key, values, builder, request.getSkips());
}
public static void addQueryParamTo(HttpRequest request, String key, Iterable<?> values,
UriBuilder builder, char... skips) {
builder.uri(request.getEndpoint());
Multimap<String, String> map = parseQueryToMap(request.getEndpoint().getQuery());
for (Object o : values)
map.put(key, o.toString());
builder.replaceQuery(makeQueryLine(map, null, skips));
request.setEndpoint(builder.build());
}
public static void replaceMatrixParam(HttpRequest request, String name, Object value,
UriBuilder builder) {
replaceMatrixParam(request, name, new Object[] { value }, builder);
}
public static void replaceMatrixParam(HttpRequest request, String name, Object[] values,
UriBuilder builder) {
builder.uri(request.getEndpoint());
builder.replaceMatrixParam(name, values);
request.setEndpoint(builder.build());
}
public static void addFormParamTo(HttpRequest request, String key, String value) {
addFormParamTo(request, key, ImmutableSet.<Object> of(value));
}
public static void addFormParamTo(HttpRequest request, String key, Iterable<?> values) {
Multimap<String, String> map = parseQueryToMap(request.getPayload().toString());
for (Object o : values)
map.put(key, o.toString());
request.setPayload(makeQueryLine(map, null));
}
public static Multimap<String, String> parseQueryToMap(String in) {
Multimap<String, String> map = LinkedListMultimap.create();
if (in == null) {
} else if (in.indexOf('&') == -1) {
if (in.contains("="))
parseKeyValueFromStringToMap(in, map);
else
map.put(in, null);
} else {
String[] parts = HttpUtils.urlDecode(in).split("&");
for (String part : parts) {
parseKeyValueFromStringToMap(part, map);
}
}
return map;
}
public static void parseKeyValueFromStringToMap(String stringToParse,
Multimap<String, String> map) {
// note that '=' can be a valid part of the value
int indexOfFirstEquals = stringToParse.indexOf('=');
String key = indexOfFirstEquals == -1 ? stringToParse : stringToParse.substring(0,
indexOfFirstEquals);
String value = indexOfFirstEquals == -1 ? null : stringToParse
.substring(indexOfFirstEquals + 1);
map.put(key, value);
}
public static SortedSet<Entry<String, String>> sortEntries(
Collection<Map.Entry<String, String>> in, Comparator<Map.Entry<String, String>> sorter) {
SortedSet<Entry<String, String>> entries = Sets.newTreeSet(sorter);
entries.addAll(in);
return entries;
}
public static String makeQueryLine(Multimap<String, String> params,
@Nullable Comparator<Map.Entry<String, String>> sorter, char... skips) {
Iterator<Map.Entry<String, String>> pairs = ((sorter == null) ? params.entries()
: sortEntries(params.entries(), sorter)).iterator();
StringBuilder formBuilder = new StringBuilder();
while (pairs.hasNext()) {
Map.Entry<String, String> pair = pairs.next();
formBuilder.append(HttpUtils.urlEncode(pair.getKey(), skips));
if (pair.getValue() != null && !pair.getValue().equals("")) {
formBuilder.append("=");
formBuilder.append(HttpUtils.urlEncode(pair.getValue(), skips));
}
if (pairs.hasNext())
formBuilder.append("&");
}
return formBuilder.toString();
}
} }

View File

@ -18,18 +18,12 @@
*/ */
package org.jclouds.http; package org.jclouds.http;
import java.util.Collections;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Provider;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
@ -46,9 +40,8 @@ public class TransformingHttpCommandImpl<T> implements TransformingHttpCommand<T
private final TransformingHttpCommandExecutorService executorService; private final TransformingHttpCommandExecutorService executorService;
private final Function<HttpResponse, T> transformer; private final Function<HttpResponse, T> transformer;
private final Provider<UriBuilder> uriBuilderProvider;
private GeneratedHttpRequest<?> request; private HttpRequest request;
private volatile int failureCount; private volatile int failureCount;
@Resource @Resource
@ -58,10 +51,8 @@ public class TransformingHttpCommandImpl<T> implements TransformingHttpCommand<T
protected volatile Exception exception; protected volatile Exception exception;
@Inject @Inject
public TransformingHttpCommandImpl(Provider<UriBuilder> uriBuilderProvider, public TransformingHttpCommandImpl(TransformingHttpCommandExecutorService executorService,
TransformingHttpCommandExecutorService executorService, HttpRequest request, Function<HttpResponse, T> transformer) {
GeneratedHttpRequest<?> request, Function<HttpResponse, T> transformer) {
this.uriBuilderProvider = uriBuilderProvider;
this.request = request; this.request = request;
this.executorService = executorService; this.executorService = executorService;
this.transformer = transformer; this.transformer = transformer;
@ -82,30 +73,6 @@ public class TransformingHttpCommandImpl<T> implements TransformingHttpCommand<T
return ++failureCount; return ++failureCount;
} }
/**
* {@inheritDoc}
* <p />
* This also removes the Host header in order to avoid ssl problems.
*/
@Override
public void changeSchemeHostAndPortTo(String scheme, String host, int port) {
UriBuilder builder = uriBuilderProvider.get().uri(request.getEndpoint());
builder.scheme(scheme);
builder.host(host);
builder.port(port);
request.setEndpoint(builder.build());
request.getHeaders().replaceValues(HttpHeaders.HOST, Collections.singletonList(host));
}
/**
* in some scenarios, HEAD commands cannot be redirected. This method changes the request to GET
* in such a case.
*
*/
public void changeToGETRequest() {
request.setMethod(HttpMethod.GET);
}
public void setException(Exception exception) { public void setException(Exception exception) {
this.exception = exception; this.exception = exception;
} }
@ -130,11 +97,6 @@ public class TransformingHttpCommandImpl<T> implements TransformingHttpCommand<T
return request; return request;
} }
@Override
public void changePathTo(String newPath) {
request.replacePath(newPath);
}
@Override @Override
public String toString() { public String toString() {
return "[request=" + request.getRequestLine() + "]"; return "[request=" + request.getRequestLine() + "]";

View File

@ -22,6 +22,7 @@ import java.io.IOException;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpCommand;
@ -75,6 +76,7 @@ import com.google.inject.Inject;
* *
* @author James Murty * @author James Murty
*/ */
@Singleton
public class BackoffLimitedRetryHandler implements HttpRetryHandler, IOExceptionRetryHandler { public class BackoffLimitedRetryHandler implements HttpRetryHandler, IOExceptionRetryHandler {
@Inject(optional = true) @Inject(optional = true)
@Named(Constants.PROPERTY_MAX_RETRIES) @Named(Constants.PROPERTY_MAX_RETRIES)

View File

@ -18,9 +18,6 @@
*/ */
package org.jclouds.http.handlers; package org.jclouds.http.handlers;
import javax.inject.Provider;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpRetryHandler; import org.jclouds.http.HttpRetryHandler;
@ -55,10 +52,10 @@ public class DelegatingRetryHandler implements HttpRetryHandler {
HttpRetryHandler serverErrorRetryHandler; HttpRetryHandler serverErrorRetryHandler;
@Inject @Inject
public DelegatingRetryHandler(Provider<UriBuilder> uriBuilderProvider) { public DelegatingRetryHandler(BackoffLimitedRetryHandler backOff,
BackoffLimitedRetryHandler backOff = new BackoffLimitedRetryHandler(); RedirectionRetryHandler redirectionRetryHandler) {
this.serverErrorRetryHandler = backOff; this.serverErrorRetryHandler = backOff;
this.redirectionRetryHandler = new RedirectionRetryHandler(uriBuilderProvider, backOff); this.redirectionRetryHandler = redirectionRetryHandler;
this.clientErrorRetryHandler = HttpRetryHandler.NEVER_RETRY; this.clientErrorRetryHandler = HttpRetryHandler.NEVER_RETRY;
} }

View File

@ -18,6 +18,9 @@
*/ */
package org.jclouds.http.handlers; package org.jclouds.http.handlers;
import static org.jclouds.http.HttpUtils.changePathTo;
import static org.jclouds.http.HttpUtils.changeSchemeHostAndPortTo;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
@ -25,6 +28,7 @@ import java.net.URI;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Provider; import javax.inject.Provider;
import javax.inject.Singleton;
import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriBuilder;
@ -44,6 +48,7 @@ import com.google.inject.Inject;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton
public class RedirectionRetryHandler implements HttpRetryHandler { public class RedirectionRetryHandler implements HttpRetryHandler {
@Inject(optional = true) @Inject(optional = true)
@Named(Constants.PROPERTY_MAX_REDIRECTS) @Named(Constants.PROPERTY_MAX_REDIRECTS)
@ -53,10 +58,10 @@ public class RedirectionRetryHandler implements HttpRetryHandler {
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
protected final BackoffLimitedRetryHandler backoffHandler; protected final BackoffLimitedRetryHandler backoffHandler;
private final Provider<UriBuilder> uriBuilderProvider; protected final Provider<UriBuilder> uriBuilderProvider;
@Inject @Inject
public RedirectionRetryHandler(Provider<UriBuilder> uriBuilderProvider, protected RedirectionRetryHandler(Provider<UriBuilder> uriBuilderProvider,
BackoffLimitedRetryHandler backoffHandler) { BackoffLimitedRetryHandler backoffHandler) {
this.backoffHandler = backoffHandler; this.backoffHandler = backoffHandler;
this.uriBuilderProvider = uriBuilderProvider; this.uriBuilderProvider = uriBuilderProvider;
@ -72,13 +77,14 @@ public class RedirectionRetryHandler implements HttpRetryHandler {
&& redirectionUrl.getHost().equals(command.getRequest().getEndpoint().getHost()) && redirectionUrl.getHost().equals(command.getRequest().getEndpoint().getHost())
&& redirectionUrl.getPort() == command.getRequest().getEndpoint().getPort()) { && redirectionUrl.getPort() == command.getRequest().getEndpoint().getPort()) {
if (!redirectionUrl.getPath().equals(command.getRequest().getEndpoint().getPath())) { if (!redirectionUrl.getPath().equals(command.getRequest().getEndpoint().getPath())) {
command.changePathTo(redirectionUrl.getPath()); changePathTo(command.getRequest(), redirectionUrl.getPath(), uriBuilderProvider
.get());
} else { } else {
return backoffHandler.shouldRetryRequest(command, response); return backoffHandler.shouldRetryRequest(command, response);
} }
} else { } else {
command.changeSchemeHostAndPortTo(redirectionUrl.getScheme(), redirectionUrl.getHost(), changeSchemeHostAndPortTo(command.getRequest(), redirectionUrl.getScheme(),
redirectionUrl.getPort()); redirectionUrl.getHost(), redirectionUrl.getPort(), uriBuilderProvider.get());
} }
return true; return true;
} else { } else {

View File

@ -20,31 +20,38 @@ package org.jclouds.rest.binders;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.http.HttpUtils.replaceMatrixParam;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder; import org.jclouds.rest.Binder;
import org.jclouds.rest.internal.GeneratedHttpRequest;
/** /**
* Binds the map to matrix parameters. * Binds the map to matrix parameters.
* *
* @author Adrian Cole * @author Adrian Cole
* @since 4.0
*/ */
public class BindMapToMatrixParams implements Binder { public class BindMapToMatrixParams implements Binder {
private final Provider<UriBuilder> builder;
@Inject
BindMapToMatrixParams(Provider<UriBuilder> builder) {
this.builder = builder;
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void bindToRequest(HttpRequest request, Object input) { public void bindToRequest(HttpRequest request, Object input) {
checkArgument(checkNotNull(request, "input") instanceof GeneratedHttpRequest,
"this binder is only valid for GeneratedHttpRequests!");
checkArgument(checkNotNull(input, "input") instanceof Map, checkArgument(checkNotNull(input, "input") instanceof Map,
"this binder is only valid for Maps!"); "this binder is only valid for Maps!");
Map<String, String> map = (Map<String, String>) input; Map<String, String> map = (Map<String, String>) input;
for (Entry<String, String> entry : map.entrySet()) { for (Entry<String, String> entry : map.entrySet()) {
((GeneratedHttpRequest) request).replaceMatrixParam(entry.getKey(), entry.getValue()); replaceMatrixParam(request, entry.getKey(), entry.getValue(), builder.get());
} }
} }

View File

@ -22,11 +22,11 @@ import java.util.concurrent.ConcurrentMap;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton; import javax.inject.Singleton;
import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl; import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.TransformingHttpCommand; import org.jclouds.http.TransformingHttpCommand;
import org.jclouds.http.TransformingHttpCommandExecutorService; import org.jclouds.http.TransformingHttpCommandExecutorService;
@ -37,7 +37,6 @@ import org.jclouds.rest.AsyncClientFactory;
import org.jclouds.rest.HttpAsyncClient; import org.jclouds.rest.HttpAsyncClient;
import org.jclouds.rest.HttpClient; import org.jclouds.rest.HttpClient;
import org.jclouds.rest.internal.AsyncRestClientProxy; import org.jclouds.rest.internal.AsyncRestClientProxy;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import com.google.common.base.Function; import com.google.common.base.Function;
@ -109,14 +108,11 @@ public class RestModule extends AbstractModule {
private static class Factory implements AsyncRestClientProxy.Factory { private static class Factory implements AsyncRestClientProxy.Factory {
@Inject @Inject
private TransformingHttpCommandExecutorService executorService; private TransformingHttpCommandExecutorService executorService;
@Inject
private Provider<UriBuilder> uriBuilderProvider;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public TransformingHttpCommand<?> create(GeneratedHttpRequest<?> request, public TransformingHttpCommand<?> create(HttpRequest request,
Function<HttpResponse, ?> transformer) { Function<HttpResponse, ?> transformer) {
return new TransformingHttpCommandImpl(uriBuilderProvider, executorService, request, return new TransformingHttpCommandImpl(executorService, request, transformer);
transformer);
} }
} }

View File

@ -34,6 +34,7 @@ import javax.inject.Singleton;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.concurrent.FutureExceptionParser; import org.jclouds.concurrent.FutureExceptionParser;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.TransformingHttpCommand; import org.jclouds.http.TransformingHttpCommand;
import org.jclouds.internal.ClassMethodArgs; import org.jclouds.internal.ClassMethodArgs;
@ -107,11 +108,11 @@ public class AsyncRestClientProxy<T> implements InvocationHandler {
if (exceptionParser instanceof InvocationContext) { if (exceptionParser instanceof InvocationContext) {
((InvocationContext) exceptionParser).setContext(null); ((InvocationContext) exceptionParser).setContext(null);
} }
GeneratedHttpRequest<T> request; HttpRequest request;
try { try {
request = annotationProcessor.createRequest(method, args); request = annotationProcessor.createRequest(method, args);
if (exceptionParser instanceof InvocationContext) { if (exceptionParser instanceof InvocationContext) {
((InvocationContext) exceptionParser).setContext(request); ((InvocationContext) exceptionParser).setContext((GeneratedHttpRequest<T>) request);
} }
} catch (RuntimeException e) { } catch (RuntimeException e) {
if (exceptionParser != null) { if (exceptionParser != null) {
@ -143,7 +144,7 @@ public class AsyncRestClientProxy<T> implements InvocationHandler {
} }
public static interface Factory { public static interface Factory {
public TransformingHttpCommand<?> create(GeneratedHttpRequest<?> request, public TransformingHttpCommand<?> create(HttpRequest request,
Function<HttpResponse, ?> transformer); Function<HttpResponse, ?> transformer);
} }

View File

@ -20,17 +20,9 @@ package org.jclouds.rest.internal;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URI; import java.net.URI;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Map.Entry;
import javax.inject.Provider;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import com.google.inject.internal.Nullable;
/** /**
* Represents a request generated from annotations * Represents a request generated from annotations
* *
@ -40,15 +32,15 @@ public class GeneratedHttpRequest<T> extends HttpRequest {
private final Class<T> declaring; private final Class<T> declaring;
private final Method javaMethod; private final Method javaMethod;
private final Object[] args; private final Object[] args;
private final RestAnnotationProcessor<T> processor;
private final Provider<UriBuilder> uriBuilderProvider;
GeneratedHttpRequest(Provider<UriBuilder> uriBuilderProvider, String method, URI endpoint, GeneratedHttpRequest(String method, URI endpoint, Class<T> declaring, Method javaMethod,
RestAnnotationProcessor<T> processor, Class<T> declaring, Method javaMethod,
Object... args) { Object... args) {
super(method, endpoint); this(method, endpoint, new char[] {}, declaring, javaMethod, args);
this.uriBuilderProvider = uriBuilderProvider; }
this.processor = processor;
GeneratedHttpRequest(String method, URI endpoint, char[] skips, Class<T> declaring,
Method javaMethod, Object... args) {
super(method, endpoint, skips);
this.declaring = declaring; this.declaring = declaring;
this.javaMethod = javaMethod; this.javaMethod = javaMethod;
this.args = args; this.args = args;
@ -66,73 +58,4 @@ public class GeneratedHttpRequest<T> extends HttpRequest {
return args; return args;
} }
public RestAnnotationProcessor<T> getProcessor() {
return processor;
}
public void replaceMatrixParam(String name, Object... values) {
UriBuilder builder = uriBuilderProvider.get().uri(getEndpoint());
builder.replaceMatrixParam(name, values);
replacePath(builder.build().getPath());
}
public void addQueryParam(String name, String... values) {
setEndpoint(processor.addQueryParam(getEndpoint(), name, values));
}
public void replaceQuery(String query, @Nullable Comparator<Entry<String, String>> sorter) {
setEndpoint(processor.replaceQuery(getEndpoint(), query, sorter));
}
public void replacePath(String path) {
UriBuilder builder = uriBuilderProvider.get().uri(getEndpoint());
builder.replacePath(path);
setEndpoint(builder.build());
}
public void addFormParam(String name, String... values) {
this
.setPayload(processor.addFormParam(getPayload().getRawContent().toString(), name,
values));
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + Arrays.hashCode(args);
result = prime * result + ((declaring == null) ? 0 : declaring.hashCode());
result = prime * result + ((javaMethod == null) ? 0 : javaMethod.hashCode());
result = prime * result + ((processor == null) ? 0 : processor.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
GeneratedHttpRequest<?> other = (GeneratedHttpRequest<?>) obj;
if (!Arrays.equals(args, other.args))
return false;
if (declaring == null) {
if (other.declaring != null)
return false;
} else if (!declaring.equals(other.declaring))
return false;
if (javaMethod == null) {
if (other.javaMethod != null)
return false;
} else if (!javaMethod.equals(other.javaMethod))
return false;
if (processor == null) {
if (other.processor != null)
return false;
} else if (!processor.equals(other.processor))
return false;
return true;
}
} }

View File

@ -20,6 +20,8 @@ package org.jclouds.rest.internal;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.http.HttpUtils.makeQueryLine;
import static org.jclouds.http.HttpUtils.parseQueryToMap;
import static org.jclouds.util.Utils.replaceTokens; import static org.jclouds.util.Utils.replaceTokens;
import java.io.InputStream; import java.io.InputStream;
@ -32,11 +34,9 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.SortedSet;
import java.util.Map.Entry; import java.util.Map.Entry;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -224,9 +224,9 @@ public class RestAnnotationProcessor<T> {
@Inject @Inject
private InputParamValidator inputParamValidator; private InputParamValidator inputParamValidator;
@SuppressWarnings("unchecked")
@VisibleForTesting @VisibleForTesting
public Function<HttpResponse, ?> createResponseParser(Method method, public Function<HttpResponse, ?> createResponseParser(Method method, HttpRequest request) {
GeneratedHttpRequest<T> request) {
Function<HttpResponse, ?> transformer; Function<HttpResponse, ?> transformer;
Class<? extends HandlerWithResult<?>> handler = getSaxResponseParserClassOrNull(method); Class<? extends HandlerWithResult<?>> handler = getSaxResponseParserClassOrNull(method);
if (handler != null) { if (handler != null) {
@ -235,7 +235,7 @@ public class RestAnnotationProcessor<T> {
transformer = injector.getInstance(getParserOrThrowException(method)); transformer = injector.getInstance(getParserOrThrowException(method));
} }
if (transformer instanceof InvocationContext) { if (transformer instanceof InvocationContext) {
((InvocationContext) transformer).setContext(request); ((InvocationContext) transformer).setContext((GeneratedHttpRequest<T>) request);
} }
return transformer; return transformer;
} }
@ -421,8 +421,8 @@ public class RestAnnotationProcessor<T> {
throw new IllegalStateException(e); throw new IllegalStateException(e);
} }
GeneratedHttpRequest<T> request = new GeneratedHttpRequest<T>(uriBuilderProvider, httpMethod, GeneratedHttpRequest<T> request = new GeneratedHttpRequest<T>(httpMethod, endpoint, skips,
endpoint, this, declaring, method, args); declaring, method, args);
addHostHeaderIfAnnotatedWithVirtualHost(headers, request.getEndpoint().getHost(), method); addHostHeaderIfAnnotatedWithVirtualHost(headers, request.getEndpoint().getHost(), method);
addFiltersIfAnnotated(method, request); addFiltersIfAnnotated(method, request);
@ -488,83 +488,6 @@ public class RestAnnotationProcessor<T> {
return builder.build(); return builder.build();
} }
public URI addQueryParam(URI in, String key, String[] values) {
return addQueryParam(uriBuilderProvider, in, key, values, skips);
}
public static URI addQueryParam(Provider<UriBuilder> uriBuilderProvider, URI in, String key,
String[] values, char... skips) {
UriBuilder builder = uriBuilderProvider.get().uri(in);
Multimap<String, String> map = parseQueryToMap(in.getQuery());
map.putAll(key, Arrays.asList(values));
builder.replaceQuery(makeQueryLine(map, null, skips));
return builder.build();
}
public String addFormParam(String in, String key, String[] values) {
return addFormParam(in, key, values, skips);
}
public static String addFormParam(String in, String key, String[] values, char... skips) {
Multimap<String, String> map = parseQueryToMap(in);
map.putAll(key, Arrays.asList(values));
return makeQueryLine(map, null, skips);
}
public static Multimap<String, String> parseQueryToMap(String in) {
Multimap<String, String> map = LinkedListMultimap.create();
if (in == null) {
} else if (in.indexOf('&') == -1) {
if (in.contains("="))
parseKeyValueFromStringToMap(in, map);
else
map.put(in, null);
} else {
String[] parts = HttpUtils.urlDecode(in).split("&");
for (String part : parts) {
parseKeyValueFromStringToMap(part, map);
}
}
return map;
}
public static void parseKeyValueFromStringToMap(String stringToParse,
Multimap<String, String> map) {
// note that '=' can be a valid part of the value
int indexOfFirstEquals = stringToParse.indexOf('=');
String key = indexOfFirstEquals == -1 ? stringToParse : stringToParse.substring(0,
indexOfFirstEquals);
String value = indexOfFirstEquals == -1 ? null : stringToParse
.substring(indexOfFirstEquals + 1);
map.put(key, value);
}
public static SortedSet<Entry<String, String>> sortEntries(
Collection<Map.Entry<String, String>> in, Comparator<Map.Entry<String, String>> sorter) {
SortedSet<Entry<String, String>> entries = Sets.newTreeSet(sorter);
entries.addAll(in);
return entries;
}
public static String makeQueryLine(Multimap<String, String> params,
@Nullable Comparator<Map.Entry<String, String>> sorter, char... skips) {
Iterator<Map.Entry<String, String>> pairs = ((sorter == null) ? params.entries()
: sortEntries(params.entries(), sorter)).iterator();
StringBuilder formBuilder = new StringBuilder();
while (pairs.hasNext()) {
Map.Entry<String, String> pair = pairs.next();
formBuilder.append(HttpUtils.urlEncode(pair.getKey(), skips));
if (pair.getValue() != null && !pair.getValue().equals("")) {
formBuilder.append("=");
formBuilder.append(HttpUtils.urlEncode(pair.getValue(), skips));
}
if (pairs.hasNext())
formBuilder.append("&");
}
return formBuilder.toString();
}
private void addMatrixParams(UriBuilder builder, Collection<Entry<String, String>> tokenValues, private void addMatrixParams(UriBuilder builder, Collection<Entry<String, String>> tokenValues,
Method method, Object... args) { Method method, Object... args) {
if (declaring.isAnnotationPresent(MatrixParams.class)) { if (declaring.isAnnotationPresent(MatrixParams.class)) {
@ -819,13 +742,13 @@ public class RestAnnotationProcessor<T> {
} }
public String getHttpMethodOrConstantOrThrowException(Method method) { public String getHttpMethodOrConstantOrThrowException(Method method) {
Set<String> httpMethods = IsHttpMethod.getHttpMethods(method); Set<String> requests = IsHttpMethod.getHttpMethods(method);
if (httpMethods == null || httpMethods.size() != 1) { if (requests == null || requests.size() != 1) {
throw new IllegalStateException( throw new IllegalStateException(
"You must use at least one, but no more than one http method or pathparam annotation on: " "You must use at least one, but no more than one http method or pathparam annotation on: "
+ method.toString()); + method.toString());
} }
return httpMethods.iterator().next(); return requests.iterator().next();
} }
public void addHostHeaderIfAnnotatedWithVirtualHost(Multimap<String, String> headers, public void addHostHeaderIfAnnotatedWithVirtualHost(Multimap<String, String> headers,

View File

@ -18,53 +18,13 @@
*/ */
package org.jclouds.http; package org.jclouds.http;
import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.replay;
import static org.testng.Assert.assertEquals;
import java.net.URI;
import java.util.Collections;
import javax.inject.Provider;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
/** /**
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class TransformingHttpCommandImplTest { public class TransformingHttpCommandImplTest {
Provider<UriBuilder> uriBuilderProvider = new Provider<UriBuilder>() {
@Override
public UriBuilder get() {
return new UriBuilderImpl();
}
};
@SuppressWarnings("unchecked")
@Test
public void testChangeSchemeHostAndPortTo() {
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
TransformingHttpCommandImpl<?> command = new TransformingHttpCommandImpl(uriBuilderProvider,
null, request, null);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/mypath"));
request.setEndpoint(URI.create("https://remotehost:443/mypath"));
Multimap<String, String> headers = HashMultimap.create();
expect(request.getHeaders()).andReturn(headers);
replay(request);
command.changeSchemeHostAndPortTo("https", "remotehost", 443);
assertEquals(headers.get(HttpHeaders.HOST), Collections.singletonList("remotehost"));
}
@Test @Test
public void testTransformingHttpCommandImpl() { public void testTransformingHttpCommandImpl() {

View File

@ -98,14 +98,18 @@ public class BackoffLimitedRetryHandlerTest {
} }
}; };
private HttpUtils utils;
@BeforeTest @BeforeTest
void setupExecutorService() throws Exception { void setupExecutorService() throws Exception {
ExecutorService execService = Executors.newCachedThreadPool(); ExecutorService execService = Executors.newCachedThreadPool();
BackoffLimitedRetryHandler backoff = new BackoffLimitedRetryHandler();
utils = new HttpUtils(0, 500, 1, 1);
RedirectionRetryHandler retry = new RedirectionRetryHandler(uriBuilderProvider, backoff);
JavaUrlHttpCommandExecutorService httpService = new JavaUrlHttpCommandExecutorService( JavaUrlHttpCommandExecutorService httpService = new JavaUrlHttpCommandExecutorService(
execService, new DelegatingRetryHandler(uriBuilderProvider), execService, new DelegatingRetryHandler(backoff, retry),
new BackoffLimitedRetryHandler(), new DelegatingErrorHandler(), new HttpWire(), new BackoffLimitedRetryHandler(), new DelegatingErrorHandler(), new HttpWire(),
new HttpUtils(0, 500, 1, 1), null); utils, null);
executorService = new TransformingHttpCommandExecutorServiceImpl(httpService); executorService = new TransformingHttpCommandExecutorServiceImpl(httpService);
} }
@ -161,8 +165,8 @@ public class BackoffLimitedRetryHandlerTest {
private HttpCommand createCommand() throws SecurityException, NoSuchMethodException { private HttpCommand createCommand() throws SecurityException, NoSuchMethodException {
Method method = IntegrationTestAsyncClient.class.getMethod("download", String.class); Method method = IntegrationTestAsyncClient.class.getMethod("download", String.class);
return new TransformingHttpCommandImpl<String>(uriBuilderProvider, executorService, processor return new TransformingHttpCommandImpl<String>(executorService, processor.createRequest(
.createRequest(method, "1"), new ReturnStringIf200()); method, "1"), new ReturnStringIf200());
} }
@Test @Test

View File

@ -29,13 +29,13 @@ import java.lang.reflect.Method;
import org.jclouds.concurrent.config.ConfiguresExecutorService; import org.jclouds.concurrent.config.ConfiguresExecutorService;
import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpUtils; import org.jclouds.http.HttpUtils;
import org.jclouds.http.TransformingHttpCommandExecutorService; import org.jclouds.http.TransformingHttpCommandExecutorService;
import org.jclouds.http.config.ConfiguresHttpCommandExecutorService; import org.jclouds.http.config.ConfiguresHttpCommandExecutorService;
import org.jclouds.logging.config.NullLoggingModule; import org.jclouds.logging.config.NullLoggingModule;
import org.jclouds.rest.RestContextFactory.ContextSpec; import org.jclouds.rest.RestContextFactory.ContextSpec;
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
@ -66,7 +66,7 @@ public abstract class RestClientTest<T> {
protected Injector injector; protected Injector injector;
protected abstract void checkFilters(GeneratedHttpRequest<T> httpMethod); protected abstract void checkFilters(HttpRequest request);
protected abstract TypeLiteral<RestAnnotationProcessor<T>> createTypeLiteral(); protected abstract TypeLiteral<RestAnnotationProcessor<T>> createTypeLiteral();
@ -101,22 +101,21 @@ public abstract class RestClientTest<T> {
} }
} }
protected void assertPayloadEquals(GeneratedHttpRequest<T> httpMethod, String toMatch) protected void assertPayloadEquals(HttpRequest request, String toMatch) throws IOException {
throws IOException { if (request.getPayload() == null) {
if (httpMethod.getPayload() == null) {
assertNull(toMatch); assertNull(toMatch);
} else { } else {
String payload = Utils.toStringAndClose(httpMethod.getPayload().getInput()); String payload = Utils.toStringAndClose(request.getPayload().getInput());
assertEquals(payload, toMatch); assertEquals(payload, toMatch);
} }
} }
protected void assertHeadersEqual(GeneratedHttpRequest<T> httpMethod, String toMatch) { protected void assertHeadersEqual(HttpRequest request, String toMatch) {
assertEquals(HttpUtils.sortAndConcatHeadersIntoString(httpMethod.getHeaders()), toMatch); assertEquals(HttpUtils.sortAndConcatHeadersIntoString(request.getHeaders()), toMatch);
} }
protected void assertRequestLineEquals(GeneratedHttpRequest<T> httpMethod, String toMatch) { protected void assertRequestLineEquals(HttpRequest request, String toMatch) {
assertEquals(httpMethod.getRequestLine(), toMatch); assertEquals(request.getRequestLine(), toMatch);
} }
protected void assertExceptionParserClassEquals(Method method, @Nullable Class<?> parserClass) { protected void assertExceptionParserClassEquals(Method method, @Nullable Class<?> parserClass) {
@ -133,8 +132,8 @@ public abstract class RestClientTest<T> {
} }
protected void assertResponseParserClassEquals(Method method, protected void assertResponseParserClassEquals(Method method,
GeneratedHttpRequest<T> httpMethod, @Nullable Class<?> parserClass) { HttpRequest request, @Nullable Class<?> parserClass) {
assertEquals(processor.createResponseParser(method, httpMethod).getClass(), parserClass); assertEquals(processor.createResponseParser(method, request).getClass(), parserClass);
} }
} }

View File

@ -18,14 +18,19 @@
*/ */
package org.jclouds.rest.binders; package org.jclouds.rest.binders;
import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createMock; import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.replay; import static org.easymock.classextension.EasyMock.replay;
import static org.easymock.classextension.EasyMock.verify;
import java.io.File; import java.io.File;
import java.net.URI; import java.net.URI;
import javax.inject.Provider;
import javax.ws.rs.HttpMethod; import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -40,27 +45,41 @@ import com.google.common.collect.ImmutableMap;
@Test(groups = "unit", testName = "rest.BindMapToMatrixParamsTest") @Test(groups = "unit", testName = "rest.BindMapToMatrixParamsTest")
public class BindMapToMatrixParamsTest { public class BindMapToMatrixParamsTest {
@Test
public void testCorrect() throws SecurityException, NoSuchMethodException {
HttpRequest request = createMock(HttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://momma/"));
request.setEndpoint(URI.create("http://momma/;imageName=foo"));
expect(request.getEndpoint()).andReturn(URI.create("http://momma/;imageName=foo"));
request.setEndpoint(URI.create("http://momma/;imageName=foo;serverId=2"));
replay(request);
BindMapToMatrixParams binder = new BindMapToMatrixParams(new Provider<UriBuilder>() {
@Override
public UriBuilder get() {
return new UriBuilderImpl();
}
});
binder.bindToRequest(request, ImmutableMap.of("imageName", "foo", "serverId", "2"));
verify(request);
}
@Test(expectedExceptions = IllegalArgumentException.class) @Test(expectedExceptions = IllegalArgumentException.class)
public void testMustBeMap() { public void testMustBeMap() {
BindMapToMatrixParams binder = new BindMapToMatrixParams(); BindMapToMatrixParams binder = new BindMapToMatrixParams(null);
HttpRequest request = new HttpRequest(HttpMethod.POST, URI.create("http://localhost")); HttpRequest request = new HttpRequest(HttpMethod.POST, URI.create("http://localhost"));
binder.bindToRequest(request, new File("foo")); binder.bindToRequest(request, new File("foo"));
} }
@Test
public void testCorrect() throws SecurityException, NoSuchMethodException {
BindMapToMatrixParams binder = new BindMapToMatrixParams();
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
request.replaceMatrixParam("imageName", "foo");
request.replaceMatrixParam("serverId", "2");
replay(request);
binder.bindToRequest(request, ImmutableMap.of("imageName", "foo", "serverId", "2"));
}
@Test(expectedExceptions = { NullPointerException.class, IllegalStateException.class }) @Test(expectedExceptions = { NullPointerException.class, IllegalStateException.class })
public void testNullIsBad() { public void testNullIsBad() {
BindMapToMatrixParams binder = new BindMapToMatrixParams(); BindMapToMatrixParams binder = new BindMapToMatrixParams(null);
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class); GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
binder.bindToRequest(request, null); binder.bindToRequest(request, null);
} }

View File

@ -130,9 +130,7 @@ import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps; import com.google.common.collect.Multimaps;
import com.google.common.io.Files; import com.google.common.io.Files;
@ -399,34 +397,34 @@ public class RestAnnotationProcessorTest {
public void testQuery() throws SecurityException, NoSuchMethodException { public void testQuery() throws SecurityException, NoSuchMethodException {
Method method = TestQuery.class.getMethod("foo"); Method method = TestQuery.class.getMethod("foo");
GeneratedHttpRequest<?> httpMethod = factory(TestQuery.class).createRequest(method, HttpRequest request = factory(TestQuery.class).createRequest(method,
new Object[] {}); new Object[] {});
assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), ""); assertEquals(request.getEndpoint().getPath(), "");
assertEquals(httpMethod.getEndpoint().getQuery(), "x-ms-version=2009-07-17&x-ms-rubbish=bin"); assertEquals(request.getEndpoint().getQuery(), "x-ms-version=2009-07-17&x-ms-rubbish=bin");
assertEquals(httpMethod.getMethod(), "FOO"); assertEquals(request.getMethod(), "FOO");
} }
public void testQuery2() throws SecurityException, NoSuchMethodException { public void testQuery2() throws SecurityException, NoSuchMethodException {
Method method = TestQuery.class.getMethod("foo2"); Method method = TestQuery.class.getMethod("foo2");
GeneratedHttpRequest<?> httpMethod = factory(TestQuery.class).createRequest(method, HttpRequest request = factory(TestQuery.class).createRequest(method,
new Object[] {}); new Object[] {});
assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), ""); assertEquals(request.getEndpoint().getPath(), "");
assertEquals(httpMethod.getEndpoint().getQuery(), assertEquals(request.getEndpoint().getQuery(),
"x-ms-version=2009-07-17&foo=bar&fooble=baz"); "x-ms-version=2009-07-17&foo=bar&fooble=baz");
assertEquals(httpMethod.getMethod(), "FOO"); assertEquals(request.getMethod(), "FOO");
} }
public void testQuery3() throws SecurityException, NoSuchMethodException { public void testQuery3() throws SecurityException, NoSuchMethodException {
Method method = TestQuery.class.getMethod("foo3", String.class); Method method = TestQuery.class.getMethod("foo3", String.class);
GeneratedHttpRequest<?> httpMethod = factory(TestQuery.class).createRequest(method, HttpRequest request = factory(TestQuery.class).createRequest(method,
new Object[] { "wonder" }); new Object[] { "wonder" });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), ""); assertEquals(request.getEndpoint().getPath(), "");
assertEquals(httpMethod.getEndpoint().getQuery(), assertEquals(request.getEndpoint().getQuery(),
"x-ms-version=2009-07-17&foo=bar&fooble=baz&robbie=wonder"); "x-ms-version=2009-07-17&foo=bar&fooble=baz&robbie=wonder");
assertEquals(httpMethod.getMethod(), "FOO"); assertEquals(request.getMethod(), "FOO");
} }
public interface TestPayloadParamVarargs { public interface TestPayloadParamVarargs {
@ -450,7 +448,7 @@ public class RestAnnotationProcessorTest {
} }
private void verifyTestPostOptions(Method method) { private void verifyTestPostOptions(Method method) {
GeneratedHttpRequest<?> httpMethod = factory(TestPayloadParamVarargs.class).createRequest( HttpRequest request = factory(TestPayloadParamVarargs.class).createRequest(
method, new Object[] { new HttpRequestOptions() { method, new Object[] { new HttpRequestOptions() {
public Multimap<String, String> buildMatrixParameters() { public Multimap<String, String> buildMatrixParameters() {
@ -478,15 +476,15 @@ public class RestAnnotationProcessorTest {
} }
} }); } });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), ""); assertEquals(request.getEndpoint().getPath(), "");
assertEquals(httpMethod.getMethod(), HttpMethod.POST); assertEquals(request.getMethod(), HttpMethod.POST);
assertEquals(httpMethod.getHeaders().size(), 2); assertEquals(request.getHeaders().size(), 2);
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections
.singletonList("application/unknown")); .singletonList("application/unknown"));
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections
.singletonList("fooya".getBytes().length + "")); .singletonList("fooya".getBytes().length + ""));
assertEquals(httpMethod.getPayload().toString(), "fooya"); assertEquals(request.getPayload().toString(), "fooya");
} }
public class TestCustomMethod { public class TestCustomMethod {
@ -497,11 +495,11 @@ public class RestAnnotationProcessorTest {
public void testCustomMethod() throws SecurityException, NoSuchMethodException { public void testCustomMethod() throws SecurityException, NoSuchMethodException {
Method method = TestCustomMethod.class.getMethod("foo"); Method method = TestCustomMethod.class.getMethod("foo");
GeneratedHttpRequest<?> httpMethod = factory(TestCustomMethod.class).createRequest(method, HttpRequest request = factory(TestCustomMethod.class).createRequest(method,
new Object[] {}); new Object[] {});
assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), ""); assertEquals(request.getEndpoint().getPath(), "");
assertEquals(httpMethod.getMethod(), "FOO"); assertEquals(request.getMethod(), "FOO");
} }
public interface Parent { public interface Parent {
@ -516,11 +514,11 @@ public class RestAnnotationProcessorTest {
public void testOverriddenMethod() throws SecurityException, NoSuchMethodException { public void testOverriddenMethod() throws SecurityException, NoSuchMethodException {
Method method = TestOverridden.class.getMethod("foo"); Method method = TestOverridden.class.getMethod("foo");
GeneratedHttpRequest<?> httpMethod = factory(TestOverridden.class).createRequest(method, HttpRequest request = factory(TestOverridden.class).createRequest(method,
new Object[] {}); new Object[] {});
assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), ""); assertEquals(request.getEndpoint().getPath(), "");
assertEquals(httpMethod.getMethod(), "POST"); assertEquals(request.getMethod(), "POST");
} }
public class TestOverriddenEndpoint implements Parent { public class TestOverriddenEndpoint implements Parent {
@ -537,22 +535,22 @@ public class RestAnnotationProcessorTest {
public void testOverriddenEndpointMethod() throws SecurityException, NoSuchMethodException { public void testOverriddenEndpointMethod() throws SecurityException, NoSuchMethodException {
Method method = TestOverriddenEndpoint.class.getMethod("foo"); Method method = TestOverriddenEndpoint.class.getMethod("foo");
GeneratedHttpRequest<?> httpMethod = factory(TestOverriddenEndpoint.class).createRequest( HttpRequest request = factory(TestOverriddenEndpoint.class).createRequest(
method, new Object[] {}); method, new Object[] {});
assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPort(), 1111); assertEquals(request.getEndpoint().getPort(), 1111);
assertEquals(httpMethod.getEndpoint().getPath(), ""); assertEquals(request.getEndpoint().getPath(), "");
assertEquals(httpMethod.getMethod(), "POST"); assertEquals(request.getMethod(), "POST");
} }
public void testOverriddenEndpointParameter() throws SecurityException, NoSuchMethodException { public void testOverriddenEndpointParameter() throws SecurityException, NoSuchMethodException {
Method method = TestOverriddenEndpoint.class.getMethod("foo", URI.class); Method method = TestOverriddenEndpoint.class.getMethod("foo", URI.class);
GeneratedHttpRequest<?> httpMethod = factory(TestOverriddenEndpoint.class).createRequest( HttpRequest request = factory(TestOverriddenEndpoint.class).createRequest(
method, new Object[] { URI.create("http://wowsa:8001") }); method, new Object[] { URI.create("http://wowsa:8001") });
assertEquals(httpMethod.getEndpoint().getHost(), "wowsa"); assertEquals(request.getEndpoint().getHost(), "wowsa");
assertEquals(httpMethod.getEndpoint().getPort(), 8001); assertEquals(request.getEndpoint().getPort(), 8001);
assertEquals(httpMethod.getEndpoint().getPath(), ""); assertEquals(request.getEndpoint().getPath(), "");
assertEquals(httpMethod.getMethod(), "POST"); assertEquals(request.getMethod(), "POST");
} }
public class TestPost { public class TestPost {
@ -579,49 +577,49 @@ public class RestAnnotationProcessorTest {
public void testCreatePostRequest() throws SecurityException, NoSuchMethodException { public void testCreatePostRequest() throws SecurityException, NoSuchMethodException {
Method method = TestPost.class.getMethod("post", String.class); Method method = TestPost.class.getMethod("post", String.class);
GeneratedHttpRequest<?> httpMethod = factory(TestPost.class).createRequest(method, "data"); HttpRequest request = factory(TestPost.class).createRequest(method, "data");
assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), ""); assertEquals(request.getEndpoint().getPath(), "");
assertEquals(httpMethod.getMethod(), HttpMethod.POST); assertEquals(request.getMethod(), HttpMethod.POST);
assertEquals(httpMethod.getHeaders().size(), 2); assertEquals(request.getHeaders().size(), 2);
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections
.singletonList("application/unknown")); .singletonList("application/unknown"));
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections
.singletonList("data".getBytes().length + "")); .singletonList("data".getBytes().length + ""));
assertEquals(httpMethod.getPayload().toString(), "data"); assertEquals(request.getPayload().toString(), "data");
} }
public void testCreatePostRequestNullOk() throws SecurityException, NoSuchMethodException { public void testCreatePostRequestNullOk() throws SecurityException, NoSuchMethodException {
Method method = TestPost.class.getMethod("post", String.class); Method method = TestPost.class.getMethod("post", String.class);
GeneratedHttpRequest<?> httpMethod = factory(TestPost.class).createRequest(method, HttpRequest request = factory(TestPost.class).createRequest(method,
new Object[] { null }); new Object[] { null });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), ""); assertEquals(request.getEndpoint().getPath(), "");
assertEquals(httpMethod.getMethod(), HttpMethod.POST); assertEquals(request.getMethod(), HttpMethod.POST);
assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(request.getHeaders().size(), 0);
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE).size(), 0); assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE).size(), 0);
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH).size(), 0); assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH).size(), 0);
assertEquals(httpMethod.getPayload(), null); assertEquals(request.getPayload(), null);
} }
public void testCreatePostJsonRequest() throws SecurityException, NoSuchMethodException { public void testCreatePostJsonRequest() throws SecurityException, NoSuchMethodException {
Method method = TestPost.class.getMethod("postAsJson", String.class); Method method = TestPost.class.getMethod("postAsJson", String.class);
GeneratedHttpRequest<?> httpMethod = factory(TestPost.class).createRequest(method, HttpRequest request = factory(TestPost.class).createRequest(method,
new Object[] { "data" }); new Object[] { "data" });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), ""); assertEquals(request.getEndpoint().getPath(), "");
assertEquals(httpMethod.getMethod(), HttpMethod.POST); assertEquals(request.getMethod(), HttpMethod.POST);
assertEquals(httpMethod.getHeaders().size(), 2); assertEquals(request.getHeaders().size(), 2);
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections
.singletonList("application/json")); .singletonList("application/json"));
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections
.singletonList("\"data\"".getBytes().length + "")); .singletonList("\"data\"".getBytes().length + ""));
assertEquals(httpMethod.getPayload().toString(), "\"data\""); assertEquals(request.getPayload().toString(), "\"data\"");
} }
public void testCreatePostWithPathRequest() throws SecurityException, NoSuchMethodException { public void testCreatePostWithPathRequest() throws SecurityException, NoSuchMethodException {
Method method = TestPost.class.getMethod("postWithPath", String.class, MapBinder.class); Method method = TestPost.class.getMethod("postWithPath", String.class, MapBinder.class);
GeneratedHttpRequest<?> httpMethod = factory(TestPost.class).createRequest(method, HttpRequest request = factory(TestPost.class).createRequest(method,
new Object[] { "data", new org.jclouds.rest.MapBinder() { new Object[] { "data", new org.jclouds.rest.MapBinder() {
public void bindToRequest(HttpRequest request, Map<String, String> postParams) { public void bindToRequest(HttpRequest request, Map<String, String> postParams) {
request.setPayload(postParams.get("fooble")); request.setPayload(postParams.get("fooble"));
@ -631,27 +629,27 @@ public class RestAnnotationProcessorTest {
throw new RuntimeException("this shouldn't be used in POST"); throw new RuntimeException("this shouldn't be used in POST");
} }
} }); } });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/data"); assertEquals(request.getEndpoint().getPath(), "/data");
assertEquals(httpMethod.getMethod(), HttpMethod.POST); assertEquals(request.getMethod(), HttpMethod.POST);
assertEquals(httpMethod.getHeaders().size(), 1); assertEquals(request.getHeaders().size(), 1);
assertEquals(httpMethod.getPayload().toString(), "data"); assertEquals(request.getPayload().toString(), "data");
} }
public void testCreatePostWithMethodBinder() throws SecurityException, NoSuchMethodException { public void testCreatePostWithMethodBinder() throws SecurityException, NoSuchMethodException {
Method method = TestPost.class.getMethod("postWithMethodBinder", String.class); Method method = TestPost.class.getMethod("postWithMethodBinder", String.class);
GeneratedHttpRequest<?> httpMethod = factory(TestPost.class).createRequest(method, HttpRequest request = factory(TestPost.class).createRequest(method,
new Object[] { "data", }); new Object[] { "data", });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/data"); assertEquals(request.getEndpoint().getPath(), "/data");
assertEquals(httpMethod.getMethod(), HttpMethod.POST); assertEquals(request.getMethod(), HttpMethod.POST);
assertEquals(httpMethod.getHeaders().size(), 2); assertEquals(request.getHeaders().size(), 2);
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections
.singletonList("application/json")); .singletonList("application/json"));
String expected = "{\"fooble\":\"data\"}"; String expected = "{\"fooble\":\"data\"}";
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections
.singletonList(expected.getBytes().length + "")); .singletonList(expected.getBytes().length + ""));
assertEquals(httpMethod.getPayload().toString(), expected); assertEquals(request.getPayload().toString(), expected);
} }
static interface TestMultipartForm { static interface TestMultipartForm {
@ -827,51 +825,51 @@ public class RestAnnotationProcessorTest {
public void testCreatePutWithMethodBinder() throws SecurityException, NoSuchMethodException { public void testCreatePutWithMethodBinder() throws SecurityException, NoSuchMethodException {
Method method = TestPut.class.getMethod("putWithMethodBinder", String.class); Method method = TestPut.class.getMethod("putWithMethodBinder", String.class);
GeneratedHttpRequest<?> httpMethod = factory(TestPut.class).createRequest(method, HttpRequest request = factory(TestPut.class).createRequest(method,
new Object[] { "data", }); new Object[] { "data", });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/data"); assertEquals(request.getEndpoint().getPath(), "/data");
assertEquals(httpMethod.getMethod(), HttpMethod.PUT); assertEquals(request.getMethod(), HttpMethod.PUT);
assertEquals(httpMethod.getHeaders().size(), 2); assertEquals(request.getHeaders().size(), 2);
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections
.singletonList("application/json")); .singletonList("application/json"));
String expected = "{\"fooble\":\"data\"}"; String expected = "{\"fooble\":\"data\"}";
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections
.singletonList(expected.getBytes().length + "")); .singletonList(expected.getBytes().length + ""));
assertEquals(httpMethod.getPayload().toString(), expected); assertEquals(request.getPayload().toString(), expected);
} }
public void testCreatePutWithMethodProduces() throws SecurityException, NoSuchMethodException { public void testCreatePutWithMethodProduces() throws SecurityException, NoSuchMethodException {
Method method = TestPut.class.getMethod("putWithMethodBinderProduces", String.class); Method method = TestPut.class.getMethod("putWithMethodBinderProduces", String.class);
GeneratedHttpRequest<?> httpMethod = factory(TestPut.class).createRequest(method, HttpRequest request = factory(TestPut.class).createRequest(method,
new Object[] { "data", }); new Object[] { "data", });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/data"); assertEquals(request.getEndpoint().getPath(), "/data");
assertEquals(httpMethod.getMethod(), HttpMethod.PUT); assertEquals(request.getMethod(), HttpMethod.PUT);
assertEquals(httpMethod.getHeaders().size(), 2); assertEquals(request.getHeaders().size(), 2);
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections
.singletonList("text/plain")); .singletonList("text/plain"));
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections
.singletonList("data".getBytes().length + "")); .singletonList("data".getBytes().length + ""));
assertEquals(httpMethod.getPayload().toString(), "data"); assertEquals(request.getPayload().toString(), "data");
} }
public void testCreatePutWithMethodConsumes() throws SecurityException, NoSuchMethodException { public void testCreatePutWithMethodConsumes() throws SecurityException, NoSuchMethodException {
Method method = TestPut.class.getMethod("putWithMethodBinderConsumes", String.class); Method method = TestPut.class.getMethod("putWithMethodBinderConsumes", String.class);
GeneratedHttpRequest<?> httpMethod = factory(TestPut.class).createRequest(method, HttpRequest request = factory(TestPut.class).createRequest(method,
new Object[] { "data", }); new Object[] { "data", });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/data"); assertEquals(request.getEndpoint().getPath(), "/data");
assertEquals(httpMethod.getMethod(), HttpMethod.PUT); assertEquals(request.getMethod(), HttpMethod.PUT);
assertEquals(httpMethod.getHeaders().size(), 3); assertEquals(request.getHeaders().size(), 3);
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections
.singletonList("application/json")); .singletonList("application/json"));
assertEquals(httpMethod.getHeaders().get(HttpHeaders.ACCEPT), Collections assertEquals(request.getHeaders().get(HttpHeaders.ACCEPT), Collections
.singletonList("application/json")); .singletonList("application/json"));
String expected = "{\"fooble\":\"data\"}"; String expected = "{\"fooble\":\"data\"}";
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections
.singletonList(expected.getBytes().length + "")); .singletonList(expected.getBytes().length + ""));
assertEquals(httpMethod.getPayload().toString(), expected); assertEquals(request.getPayload().toString(), expected);
} }
static class TestRequestFilter1 implements HttpRequestFilter { static class TestRequestFilter1 implements HttpRequestFilter {
@ -901,19 +899,19 @@ public class RestAnnotationProcessorTest {
@Test @Test
public void testRequestFilter() throws SecurityException, NoSuchMethodException { public void testRequestFilter() throws SecurityException, NoSuchMethodException {
Method method = TestRequestFilter.class.getMethod("get"); Method method = TestRequestFilter.class.getMethod("get");
GeneratedHttpRequest<?> httpMethod = factory(TestRequestFilter.class).createRequest(method, HttpRequest request = factory(TestRequestFilter.class).createRequest(method,
new Object[] {}); new Object[] {});
assertEquals(httpMethod.getFilters().size(), 2); assertEquals(request.getFilters().size(), 2);
assertEquals(httpMethod.getFilters().get(0).getClass(), TestRequestFilter1.class); assertEquals(request.getFilters().get(0).getClass(), TestRequestFilter1.class);
assertEquals(httpMethod.getFilters().get(1).getClass(), TestRequestFilter2.class); assertEquals(request.getFilters().get(1).getClass(), TestRequestFilter2.class);
} }
public void testRequestFilterOverride() throws SecurityException, NoSuchMethodException { public void testRequestFilterOverride() throws SecurityException, NoSuchMethodException {
Method method = TestRequestFilter.class.getMethod("getOverride"); Method method = TestRequestFilter.class.getMethod("getOverride");
GeneratedHttpRequest<?> httpMethod = factory(TestRequestFilter.class).createRequest(method, HttpRequest request = factory(TestRequestFilter.class).createRequest(method,
new Object[] {}); new Object[] {});
assertEquals(httpMethod.getFilters().size(), 1); assertEquals(request.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), TestRequestFilter2.class); assertEquals(request.getFilters().get(0).getClass(), TestRequestFilter2.class);
} }
@SkipEncoding('/') @SkipEncoding('/')
@ -927,21 +925,21 @@ public class RestAnnotationProcessorTest {
@Test @Test
public void testSkipEncoding() throws SecurityException, NoSuchMethodException { public void testSkipEncoding() throws SecurityException, NoSuchMethodException {
Method method = TestEncoding.class.getMethod("twoPaths", String.class, String.class); Method method = TestEncoding.class.getMethod("twoPaths", String.class, String.class);
GeneratedHttpRequest<?> httpMethod = factory(TestEncoding.class).createRequest(method, HttpRequest request = factory(TestEncoding.class).createRequest(method,
new Object[] { "1", "localhost" }); new Object[] { "1", "localhost" });
assertEquals(httpMethod.getEndpoint().getPath(), "/1/localhost"); assertEquals(request.getEndpoint().getPath(), "/1/localhost");
assertEquals(httpMethod.getMethod(), HttpMethod.GET); assertEquals(request.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(request.getHeaders().size(), 0);
} }
@Test @Test
public void testEncodingPath() throws SecurityException, NoSuchMethodException { public void testEncodingPath() throws SecurityException, NoSuchMethodException {
Method method = TestEncoding.class.getMethod("twoPaths", String.class, String.class); Method method = TestEncoding.class.getMethod("twoPaths", String.class, String.class);
GeneratedHttpRequest<?> httpMethod = factory(TestEncoding.class).createRequest(method, HttpRequest request = factory(TestEncoding.class).createRequest(method,
new Object[] { "/", "localhost" }); new Object[] { "/", "localhost" });
assertEquals(httpMethod.getEndpoint().getPath(), "///localhost"); assertEquals(request.getEndpoint().getPath(), "///localhost");
assertEquals(httpMethod.getMethod(), HttpMethod.GET); assertEquals(request.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(request.getHeaders().size(), 0);
} }
@SkipEncoding('/') @SkipEncoding('/')
@ -959,12 +957,12 @@ public class RestAnnotationProcessorTest {
@Test(enabled = false) @Test(enabled = false)
public void testConstantPathParam() throws SecurityException, NoSuchMethodException, IOException { public void testConstantPathParam() throws SecurityException, NoSuchMethodException, IOException {
Method method = TestConstantPathParam.class.getMethod("twoPaths", String.class, String.class); Method method = TestConstantPathParam.class.getMethod("twoPaths", String.class, String.class);
GeneratedHttpRequest<?> httpMethod = factory(TestConstantPathParam.class).createRequest( HttpRequest request = factory(TestConstantPathParam.class).createRequest(
method, new Object[] { "1", "localhost" }); method, new Object[] { "1", "localhost" });
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"GET http://localhost:9999/v1/ralphie/1/localhost HTTP/1.1"); "GET http://localhost:9999/v1/ralphie/1/localhost HTTP/1.1");
assertHeadersEqual(httpMethod, ""); assertHeadersEqual(request, "");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
} }
public class TestPath { public class TestPath {
@ -1020,55 +1018,55 @@ public class RestAnnotationProcessorTest {
public void testPathParamExtractor() throws SecurityException, NoSuchMethodException, public void testPathParamExtractor() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = TestPath.class.getMethod("onePathParamExtractor", String.class); Method method = TestPath.class.getMethod("onePathParamExtractor", String.class);
GeneratedHttpRequest<?> httpMethod = factory(TestPath.class).createRequest(method, HttpRequest request = factory(TestPath.class).createRequest(method,
new Object[] { "localhost" }); new Object[] { "localhost" });
assertRequestLineEquals(httpMethod, "GET http://localhost:9999/l HTTP/1.1"); assertRequestLineEquals(request, "GET http://localhost:9999/l HTTP/1.1");
assertHeadersEqual(httpMethod, ""); assertHeadersEqual(request, "");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
} }
@Test @Test
public void testQueryParamExtractor() throws SecurityException, NoSuchMethodException, public void testQueryParamExtractor() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = TestPath.class.getMethod("oneQueryParamExtractor", String.class); Method method = TestPath.class.getMethod("oneQueryParamExtractor", String.class);
GeneratedHttpRequest<?> httpMethod = factory(TestPath.class).createRequest(method, HttpRequest request = factory(TestPath.class).createRequest(method,
"localhost"); "localhost");
assertRequestLineEquals(httpMethod, "GET http://localhost:9999/?one=l HTTP/1.1"); assertRequestLineEquals(request, "GET http://localhost:9999/?one=l HTTP/1.1");
assertHeadersEqual(httpMethod, ""); assertHeadersEqual(request, "");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
} }
@Test @Test
public void testMatrixParamExtractor() throws SecurityException, NoSuchMethodException, public void testMatrixParamExtractor() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = TestPath.class.getMethod("oneMatrixParamExtractor", String.class); Method method = TestPath.class.getMethod("oneMatrixParamExtractor", String.class);
GeneratedHttpRequest<?> httpMethod = factory(TestPath.class).createRequest(method, HttpRequest request = factory(TestPath.class).createRequest(method,
new Object[] { "localhost" }); new Object[] { "localhost" });
assertRequestLineEquals(httpMethod, "GET http://localhost:9999/;one=l HTTP/1.1"); assertRequestLineEquals(request, "GET http://localhost:9999/;one=l HTTP/1.1");
assertHeadersEqual(httpMethod, ""); assertHeadersEqual(request, "");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
} }
@Test @Test
public void testFormParamExtractor() throws SecurityException, NoSuchMethodException, public void testFormParamExtractor() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = TestPath.class.getMethod("oneFormParamExtractor", String.class); Method method = TestPath.class.getMethod("oneFormParamExtractor", String.class);
GeneratedHttpRequest<?> httpMethod = factory(TestPath.class).createRequest(method, HttpRequest request = factory(TestPath.class).createRequest(method,
new Object[] { "localhost" }); new Object[] { "localhost" });
assertRequestLineEquals(httpMethod, "POST http://localhost:9999/ HTTP/1.1"); assertRequestLineEquals(request, "POST http://localhost:9999/ HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(request,
"Content-Length: 5\nContent-Type: application/x-www-form-urlencoded\n"); "Content-Length: 5\nContent-Type: application/x-www-form-urlencoded\n");
assertPayloadEquals(httpMethod, "one=l"); assertPayloadEquals(request, "one=l");
} }
@Test @Test
public void testParamExtractorMethod() throws SecurityException, NoSuchMethodException { public void testParamExtractorMethod() throws SecurityException, NoSuchMethodException {
Method method = TestPath.class.getMethod("onePathParamExtractorMethod", String.class); Method method = TestPath.class.getMethod("onePathParamExtractorMethod", String.class);
GeneratedHttpRequest<?> httpMethod = factory(TestPath.class).createRequest(method, HttpRequest request = factory(TestPath.class).createRequest(method,
new Object[] { "localhost" }); new Object[] { "localhost" });
assertEquals(httpMethod.getEndpoint().getPath(), "/l"); assertEquals(request.getEndpoint().getPath(), "/l");
assertEquals(httpMethod.getMethod(), HttpMethod.GET); assertEquals(request.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(request.getHeaders().size(), 0);
} }
static class FirstCharacter implements Function<Object, String> { static class FirstCharacter implements Function<Object, String> {
@ -1181,31 +1179,6 @@ public class RestAnnotationProcessorTest {
assertEquals(query, "x-amz-copy-source=/robot"); assertEquals(query, "x-amz-copy-source=/robot");
} }
@Test
public void testParseQueryToMapSingleParam() {
Multimap<String, String> parsedMap = RestAnnotationProcessor.parseQueryToMap("v=1.3");
assert parsedMap.keySet().size() == 1 : "Expected 1 key, found: " + parsedMap.keySet().size();
assert parsedMap.keySet().contains("v") : "Expected v to be a part of the keys";
String valueForV = Iterables.getOnlyElement(parsedMap.get("v"));
assert valueForV.equals("1.3") : "Expected the value for 'v' to be '1.3', found: "
+ valueForV;
}
@Test
public void testParseQueryToMapMultiParam() {
Multimap<String, String> parsedMap = RestAnnotationProcessor.parseQueryToMap("v=1.3&sig=123");
assert parsedMap.keySet().size() == 2 : "Expected 2 keys, found: "
+ parsedMap.keySet().size();
assert parsedMap.keySet().contains("v") : "Expected v to be a part of the keys";
assert parsedMap.keySet().contains("sig") : "Expected sig to be a part of the keys";
String valueForV = Iterables.getOnlyElement(parsedMap.get("v"));
assert valueForV.equals("1.3") : "Expected the value for 'v' to be '1.3', found: "
+ valueForV;
String valueForSig = Iterables.getOnlyElement(parsedMap.get("sig"));
assert valueForSig.equals("123") : "Expected the value for 'v' to be '123', found: "
+ valueForSig;
}
private interface TestMapMatrixParams { private interface TestMapMatrixParams {
@POST @POST
@Path("objects/{id}/action/{action}") @Path("objects/{id}/action/{action}")
@ -1218,25 +1191,12 @@ public class RestAnnotationProcessorTest {
UnsupportedEncodingException { UnsupportedEncodingException {
Method method = TestMapMatrixParams.class.getMethod("action", String.class, String.class, Method method = TestMapMatrixParams.class.getMethod("action", String.class, String.class,
Map.class); Map.class);
GeneratedHttpRequest<TestMapMatrixParams> httpMethod = factory(TestMapMatrixParams.class) HttpRequest request = factory(TestMapMatrixParams.class)
.createRequest(method, .createRequest(method,
new Object[] { "robot", "kill", ImmutableMap.of("death", "slow") }); new Object[] { "robot", "kill", ImmutableMap.of("death", "slow") });
assertEquals(httpMethod.getRequestLine(), assertEquals(request.getRequestLine(),
"POST http://localhost:9999/objects/robot/action/kill;death=slow HTTP/1.1"); "POST http://localhost:9999/objects/robot/action/kill;death=slow HTTP/1.1");
assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(request.getHeaders().size(), 0);
}
public void testParseBase64InForm() {
Multimap<String, String> expects = LinkedListMultimap.create();
expects.put("Version", "2009-11-30");
expects.put("Action", "ModifyInstanceAttribute");
expects.put("Attribute", "userData");
expects.put("Value", "dGVzdA==");
expects.put("InstanceId", "1");
assertEquals(
expects,
RestAnnotationProcessor
.parseQueryToMap("Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=userData&Value=dGVzdA%3D%3D&InstanceId=1"));
} }
@SkipEncoding('/') @SkipEncoding('/')
@ -1451,13 +1411,13 @@ public class RestAnnotationProcessorTest {
public void testPutPayload() throws SecurityException, NoSuchMethodException { public void testPutPayload() throws SecurityException, NoSuchMethodException {
Method method = TestTransformers.class.getMethod("put", Payload.class); Method method = TestTransformers.class.getMethod("put", Payload.class);
GeneratedHttpRequest<?> httpMethod = factory(TestQuery.class).createRequest(method, HttpRequest request = factory(TestQuery.class).createRequest(method,
Payloads.newStringPayload("whoops")); Payloads.newStringPayload("whoops"));
assertEquals(httpMethod.getRequestLine(), assertEquals(request.getRequestLine(),
"PUT http://localhost:9999?x-ms-version=2009-07-17 HTTP/1.1"); "PUT http://localhost:9999?x-ms-version=2009-07-17 HTTP/1.1");
assertEquals(httpMethod.getHeaders(), Multimaps.forMap(ImmutableMap.of("Content-Length", "6", assertEquals(request.getHeaders(), Multimaps.forMap(ImmutableMap.of("Content-Length", "6",
"Content-Type", "application/unknown"))); "Content-Type", "application/unknown")));
assertEquals(httpMethod.getPayload().getRawContent(), "whoops"); assertEquals(request.getPayload().getRawContent(), "whoops");
} }
@SuppressWarnings("static-access") @SuppressWarnings("static-access")
@ -1513,8 +1473,7 @@ public class RestAnnotationProcessorTest {
RestAnnotationProcessor<TestTransformers> processor = factory(TestTransformers.class); RestAnnotationProcessor<TestTransformers> processor = factory(TestTransformers.class);
Method method = TestTransformers.class.getMethod("oneTransformerWithContext"); Method method = TestTransformers.class.getMethod("oneTransformerWithContext");
GeneratedHttpRequest<TestTransformers> request = new GeneratedHttpRequest<TestTransformers>( GeneratedHttpRequest<TestTransformers> request = new GeneratedHttpRequest<TestTransformers>(
uriBuilderProvider, "GET", URI.create("http://localhost"), processor, "GET", URI.create("http://localhost"), TestTransformers.class, method);
TestTransformers.class, method);
Function<HttpResponse, ?> transformer = processor.createResponseParser(method, request); Function<HttpResponse, ?> transformer = processor.createResponseParser(method, request);
assertEquals(transformer.getClass(), ReturnStringIf200Context.class); assertEquals(transformer.getClass(), ReturnStringIf200Context.class);
assertEquals(((ReturnStringIf200Context) transformer).request, request); assertEquals(((ReturnStringIf200Context) transformer).request, request);
@ -1579,15 +1538,15 @@ public class RestAnnotationProcessorTest {
GetOptions options = GetOptions.Builder.ifModifiedSince(date); GetOptions options = GetOptions.Builder.ifModifiedSince(date);
HttpRequestOptions[] optionsHolder = new HttpRequestOptions[] {}; HttpRequestOptions[] optionsHolder = new HttpRequestOptions[] {};
Method method = TestRequest.class.getMethod("get", String.class, optionsHolder.getClass()); Method method = TestRequest.class.getMethod("get", String.class, optionsHolder.getClass());
GeneratedHttpRequest<?> httpMethod = factory(TestRequest.class).createRequest(method, HttpRequest request = factory(TestRequest.class).createRequest(method,
new Object[] { "1", options }); new Object[] { "1", options });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/1"); assertEquals(request.getEndpoint().getPath(), "/1");
assertEquals(httpMethod.getMethod(), HttpMethod.GET); assertEquals(request.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 2); assertEquals(request.getHeaders().size(), 2);
assertEquals(httpMethod.getHeaders().get(HttpHeaders.HOST), Collections assertEquals(request.getHeaders().get(HttpHeaders.HOST), Collections
.singletonList("localhost")); .singletonList("localhost"));
assertEquals(httpMethod.getHeaders().get(HttpHeaders.IF_MODIFIED_SINCE), Collections assertEquals(request.getHeaders().get(HttpHeaders.IF_MODIFIED_SINCE), Collections
.singletonList(dateService.rfc822DateFormat(date))); .singletonList(dateService.rfc822DateFormat(date)));
} }
@ -1596,15 +1555,15 @@ public class RestAnnotationProcessorTest {
Date date = new Date(); Date date = new Date();
GetOptions options = GetOptions.Builder.ifModifiedSince(date); GetOptions options = GetOptions.Builder.ifModifiedSince(date);
Method method = TestRequest.class.getMethod("get", String.class, HttpRequestOptions.class); Method method = TestRequest.class.getMethod("get", String.class, HttpRequestOptions.class);
GeneratedHttpRequest<?> httpMethod = factory(TestRequest.class).createRequest(method, HttpRequest request = factory(TestRequest.class).createRequest(method,
new Object[] { "1", options }); new Object[] { "1", options });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/1"); assertEquals(request.getEndpoint().getPath(), "/1");
assertEquals(httpMethod.getMethod(), HttpMethod.GET); assertEquals(request.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 2); assertEquals(request.getHeaders().size(), 2);
assertEquals(httpMethod.getHeaders().get(HttpHeaders.HOST), Collections assertEquals(request.getHeaders().get(HttpHeaders.HOST), Collections
.singletonList("localhost")); .singletonList("localhost"));
assertEquals(httpMethod.getHeaders().get(HttpHeaders.IF_MODIFIED_SINCE), Collections assertEquals(request.getHeaders().get(HttpHeaders.IF_MODIFIED_SINCE), Collections
.singletonList(dateService.rfc822DateFormat(date))); .singletonList(dateService.rfc822DateFormat(date)));
} }
@ -1619,33 +1578,33 @@ public class RestAnnotationProcessorTest {
NoSuchMethodException, IOException { NoSuchMethodException, IOException {
PrefixOptions options = new PrefixOptions().withPrefix("1"); PrefixOptions options = new PrefixOptions().withPrefix("1");
Method method = TestRequest.class.getMethod("get", String.class, HttpRequestOptions.class); Method method = TestRequest.class.getMethod("get", String.class, HttpRequestOptions.class);
GeneratedHttpRequest<?> httpMethod = factory(TestRequest.class).createRequest(method, HttpRequest request = factory(TestRequest.class).createRequest(method,
new Object[] { "1", options }); new Object[] { "1", options });
assertRequestLineEquals(httpMethod, "GET http://localhost:9999/1?prefix=1 HTTP/1.1"); assertRequestLineEquals(request, "GET http://localhost:9999/1?prefix=1 HTTP/1.1");
assertHeadersEqual(httpMethod, "Host: localhost\n"); assertHeadersEqual(request, "Host: localhost\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
} }
public void testCreateGetQuery() throws SecurityException, NoSuchMethodException { public void testCreateGetQuery() throws SecurityException, NoSuchMethodException {
Method method = TestRequest.class.getMethod("getQuery", String.class); Method method = TestRequest.class.getMethod("getQuery", String.class);
GeneratedHttpRequest<?> httpMethod = factory(TestRequest.class).createRequest(method, HttpRequest request = factory(TestRequest.class).createRequest(method,
new Object[] { "1" }); new Object[] { "1" });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/1"); assertEquals(request.getEndpoint().getPath(), "/1");
assertEquals(httpMethod.getEndpoint().getQuery(), "max-keys=0"); assertEquals(request.getEndpoint().getQuery(), "max-keys=0");
assertEquals(httpMethod.getMethod(), HttpMethod.GET); assertEquals(request.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(request.getHeaders().size(), 0);
} }
public void testCreateGetQueryNull() throws SecurityException, NoSuchMethodException { public void testCreateGetQueryNull() throws SecurityException, NoSuchMethodException {
Method method = TestRequest.class.getMethod("getQueryNull", String.class); Method method = TestRequest.class.getMethod("getQueryNull", String.class);
GeneratedHttpRequest<?> httpMethod = factory(TestRequest.class).createRequest(method, HttpRequest request = factory(TestRequest.class).createRequest(method,
new Object[] { "1" }); new Object[] { "1" });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/1"); assertEquals(request.getEndpoint().getPath(), "/1");
assertEquals(httpMethod.getEndpoint().getQuery(), "acl"); assertEquals(request.getEndpoint().getQuery(), "acl");
assertEquals(httpMethod.getMethod(), HttpMethod.GET); assertEquals(request.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(request.getHeaders().size(), 0);
} }
public class PayloadOptions extends BaseHttpRequestOptions { public class PayloadOptions extends BaseHttpRequestOptions {
@ -1660,18 +1619,18 @@ public class RestAnnotationProcessorTest {
PayloadOptions options = new PayloadOptions(); PayloadOptions options = new PayloadOptions();
Method method = TestRequest.class.getMethod("putOptions", String.class, Method method = TestRequest.class.getMethod("putOptions", String.class,
HttpRequestOptions.class); HttpRequestOptions.class);
GeneratedHttpRequest<?> httpMethod = factory(TestRequest.class).createRequest(method, HttpRequest request = factory(TestRequest.class).createRequest(method,
new Object[] { "1", options }); new Object[] { "1", options });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/1"); assertEquals(request.getEndpoint().getPath(), "/1");
assertEquals(httpMethod.getMethod(), HttpMethod.PUT); assertEquals(request.getMethod(), HttpMethod.PUT);
assertEquals(httpMethod.getHeaders().size(), 3); assertEquals(request.getHeaders().size(), 3);
assertEquals(httpMethod.getHeaders().get(HttpHeaders.HOST), Collections assertEquals(request.getHeaders().get(HttpHeaders.HOST), Collections
.singletonList("localhost")); .singletonList("localhost"));
assertEquals(httpMethod.getPayload().toString(), "foo"); assertEquals(request.getPayload().toString(), "foo");
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections
.singletonList("application/unknown")); .singletonList("application/unknown"));
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections
.singletonList("foo".getBytes().length + "")); .singletonList("foo".getBytes().length + ""));
} }
@ -1684,47 +1643,47 @@ public class RestAnnotationProcessorTest {
public void testCreateGetRequest(String key) throws SecurityException, NoSuchMethodException, public void testCreateGetRequest(String key) throws SecurityException, NoSuchMethodException,
UnsupportedEncodingException { UnsupportedEncodingException {
Method method = TestRequest.class.getMethod("get", String.class, String.class); Method method = TestRequest.class.getMethod("get", String.class, String.class);
GeneratedHttpRequest<?> httpMethod = factory(TestRequest.class).createRequest(method, HttpRequest request = factory(TestRequest.class).createRequest(method,
new Object[] { key, "localhost" }); new Object[] { key, "localhost" });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getHost(), "localhost");
String expectedPath = "/" + URLEncoder.encode(key, "UTF-8").replaceAll("\\+", "%20"); String expectedPath = "/" + URLEncoder.encode(key, "UTF-8").replaceAll("\\+", "%20");
assertEquals(httpMethod.getEndpoint().getRawPath(), expectedPath); assertEquals(request.getEndpoint().getRawPath(), expectedPath);
assertEquals(httpMethod.getEndpoint().getPath(), "/" + key); assertEquals(request.getEndpoint().getPath(), "/" + key);
assertEquals(httpMethod.getMethod(), HttpMethod.GET); assertEquals(request.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 1); assertEquals(request.getHeaders().size(), 1);
assertEquals(httpMethod.getHeaders().get(HttpHeaders.HOST), Collections assertEquals(request.getHeaders().get(HttpHeaders.HOST), Collections
.singletonList("localhost")); .singletonList("localhost"));
} }
public void testCreatePutRequest() throws SecurityException, NoSuchMethodException { public void testCreatePutRequest() throws SecurityException, NoSuchMethodException {
Method method = TestRequest.class.getMethod("put", String.class, String.class); Method method = TestRequest.class.getMethod("put", String.class, String.class);
GeneratedHttpRequest<?> httpMethod = factory(TestRequest.class).createRequest(method, HttpRequest request = factory(TestRequest.class).createRequest(method,
new Object[] { "111", "data" }); new Object[] { "111", "data" });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/1"); assertEquals(request.getEndpoint().getPath(), "/1");
assertEquals(httpMethod.getMethod(), HttpMethod.PUT); assertEquals(request.getMethod(), HttpMethod.PUT);
assertEquals(httpMethod.getHeaders().size(), 2); assertEquals(request.getHeaders().size(), 2);
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections
.singletonList("application/unknown")); .singletonList("application/unknown"));
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections
.singletonList("data".getBytes().length + "")); .singletonList("data".getBytes().length + ""));
assertEquals(httpMethod.getPayload().toString(), "data"); assertEquals(request.getPayload().toString(), "data");
} }
public void testCreatePutHeader() throws SecurityException, NoSuchMethodException { public void testCreatePutHeader() throws SecurityException, NoSuchMethodException {
Method method = TestRequest.class.getMethod("putHeader", String.class, String.class); Method method = TestRequest.class.getMethod("putHeader", String.class, String.class);
GeneratedHttpRequest<?> httpMethod = factory(TestRequest.class).createRequest(method, HttpRequest request = factory(TestRequest.class).createRequest(method,
new Object[] { "1", "data" }); new Object[] { "1", "data" });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/1"); assertEquals(request.getEndpoint().getPath(), "/1");
assertEquals(httpMethod.getMethod(), HttpMethod.PUT); assertEquals(request.getMethod(), HttpMethod.PUT);
assertEquals(httpMethod.getHeaders().size(), 3); assertEquals(request.getHeaders().size(), 3);
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections
.singletonList("application/unknown")); .singletonList("application/unknown"));
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections
.singletonList("data".getBytes().length + "")); .singletonList("data".getBytes().length + ""));
assertEquals(httpMethod.getHeaders().get("foo"), Collections.singletonList("--1--")); assertEquals(request.getHeaders().get("foo"), Collections.singletonList("--1--"));
assertEquals(httpMethod.getPayload().toString(), "data"); assertEquals(request.getPayload().toString(), "data");
} }
public class TestVirtualHostMethod { public class TestVirtualHostMethod {
@ -1739,13 +1698,13 @@ public class RestAnnotationProcessorTest {
@Test @Test
public void testVirtualHostMethod() throws SecurityException, NoSuchMethodException { public void testVirtualHostMethod() throws SecurityException, NoSuchMethodException {
Method method = TestVirtualHostMethod.class.getMethod("get", String.class, String.class); Method method = TestVirtualHostMethod.class.getMethod("get", String.class, String.class);
GeneratedHttpRequest<?> httpMethod = factory(TestVirtualHostMethod.class).createRequest( HttpRequest request = factory(TestVirtualHostMethod.class).createRequest(
method, new Object[] { "1", "localhost" }); method, new Object[] { "1", "localhost" });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/1"); assertEquals(request.getEndpoint().getPath(), "/1");
assertEquals(httpMethod.getMethod(), HttpMethod.GET); assertEquals(request.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 1); assertEquals(request.getHeaders().size(), 1);
assertEquals(httpMethod.getHeaders().get(HttpHeaders.HOST), Collections assertEquals(request.getHeaders().get(HttpHeaders.HOST), Collections
.singletonList("localhost")); .singletonList("localhost"));
} }
@ -1775,36 +1734,36 @@ public class RestAnnotationProcessorTest {
@Test @Test
public void testVirtualHost() throws SecurityException, NoSuchMethodException { public void testVirtualHost() throws SecurityException, NoSuchMethodException {
Method method = TestVirtualHost.class.getMethod("get", String.class, String.class); Method method = TestVirtualHost.class.getMethod("get", String.class, String.class);
GeneratedHttpRequest<?> httpMethod = factory(TestVirtualHost.class).createRequest(method, HttpRequest request = factory(TestVirtualHost.class).createRequest(method,
new Object[] { "1", "localhost" }); new Object[] { "1", "localhost" });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/1"); assertEquals(request.getEndpoint().getPath(), "/1");
assertEquals(httpMethod.getMethod(), HttpMethod.GET); assertEquals(request.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 1); assertEquals(request.getHeaders().size(), 1);
assertEquals(httpMethod.getHeaders().get(HttpHeaders.HOST), Collections assertEquals(request.getHeaders().get(HttpHeaders.HOST), Collections
.singletonList("localhost")); .singletonList("localhost"));
} }
@Test @Test
public void testHostPrefix() throws SecurityException, NoSuchMethodException { public void testHostPrefix() throws SecurityException, NoSuchMethodException {
Method method = TestVirtualHost.class.getMethod("getPrefix", String.class, String.class); Method method = TestVirtualHost.class.getMethod("getPrefix", String.class, String.class);
GeneratedHttpRequest<?> httpMethod = factory(TestVirtualHost.class).createRequest(method, HttpRequest request = factory(TestVirtualHost.class).createRequest(method,
new Object[] { "1", "holy" }); new Object[] { "1", "holy" });
assertEquals(httpMethod.getEndpoint().getHost(), "holylocalhost"); assertEquals(request.getEndpoint().getHost(), "holylocalhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/1"); assertEquals(request.getEndpoint().getPath(), "/1");
assertEquals(httpMethod.getMethod(), HttpMethod.GET); assertEquals(request.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(request.getHeaders().size(), 0);
} }
@Test @Test
public void testHostPrefixDot() throws SecurityException, NoSuchMethodException { public void testHostPrefixDot() throws SecurityException, NoSuchMethodException {
Method method = TestVirtualHost.class.getMethod("getPrefixDot", String.class, String.class); Method method = TestVirtualHost.class.getMethod("getPrefixDot", String.class, String.class);
GeneratedHttpRequest<?> httpMethod = factory(TestVirtualHost.class).createRequest(method, HttpRequest request = factory(TestVirtualHost.class).createRequest(method,
new Object[] { "1", "holy" }); new Object[] { "1", "holy" });
assertEquals(httpMethod.getEndpoint().getHost(), "holy.localhost"); assertEquals(request.getEndpoint().getHost(), "holy.localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/1"); assertEquals(request.getEndpoint().getPath(), "/1");
assertEquals(httpMethod.getMethod(), HttpMethod.GET); assertEquals(request.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(request.getHeaders().size(), 0);
} }
@Test(expectedExceptions = IllegalArgumentException.class) @Test(expectedExceptions = IllegalArgumentException.class)
@ -1897,9 +1856,8 @@ public class RestAnnotationProcessorTest {
public void testPut() throws SecurityException, NoSuchMethodException { public void testPut() throws SecurityException, NoSuchMethodException {
RestAnnotationProcessor<TestPayload> processor = factory(TestPayload.class); RestAnnotationProcessor<TestPayload> processor = factory(TestPayload.class);
Method method = TestPayload.class.getMethod("put", String.class); Method method = TestPayload.class.getMethod("put", String.class);
GeneratedHttpRequest<TestPayload> request = new GeneratedHttpRequest<TestPayload>( GeneratedHttpRequest<TestPayload> request = new GeneratedHttpRequest<TestPayload>("GET", URI
uriBuilderProvider, "GET", URI.create("http://localhost"), processor, .create("http://localhost"), TestPayload.class, method, "test");
TestPayload.class, method, "test");
processor.decorateRequest(request); processor.decorateRequest(request);
assertEquals(request.getPayload().toString(), "test"); assertEquals(request.getPayload().toString(), "test");
assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections
@ -1915,9 +1873,8 @@ public class RestAnnotationProcessorTest {
RestAnnotationProcessor<TestPayload> processor = factory(TestPayload.class); RestAnnotationProcessor<TestPayload> processor = factory(TestPayload.class);
Method method = TestPayload.class.getMethod("putWithPath", String.class, String.class); Method method = TestPayload.class.getMethod("putWithPath", String.class, String.class);
GeneratedHttpRequest<TestPayload> request = new GeneratedHttpRequest<TestPayload>( GeneratedHttpRequest<TestPayload> request = new GeneratedHttpRequest<TestPayload>("GET", URI
uriBuilderProvider, "GET", URI.create("http://localhost"), processor, .create("http://localhost"), TestPayload.class, method, "rabble", "test");
TestPayload.class, method, "rabble", "test");
processor.decorateRequest(request); processor.decorateRequest(request);
assertEquals(request.getPayload().toString(), "test"); assertEquals(request.getPayload().toString(), "test");
assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections
@ -2044,22 +2001,22 @@ public class RestAnnotationProcessorTest {
} }
protected void assertPayloadEquals(GeneratedHttpRequest<?> httpMethod, String toMatch) protected void assertPayloadEquals(HttpRequest request, String toMatch)
throws IOException { throws IOException {
if (httpMethod.getPayload() == null) { if (request.getPayload() == null) {
assertNull(toMatch); assertNull(toMatch);
} else { } else {
String payload = Utils.toStringAndClose(httpMethod.getPayload().getInput()); String payload = Utils.toStringAndClose(request.getPayload().getInput());
assertEquals(payload, toMatch); assertEquals(payload, toMatch);
} }
} }
protected void assertHeadersEqual(GeneratedHttpRequest<?> httpMethod, String toMatch) { protected void assertHeadersEqual(HttpRequest request, String toMatch) {
assertEquals(HttpUtils.sortAndConcatHeadersIntoString(httpMethod.getHeaders()), toMatch); assertEquals(HttpUtils.sortAndConcatHeadersIntoString(request.getHeaders()), toMatch);
} }
protected void assertRequestLineEquals(GeneratedHttpRequest<?> httpMethod, String toMatch) { protected void assertRequestLineEquals(HttpRequest request, String toMatch) {
assertEquals(httpMethod.getRequestLine(), toMatch); assertEquals(request.getRequestLine(), toMatch);
} }
} }

View File

@ -18,14 +18,31 @@
*/ */
package org.jclouds.util; package org.jclouds.util;
import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.replay;
import static org.jclouds.http.HttpUtils.changeSchemeHostAndPortTo;
import static org.jclouds.http.HttpUtils.parseQueryToMap;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.net.URI; import java.net.URI;
import java.util.Collections;
import javax.inject.Provider;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.PerformanceTest; import org.jclouds.PerformanceTest;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpUtils; import org.jclouds.http.HttpUtils;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Iterables;
import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.Multimap;
/** /**
* This tests the performance of Digest commands. * This tests the performance of Digest commands.
* *
@ -33,6 +50,62 @@ import org.testng.annotations.Test;
*/ */
@Test(groups = "performance", sequential = true, testName = "jclouds.HttpUtils") @Test(groups = "performance", sequential = true, testName = "jclouds.HttpUtils")
public class HttpUtilsTest extends PerformanceTest { public class HttpUtilsTest extends PerformanceTest {
Provider<UriBuilder> uriBuilderProvider = new Provider<UriBuilder>() {
@Override
public UriBuilder get() {
return new UriBuilderImpl();
}
};
public void testParseBase64InForm() {
Multimap<String, String> expects = LinkedListMultimap.create();
expects.put("Version", "2009-11-30");
expects.put("Action", "ModifyInstanceAttribute");
expects.put("Attribute", "userData");
expects.put("Value", "dGVzdA==");
expects.put("InstanceId", "1");
assertEquals(
expects,
parseQueryToMap("Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=userData&Value=dGVzdA%3D%3D&InstanceId=1"));
}
@Test
public void testParseQueryToMapSingleParam() {
Multimap<String, String> parsedMap = parseQueryToMap("v=1.3");
assert parsedMap.keySet().size() == 1 : "Expected 1 key, found: " + parsedMap.keySet().size();
assert parsedMap.keySet().contains("v") : "Expected v to be a part of the keys";
String valueForV = Iterables.getOnlyElement(parsedMap.get("v"));
assert valueForV.equals("1.3") : "Expected the value for 'v' to be '1.3', found: "
+ valueForV;
}
@Test
public void testParseQueryToMapMultiParam() {
Multimap<String, String> parsedMap = parseQueryToMap("v=1.3&sig=123");
assert parsedMap.keySet().size() == 2 : "Expected 2 keys, found: "
+ parsedMap.keySet().size();
assert parsedMap.keySet().contains("v") : "Expected v to be a part of the keys";
assert parsedMap.keySet().contains("sig") : "Expected sig to be a part of the keys";
String valueForV = Iterables.getOnlyElement(parsedMap.get("v"));
assert valueForV.equals("1.3") : "Expected the value for 'v' to be '1.3', found: "
+ valueForV;
String valueForSig = Iterables.getOnlyElement(parsedMap.get("sig"));
assert valueForSig.equals("123") : "Expected the value for 'v' to be '123', found: "
+ valueForSig;
}
@Test
public void testChangeSchemeHostAndPortTo() {
HttpRequest request = createMock(HttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/mypath"));
request.setEndpoint(URI.create("https://remotehost:443/mypath"));
Multimap<String, String> headers = HashMultimap.create();
expect(request.getHeaders()).andReturn(headers);
replay(request);
changeSchemeHostAndPortTo(request, "https", "remotehost", 443, uriBuilderProvider.get());
assertEquals(headers.get(HttpHeaders.HOST), Collections.singletonList("remotehost"));
}
public void testIsEncoded() { public void testIsEncoded() {
assert HttpUtils.isUrlEncoded("/read-tests/%73%6f%6d%65%20%66%69%6c%65"); assert HttpUtils.isUrlEncoded("/read-tests/%73%6f%6d%65%20%66%69%6c%65");

View File

@ -23,20 +23,34 @@
*/ */
package org.jclouds.gogrid.binders; package org.jclouds.gogrid.binders;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.gogrid.reference.GoGridQueryParams.ID_KEY; import static org.jclouds.gogrid.reference.GoGridQueryParams.ID_KEY;
import static org.jclouds.http.HttpUtils.addQueryParamTo;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder; import org.jclouds.rest.Binder;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import com.google.common.collect.ImmutableList;
import com.google.common.primitives.Longs;
/** /**
* Binds IDs to corresponding query parameters * Binds IDs to corresponding query parameters
* *
* @author Oleksiy Yarmula * @author Oleksiy Yarmula
*/ */
@Singleton
public class BindIdsToQueryParams implements Binder { public class BindIdsToQueryParams implements Binder {
private final Provider<UriBuilder> builder;
@Inject
BindIdsToQueryParams(Provider<UriBuilder> builder) {
this.builder = builder;
}
/** /**
* Binds the ids to query parameters. The pattern, as specified by GoGrid's specification, is: * Binds the ids to query parameters. The pattern, as specified by GoGrid's specification, is:
@ -50,21 +64,16 @@ public class BindIdsToQueryParams implements Binder {
*/ */
@Override @Override
public void bindToRequest(HttpRequest request, Object input) { public void bindToRequest(HttpRequest request, Object input) {
checkArgument(checkNotNull(request, "request is null") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest<?> generatedRequest = (GeneratedHttpRequest<?>) request;
if (checkNotNull(input, "input is null") instanceof Long[]){ if (checkNotNull(input, "input is null") instanceof Long[]) {
Long[] names = (Long[]) input; Long[] names = (Long[]) input;
for (long id : names) addQueryParamTo(request, ID_KEY, ImmutableList.copyOf(names), builder.get());
generatedRequest.addQueryParam(ID_KEY, id + "");
} else if (input instanceof long[]) { } else if (input instanceof long[]) {
long[] names = (long[]) input; long[] names = (long[]) input;
addQueryParamTo(request, ID_KEY, Longs.asList(names), builder.get());
for (long id : names)
generatedRequest.addQueryParam(ID_KEY, id + "");
} else { } else {
throw new IllegalArgumentException("this binder is only valid for Long[] arguments: "+input.getClass()); throw new IllegalArgumentException("this binder is only valid for Long[] arguments: "
+ input.getClass());
} }
} }

View File

@ -26,10 +26,16 @@ package org.jclouds.gogrid.binders;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.gogrid.reference.GoGridQueryParams.NAME_KEY; import static org.jclouds.gogrid.reference.GoGridQueryParams.NAME_KEY;
import static org.jclouds.http.HttpUtils.addQueryParamTo;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder; import org.jclouds.rest.Binder;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import com.google.common.collect.ImmutableList;
/** /**
* Binds names to corresponding query parameters * Binds names to corresponding query parameters
@ -37,6 +43,12 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
* @author Oleksiy Yarmula * @author Oleksiy Yarmula
*/ */
public class BindNamesToQueryParams implements Binder { public class BindNamesToQueryParams implements Binder {
private final Provider<UriBuilder> builder;
@Inject
BindNamesToQueryParams(Provider<UriBuilder> builder) {
this.builder = builder;
}
/** /**
* Binds the names to query parameters. The pattern, as specified by GoGrid's specification, is: * Binds the names to query parameters. The pattern, as specified by GoGrid's specification, is:
@ -51,17 +63,9 @@ public class BindNamesToQueryParams implements Binder {
*/ */
@Override @Override
public void bindToRequest(HttpRequest request, Object input) { public void bindToRequest(HttpRequest request, Object input) {
checkArgument(checkNotNull(request, "request is null") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!");
checkArgument(checkNotNull(input, "input is null") instanceof String[], checkArgument(checkNotNull(input, "input is null") instanceof String[],
"this binder is only valid for String[] arguments"); "this binder is only valid for String[] arguments");
String[] names = (String[]) input; String[] names = (String[]) input;
GeneratedHttpRequest<?> generatedRequest = (GeneratedHttpRequest<?>) request; addQueryParamTo(request, NAME_KEY, ImmutableList.copyOf(names), builder.get());
for (String name : names) {
generatedRequest.addQueryParam(NAME_KEY, name);
}
} }
} }

View File

@ -21,10 +21,14 @@ package org.jclouds.gogrid.binders;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.gogrid.reference.GoGridQueryParams.OBJECT_KEY; import static org.jclouds.gogrid.reference.GoGridQueryParams.OBJECT_KEY;
import static org.jclouds.http.HttpUtils.addQueryParamTo;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder; import org.jclouds.rest.Binder;
import org.jclouds.rest.internal.GeneratedHttpRequest;
/** /**
* *
@ -33,6 +37,12 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
* @author Oleksiy Yarmula * @author Oleksiy Yarmula
*/ */
public class BindObjectNameToGetJobsRequestQueryParams implements Binder { public class BindObjectNameToGetJobsRequestQueryParams implements Binder {
private final Provider<UriBuilder> builder;
@Inject
BindObjectNameToGetJobsRequestQueryParams(Provider<UriBuilder> builder) {
this.builder = builder;
}
/** /**
* Maps the object's name to the input of <a * Maps the object's name to the input of <a
@ -40,15 +50,11 @@ public class BindObjectNameToGetJobsRequestQueryParams implements Binder {
*/ */
@Override @Override
public void bindToRequest(HttpRequest request, Object input) { public void bindToRequest(HttpRequest request, Object input) {
checkArgument(checkNotNull(request, "request is null") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!");
checkArgument(checkNotNull(input, "input is null") instanceof String, checkArgument(checkNotNull(input, "input is null") instanceof String,
"this binder is only valid for String arguments"); "this binder is only valid for String arguments");
String serverName = (String) input; String serverName = (String) input;
GeneratedHttpRequest<?> generatedRequest = (GeneratedHttpRequest<?>) request; addQueryParamTo(request, OBJECT_KEY, serverName, builder.get());
generatedRequest.addQueryParam(OBJECT_KEY, serverName);
} }
} }

View File

@ -22,13 +22,17 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import static org.jclouds.gogrid.reference.GoGridQueryParams.REAL_IP_LIST_KEY; import static org.jclouds.gogrid.reference.GoGridQueryParams.REAL_IP_LIST_KEY;
import static org.jclouds.http.HttpUtils.addQueryParamTo;
import java.util.List; import java.util.List;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.gogrid.domain.IpPortPair; import org.jclouds.gogrid.domain.IpPortPair;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder; import org.jclouds.rest.Binder;
import org.jclouds.rest.internal.GeneratedHttpRequest;
/** /**
* Binds a list of real IPs to the request. * Binds a list of real IPs to the request.
@ -38,17 +42,20 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
* @author Oleksiy Yarmula * @author Oleksiy Yarmula
*/ */
public class BindRealIpPortPairsToQueryParams implements Binder { public class BindRealIpPortPairsToQueryParams implements Binder {
private final Provider<UriBuilder> builder;
@Inject
BindRealIpPortPairsToQueryParams(Provider<UriBuilder> builder) {
this.builder = builder;
}
@SuppressWarnings( { "unchecked" }) @SuppressWarnings( { "unchecked" })
@Override @Override
public void bindToRequest(HttpRequest request, Object input) { public void bindToRequest(HttpRequest request, Object input) {
checkArgument(checkNotNull(request, "request is null") instanceof GeneratedHttpRequest,
"this binder is only valid for GeneratedHttpRequests!");
checkArgument(checkNotNull(input, "input is null") instanceof List, checkArgument(checkNotNull(input, "input is null") instanceof List,
"this binder is only valid for a List argument"); "this binder is only valid for a List argument");
List<IpPortPair> ipPortPairs = (List<IpPortPair>) input; List<IpPortPair> ipPortPairs = (List<IpPortPair>) input;
GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request;
int i = 0; int i = 0;
for (IpPortPair ipPortPair : ipPortPairs) { for (IpPortPair ipPortPair : ipPortPairs) {
@ -57,9 +64,10 @@ public class BindRealIpPortPairsToQueryParams implements Binder {
"There must be an IP address defined in Ip object"); "There must be an IP address defined in Ip object");
checkState(ipPortPair.getPort() > 0, "The port number must be a positive integer"); checkState(ipPortPair.getPort() > 0, "The port number must be a positive integer");
generatedRequest.addQueryParam(REAL_IP_LIST_KEY + i + ".ip", ipPortPair.getIp().getIp()); addQueryParamTo(request, REAL_IP_LIST_KEY + i + ".ip", ipPortPair.getIp().getIp(), builder
generatedRequest.addQueryParam(REAL_IP_LIST_KEY + i + ".port", String.valueOf(ipPortPair .get());
.getPort())); addQueryParamTo(request, REAL_IP_LIST_KEY + i + ".port", String.valueOf(ipPortPair
.getPort()), builder.get());
i++; i++;
} }
} }

View File

@ -22,11 +22,15 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import static org.jclouds.gogrid.reference.GoGridQueryParams.VIRTUAL_IP_KEY; import static org.jclouds.gogrid.reference.GoGridQueryParams.VIRTUAL_IP_KEY;
import static org.jclouds.http.HttpUtils.addQueryParamTo;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.gogrid.domain.IpPortPair; import org.jclouds.gogrid.domain.IpPortPair;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder; import org.jclouds.rest.Binder;
import org.jclouds.rest.internal.GeneratedHttpRequest;
/** /**
* Binds a virtual IP to the request. * Binds a virtual IP to the request.
@ -36,22 +40,26 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
* @author Oleksiy Yarmula * @author Oleksiy Yarmula
*/ */
public class BindVirtualIpPortPairToQueryParams implements Binder { public class BindVirtualIpPortPairToQueryParams implements Binder {
private final Provider<UriBuilder> builder;
@Inject
BindVirtualIpPortPairToQueryParams(Provider<UriBuilder> builder) {
this.builder = builder;
}
@Override @Override
public void bindToRequest(HttpRequest request, Object input) { public void bindToRequest(HttpRequest request, Object input) {
checkArgument(checkNotNull(request, "request is null") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!");
checkArgument(checkNotNull(input, "input is null") instanceof IpPortPair, checkArgument(checkNotNull(input, "input is null") instanceof IpPortPair,
"this binder is only valid for a IpPortPair argument"); "this binder is only valid for a IpPortPair argument");
IpPortPair ipPortPair = (IpPortPair) input; IpPortPair ipPortPair = (IpPortPair) input;
GeneratedHttpRequest<?> generatedRequest = (GeneratedHttpRequest<?>) request;
checkNotNull(ipPortPair.getIp(), "There must be an IP address defined"); checkNotNull(ipPortPair.getIp(), "There must be an IP address defined");
checkNotNull(ipPortPair.getIp().getIp(), "There must be an IP address defined in Ip object"); checkNotNull(ipPortPair.getIp().getIp(), "There must be an IP address defined in Ip object");
checkState(ipPortPair.getPort() > 0, "The port number must be a positive integer"); checkState(ipPortPair.getPort() > 0, "The port number must be a positive integer");
generatedRequest.addQueryParam(VIRTUAL_IP_KEY + "ip", ipPortPair.getIp().getIp()); addQueryParamTo(request, VIRTUAL_IP_KEY + "ip", ipPortPair.getIp().getIp(), builder.get());
generatedRequest.addQueryParam(VIRTUAL_IP_KEY + "port", String.valueOf(ipPortPair.getPort())); addQueryParamTo(request, VIRTUAL_IP_KEY + "port", String.valueOf(ipPortPair.getPort()),
builder.get());
} }
} }

View File

@ -23,11 +23,12 @@
*/ */
package org.jclouds.gogrid.filters; package org.jclouds.gogrid.filters;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.lang.String.format; import static java.lang.String.format;
import static org.jclouds.Constants.PROPERTY_CREDENTIAL; import static org.jclouds.Constants.PROPERTY_CREDENTIAL;
import static org.jclouds.Constants.PROPERTY_IDENTITY; import static org.jclouds.Constants.PROPERTY_IDENTITY;
import static org.jclouds.http.HttpUtils.logRequest;
import static org.jclouds.http.HttpUtils.makeQueryLine;
import static org.jclouds.http.HttpUtils.parseQueryToMap;
import java.net.URI; import java.net.URI;
@ -40,10 +41,7 @@ import org.jclouds.date.TimeStamp;
import org.jclouds.encryption.EncryptionService; import org.jclouds.encryption.EncryptionService;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpRequestFilter; import org.jclouds.http.HttpRequestFilter;
import org.jclouds.http.HttpUtils;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
@ -72,25 +70,23 @@ public class SharedKeyLiteAuthentication implements HttpRequestFilter {
} }
public void filter(HttpRequest request) { public void filter(HttpRequest request) {
checkArgument(checkNotNull(request, "input") instanceof GeneratedHttpRequest<?>,
"this decorator is only valid for GeneratedHttpRequests!");
String toSign = createStringToSign(); String toSign = createStringToSign();
String signatureMd5 = getMd5For(toSign); String signatureMd5 = getMd5For(toSign);
String query = request.getEndpoint().getQuery(); String query = request.getEndpoint().getQuery();
Multimap<String, String> decodedParams = RestAnnotationProcessor.parseQueryToMap(query); Multimap<String, String> decodedParams = parseQueryToMap(query);
decodedParams.replaceValues("sig", ImmutableSet.of(signatureMd5)); decodedParams.replaceValues("sig", ImmutableSet.of(signatureMd5));
decodedParams.replaceValues("api_key", ImmutableSet.of(apiKey)); decodedParams.replaceValues("api_key", ImmutableSet.of(apiKey));
String updatedQuery = RestAnnotationProcessor.makeQueryLine(decodedParams, null); String updatedQuery = makeQueryLine(decodedParams, null);
String requestBasePart = request.getEndpoint().toASCIIString(); String requestBasePart = request.getEndpoint().toASCIIString();
String updatedEndpoint = requestBasePart.substring(0, requestBasePart.indexOf("?") + 1) String updatedEndpoint = requestBasePart.substring(0, requestBasePart.indexOf("?") + 1)
+ updatedQuery; + updatedQuery;
request.setEndpoint(URI.create(updatedEndpoint)); request.setEndpoint(URI.create(updatedEndpoint));
HttpUtils.logRequest(signatureLog, request, "<<"); logRequest(signatureLog, request, "<<");
} }
private String createStringToSign() { private String createStringToSign() {

View File

@ -18,10 +18,15 @@
*/ */
package org.jclouds.gogrid.binders; package org.jclouds.gogrid.binders;
import static org.easymock.classextension.EasyMock.createMock; import static org.testng.Assert.assertEquals;
import static org.easymock.classextension.EasyMock.replay;
import org.jclouds.rest.internal.GeneratedHttpRequest; import java.net.URI;
import javax.inject.Provider;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.http.HttpRequest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
/** /**
@ -32,32 +37,39 @@ import org.testng.annotations.Test;
public class BindIdsToQueryParamsTest { public class BindIdsToQueryParamsTest {
@Test @Test
public void testBinding() { public void testWithWrapper() throws SecurityException, NoSuchMethodException {
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
Long[] input = { 123L, 456L };
BindIdsToQueryParams binder = new BindIdsToQueryParams(); HttpRequest request = new HttpRequest("GET", URI.create("http://momma/"));
request.addQueryParam("id", "123"); BindIdsToQueryParams binder = new BindIdsToQueryParams(new Provider<UriBuilder>() {
request.addQueryParam("id", "456");
replay(request);
binder.bindToRequest(request, input); @Override
public UriBuilder get() {
return new UriBuilderImpl();
}
});
binder.bindToRequest(request, new Long[] { 123L, 456L });
assertEquals(request.getRequestLine(), "GET http://momma/?id=123&id=456 HTTP/1.1");
} }
@Test @Test
public void testBinding2() { public void testWithPrimitive() {
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class); HttpRequest request = new HttpRequest("GET", URI.create("http://momma/"));
long[] input = { 123L, 456L };
BindIdsToQueryParams binder = new BindIdsToQueryParams(); BindIdsToQueryParams binder = new BindIdsToQueryParams(new Provider<UriBuilder>() {
request.addQueryParam("id", "123"); @Override
request.addQueryParam("id", "456"); public UriBuilder get() {
replay(request); return new UriBuilderImpl();
}
binder.bindToRequest(request, input); });
binder.bindToRequest(request, new long[] { 123L, 456L });
assertEquals(request.getRequestLine(), "GET http://momma/?id=123&id=456 HTTP/1.1");
} }
} }

View File

@ -18,11 +18,16 @@
*/ */
package org.jclouds.gogrid.binders; package org.jclouds.gogrid.binders;
import org.jclouds.rest.internal.GeneratedHttpRequest; import static org.testng.Assert.assertEquals;
import org.testng.annotations.Test;
import static org.easymock.classextension.EasyMock.createMock; import java.net.URI;
import static org.easymock.classextension.EasyMock.replay;
import javax.inject.Provider;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.http.HttpRequest;
import org.testng.annotations.Test;
/** /**
* Tests that name bindings are proper for request * Tests that name bindings are proper for request
@ -33,17 +38,22 @@ public class BindNamesToQueryParamsTest {
@Test @Test
public void testBinding() { public void testBinding() {
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class); String[] input = { "hello", "world" };
String[] input = {"hello", "world"};
BindNamesToQueryParams binder = new BindNamesToQueryParams(); HttpRequest request = new HttpRequest("GET", URI.create("http://momma/"));
request.addQueryParam("name", "hello"); BindNamesToQueryParams binder = new BindNamesToQueryParams(new Provider<UriBuilder>() {
request.addQueryParam("name", "world");
replay(request); @Override
public UriBuilder get() {
return new UriBuilderImpl();
}
});
binder.bindToRequest(request, input); binder.bindToRequest(request, input);
assertEquals(request.getRequestLine(), "GET http://momma/?name=hello&name=world HTTP/1.1");
} }
} }

View File

@ -48,18 +48,6 @@ public class HttpCommandMock implements HttpCommand {
return false; return false;
} }
@Override
public void changeSchemeHostAndPortTo(String scheme, String host, int port) {
}
@Override
public void changeToGETRequest() {
}
@Override
public void changePathTo(String newPath) {
}
@Override @Override
public int incrementFailureCount() { public int incrementFailureCount() {
return 0; return 0;

View File

@ -25,12 +25,12 @@ import java.util.Properties;
import org.jclouds.date.TimeStamp; import org.jclouds.date.TimeStamp;
import org.jclouds.gogrid.config.GoGridRestClientModule; import org.jclouds.gogrid.config.GoGridRestClientModule;
import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication; import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextFactory.ContextSpec; import org.jclouds.rest.RestContextFactory.ContextSpec;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.inject.Module; import com.google.inject.Module;
@ -41,9 +41,9 @@ import com.google.inject.Module;
*/ */
public abstract class BaseGoGridAsyncClientTest<T> extends RestClientTest<T> { public abstract class BaseGoGridAsyncClientTest<T> extends RestClientTest<T> {
@Override @Override
protected void checkFilters(GeneratedHttpRequest<T> httpMethod) { protected void checkFilters(HttpRequest request) {
assertEquals(httpMethod.getFilters().size(), 1); assertEquals(request.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class); assertEquals(request.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class);
} }
@RequiresHttp @RequiresHttp

View File

@ -30,6 +30,7 @@ import java.lang.reflect.Method;
import java.util.Date; import java.util.Date;
import java.util.Properties; import java.util.Properties;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
@ -663,9 +664,9 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
} }
@Override @Override
protected void checkFilters(GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest) { protected void checkFilters(HttpRequest request) {
assertEquals(httpRequest.getFilters().size(), 1); assertEquals(request.getFilters().size(), 1);
assertEquals(httpRequest.getFilters().get(0).getClass(), BasicAuthentication.class); assertEquals(request.getFilters().get(0).getClass(), BasicAuthentication.class);
} }
@Override @Override

View File

@ -33,6 +33,7 @@ import javax.ws.rs.core.HttpHeaders;
import org.jclouds.blobstore.binders.BindBlobToMultipartFormTest; import org.jclouds.blobstore.binders.BindBlobToMultipartFormTest;
import org.jclouds.blobstore.functions.ReturnNullOnKeyNotFound; import org.jclouds.blobstore.functions.ReturnNullOnKeyNotFound;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.CloseContentAndReturn;
@ -54,7 +55,6 @@ import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextFactory.ContextSpec; import org.jclouds.rest.RestContextFactory.ContextSpec;
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -73,50 +73,47 @@ public class PCSAsyncClientTest extends RestClientTest<PCSAsyncClient> {
public void testList() throws SecurityException, NoSuchMethodException, IOException { public void testList() throws SecurityException, NoSuchMethodException, IOException {
Method method = PCSAsyncClient.class.getMethod("list"); Method method = PCSAsyncClient.class.getMethod("list");
GeneratedHttpRequest<PCSAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, new Object[] {});
new Object[] {});
assertRequestLineEquals(httpMethod, "GET http://root HTTP/1.1"); assertRequestLineEquals(request, "GET http://root HTTP/1.1");
assertHeadersEqual(httpMethod, "X-Cloud-Depth: 2\n"); assertHeadersEqual(request, "X-Cloud-Depth: 2\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, ContainerHandler.class); assertSaxResponseParserClassEquals(method, ContainerHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testCreateContainer() throws SecurityException, NoSuchMethodException, IOException { public void testCreateContainer() throws SecurityException, NoSuchMethodException, IOException {
Method method = PCSAsyncClient.class.getMethod("createContainer", String.class); Method method = PCSAsyncClient.class.getMethod("createContainer", String.class);
GeneratedHttpRequest<PCSAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, new Object[] { "container" });
new Object[] { "container" });
assertRequestLineEquals(httpMethod, "POST http://root/contents HTTP/1.1"); assertRequestLineEquals(request, "POST http://root/contents HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(request,
"Content-Length: 45\nContent-Type: application/vnd.csp.container-info+xml\n"); "Content-Length: 45\nContent-Type: application/vnd.csp.container-info+xml\n");
assertPayloadEquals(httpMethod, "<container><name>container</name></container>"); assertPayloadEquals(request, "<container><name>container</name></container>");
assertResponseParserClassEquals(method, httpMethod, assertResponseParserClassEquals(method, request, ParseURIFromListOrLocationHeaderIf20x.class);
ParseURIFromListOrLocationHeaderIf20x.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testDeleteContainer() throws SecurityException, NoSuchMethodException { public void testDeleteContainer() throws SecurityException, NoSuchMethodException {
Method method = PCSAsyncClient.class.getMethod("deleteContainer", URI.class); Method method = PCSAsyncClient.class.getMethod("deleteContainer", URI.class);
GeneratedHttpRequest<PCSAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, new Object[] { URI
new Object[] { URI.create("http://localhost/container/1234") }); .create("http://localhost/container/1234") });
assertEquals(httpMethod.getRequestLine(), "DELETE http://localhost/container/1234 HTTP/1.1"); assertEquals(request.getRequestLine(), "DELETE http://localhost/container/1234 HTTP/1.1");
assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(request.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method, httpMethod).getClass(), assertEquals(processor.createResponseParser(method, request).getClass(),
CloseContentAndReturn.class); CloseContentAndReturn.class);
assertEquals(RestAnnotationProcessor.getSaxResponseParserClassOrNull(method), null); assertEquals(RestAnnotationProcessor.getSaxResponseParserClassOrNull(method), null);
assertEquals(httpMethod.getFilters().size(), 1); assertEquals(request.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class); assertEquals(request.getFilters().get(0).getClass(), BasicAuthentication.class);
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ReturnVoidOnNotFoundOr404.class); ReturnVoidOnNotFoundOr404.class);
@ -124,16 +121,16 @@ public class PCSAsyncClientTest extends RestClientTest<PCSAsyncClient> {
public void testListURI() throws SecurityException, NoSuchMethodException { public void testListURI() throws SecurityException, NoSuchMethodException {
Method method = PCSAsyncClient.class.getMethod("list", URI.class); Method method = PCSAsyncClient.class.getMethod("list", URI.class);
GeneratedHttpRequest<PCSAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, new Object[] { URI
new Object[] { URI.create("http://localhost/mycontainer") }); .create("http://localhost/mycontainer") });
assertEquals(httpMethod.getRequestLine(), "GET http://localhost/mycontainer HTTP/1.1"); assertEquals(request.getRequestLine(), "GET http://localhost/mycontainer HTTP/1.1");
assertEquals(httpMethod.getHeaders().size(), 1); assertEquals(request.getHeaders().size(), 1);
assertEquals(httpMethod.getHeaders().get("X-Cloud-Depth"), Collections.singletonList("2")); assertEquals(request.getHeaders().get("X-Cloud-Depth"), Collections.singletonList("2"));
assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseSax.class); assertEquals(processor.createResponseParser(method, request).getClass(), ParseSax.class);
assertEquals(RestAnnotationProcessor.getSaxResponseParserClassOrNull(method), assertEquals(RestAnnotationProcessor.getSaxResponseParserClassOrNull(method),
ContainerHandler.class); ContainerHandler.class);
assertEquals(httpMethod.getFilters().size(), 1); assertEquals(request.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class); assertEquals(request.getFilters().get(0).getClass(), BasicAuthentication.class);
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
MapHttp4xxCodesToExceptions.class); MapHttp4xxCodesToExceptions.class);
@ -141,16 +138,16 @@ public class PCSAsyncClientTest extends RestClientTest<PCSAsyncClient> {
public void testGetFileInfo() throws SecurityException, NoSuchMethodException { public void testGetFileInfo() throws SecurityException, NoSuchMethodException {
Method method = PCSAsyncClient.class.getMethod("getFileInfo", URI.class); Method method = PCSAsyncClient.class.getMethod("getFileInfo", URI.class);
GeneratedHttpRequest<PCSAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, new Object[] { URI
new Object[] { URI.create("http://localhost/myfile") }); .create("http://localhost/myfile") });
assertEquals(httpMethod.getRequestLine(), "GET http://localhost/myfile HTTP/1.1"); assertEquals(request.getRequestLine(), "GET http://localhost/myfile HTTP/1.1");
assertEquals(httpMethod.getHeaders().size(), 1); assertEquals(request.getHeaders().size(), 1);
assertEquals(httpMethod.getHeaders().get("X-Cloud-Depth"), Collections.singletonList("2")); assertEquals(request.getHeaders().get("X-Cloud-Depth"), Collections.singletonList("2"));
assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseSax.class); assertEquals(processor.createResponseParser(method, request).getClass(), ParseSax.class);
assertEquals(RestAnnotationProcessor.getSaxResponseParserClassOrNull(method), assertEquals(RestAnnotationProcessor.getSaxResponseParserClassOrNull(method),
FileHandler.class); FileHandler.class);
assertEquals(httpMethod.getFilters().size(), 1); assertEquals(request.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class); assertEquals(request.getFilters().get(0).getClass(), BasicAuthentication.class);
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ReturnNullOnKeyNotFound.class); ReturnNullOnKeyNotFound.class);
@ -158,70 +155,69 @@ public class PCSAsyncClientTest extends RestClientTest<PCSAsyncClient> {
public void testUploadFile() throws SecurityException, NoSuchMethodException, IOException { public void testUploadFile() throws SecurityException, NoSuchMethodException, IOException {
Method method = PCSAsyncClient.class.getMethod("uploadFile", URI.class, PCSFile.class); Method method = PCSAsyncClient.class.getMethod("uploadFile", URI.class, PCSFile.class);
GeneratedHttpRequest<PCSAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, new Object[] {
new Object[] { URI.create("http://localhost/mycontainer"), URI.create("http://localhost/mycontainer"),
blobToPCSFile.apply(BindBlobToMultipartFormTest.TEST_BLOB) }); blobToPCSFile.apply(BindBlobToMultipartFormTest.TEST_BLOB) });
assertRequestLineEquals(httpMethod, "POST http://localhost/mycontainer/contents HTTP/1.1"); assertRequestLineEquals(request, "POST http://localhost/mycontainer/contents HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(request,
"Content-Length: 113\nContent-Type: multipart/form-data; boundary=--JCLOUDS--\n"); "Content-Length: 113\nContent-Type: multipart/form-data; boundary=--JCLOUDS--\n");
assertPayloadEquals(httpMethod, BindBlobToMultipartFormTest.EXPECTS); assertPayloadEquals(request, BindBlobToMultipartFormTest.EXPECTS);
assertResponseParserClassEquals(method, httpMethod, assertResponseParserClassEquals(method, request, ParseURIFromListOrLocationHeaderIf20x.class);
ParseURIFromListOrLocationHeaderIf20x.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testUploadBlock() throws SecurityException, NoSuchMethodException, IOException { public void testUploadBlock() throws SecurityException, NoSuchMethodException, IOException {
Method method = PCSAsyncClient.class.getMethod("uploadBlock", URI.class, PCSFile.class, Array Method method = PCSAsyncClient.class.getMethod("uploadBlock", URI.class, PCSFile.class, Array
.newInstance(PutBlockOptions.class, 0).getClass()); .newInstance(PutBlockOptions.class, 0).getClass());
GeneratedHttpRequest<PCSAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, new Object[] {
new Object[] { URI.create("http://localhost/mycontainer"), URI.create("http://localhost/mycontainer"),
blobToPCSFile.apply(BindBlobToMultipartFormTest.TEST_BLOB) }); blobToPCSFile.apply(BindBlobToMultipartFormTest.TEST_BLOB) });
assertRequestLineEquals(httpMethod, "PUT http://localhost/mycontainer/content HTTP/1.1"); assertRequestLineEquals(request, "PUT http://localhost/mycontainer/content HTTP/1.1");
assertHeadersEqual(httpMethod, "Content-Length: 5\n"); assertHeadersEqual(request, "Content-Length: 5\n");
assertPayloadEquals(httpMethod, "hello"); assertPayloadEquals(request, "hello");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testDownloadFile() throws SecurityException, NoSuchMethodException, IOException { public void testDownloadFile() throws SecurityException, NoSuchMethodException, IOException {
Method method = PCSAsyncClient.class.getMethod("downloadFile", URI.class); Method method = PCSAsyncClient.class.getMethod("downloadFile", URI.class);
GeneratedHttpRequest<PCSAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, new Object[] { URI
new Object[] { URI.create("http://localhost/container") }); .create("http://localhost/container") });
assertRequestLineEquals(httpMethod, "GET http://localhost/container/content HTTP/1.1"); assertRequestLineEquals(request, "GET http://localhost/container/content HTTP/1.1");
assertHeadersEqual(httpMethod, ""); assertHeadersEqual(request, "");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ReturnInputStream.class); assertResponseParserClassEquals(method, request, ReturnInputStream.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnNullOnKeyNotFound.class); assertExceptionParserClassEquals(method, ReturnNullOnKeyNotFound.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testDeleteFile() throws SecurityException, NoSuchMethodException, IOException { public void testDeleteFile() throws SecurityException, NoSuchMethodException, IOException {
Method method = PCSAsyncClient.class.getMethod("deleteFile", URI.class); Method method = PCSAsyncClient.class.getMethod("deleteFile", URI.class);
GeneratedHttpRequest<PCSAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, new Object[] { URI
new Object[] { URI.create("http://localhost/contents/file") }); .create("http://localhost/contents/file") });
assertEquals(httpMethod.getRequestLine(), "DELETE http://localhost/contents/file HTTP/1.1"); assertEquals(request.getRequestLine(), "DELETE http://localhost/contents/file HTTP/1.1");
assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(request.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method, httpMethod).getClass(), assertEquals(processor.createResponseParser(method, request).getClass(),
CloseContentAndReturn.class); CloseContentAndReturn.class);
assertEquals(RestAnnotationProcessor.getSaxResponseParserClassOrNull(method), null); assertEquals(RestAnnotationProcessor.getSaxResponseParserClassOrNull(method), null);
assertEquals(httpMethod.getFilters().size(), 1); assertEquals(request.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class); assertEquals(request.getFilters().get(0).getClass(), BasicAuthentication.class);
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ReturnVoidOnNotFoundOr404.class); ReturnVoidOnNotFoundOr404.class);
@ -230,21 +226,21 @@ public class PCSAsyncClientTest extends RestClientTest<PCSAsyncClient> {
public void testPutMetadata() throws SecurityException, NoSuchMethodException { public void testPutMetadata() throws SecurityException, NoSuchMethodException {
Method method = PCSAsyncClient.class.getMethod("putMetadataItem", URI.class, String.class, Method method = PCSAsyncClient.class.getMethod("putMetadataItem", URI.class, String.class,
String.class); String.class);
GeneratedHttpRequest<PCSAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, new Object[] {
new Object[] { URI.create("http://localhost/contents/file"), "pow", "bar" }); URI.create("http://localhost/contents/file"), "pow", "bar" });
assertEquals(httpMethod.getRequestLine(), assertEquals(request.getRequestLine(),
"PUT http://localhost/contents/file/metadata/pow HTTP/1.1"); "PUT http://localhost/contents/file/metadata/pow HTTP/1.1");
assertEquals(httpMethod.getMethod(), HttpMethod.PUT); assertEquals(request.getMethod(), HttpMethod.PUT);
assertEquals(httpMethod.getHeaders().size(), 2); assertEquals(request.getHeaders().size(), 2);
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections
.singletonList(httpMethod.getPayload().toString().getBytes().length + "")); .singletonList(request.getPayload().toString().getBytes().length + ""));
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections
.singletonList("application/unknown")); .singletonList("application/unknown"));
assertEquals("bar", httpMethod.getPayload().getRawContent()); assertEquals("bar", request.getPayload().getRawContent());
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
MapHttp4xxCodesToExceptions.class); MapHttp4xxCodesToExceptions.class);
assertEquals(processor.createResponseParser(method, httpMethod).getClass(), assertEquals(processor.createResponseParser(method, request).getClass(),
CloseContentAndReturn.class); CloseContentAndReturn.class);
} }
@ -252,25 +248,24 @@ public class PCSAsyncClientTest extends RestClientTest<PCSAsyncClient> {
Method method = PCSAsyncClient.class.getMethod("addMetadataItemToMap", URI.class, Method method = PCSAsyncClient.class.getMethod("addMetadataItemToMap", URI.class,
String.class, Map.class); String.class, Map.class);
GeneratedHttpRequest<PCSAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, new Object[] {
new Object[] { URI.create("http://localhost/pow"), "newkey", URI.create("http://localhost/pow"), "newkey", ImmutableMap.of("key", "value") });
ImmutableMap.of("key", "value") }); assertEquals(request.getRequestLine(), "GET http://localhost/pow/metadata/newkey HTTP/1.1");
assertEquals(httpMethod.getRequestLine(), "GET http://localhost/pow/metadata/newkey HTTP/1.1");
assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(request.getHeaders().size(), 0);
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
MapHttp4xxCodesToExceptions.class); MapHttp4xxCodesToExceptions.class);
assertEquals(processor.createResponseParser(method, httpMethod).getClass(), assertEquals(processor.createResponseParser(method, request).getClass(),
AddMetadataItemIntoMap.class); AddMetadataItemIntoMap.class);
} }
private BlobToPCSFile blobToPCSFile; private BlobToPCSFile blobToPCSFile;
@Override @Override
protected void checkFilters(GeneratedHttpRequest<PCSAsyncClient> httpMethod) { protected void checkFilters(HttpRequest request) {
assertEquals(httpMethod.getFilters().size(), 1); assertEquals(request.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class); assertEquals(request.getFilters().get(0).getClass(), BasicAuthentication.class);
} }
@Override @Override
@ -300,9 +295,10 @@ public class PCSAsyncClientTest extends RestClientTest<PCSAsyncClient> {
} }
@Override @Override
protected Response provideCloudResponse(AsyncClientFactory factory){ protected Response provideCloudResponse(AsyncClientFactory factory) {
return null; return null;
} }
@Override @Override
protected URI provideRootContainerUrl(Response response) { protected URI provideRootContainerUrl(Response response) {
return URI.create("http://root"); return URI.create("http://root");
@ -312,9 +308,9 @@ public class PCSAsyncClientTest extends RestClientTest<PCSAsyncClient> {
@Override @Override
public ContextSpec<PCSClient, PCSAsyncClient> createContextSpec() { public ContextSpec<PCSClient, PCSAsyncClient> createContextSpec() {
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty("pcs.apiversion","foo"); properties.setProperty("pcs.apiversion", "foo");
properties.setProperty("pcs.endpoint","http://goo"); properties.setProperty("pcs.endpoint", "http://goo");
return new RestContextFactory().createContextSpec("pcs", "identity", "credential", return new RestContextFactory()
properties); .createContextSpec("pcs", "identity", "credential", properties);
} }
} }

View File

@ -25,6 +25,7 @@ import java.lang.reflect.Method;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.mezeo.pcs2.PCSCloudAsyncClient.Response; import org.jclouds.mezeo.pcs2.PCSCloudAsyncClient.Response;
@ -32,7 +33,6 @@ import org.jclouds.mezeo.pcs2.xml.CloudXlinkHandler;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory.ContextSpec; import org.jclouds.rest.RestContextFactory.ContextSpec;
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -48,14 +48,14 @@ public class PCSCloudTest extends RestClientTest<PCSCloudAsyncClient> {
public void testAuthenticate() throws SecurityException, NoSuchMethodException { public void testAuthenticate() throws SecurityException, NoSuchMethodException {
Method method = PCSCloudAsyncClient.class.getMethod("authenticate"); Method method = PCSCloudAsyncClient.class.getMethod("authenticate");
GeneratedHttpRequest<PCSCloudAsyncClient> httpMethod = processor.createRequest(method); HttpRequest request = processor.createRequest(method);
assertEquals(httpMethod.getRequestLine(), "GET http://localhost:8080/ HTTP/1.1"); assertEquals(request.getRequestLine(), "GET http://localhost:8080/ HTTP/1.1");
assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(request.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseSax.class); assertEquals(processor.createResponseParser(method, request).getClass(), ParseSax.class);
assertEquals(RestAnnotationProcessor.getSaxResponseParserClassOrNull(method), assertEquals(RestAnnotationProcessor.getSaxResponseParserClassOrNull(method),
CloudXlinkHandler.class); CloudXlinkHandler.class);
assertEquals(httpMethod.getFilters().size(), 1); assertEquals(request.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class); assertEquals(request.getFilters().get(0).getClass(), BasicAuthentication.class);
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
MapHttp4xxCodesToExceptions.class); MapHttp4xxCodesToExceptions.class);
@ -74,7 +74,7 @@ public class PCSCloudTest extends RestClientTest<PCSCloudAsyncClient> {
} }
@Override @Override
protected void checkFilters(GeneratedHttpRequest<PCSCloudAsyncClient> httpMethod) { protected void checkFilters(HttpRequest request) {
} }

View File

@ -20,23 +20,33 @@ package org.jclouds.nirvanix.sdn.binders;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.http.HttpUtils.addQueryParamTo;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder; import org.jclouds.rest.Binder;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
@Singleton
public class BindMetadataToQueryParams implements Binder { public class BindMetadataToQueryParams implements Binder {
private final Provider<UriBuilder> builder;
@Inject
BindMetadataToQueryParams(Provider<UriBuilder> builder) {
this.builder = builder;
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void bindToRequest(HttpRequest request, Object input) { public void bindToRequest(HttpRequest request, Object input) {
checkArgument(checkNotNull(request, "input") instanceof GeneratedHttpRequest,
"this binder is only valid for GeneratedHttpRequests!");
checkArgument(checkNotNull(input, "input") instanceof Map, checkArgument(checkNotNull(input, "input") instanceof Map,
"this binder is only valid for Maps!"); "this binder is only valid for Maps!");
Map<String, String> userMetadata = (Map<String, String>) input; Map<String, String> userMetadata = (Map<String, String>) input;
@ -44,6 +54,6 @@ public class BindMetadataToQueryParams implements Binder {
for (Entry<String, String> entry : userMetadata.entrySet()) { for (Entry<String, String> entry : userMetadata.entrySet()) {
metadata.add(String.format("%s:%s", entry.getKey().toLowerCase(), entry.getValue())); metadata.add(String.format("%s:%s", entry.getKey().toLowerCase(), entry.getValue()));
} }
((GeneratedHttpRequest) request).addQueryParam("metadata", metadata.toArray(new String[] {})); addQueryParamTo(request, "metadata", metadata, builder.get());
} }
} }

View File

@ -18,8 +18,7 @@
*/ */
package org.jclouds.nirvanix.sdn.filters; package org.jclouds.nirvanix.sdn.filters;
import static com.google.common.base.Preconditions.checkArgument; import static org.jclouds.http.HttpUtils.addQueryParamTo;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
@ -27,13 +26,13 @@ import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Provider; import javax.inject.Provider;
import javax.inject.Singleton; import javax.inject.Singleton;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.http.HttpException; import org.jclouds.http.HttpException;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpRequestFilter; import org.jclouds.http.HttpRequestFilter;
import org.jclouds.nirvanix.sdn.SessionToken; import org.jclouds.nirvanix.sdn.SessionToken;
import org.jclouds.nirvanix.sdn.reference.SDNQueryParams; import org.jclouds.nirvanix.sdn.reference.SDNQueryParams;
import org.jclouds.rest.internal.GeneratedHttpRequest;
/** /**
* Adds the Session Token to the request. This will update the Session Token before 20 minutes is * Adds the Session Token to the request. This will update the Session Token before 20 minutes is
@ -46,6 +45,7 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
public class AddSessionTokenToRequest implements HttpRequestFilter { public class AddSessionTokenToRequest implements HttpRequestFilter {
private final Provider<String> authTokenProvider; private final Provider<String> authTokenProvider;
private final Provider<UriBuilder> builder;
public final long BILLION = 1000000000; public final long BILLION = 1000000000;
public final long MINUTES = 60 * BILLION; public final long MINUTES = 60 * BILLION;
@ -80,17 +80,15 @@ public class AddSessionTokenToRequest implements HttpRequestFilter {
} }
@Inject @Inject
public AddSessionTokenToRequest(@SessionToken Provider<String> authTokenProvider) { public AddSessionTokenToRequest(@SessionToken Provider<String> authTokenProvider,
Provider<UriBuilder> builder) {
this.builder = builder;
this.authTokenProvider = authTokenProvider; this.authTokenProvider = authTokenProvider;
authToken = new AtomicReference<String>(); authToken = new AtomicReference<String>();
} }
public void filter(HttpRequest request) throws HttpException { public void filter(HttpRequest request) throws HttpException {
checkArgument(checkNotNull(request, "input") instanceof GeneratedHttpRequest<?>, addQueryParamTo(request, SDNQueryParams.SESSIONTOKEN, getSessionToken(), builder.get());
"this decorator is only valid for GeneratedHttpRequests!");
((GeneratedHttpRequest<?>) request).addQueryParam(SDNQueryParams.SESSIONTOKEN,
getSessionToken());
} }
} }

View File

@ -18,18 +18,18 @@
*/ */
package org.jclouds.nirvanix.sdn.filters; package org.jclouds.nirvanix.sdn.filters;
import static com.google.common.base.Preconditions.checkArgument; import static org.jclouds.http.HttpUtils.changePathTo;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton; import javax.inject.Singleton;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.http.HttpException; import org.jclouds.http.HttpException;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpRequestFilter; import org.jclouds.http.HttpRequestFilter;
import org.jclouds.nirvanix.sdn.reference.SDNConstants; import org.jclouds.nirvanix.sdn.reference.SDNConstants;
import org.jclouds.rest.internal.GeneratedHttpRequest;
/** /**
* Adds the Session Token to the request. This will update the Session Token before 20 minutes is * Adds the Session Token to the request. This will update the Session Token before 20 minutes is
@ -43,18 +43,18 @@ public class InsertUserContextIntoPath implements HttpRequestFilter {
private final AddSessionTokenToRequest sessionManager; private final AddSessionTokenToRequest sessionManager;
private final String pathPrefix; private final String pathPrefix;
private final Provider<UriBuilder> builder;
@Inject @Inject
public InsertUserContextIntoPath(AddSessionTokenToRequest sessionManager, public InsertUserContextIntoPath(AddSessionTokenToRequest sessionManager,
@Named(SDNConstants.PROPERTY_SDN_APPNAME) String appname, @Named(SDNConstants.PROPERTY_SDN_APPNAME) String appname,
@Named(SDNConstants.PROPERTY_SDN_USERNAME) String username) { @Named(SDNConstants.PROPERTY_SDN_USERNAME) String username, Provider<UriBuilder> builder) {
this.builder = builder;
this.sessionManager = sessionManager; this.sessionManager = sessionManager;
this.pathPrefix = String.format("/%s/%s/", appname, username); this.pathPrefix = String.format("/%s/%s/", appname, username);
} }
public void filter(HttpRequest request) throws HttpException { public void filter(HttpRequest request) throws HttpException {
checkArgument(checkNotNull(request, "input") instanceof GeneratedHttpRequest<?>,
"this decorator is only valid for GeneratedHttpRequests!");
String sessionToken = sessionManager.getSessionToken(); String sessionToken = sessionManager.getSessionToken();
int prefixIndex = request.getEndpoint().getPath().indexOf(pathPrefix); int prefixIndex = request.getEndpoint().getPath().indexOf(pathPrefix);
String path; String path;
@ -63,8 +63,7 @@ public class InsertUserContextIntoPath implements HttpRequestFilter {
} else { // replace token } else { // replace token
path = "/" + sessionToken + request.getEndpoint().getPath().substring(prefixIndex); path = "/" + sessionToken + request.getEndpoint().getPath().substring(prefixIndex);
} }
((GeneratedHttpRequest<?>) request).replacePath(path); changePathTo(request, path, builder.get());
} }
} }

View File

@ -28,6 +28,7 @@ import java.util.Properties;
import org.jclouds.blobstore.binders.BindBlobToMultipartFormTest; import org.jclouds.blobstore.binders.BindBlobToMultipartFormTest;
import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.Blob;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.http.functions.ReturnStringIf200; import org.jclouds.http.functions.ReturnStringIf200;
@ -41,7 +42,6 @@ import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextFactory.ContextSpec; import org.jclouds.rest.RestContextFactory.ContextSpec;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -60,20 +60,19 @@ public class SDNAsyncClientTest extends RestClientTest<SDNAsyncClient> {
public void testGetStorageNode() throws SecurityException, NoSuchMethodException, IOException { public void testGetStorageNode() throws SecurityException, NoSuchMethodException, IOException {
Method method = SDNAsyncClient.class.getMethod("getStorageNode", String.class, long.class); Method method = SDNAsyncClient.class.getMethod("getStorageNode", String.class, long.class);
GeneratedHttpRequest<SDNAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, "adriansmovies", 734859264);
"adriansmovies", 734859264);
assertRequestLineEquals( assertRequestLineEquals(
httpMethod, request,
"GET http://services.nirvanix.com/ws/IMFS/GetStorageNode.ashx?output=json&destFolderPath=adriansmovies&sizeBytes=734859264 HTTP/1.1"); "GET http://services.nirvanix.com/ws/IMFS/GetStorageNode.ashx?output=json&destFolderPath=adriansmovies&sizeBytes=734859264 HTTP/1.1");
assertHeadersEqual(httpMethod, ""); assertHeadersEqual(request, "");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseUploadInfoFromJsonResponse.class); assertResponseParserClassEquals(method, request, ParseUploadInfoFromJsonResponse.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
@ -81,13 +80,13 @@ public class SDNAsyncClientTest extends RestClientTest<SDNAsyncClient> {
Method method = SDNAsyncClient.class.getMethod("upload", URI.class, String.class, Method method = SDNAsyncClient.class.getMethod("upload", URI.class, String.class,
String.class, Blob.class); String.class, Blob.class);
Blob blob = BindBlobToMultipartFormTest.TEST_BLOB; Blob blob = BindBlobToMultipartFormTest.TEST_BLOB;
GeneratedHttpRequest<SDNAsyncClient> httpMethod = processor.createRequest(method, URI HttpRequest request = processor.createRequest(method, URI.create("http://uploader"), "token",
.create("http://uploader"), "token", "adriansmovies", blob); "adriansmovies", blob);
assertRequestLineEquals( assertRequestLineEquals(
httpMethod, request,
"POST http://uploader/Upload.ashx?output=json&destFolderPath=adriansmovies&uploadToken=token HTTP/1.1"); "POST http://uploader/Upload.ashx?output=json&destFolderPath=adriansmovies&uploadToken=token HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(request,
"Content-Length: 113\nContent-Type: multipart/form-data; boundary=--JCLOUDS--\n"); "Content-Length: 113\nContent-Type: multipart/form-data; boundary=--JCLOUDS--\n");
StringBuffer expects = new StringBuffer(); StringBuffer expects = new StringBuffer();
expects.append("----JCLOUDS--\r\n"); expects.append("----JCLOUDS--\r\n");
@ -96,74 +95,72 @@ public class SDNAsyncClientTest extends RestClientTest<SDNAsyncClient> {
expects.append("hello\r\n"); expects.append("hello\r\n");
expects.append("----JCLOUDS----\r\n"); expects.append("----JCLOUDS----\r\n");
assertPayloadEquals(httpMethod, expects.toString()); assertPayloadEquals(request, expects.toString());
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testSetMetadata() throws SecurityException, NoSuchMethodException, IOException { public void testSetMetadata() throws SecurityException, NoSuchMethodException, IOException {
Method method = SDNAsyncClient.class.getMethod("setMetadata", String.class, Map.class); Method method = SDNAsyncClient.class.getMethod("setMetadata", String.class, Map.class);
GeneratedHttpRequest<SDNAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, "adriansmovies/sushi.avi", ImmutableMap
"adriansmovies/sushi.avi", ImmutableMap.of("Chef", "Kawasaki")); .of("Chef", "Kawasaki"));
assertRequestLineEquals( assertRequestLineEquals(
httpMethod, request,
"GET http://services.nirvanix.com/ws/Metadata/SetMetadata.ashx?output=json&path=adriansmovies/sushi.avi&metadata=chef:Kawasaki HTTP/1.1"); "GET http://services.nirvanix.com/ws/Metadata/SetMetadata.ashx?output=json&path=adriansmovies/sushi.avi&metadata=chef:Kawasaki HTTP/1.1");
assertHeadersEqual(httpMethod, ""); assertHeadersEqual(request, "");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testGetMetadata() throws SecurityException, NoSuchMethodException, IOException { public void testGetMetadata() throws SecurityException, NoSuchMethodException, IOException {
Method method = SDNAsyncClient.class.getMethod("getMetadata", String.class); Method method = SDNAsyncClient.class.getMethod("getMetadata", String.class);
GeneratedHttpRequest<SDNAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, "adriansmovies/sushi.avi");
"adriansmovies/sushi.avi");
assertRequestLineEquals( assertRequestLineEquals(
httpMethod, request,
"GET http://services.nirvanix.com/ws/Metadata/GetMetadata.ashx?output=json&path=adriansmovies/sushi.avi HTTP/1.1"); "GET http://services.nirvanix.com/ws/Metadata/GetMetadata.ashx?output=json&path=adriansmovies/sushi.avi HTTP/1.1");
assertHeadersEqual(httpMethod, ""); assertHeadersEqual(request, "");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseMetadataFromJsonResponse.class); assertResponseParserClassEquals(method, request, ParseMetadataFromJsonResponse.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testGetFile() throws SecurityException, NoSuchMethodException, IOException { public void testGetFile() throws SecurityException, NoSuchMethodException, IOException {
Method method = SDNAsyncClient.class.getMethod("getFile", String.class); Method method = SDNAsyncClient.class.getMethod("getFile", String.class);
GeneratedHttpRequest<SDNAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, "adriansmovies/sushi.avi");
"adriansmovies/sushi.avi");
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"GET http://services.nirvanix.com/adriansmovies/sushi.avi?output=json HTTP/1.1"); "GET http://services.nirvanix.com/adriansmovies/sushi.avi?output=json HTTP/1.1");
assertHeadersEqual(httpMethod, ""); assertHeadersEqual(request, "");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ReturnStringIf200.class); assertResponseParserClassEquals(method, request, ReturnStringIf200.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
assertEquals(httpMethod.getFilters().size(), 1); assertEquals(request.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), InsertUserContextIntoPath.class); assertEquals(request.getFilters().get(0).getClass(), InsertUserContextIntoPath.class);
} }
@Override @Override
protected void checkFilters(GeneratedHttpRequest<SDNAsyncClient> httpMethod) { protected void checkFilters(HttpRequest request) {
assertEquals(httpMethod.getFilters().size(), 1); assertEquals(request.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), AddSessionTokenToRequest.class); assertEquals(request.getFilters().get(0).getClass(), AddSessionTokenToRequest.class);
} }
@Override @Override

View File

@ -30,7 +30,6 @@ import org.jclouds.nirvanix.sdn.SDNAuthenticationLiveTest.SDNAuthClient;
import org.jclouds.nirvanix.sdn.functions.ParseSessionTokenFromJsonResponse; import org.jclouds.nirvanix.sdn.functions.ParseSessionTokenFromJsonResponse;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory.ContextSpec; import org.jclouds.rest.RestContextFactory.ContextSpec;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -47,20 +46,19 @@ public class SDNAuthAsyncClientTest extends RestClientTest<SDNAuthAsyncClient> {
public void testAuthenticate() throws SecurityException, NoSuchMethodException { public void testAuthenticate() throws SecurityException, NoSuchMethodException {
Method method = SDNAuthAsyncClient.class.getMethod("authenticate", String.class, Method method = SDNAuthAsyncClient.class.getMethod("authenticate", String.class,
String.class, String.class); String.class, String.class);
HttpRequest httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, new Object[] { "apple", "foo", "bar" });
new Object[] { "apple", "foo", "bar" }); assertEquals(request.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getPath(), "/ws/Authentication/Login.ashx");
assertEquals(httpMethod.getEndpoint().getPath(), "/ws/Authentication/Login.ashx"); assertEquals(request.getEndpoint().getQuery(),
assertEquals(httpMethod.getEndpoint().getQuery(),
"output=json&appKey=apple&password=bar&username=foo"); "output=json&appKey=apple&password=bar&username=foo");
assertEquals(httpMethod.getMethod(), HttpMethod.GET); assertEquals(request.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(request.getHeaders().size(), 0);
assertEquals(RestAnnotationProcessor.getParserOrThrowException(method), assertEquals(RestAnnotationProcessor.getParserOrThrowException(method),
ParseSessionTokenFromJsonResponse.class); ParseSessionTokenFromJsonResponse.class);
} }
@Override @Override
protected void checkFilters(GeneratedHttpRequest<SDNAuthAsyncClient> httpMethod) { protected void checkFilters(HttpRequest request) {
} }

View File

@ -19,13 +19,16 @@
package org.jclouds.nirvanix.sdn.binders; package org.jclouds.nirvanix.sdn.binders;
import static org.easymock.classextension.EasyMock.createMock; import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.replay; import static org.testng.Assert.assertEquals;
import java.io.File; import java.io.File;
import java.net.URI; import java.net.URI;
import javax.inject.Provider;
import javax.ws.rs.HttpMethod; import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -42,24 +45,34 @@ public class BindMetadataToQueryParamsTest {
@Test(expectedExceptions = IllegalArgumentException.class) @Test(expectedExceptions = IllegalArgumentException.class)
public void testMustBeMap() { public void testMustBeMap() {
BindMetadataToQueryParams binder = new BindMetadataToQueryParams(); BindMetadataToQueryParams binder = new BindMetadataToQueryParams(null);
HttpRequest request = new HttpRequest(HttpMethod.POST, URI.create("http://localhost")); HttpRequest request = new HttpRequest(HttpMethod.POST, URI.create("http://localhost"), new char[]{ '/', ':' });
binder.bindToRequest(request, new File("foo")); binder.bindToRequest(request, new File("foo"));
} }
@Test @Test
public void testCorrect() throws SecurityException, NoSuchMethodException { public void testCorrect() throws SecurityException, NoSuchMethodException {
BindMetadataToQueryParams binder = new BindMetadataToQueryParams();
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class); HttpRequest request = new HttpRequest("GET", URI.create("http://momma/"), new char[]{ '/', ':' });
request.addQueryParam("metadata", "imagename:foo", "serverid:2");
replay(request); BindMetadataToQueryParams binder = new BindMetadataToQueryParams(new Provider<UriBuilder>() {
@Override
public UriBuilder get() {
return new UriBuilderImpl();
}
});
binder.bindToRequest(request, ImmutableMap.of("imageName", "foo", "serverId", "2")); binder.bindToRequest(request, ImmutableMap.of("imageName", "foo", "serverId", "2"));
assertEquals(request.getRequestLine(), "GET http://momma/?metadata=imagename:foo&metadata=serverid:2 HTTP/1.1");
} }
@Test(expectedExceptions = { NullPointerException.class, IllegalStateException.class }) @Test(expectedExceptions = { NullPointerException.class, IllegalStateException.class })
public void testNullIsBad() { public void testNullIsBad() {
BindMetadataToQueryParams binder = new BindMetadataToQueryParams(); BindMetadataToQueryParams binder = new BindMetadataToQueryParams(null);
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class); GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
binder.bindToRequest(request, null); binder.bindToRequest(request, null);
} }

View File

@ -44,6 +44,7 @@ import org.jclouds.chef.functions.ParseUserFromJson;
import org.jclouds.concurrent.config.ConfiguresExecutorService; import org.jclouds.concurrent.config.ConfiguresExecutorService;
import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.date.TimeStamp; import org.jclouds.date.TimeStamp;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.http.TransformingHttpCommandExecutorService; import org.jclouds.http.TransformingHttpCommandExecutorService;
import org.jclouds.http.config.ConfiguresHttpCommandExecutorService; import org.jclouds.http.config.ConfiguresHttpCommandExecutorService;
@ -278,9 +279,9 @@ public class OpscodePlatformAsyncClientTest extends RestClientTest<OpscodePlatfo
} }
@Override @Override
protected void checkFilters(GeneratedHttpRequest<OpscodePlatformAsyncClient> httpRequest) { protected void checkFilters(HttpRequest request) {
assertEquals(httpRequest.getFilters().size(), 1); assertEquals(request.getFilters().size(), 1);
assertEquals(httpRequest.getFilters().get(0).getClass(), SignedHeaderAuth.class); assertEquals(request.getFilters().get(0).getClass(), SignedHeaderAuth.class);
} }
@Override @Override

View File

@ -18,16 +18,19 @@
*/ */
package org.jclouds.rackspace.filters; package org.jclouds.rackspace.filters;
import static org.jclouds.http.HttpUtils.addQueryParamTo;
import java.util.Date; import java.util.Date;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton; import javax.inject.Singleton;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.date.TimeStamp; import org.jclouds.date.TimeStamp;
import org.jclouds.http.HttpException; import org.jclouds.http.HttpException;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpRequestFilter; import org.jclouds.http.HttpRequestFilter;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
@ -40,15 +43,16 @@ import com.google.common.base.Supplier;
@Singleton @Singleton
public class AddTimestampQuery implements HttpRequestFilter { public class AddTimestampQuery implements HttpRequestFilter {
private final Supplier<Date> dateProvider; private final Supplier<Date> dateProvider;
private final Provider<UriBuilder> builder;
@Inject @Inject
public AddTimestampQuery(@TimeStamp Supplier<Date> dateProvider) { public AddTimestampQuery(@TimeStamp Supplier<Date> dateProvider, Provider<UriBuilder> builder) {
this.builder = builder;
this.dateProvider = dateProvider; this.dateProvider = dateProvider;
} }
public void filter(HttpRequest in) throws HttpException { public void filter(HttpRequest request) throws HttpException {
GeneratedHttpRequest<?> request = (GeneratedHttpRequest<?>) in; addQueryParamTo(request, "now", dateProvider.get().getTime() + "", builder.get());
request.addQueryParam("now", dateProvider.get().getTime() + "");
} }
} }

View File

@ -32,7 +32,6 @@ import org.jclouds.rackspace.functions.ParseAuthenticationResponseFromHeaders;
import org.jclouds.rackspace.reference.RackspaceHeaders; import org.jclouds.rackspace.reference.RackspaceHeaders;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory.ContextSpec; import org.jclouds.rest.RestContextFactory.ContextSpec;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -49,14 +48,14 @@ public class RackspaceAuthAsyncClientTest extends RestClientTest<RackspaceAuthAs
public void testAuthenticate() throws SecurityException, NoSuchMethodException { public void testAuthenticate() throws SecurityException, NoSuchMethodException {
Method method = RackspaceAuthAsyncClient.class.getMethod("authenticate", String.class, Method method = RackspaceAuthAsyncClient.class.getMethod("authenticate", String.class,
String.class); String.class);
HttpRequest httpMethod = processor.createRequest(method, "foo", "bar"); HttpRequest request = processor.createRequest(method, "foo", "bar");
assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/auth"); assertEquals(request.getEndpoint().getPath(), "/auth");
assertEquals(httpMethod.getMethod(), HttpMethod.GET); assertEquals(request.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 2); assertEquals(request.getHeaders().size(), 2);
assertEquals(httpMethod.getHeaders().get(RackspaceHeaders.AUTH_USER), Collections assertEquals(request.getHeaders().get(RackspaceHeaders.AUTH_USER), Collections
.singletonList("foo")); .singletonList("foo"));
assertEquals(httpMethod.getHeaders().get(RackspaceHeaders.AUTH_KEY), Collections assertEquals(request.getHeaders().get(RackspaceHeaders.AUTH_KEY), Collections
.singletonList("bar")); .singletonList("bar"));
assertEquals(RestAnnotationProcessor.getParserOrThrowException(method), assertEquals(RestAnnotationProcessor.getParserOrThrowException(method),
ParseAuthenticationResponseFromHeaders.class); ParseAuthenticationResponseFromHeaders.class);
@ -70,7 +69,7 @@ public class RackspaceAuthAsyncClientTest extends RestClientTest<RackspaceAuthAs
} }
@Override @Override
protected void checkFilters(GeneratedHttpRequest<RackspaceAuthAsyncClient> httpMethod) { protected void checkFilters(HttpRequest request) {
} }
@Override @Override

View File

@ -18,12 +18,16 @@
*/ */
package org.jclouds.rackspace.filters; package org.jclouds.rackspace.filters;
import static org.easymock.classextension.EasyMock.createMock; import static org.testng.Assert.assertEquals;
import static org.easymock.classextension.EasyMock.replay;
import java.net.URI;
import java.util.Date; import java.util.Date;
import org.jclouds.rest.internal.GeneratedHttpRequest; import javax.inject.Provider;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.http.HttpRequest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
@ -47,12 +51,23 @@ public class AddTimestampQueryTest {
} }
}; };
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
request.addQueryParam("now", date.getTime() + "");
replay(request);
AddTimestampQuery filter = new AddTimestampQuery(dateSupplier); HttpRequest request = new HttpRequest("GET", URI.create("http://momma/"));
AddTimestampQuery filter = new AddTimestampQuery(dateSupplier, new Provider<UriBuilder>() {
@Override
public UriBuilder get() {
return new UriBuilderImpl();
}
});
filter.filter(request); filter.filter(request);
assertEquals(request.getRequestLine(), String.format("GET http://momma/?now=%s HTTP/1.1",
date.getTime()));
} }
} }

View File

@ -24,10 +24,10 @@ import static org.testng.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory.ContextSpec; import org.jclouds.rest.RestContextFactory.ContextSpec;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.twitter.functions.ParseStatusesFromJsonResponse; import org.jclouds.twitter.functions.ParseStatusesFromJsonResponse;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -44,23 +44,23 @@ public class TwitterAsyncClientTest extends RestClientTest<TwitterAsyncClient> {
public void testGetMyMentions() throws SecurityException, NoSuchMethodException, IOException { public void testGetMyMentions() throws SecurityException, NoSuchMethodException, IOException {
Method method = TwitterAsyncClient.class.getMethod("getMyMentions"); Method method = TwitterAsyncClient.class.getMethod("getMyMentions");
GeneratedHttpRequest<TwitterAsyncClient> httpMethod = processor.createRequest(method); HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(httpMethod, "GET http://twitter.com/statuses/mentions.json HTTP/1.1"); assertRequestLineEquals(request, "GET http://twitter.com/statuses/mentions.json HTTP/1.1");
assertHeadersEqual(httpMethod, ""); assertHeadersEqual(request, "");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseStatusesFromJsonResponse.class); assertResponseParserClassEquals(method, request, ParseStatusesFromJsonResponse.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
@Override @Override
protected void checkFilters(GeneratedHttpRequest<TwitterAsyncClient> httpMethod) { protected void checkFilters(HttpRequest request) {
assertEquals(httpMethod.getFilters().size(), 1); assertEquals(request.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class); assertEquals(request.getFilters().get(0).getClass(), BasicAuthentication.class);
} }
@Override @Override

View File

@ -32,6 +32,7 @@ import java.util.Properties;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Provider; import javax.inject.Provider;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
@ -41,7 +42,6 @@ import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextFactory.ContextSpec; import org.jclouds.rest.RestContextFactory.ContextSpec;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import org.jclouds.vcloud.config.VCloudRestClientModule; import org.jclouds.vcloud.config.VCloudRestClientModule;
@ -81,22 +81,21 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC",
String.class, String.class, String.class, Array.newInstance( String.class, String.class, String.class, Array.newInstance(
InstantiateVAppTemplateOptions.class, 0).getClass()); InstantiateVAppTemplateOptions.class, 0).getClass());
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "1", HttpRequest request = processor.createRequest(method, "1", "my-vapp", 3 + "");
"my-vapp", 3 + "");
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); "POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Accept: application/vnd.vmware.vcloud.vApp+xml\nContent-Length: 667\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n"); "Accept: application/vnd.vmware.vcloud.vApp+xml\nContent-Length: 667\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n");
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream( assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream(
"/newvapp-hosting.xml"))); "/newvapp-hosting.xml")));
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VAppHandler.class); assertSaxResponseParserClassEquals(method, VAppHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testInstantiateVAppTemplateOptions() throws SecurityException, public void testInstantiateVAppTemplateOptions() throws SecurityException,
@ -104,23 +103,23 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC",
String.class, String.class, String.class, Array.newInstance( String.class, String.class, String.class, Array.newInstance(
InstantiateVAppTemplateOptions.class, 0).getClass()); InstantiateVAppTemplateOptions.class, 0).getClass());
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "1", HttpRequest request = processor.createRequest(method, "1", "my-vapp", 3 + "", processorCount(
"my-vapp", 3 + "", processorCount(1).memory(512).disk(1024).fenceMode("allowInOut") 1).memory(512).disk(1024).fenceMode("allowInOut").inNetwork(
.inNetwork(URI.create("https://vcloud.safesecureweb.com/network/1990"))); URI.create("https://vcloud.safesecureweb.com/network/1990")));
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); "POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Accept: application/vnd.vmware.vcloud.vApp+xml\nContent-Length: 2051\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n"); "Accept: application/vnd.vmware.vcloud.vApp+xml\nContent-Length: 2051\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n");
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream( assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream(
"/newvapp-hostingcpumemdisk.xml"))); "/newvapp-hostingcpumemdisk.xml")));
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VAppHandler.class); assertSaxResponseParserClassEquals(method, VAppHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
@Test(expectedExceptions = IllegalArgumentException.class) @Test(expectedExceptions = IllegalArgumentException.class)
@ -136,44 +135,43 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testCloneVApp() throws SecurityException, NoSuchMethodException, IOException { public void testCloneVApp() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("cloneVAppInVDC", String.class, Method method = VCloudAsyncClient.class.getMethod("cloneVAppInVDC", String.class,
String.class, String.class, Array.newInstance(CloneVAppOptions.class, 0).getClass()); String.class, String.class, Array.newInstance(CloneVAppOptions.class, 0).getClass());
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "1", HttpRequest request = processor.createRequest(method, "1", "4181", "my-vapp");
"4181", "my-vapp");
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/cloneVApp HTTP/1.1"); "POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/cloneVApp HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Accept: application/vnd.vmware.vcloud.task+xml\nContent-Length: 390\nContent-Type: application/vnd.vmware.vcloud.cloneVAppParams+xml\n"); "Accept: application/vnd.vmware.vcloud.task+xml\nContent-Length: 390\nContent-Type: application/vnd.vmware.vcloud.cloneVAppParams+xml\n");
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream( assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream(
"/cloneVApp-default.xml"))); "/cloneVApp-default.xml")));
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class); assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testCloneVAppOptions() throws SecurityException, NoSuchMethodException, IOException { public void testCloneVAppOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("cloneVAppInVDC", String.class, Method method = VCloudAsyncClient.class.getMethod("cloneVAppInVDC", String.class,
String.class, String.class, Array.newInstance(CloneVAppOptions.class, 0).getClass()); String.class, String.class, Array.newInstance(CloneVAppOptions.class, 0).getClass());
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "1", HttpRequest request = processor.createRequest(method, "1", "201", "new-linux-server",
"201", "new-linux-server", new CloneVAppOptions().deploy().powerOn() new CloneVAppOptions().deploy().powerOn().withDescription(
.withDescription("The description of the new vApp")); "The description of the new vApp"));
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/cloneVApp HTTP/1.1"); "POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/cloneVApp HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Accept: application/vnd.vmware.vcloud.task+xml\nContent-Length: 454\nContent-Type: application/vnd.vmware.vcloud.cloneVAppParams+xml\n"); "Accept: application/vnd.vmware.vcloud.task+xml\nContent-Length: 454\nContent-Type: application/vnd.vmware.vcloud.cloneVAppParams+xml\n");
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream( assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream(
"/cloneVApp.xml"))); "/cloneVApp.xml")));
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class); assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
@Test(expectedExceptions = IllegalArgumentException.class) @Test(expectedExceptions = IllegalArgumentException.class)
@ -188,361 +186,360 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testDefaultOrganization() throws SecurityException, NoSuchMethodException, public void testDefaultOrganization() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = VCloudAsyncClient.class.getMethod("getDefaultOrganization"); Method method = VCloudAsyncClient.class.getMethod("getDefaultOrganization");
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method); HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/org HTTP/1.1");
"GET https://vcloud.safesecureweb.com/api/v0.8/org HTTP/1.1"); assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.org+xml\n");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.org+xml\n"); assertPayloadEquals(request, null);
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, OrgHandler.class); assertSaxResponseParserClassEquals(method, OrgHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testOrganization() throws SecurityException, NoSuchMethodException, IOException { public void testOrganization() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getOrganization", String.class); Method method = VCloudAsyncClient.class.getMethod("getOrganization", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "1"); HttpRequest request = processor.createRequest(method, "1");
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"GET https://vcloud.safesecureweb.com/api/v0.8/org/1 HTTP/1.1"); "GET https://vcloud.safesecureweb.com/api/v0.8/org/1 HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.org+xml\n"); assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.org+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, OrgHandler.class); assertSaxResponseParserClassEquals(method, OrgHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testDefaultCatalog() throws SecurityException, NoSuchMethodException, IOException { public void testDefaultCatalog() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getDefaultCatalog"); Method method = VCloudAsyncClient.class.getMethod("getDefaultCatalog");
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method); HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"GET https://vcloud.safesecureweb.com/api/v0.8/catalog HTTP/1.1"); "GET https://vcloud.safesecureweb.com/api/v0.8/catalog HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.catalog+xml\n"); assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalog+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, CatalogHandler.class); assertSaxResponseParserClassEquals(method, CatalogHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testCatalog() throws SecurityException, NoSuchMethodException, IOException { public void testCatalog() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getCatalog", String.class); Method method = VCloudAsyncClient.class.getMethod("getCatalog", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "1"); HttpRequest request = processor.createRequest(method, "1");
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"GET https://vcloud.safesecureweb.com/api/v0.8/catalog/1 HTTP/1.1"); "GET https://vcloud.safesecureweb.com/api/v0.8/catalog/1 HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.catalog+xml\n"); assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalog+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, CatalogHandler.class); assertSaxResponseParserClassEquals(method, CatalogHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testNetwork() throws SecurityException, NoSuchMethodException, IOException { public void testNetwork() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getNetwork", String.class); Method method = VCloudAsyncClient.class.getMethod("getNetwork", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "2"); HttpRequest request = processor.createRequest(method, "2");
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"GET https://vcloud.safesecureweb.com/api/v0.8/network/2 HTTP/1.1"); "GET https://vcloud.safesecureweb.com/api/v0.8/network/2 HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.network+xml\n"); assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.network+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, NetworkHandler.class); assertSaxResponseParserClassEquals(method, NetworkHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testCatalogItem() throws SecurityException, NoSuchMethodException, IOException { public void testCatalogItem() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getCatalogItem", String.class); Method method = VCloudAsyncClient.class.getMethod("getCatalogItem", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "2"); HttpRequest request = processor.createRequest(method, "2");
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"GET https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2 HTTP/1.1"); "GET https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2 HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.catalogItem+xml\n"); assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalogItem+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, CatalogItemHandler.class); assertSaxResponseParserClassEquals(method, CatalogItemHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testVAppTemplate() throws SecurityException, NoSuchMethodException, IOException { public void testVAppTemplate() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getVAppTemplate", String.class); Method method = VCloudAsyncClient.class.getMethod("getVAppTemplate", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "2"); HttpRequest request = processor.createRequest(method, "2");
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"GET https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/2 HTTP/1.1"); "GET https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/2 HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n"); assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VAppTemplateHandler.class); assertSaxResponseParserClassEquals(method, VAppTemplateHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testGetDefaultVDC() throws SecurityException, NoSuchMethodException, IOException { public void testGetDefaultVDC() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getDefaultVDC"); Method method = VCloudAsyncClient.class.getMethod("getDefaultVDC");
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method); HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"GET https://vcloud.safesecureweb.com/api/v0.8/vdc/1 HTTP/1.1"); "GET https://vcloud.safesecureweb.com/api/v0.8/vdc/1 HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.vdc+xml\n"); assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VDCHandler.class); assertSaxResponseParserClassEquals(method, VDCHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testGetVDC() throws SecurityException, NoSuchMethodException, IOException { public void testGetVDC() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getVDC", String.class); Method method = VCloudAsyncClient.class.getMethod("getVDC", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "1"); HttpRequest request = processor.createRequest(method, "1");
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"GET https://vcloud.safesecureweb.com/api/v0.8/vdc/1 HTTP/1.1"); "GET https://vcloud.safesecureweb.com/api/v0.8/vdc/1 HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.vdc+xml\n"); assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VDCHandler.class); assertSaxResponseParserClassEquals(method, VDCHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testGetDefaultTasksList() throws SecurityException, NoSuchMethodException, public void testGetDefaultTasksList() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = VCloudAsyncClient.class.getMethod("getDefaultTasksList"); Method method = VCloudAsyncClient.class.getMethod("getDefaultTasksList");
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method); HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"GET https://vcloud.safesecureweb.com/api/v0.8/taskslist HTTP/1.1"); "GET https://vcloud.safesecureweb.com/api/v0.8/taskslist HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.tasksList+xml\n"); assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.tasksList+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TasksListHandler.class); assertSaxResponseParserClassEquals(method, TasksListHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testGetTasksList() throws SecurityException, NoSuchMethodException, IOException { public void testGetTasksList() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getTasksList", String.class); Method method = VCloudAsyncClient.class.getMethod("getTasksList", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "1"); HttpRequest request = processor.createRequest(method, "1");
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"GET https://vcloud.safesecureweb.com/api/v0.8/tasksList/1 HTTP/1.1"); "GET https://vcloud.safesecureweb.com/api/v0.8/tasksList/1 HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.tasksList+xml\n"); assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.tasksList+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TasksListHandler.class); assertSaxResponseParserClassEquals(method, TasksListHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testDeployVApp() throws SecurityException, NoSuchMethodException, IOException { public void testDeployVApp() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("deployVApp", String.class); Method method = VCloudAsyncClient.class.getMethod("deployVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1); HttpRequest request = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/action/deploy HTTP/1.1"); "POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/action/deploy HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class); assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testGetVApp() throws SecurityException, NoSuchMethodException, IOException { public void testGetVApp() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getVApp", String.class); Method method = VCloudAsyncClient.class.getMethod("getVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1); HttpRequest request = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"GET https://vcloud.safesecureweb.com/api/v0.8/vApp/1 HTTP/1.1"); "GET https://vcloud.safesecureweb.com/api/v0.8/vApp/1 HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.vApp+xml\n"); assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VAppHandler.class); assertSaxResponseParserClassEquals(method, VAppHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testUndeployVApp() throws SecurityException, NoSuchMethodException, IOException { public void testUndeployVApp() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("undeployVApp", String.class); Method method = VCloudAsyncClient.class.getMethod("undeployVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1); HttpRequest request = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/action/undeploy HTTP/1.1"); "POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/action/undeploy HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class); assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testDeleteVApp() throws SecurityException, NoSuchMethodException, IOException { public void testDeleteVApp() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("deleteVApp", String.class); Method method = VCloudAsyncClient.class.getMethod("deleteVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1); HttpRequest request = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"DELETE https://vcloud.safesecureweb.com/api/v0.8/vApp/1 HTTP/1.1"); "DELETE https://vcloud.safesecureweb.com/api/v0.8/vApp/1 HTTP/1.1");
assertHeadersEqual(httpMethod, ""); assertHeadersEqual(request, "");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class); assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testPowerOn() throws SecurityException, NoSuchMethodException, IOException { public void testPowerOn() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("powerOnVApp", String.class); Method method = VCloudAsyncClient.class.getMethod("powerOnVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1); HttpRequest request = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/power/action/powerOn HTTP/1.1"); "POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/power/action/powerOn HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class); assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testPowerOff() throws SecurityException, NoSuchMethodException, IOException { public void testPowerOff() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("powerOffVApp", String.class); Method method = VCloudAsyncClient.class.getMethod("powerOffVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1); HttpRequest request = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/power/action/powerOff HTTP/1.1"); "POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/power/action/powerOff HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class); assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testReset() throws SecurityException, NoSuchMethodException, IOException { public void testReset() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("resetVApp", String.class); Method method = VCloudAsyncClient.class.getMethod("resetVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1); HttpRequest request = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/power/action/reset HTTP/1.1"); "POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/power/action/reset HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class); assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testSuspend() throws SecurityException, NoSuchMethodException, IOException { public void testSuspend() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("suspendVApp", String.class); Method method = VCloudAsyncClient.class.getMethod("suspendVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1); HttpRequest request = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/power/action/suspend HTTP/1.1"); "POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/power/action/suspend HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class); assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testShutdown() throws SecurityException, NoSuchMethodException, IOException { public void testShutdown() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("shutdownVApp", String.class); Method method = VCloudAsyncClient.class.getMethod("shutdownVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1); HttpRequest request = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/power/action/shutdown HTTP/1.1"); "POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/power/action/shutdown HTTP/1.1");
assertHeadersEqual(httpMethod, ""); assertHeadersEqual(request, "");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testGetTask() throws SecurityException, NoSuchMethodException, IOException { public void testGetTask() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getTask", String.class); Method method = VCloudAsyncClient.class.getMethod("getTask", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "1"); HttpRequest request = processor.createRequest(method, "1");
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"GET https://vcloud.safesecureweb.com/api/v0.8/task/1 HTTP/1.1"); "GET https://vcloud.safesecureweb.com/api/v0.8/task/1 HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class); assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testCancelTask() throws SecurityException, NoSuchMethodException, IOException { public void testCancelTask() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("cancelTask", String.class); Method method = VCloudAsyncClient.class.getMethod("cancelTask", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "1"); HttpRequest request = processor.createRequest(method, "1");
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/task/1/action/cancel HTTP/1.1"); "POST https://vcloud.safesecureweb.com/api/v0.8/task/1/action/cancel HTTP/1.1");
assertHeadersEqual(httpMethod, ""); assertHeadersEqual(request, "");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
@Override @Override
protected void checkFilters(GeneratedHttpRequest<VCloudAsyncClient> httpMethod) { protected void checkFilters(HttpRequest request) {
assertEquals(httpMethod.getFilters().size(), 1); assertEquals(request.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), SetVCloudTokenCookie.class); assertEquals(request.getFilters().get(0).getClass(), SetVCloudTokenCookie.class);
} }
@Override @Override

View File

@ -27,11 +27,11 @@ import java.net.URI;
import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.HttpHeaders;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory.ContextSpec; import org.jclouds.rest.RestContextFactory.ContextSpec;
import org.jclouds.rest.annotations.Provider; import org.jclouds.rest.annotations.Provider;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.vcloud.VCloudLoginLiveTest.VCloudLoginClient; import org.jclouds.vcloud.VCloudLoginLiveTest.VCloudLoginClient;
import org.jclouds.vcloud.endpoints.VCloudLogin; import org.jclouds.vcloud.endpoints.VCloudLogin;
@ -54,24 +54,24 @@ public class VCloudLoginTest extends RestClientTest<VCloudLoginAsyncClient> {
public void testLogin() throws SecurityException, NoSuchMethodException, IOException { public void testLogin() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudLoginAsyncClient.class.getMethod("login"); Method method = VCloudLoginAsyncClient.class.getMethod("login");
GeneratedHttpRequest<VCloudLoginAsyncClient> httpMethod = processor.createRequest(method); HttpRequest request = processor.createRequest(method);
assertEquals(httpMethod.getRequestLine(), "POST http://localhost:8080/login HTTP/1.1"); assertEquals(request.getRequestLine(), "POST http://localhost:8080/login HTTP/1.1");
assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT assertHeadersEqual(request, HttpHeaders.ACCEPT
+ ": application/vnd.vmware.vcloud.organizationList+xml\n"); + ": application/vnd.vmware.vcloud.organizationList+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseLoginResponseFromHeaders.class); assertResponseParserClassEquals(method, request, ParseLoginResponseFromHeaders.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
@Override @Override
protected void checkFilters(GeneratedHttpRequest<VCloudLoginAsyncClient> httpMethod) { protected void checkFilters(HttpRequest request) {
assertEquals(httpMethod.getFilters().size(), 1); assertEquals(request.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class); assertEquals(request.getFilters().get(0).getClass(), BasicAuthentication.class);
} }
@Override @Override

View File

@ -24,10 +24,10 @@ import static org.testng.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory.ContextSpec; import org.jclouds.rest.RestContextFactory.ContextSpec;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.vcloud.VCloudVersionsLiveTest.VCloudVersionsClient; import org.jclouds.vcloud.VCloudVersionsLiveTest.VCloudVersionsClient;
import org.jclouds.vcloud.internal.VCloudVersionsAsyncClient; import org.jclouds.vcloud.internal.VCloudVersionsAsyncClient;
@ -46,22 +46,22 @@ public class VCloudVersionsTest extends RestClientTest<VCloudVersionsAsyncClient
public void testVersions() throws SecurityException, NoSuchMethodException, IOException { public void testVersions() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudVersionsAsyncClient.class.getMethod("getSupportedVersions"); Method method = VCloudVersionsAsyncClient.class.getMethod("getSupportedVersions");
GeneratedHttpRequest<VCloudVersionsAsyncClient> httpMethod = processor.createRequest(method); HttpRequest request = processor.createRequest(method);
assertEquals(httpMethod.getRequestLine(), "GET http://localhost:8080/versions HTTP/1.1"); assertEquals(request.getRequestLine(), "GET http://localhost:8080/versions HTTP/1.1");
assertHeadersEqual(httpMethod, ""); assertHeadersEqual(request, "");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, SupportedVersionsHandler.class); assertSaxResponseParserClassEquals(method, SupportedVersionsHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
@Override @Override
protected void checkFilters(GeneratedHttpRequest<VCloudVersionsAsyncClient> httpMethod) { protected void checkFilters(HttpRequest request) {
assertEquals(httpMethod.getFilters().size(), 0); assertEquals(request.getFilters().size(), 0);
} }
@Override @Override

View File

@ -29,13 +29,13 @@ import java.util.Properties;
import javax.inject.Named; import javax.inject.Named;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextFactory.ContextSpec; import org.jclouds.rest.RestContextFactory.ContextSpec;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.NamedResource;
@ -62,26 +62,25 @@ public class HostingDotComVCloudAsyncClientTest extends
RestClientTest<HostingDotComVCloudAsyncClient> { RestClientTest<HostingDotComVCloudAsyncClient> {
public void testCatalog() throws SecurityException, NoSuchMethodException, IOException { public void testCatalog() throws SecurityException, NoSuchMethodException, IOException {
Method method = HostingDotComVCloudAsyncClient.class.getMethod("getDefaultCatalog"); Method method = HostingDotComVCloudAsyncClient.class.getMethod("getDefaultCatalog");
GeneratedHttpRequest<HostingDotComVCloudAsyncClient> httpMethod = processor HttpRequest request = processor.createRequest(method);
.createRequest(method);
assertRequestLineEquals(httpMethod, "GET https://catalog HTTP/1.1"); assertRequestLineEquals(request, "GET https://catalog HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Accept: application/vnd.vmware.vcloud.catalog+xml\nContent-Type: application/vnd.vmware.vcloud.catalog+xml\n"); "Accept: application/vnd.vmware.vcloud.catalog+xml\nContent-Type: application/vnd.vmware.vcloud.catalog+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, CatalogHandler.class); assertSaxResponseParserClassEquals(method, CatalogHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
@Override @Override
protected void checkFilters(GeneratedHttpRequest<HostingDotComVCloudAsyncClient> httpMethod) { protected void checkFilters(HttpRequest request) {
assertEquals(httpMethod.getFilters().size(), 1); assertEquals(request.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), SetVCloudTokenCookie.class); assertEquals(request.getFilters().get(0).getClass(), SetVCloudTokenCookie.class);
} }
@Override @Override
@ -89,6 +88,7 @@ public class HostingDotComVCloudAsyncClientTest extends
return new TypeLiteral<RestAnnotationProcessor<HostingDotComVCloudAsyncClient>>() { return new TypeLiteral<RestAnnotationProcessor<HostingDotComVCloudAsyncClient>>() {
}; };
} }
@Override @Override
protected Module createModule() { protected Module createModule() {
return new HostingDotComVCloudRestClientModuleExtension(); return new HostingDotComVCloudRestClientModuleExtension();

View File

@ -20,7 +20,6 @@ package org.jclouds.vcloud.terremark.binders;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import java.util.Properties; import java.util.Properties;
@ -31,7 +30,6 @@ import javax.xml.transform.TransformerException;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.rest.binders.BindToStringPayload; import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.vcloud.terremark.domain.NodeConfiguration; import org.jclouds.vcloud.terremark.domain.NodeConfiguration;
import com.jamesmurty.utils.XMLBuilder; import com.jamesmurty.utils.XMLBuilder;
@ -44,20 +42,13 @@ import com.jamesmurty.utils.XMLBuilder;
@Singleton @Singleton
public class BindNodeConfigurationToXmlPayload extends BindToStringPayload { public class BindNodeConfigurationToXmlPayload extends BindToStringPayload {
@SuppressWarnings("unchecked")
@Override @Override
public void bindToRequest(HttpRequest request, Object input) { public void bindToRequest(HttpRequest request, Object input) {
checkArgument( NodeConfiguration nodeConfiguration = (NodeConfiguration) checkNotNull(input,
checkNotNull(request, "request") instanceof GeneratedHttpRequest, "nodeConfiguration");
"this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request;
checkState(gRequest.getArgs() != null,
"args should be initialized at this point");
NodeConfiguration nodeConfiguration = (NodeConfiguration) checkNotNull(
input, "nodeConfiguration");
checkArgument(nodeConfiguration.getDescription() != null checkArgument(nodeConfiguration.getDescription() != null
|| nodeConfiguration.getEnabled() != null || nodeConfiguration.getEnabled() != null || nodeConfiguration.getName() != null,
|| nodeConfiguration.getName() != null, "no configuration set"); "no configuration set");
try { try {
super.bindToRequest(request, generateXml(nodeConfiguration)); super.bindToRequest(request, generateXml(nodeConfiguration));
} catch (ParserConfigurationException e) { } catch (ParserConfigurationException e) {
@ -71,8 +62,7 @@ public class BindNodeConfigurationToXmlPayload extends BindToStringPayload {
} }
protected String generateXml(NodeConfiguration nodeConfiguration) protected String generateXml(NodeConfiguration nodeConfiguration)
throws ParserConfigurationException, FactoryConfigurationError, throws ParserConfigurationException, FactoryConfigurationError, TransformerException {
TransformerException {
XMLBuilder rootBuilder = XMLBuilder.create("NodeService").a("xmlns", XMLBuilder rootBuilder = XMLBuilder.create("NodeService").a("xmlns",
"urn:tmrk:vCloudExpressExtensions-1.6").a("xmlns:i", "urn:tmrk:vCloudExpressExtensions-1.6").a("xmlns:i",
"http://www.w3.org/2001/XMLSchema-instance"); "http://www.w3.org/2001/XMLSchema-instance");
@ -83,8 +73,7 @@ public class BindNodeConfigurationToXmlPayload extends BindToStringPayload {
if (nodeConfiguration.getEnabled() != null) if (nodeConfiguration.getEnabled() != null)
rootBuilder.e("Enabled").t(nodeConfiguration.getEnabled()); rootBuilder.e("Enabled").t(nodeConfiguration.getEnabled());
Properties outputProperties = new Properties(); Properties outputProperties = new Properties();
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
"yes");
return rootBuilder.asString(outputProperties); return rootBuilder.asString(outputProperties);
} }

View File

@ -31,6 +31,7 @@ import java.util.Properties;
import javax.inject.Named; import javax.inject.Named;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
@ -40,7 +41,6 @@ import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextFactory.ContextSpec; import org.jclouds.rest.RestContextFactory.ContextSpec;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.VCloudClient;
@ -85,49 +85,47 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
*/ */
public void testCatalog() throws SecurityException, NoSuchMethodException, IOException { public void testCatalog() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("getCatalog", String.class); Method method = TerremarkVCloudAsyncClient.class.getMethod("getCatalog", String.class);
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, "1");
"1");
assertRequestLineEquals(httpMethod, "GET https://catalog HTTP/1.1"); assertRequestLineEquals(request, "GET https://catalog HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.catalog+xml\n"); assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalog+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, CatalogHandler.class); assertSaxResponseParserClassEquals(method, CatalogHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testGetDefaultVDC() throws SecurityException, NoSuchMethodException, IOException { public void testGetDefaultVDC() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("getDefaultVDC"); Method method = TerremarkVCloudAsyncClient.class.getMethod("getDefaultVDC");
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method); HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(httpMethod, "GET https://vdc/1 HTTP/1.1"); assertRequestLineEquals(request, "GET https://vdc/1 HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.vdc+xml\n"); assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TerremarkVDCHandler.class); assertSaxResponseParserClassEquals(method, TerremarkVDCHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testGetVDC() throws SecurityException, NoSuchMethodException, IOException { public void testGetVDC() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("getVDC", String.class); Method method = TerremarkVCloudAsyncClient.class.getMethod("getVDC", String.class);
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, "1");
"1");
assertRequestLineEquals(httpMethod, "GET https://vcloud/vdc/1 HTTP/1.1"); assertRequestLineEquals(request, "GET https://vcloud/vdc/1 HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.vdc+xml\n"); assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TerremarkVDCHandler.class); assertSaxResponseParserClassEquals(method, TerremarkVDCHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testInstantiateVAppTemplate() throws SecurityException, NoSuchMethodException, public void testInstantiateVAppTemplate() throws SecurityException, NoSuchMethodException,
@ -135,22 +133,21 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
Method method = TerremarkVCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", Method method = TerremarkVCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC",
String.class, String.class, String.class, Array.newInstance( String.class, String.class, String.class, Array.newInstance(
InstantiateVAppTemplateOptions.class, 0).getClass()); InstantiateVAppTemplateOptions.class, 0).getClass());
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, "1", "name", 3 + "");
"1", "name", 3 + "");
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"POST https://vcloud/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); "POST https://vcloud/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Accept: application/vnd.vmware.vcloud.vApp+xml\nContent-Length: 695\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n"); "Accept: application/vnd.vmware.vcloud.vApp+xml\nContent-Length: 695\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n");
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream( assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream(
"/terremark/InstantiateVAppTemplateParams-test.xml"))); "/terremark/InstantiateVAppTemplateParams-test.xml")));
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VAppHandler.class); assertSaxResponseParserClassEquals(method, VAppHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testInstantiateVAppTemplateOptions() throws SecurityException, public void testInstantiateVAppTemplateOptions() throws SecurityException,
@ -158,24 +155,24 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
Method method = TerremarkVCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", Method method = TerremarkVCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC",
String.class, String.class, String.class, Array.newInstance( String.class, String.class, String.class, Array.newInstance(
InstantiateVAppTemplateOptions.class, 0).getClass()); InstantiateVAppTemplateOptions.class, 0).getClass());
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, "1", "name", 3 + "",
"1", "name", 3 + "", TerremarkInstantiateVAppTemplateOptions.Builder.processorCount( TerremarkInstantiateVAppTemplateOptions.Builder.processorCount(2).memory(512).inRow(
2).memory(512).inRow("row").inGroup("group").withPassword("password") "row").inGroup("group").withPassword("password").inNetwork(
.inNetwork(URI.create("http://network"))); URI.create("http://network")));
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"POST https://vcloud/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); "POST https://vcloud/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Accept: application/vnd.vmware.vcloud.vApp+xml\nContent-Length: 1910\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n"); "Accept: application/vnd.vmware.vcloud.vApp+xml\nContent-Length: 1910\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n");
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream( assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream(
"/terremark/InstantiateVAppTemplateParams-options-test.xml"))); "/terremark/InstantiateVAppTemplateParams-options-test.xml")));
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VAppHandler.class); assertSaxResponseParserClassEquals(method, VAppHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testAddInternetService() throws SecurityException, NoSuchMethodException, public void testAddInternetService() throws SecurityException, NoSuchMethodException,
@ -183,22 +180,21 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetServiceToVDC", Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetServiceToVDC",
String.class, String.class, Protocol.class, int.class, Array.newInstance( String.class, String.class, Protocol.class, int.class, Array.newInstance(
AddInternetServiceOptions.class, 0).getClass()); AddInternetServiceOptions.class, 0).getClass());
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, "1", "name", Protocol.TCP, 22);
"1", "name", Protocol.TCP, 22);
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"POST https://vcloud/extensions/vdc/1/internetServices HTTP/1.1"); "POST https://vcloud/extensions/vdc/1/internetServices HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Accept: application/vnd.tmrk.vCloud.internetService+xml\nContent-Length: 298\nContent-Type: application/vnd.tmrk.vCloud.internetService+xml\n"); "Accept: application/vnd.tmrk.vCloud.internetService+xml\nContent-Length: 298\nContent-Type: application/vnd.tmrk.vCloud.internetService+xml\n");
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream( assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream(
"/terremark/CreateInternetService-test2.xml"))); "/terremark/CreateInternetService-test2.xml")));
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class); assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testAddInternetServiceOptions() throws SecurityException, NoSuchMethodException, public void testAddInternetServiceOptions() throws SecurityException, NoSuchMethodException,
@ -206,79 +202,73 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetServiceToVDC", Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetServiceToVDC",
String.class, String.class, Protocol.class, int.class, Array.newInstance( String.class, String.class, Protocol.class, int.class, Array.newInstance(
AddInternetServiceOptions.class, 0).getClass()); AddInternetServiceOptions.class, 0).getClass());
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, "1", "name", Protocol.TCP, 22,
"1", "name", Protocol.TCP, 22, disabled().withDescription("yahoo")); disabled().withDescription("yahoo"));
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"POST https://vcloud/extensions/vdc/1/internetServices HTTP/1.1"); "POST https://vcloud/extensions/vdc/1/internetServices HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Accept: application/vnd.tmrk.vCloud.internetService+xml\nContent-Length: 336\nContent-Type: application/vnd.tmrk.vCloud.internetService+xml\n"); "Accept: application/vnd.tmrk.vCloud.internetService+xml\nContent-Length: 336\nContent-Type: application/vnd.tmrk.vCloud.internetService+xml\n");
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream( assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream(
"/terremark/CreateInternetService-options-test.xml"))); "/terremark/CreateInternetService-options-test.xml")));
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class); assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testGetAllInternetServices() throws SecurityException, NoSuchMethodException, public void testGetAllInternetServices() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("getAllInternetServicesInVDC", Method method = TerremarkVCloudAsyncClient.class.getMethod("getAllInternetServicesInVDC",
String.class); String.class);
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, "1");
"1");
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"GET https://vcloud/extensions/vdc/1/internetServices HTTP/1.1"); "GET https://vcloud/extensions/vdc/1/internetServices HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.internetServicesList+xml\n");
"Accept: application/vnd.tmrk.vCloud.internetServicesList+xml\n"); assertPayloadEquals(request, null);
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, InternetServicesHandler.class); assertSaxResponseParserClassEquals(method, InternetServicesHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testGetInternetService() throws SecurityException, NoSuchMethodException, public void testGetInternetService() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("getInternetService", int.class); Method method = TerremarkVCloudAsyncClient.class.getMethod("getInternetService", int.class);
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, 12);
12);
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request, "GET https://vcloud/extensions/internetService/12 HTTP/1.1");
"GET https://vcloud/extensions/internetService/12 HTTP/1.1"); assertHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.internetServicesList+xml\n");
assertHeadersEqual(httpMethod, assertPayloadEquals(request, null);
"Accept: application/vnd.tmrk.vCloud.internetServicesList+xml\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class); assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testDeleteInternetService() throws SecurityException, NoSuchMethodException, public void testDeleteInternetService() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = TerremarkVCloudAsyncClient.class Method method = TerremarkVCloudAsyncClient.class
.getMethod("deleteInternetService", int.class); .getMethod("deleteInternetService", int.class);
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, 12);
12);
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"DELETE https://vcloud/extensions/internetService/12 HTTP/1.1"); "DELETE https://vcloud/extensions/internetService/12 HTTP/1.1");
assertHeadersEqual(httpMethod, ""); assertHeadersEqual(request, "");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class); assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testAddInternetServiceToExistingIp() throws SecurityException, public void testAddInternetServiceToExistingIp() throws SecurityException,
@ -286,22 +276,21 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetServiceToExistingIp", Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetServiceToExistingIp",
int.class, String.class, Protocol.class, int.class, Array.newInstance( int.class, String.class, Protocol.class, int.class, Array.newInstance(
AddInternetServiceOptions.class, 0).getClass()); AddInternetServiceOptions.class, 0).getClass());
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, 12, "name", Protocol.TCP, 22);
12, "name", Protocol.TCP, 22);
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"POST https://vcloud/extensions/publicIp/12/internetServices HTTP/1.1"); "POST https://vcloud/extensions/publicIp/12/internetServices HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Accept: application/vnd.tmrk.vCloud.internetService+xml\nContent-Length: 298\nContent-Type: application/vnd.tmrk.vCloud.internetService+xml\n"); "Accept: application/vnd.tmrk.vCloud.internetService+xml\nContent-Length: 298\nContent-Type: application/vnd.tmrk.vCloud.internetService+xml\n");
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream( assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream(
"/terremark/CreateInternetService-test2.xml"))); "/terremark/CreateInternetService-test2.xml")));
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class); assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testAddInternetServiceToExistingIpOptions() throws SecurityException, public void testAddInternetServiceToExistingIpOptions() throws SecurityException,
@ -309,203 +298,194 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetServiceToExistingIp", Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetServiceToExistingIp",
int.class, String.class, Protocol.class, int.class, Array.newInstance( int.class, String.class, Protocol.class, int.class, Array.newInstance(
AddInternetServiceOptions.class, 0).getClass()); AddInternetServiceOptions.class, 0).getClass());
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, 12, "name", Protocol.TCP, 22,
12, "name", Protocol.TCP, 22, disabled().withDescription("yahoo")); disabled().withDescription("yahoo"));
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"POST https://vcloud/extensions/publicIp/12/internetServices HTTP/1.1"); "POST https://vcloud/extensions/publicIp/12/internetServices HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Accept: application/vnd.tmrk.vCloud.internetService+xml\nContent-Length: 336\nContent-Type: application/vnd.tmrk.vCloud.internetService+xml\n"); "Accept: application/vnd.tmrk.vCloud.internetService+xml\nContent-Length: 336\nContent-Type: application/vnd.tmrk.vCloud.internetService+xml\n");
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream( assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream(
"/terremark/CreateInternetService-options-test.xml"))); "/terremark/CreateInternetService-options-test.xml")));
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class); assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testAddNode() throws SecurityException, NoSuchMethodException, IOException { public void testAddNode() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("addNode", int.class, Method method = TerremarkVCloudAsyncClient.class.getMethod("addNode", int.class,
String.class, String.class, int.class, Array.newInstance(AddNodeOptions.class, 0) String.class, String.class, int.class, Array.newInstance(AddNodeOptions.class, 0)
.getClass()); .getClass());
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, 12, "10.2.2.2", "name", 22);
12, "10.2.2.2", "name", 22);
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"POST https://vcloud/extensions/internetService/12/nodeServices HTTP/1.1"); "POST https://vcloud/extensions/internetService/12/nodeServices HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Accept: application/vnd.tmrk.vCloud.nodeService+xml\nContent-Length: 295\nContent-Type: application/vnd.tmrk.vCloud.nodeService+xml\n"); "Accept: application/vnd.tmrk.vCloud.nodeService+xml\nContent-Length: 295\nContent-Type: application/vnd.tmrk.vCloud.nodeService+xml\n");
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream( assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream(
"/terremark/CreateNodeService-test2.xml"))); "/terremark/CreateNodeService-test2.xml")));
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, NodeHandler.class); assertSaxResponseParserClassEquals(method, NodeHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testAddNodeOptions() throws SecurityException, NoSuchMethodException, IOException { public void testAddNodeOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("addNode", int.class, Method method = TerremarkVCloudAsyncClient.class.getMethod("addNode", int.class,
String.class, String.class, int.class, Array.newInstance(AddNodeOptions.class, 0) String.class, String.class, int.class, Array.newInstance(AddNodeOptions.class, 0)
.getClass()); .getClass());
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, 12, "10.2.2.2", "name", 22,
12, "10.2.2.2", "name", 22, AddNodeOptions.Builder.disabled().withDescription( AddNodeOptions.Builder.disabled().withDescription("yahoo"));
"yahoo"));
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"POST https://vcloud/extensions/internetService/12/nodeServices HTTP/1.1"); "POST https://vcloud/extensions/internetService/12/nodeServices HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Accept: application/vnd.tmrk.vCloud.nodeService+xml\nContent-Length: 333\nContent-Type: application/vnd.tmrk.vCloud.nodeService+xml\n"); "Accept: application/vnd.tmrk.vCloud.nodeService+xml\nContent-Length: 333\nContent-Type: application/vnd.tmrk.vCloud.nodeService+xml\n");
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream( assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream(
"/terremark/CreateNodeService-options-test.xml"))); "/terremark/CreateNodeService-options-test.xml")));
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, NodeHandler.class); assertSaxResponseParserClassEquals(method, NodeHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testGetKeyPair() throws SecurityException, NoSuchMethodException, IOException { public void testGetKeyPair() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("getNode", int.class); Method method = TerremarkVCloudAsyncClient.class.getMethod("getNode", int.class);
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, 12);
12);
assertRequestLineEquals(httpMethod, "GET https://vcloud/extensions/nodeService/12 HTTP/1.1"); assertRequestLineEquals(request, "GET https://vcloud/extensions/nodeService/12 HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.tmrk.vCloud.nodeService+xml\n"); assertHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.nodeService+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, NodeHandler.class); assertSaxResponseParserClassEquals(method, NodeHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testConfigureNode() throws SecurityException, NoSuchMethodException, IOException { public void testConfigureNode() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("configureNode", int.class, Method method = TerremarkVCloudAsyncClient.class.getMethod("configureNode", int.class,
NodeConfiguration.class); NodeConfiguration.class);
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, 12, new NodeConfiguration()
12, new NodeConfiguration().changeDescriptionTo("eggs")); .changeDescriptionTo("eggs"));
assertRequestLineEquals(httpMethod, "PUT https://vcloud/extensions/nodeService/12 HTTP/1.1"); assertRequestLineEquals(request, "PUT https://vcloud/extensions/nodeService/12 HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, request,
"Accept: application/vnd.tmrk.vCloud.nodeService+xml\nContent-Length: 155\nContent-Type: application/vnd.tmrk.vCloud.nodeService+xml\n"); "Accept: application/vnd.tmrk.vCloud.nodeService+xml\nContent-Length: 155\nContent-Type: application/vnd.tmrk.vCloud.nodeService+xml\n");
assertPayloadEquals( assertPayloadEquals(
httpMethod, request,
"<NodeService xmlns=\"urn:tmrk:vCloudExpressExtensions-1.6\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><Description>eggs</Description></NodeService>"); "<NodeService xmlns=\"urn:tmrk:vCloudExpressExtensions-1.6\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><Description>eggs</Description></NodeService>");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, NodeHandler.class); assertSaxResponseParserClassEquals(method, NodeHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testGetNodes() throws SecurityException, NoSuchMethodException, IOException { public void testGetNodes() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("getNodes", int.class); Method method = TerremarkVCloudAsyncClient.class.getMethod("getNodes", int.class);
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, 12);
12);
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"GET https://vcloud/extensions/internetService/12/nodeServices HTTP/1.1"); "GET https://vcloud/extensions/internetService/12/nodeServices HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.tmrk.vCloud.nodeService+xml\n"); assertHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.nodeService+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, NodesHandler.class); assertSaxResponseParserClassEquals(method, NodesHandler.class);
assertExceptionParserClassEquals(method, ReturnEmptySetOnUnauthorized.class); assertExceptionParserClassEquals(method, ReturnEmptySetOnUnauthorized.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testDeleteNode() throws SecurityException, NoSuchMethodException, IOException { public void testDeleteNode() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("deleteNode", int.class); Method method = TerremarkVCloudAsyncClient.class.getMethod("deleteNode", int.class);
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, 12);
12);
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request, "DELETE https://vcloud/extensions/nodeService/12 HTTP/1.1");
"DELETE https://vcloud/extensions/nodeService/12 HTTP/1.1"); assertHeadersEqual(request, "");
assertHeadersEqual(httpMethod, ""); assertPayloadEquals(request, null);
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class); assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
checkFilters(httpMethod); checkFilters(request);
} }
public void testGetCustomizationOptionsOfCatalogItem() throws SecurityException, public void testGetCustomizationOptionsOfCatalogItem() throws SecurityException,
NoSuchMethodException, IOException { NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod( Method method = TerremarkVCloudAsyncClient.class.getMethod(
"getCustomizationOptionsOfCatalogItem", String.class); "getCustomizationOptionsOfCatalogItem", String.class);
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, 12);
12);
assertRequestLineEquals(httpMethod, assertRequestLineEquals(request,
"GET https://vcloud/extensions/template/12/options/customization HTTP/1.1"); "GET https://vcloud/extensions/template/12/options/customization HTTP/1.1");
assertHeadersEqual(httpMethod, assertHeadersEqual(request,
"Accept: application/vnd.tmrk.vCloud.catalogItemCustomizationParameters+xml\n"); "Accept: application/vnd.tmrk.vCloud.catalogItemCustomizationParameters+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, CustomizationParametersHandler.class); assertSaxResponseParserClassEquals(method, CustomizationParametersHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testListKeyPairs() throws SecurityException, NoSuchMethodException, IOException { public void testListKeyPairs() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("listKeyPairs"); Method method = TerremarkVCloudAsyncClient.class.getMethod("listKeyPairs");
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method); HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(httpMethod, "GET https://keysList HTTP/1.1"); assertRequestLineEquals(request, "GET https://keysList HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.tmrk.vcloudExpress.keysList+xml\n"); assertHeadersEqual(request, "Accept: application/vnd.tmrk.vcloudExpress.keysList+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, KeyPairsHandler.class); assertSaxResponseParserClassEquals(method, KeyPairsHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testListKeyPairsInOrg() throws SecurityException, NoSuchMethodException, IOException { public void testListKeyPairsInOrg() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("listKeyPairsInOrg", String.class); Method method = TerremarkVCloudAsyncClient.class.getMethod("listKeyPairsInOrg", String.class);
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, "org1");
"org1");
assertRequestLineEquals(httpMethod, "GET https://vcloud/extensions/org/org1/keys HTTP/1.1"); assertRequestLineEquals(request, "GET https://vcloud/extensions/org/org1/keys HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.tmrk.vcloudExpress.keysList+xml\n"); assertHeadersEqual(request, "Accept: application/vnd.tmrk.vcloudExpress.keysList+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, KeyPairsHandler.class); assertSaxResponseParserClassEquals(method, KeyPairsHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(request);
} }
public void testGetNode() throws SecurityException, NoSuchMethodException, IOException { public void testGetNode() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("getNode", int.class); Method method = TerremarkVCloudAsyncClient.class.getMethod("getNode", int.class);
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, 12);
12);
assertRequestLineEquals(httpMethod, "GET https://vcloud/extensions/nodeService/12 HTTP/1.1"); assertRequestLineEquals(request, "GET https://vcloud/extensions/nodeService/12 HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.tmrk.vCloud.nodeService+xml\n"); assertHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.nodeService+xml\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, NodeHandler.class); assertSaxResponseParserClassEquals(method, NodeHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpMethod); checkFilters(request);
} }
// TODO // TODO
@ -513,45 +493,44 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
// NoSuchMethodException, IOException { // NoSuchMethodException, IOException {
// Method method = TerremarkVCloudAsyncClient.class.getMethod( // Method method = TerremarkVCloudAsyncClient.class.getMethod(
// "configureKeyPair", int.class, KeyPairConfiguration.class); // "configureKeyPair", int.class, KeyPairConfiguration.class);
// GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor // HttpRequest request = processor
// .createRequest(method, 12, new KeyPairConfiguration() // .createRequest(method, 12, new KeyPairConfiguration()
// .changeDescriptionTo("eggs")); // .changeDescriptionTo("eggs"));
// //
// assertRequestLineEquals(httpMethod, // assertRequestLineEquals(request,
// "PUT https://vcloud/extensions/keyPairService/12 HTTP/1.1"); // "PUT https://vcloud/extensions/keyPairService/12 HTTP/1.1");
// assertHeadersEqual( // assertHeadersEqual(
// httpMethod, // request,
// "Accept: application/vnd.tmrk.vCloud.keyPairService+xml\nContent-Length: 155\nContent-Type: application/vnd.tmrk.vCloud.keyPairService+xml\n"); // "Accept: application/vnd.tmrk.vCloud.keyPairService+xml\nContent-Length: 155\nContent-Type: application/vnd.tmrk.vCloud.keyPairService+xml\n");
// assertPayloadEquals( // assertPayloadEquals(
// httpMethod, // request,
// "<KeyPairService xmlns=\"urn:tmrk:vCloudExpressExtensions-1.6\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><Description>eggs</Description></KeyPairService>"); // "<KeyPairService xmlns=\"urn:tmrk:vCloudExpressExtensions-1.6\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><Description>eggs</Description></KeyPairService>");
// assertResponseParserClassEquals(method, httpMethod, ParseSax.class); // assertResponseParserClassEquals(method, request, ParseSax.class);
// assertSaxResponseParserClassEquals(method, KeyPairHandler.class); // assertSaxResponseParserClassEquals(method, KeyPairHandler.class);
// assertExceptionParserClassEquals(method, null); // assertExceptionParserClassEquals(method, null);
// //
// checkFilters(httpMethod); // checkFilters(request);
// } // }
public void testDeleteKeyPair() throws SecurityException, NoSuchMethodException, IOException { public void testDeleteKeyPair() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("deleteKeyPair", int.class); Method method = TerremarkVCloudAsyncClient.class.getMethod("deleteKeyPair", int.class);
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, HttpRequest request = processor.createRequest(method, 12);
12);
assertRequestLineEquals(httpMethod, "DELETE https://vcloud/extensions/key/12 HTTP/1.1"); assertRequestLineEquals(request, "DELETE https://vcloud/extensions/key/12 HTTP/1.1");
assertHeadersEqual(httpMethod, ""); assertHeadersEqual(request, "");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(request, null);
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class); assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
checkFilters(httpMethod); checkFilters(request);
} }
@Override @Override
protected void checkFilters(GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod) { protected void checkFilters(HttpRequest request) {
assertEquals(httpMethod.getFilters().size(), 1); assertEquals(request.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), SetVCloudTokenCookie.class); assertEquals(request.getFilters().get(0).getClass(), SetVCloudTokenCookie.class);
} }
@Override @Override

View File

@ -28,8 +28,7 @@ import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.util.Properties; import java.util.Properties;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.http.HttpRequest;
import com.google.inject.name.Names;
import org.jclouds.vcloud.VCloudPropertiesBuilder; import org.jclouds.vcloud.VCloudPropertiesBuilder;
import org.jclouds.vcloud.terremark.domain.NodeConfiguration; import org.jclouds.vcloud.terremark.domain.NodeConfiguration;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -40,6 +39,7 @@ import com.google.common.collect.Multimaps;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.name.Names;
/** /**
* Tests behavior of {@code BindNodeConfigurationToXmlPayload} * Tests behavior of {@code BindNodeConfigurationToXmlPayload}
@ -100,8 +100,7 @@ public class BindNodeConfigurationToXmlPayloadTest {
.getInstance(BindNodeConfigurationToXmlPayload.class); .getInstance(BindNodeConfigurationToXmlPayload.class);
Multimap<String, String> headers = Multimaps.synchronizedMultimap(HashMultimap Multimap<String, String> headers = Multimaps.synchronizedMultimap(HashMultimap
.<String, String> create()); .<String, String> create());
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class); HttpRequest request = createMock(HttpRequest.class);
expect(request.getArgs()).andReturn(new Object[] { config }).atLeastOnce();
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes(); expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
expect(request.getFirstHeaderOrNull("Content-Type")).andReturn(null).atLeastOnce(); expect(request.getFirstHeaderOrNull("Content-Type")).andReturn(null).atLeastOnce();
expect(request.getHeaders()).andReturn(headers).atLeastOnce(); expect(request.getHeaders()).andReturn(headers).atLeastOnce();