diff --git a/atmos/src/test/java/org/jclouds/atmosonline/saas/AtmosStorageAsyncClientTest.java b/atmos/src/test/java/org/jclouds/atmosonline/saas/AtmosStorageAsyncClientTest.java index 388d09af10..9aa40fb1f3 100644 --- a/atmos/src/test/java/org/jclouds/atmosonline/saas/AtmosStorageAsyncClientTest.java +++ b/atmos/src/test/java/org/jclouds/atmosonline/saas/AtmosStorageAsyncClientTest.java @@ -40,6 +40,7 @@ import org.jclouds.blobstore.binders.BindBlobToMultipartFormTest; import org.jclouds.blobstore.functions.ThrowContainerNotFoundOn404; import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404; import org.jclouds.date.TimeStamp; +import org.jclouds.http.HttpRequest; import org.jclouds.http.RequiresHttp; import org.jclouds.http.functions.CloseContentAndReturn; 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.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; -import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -72,190 +72,182 @@ public class AtmosStorageAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method); + HttpRequest request = processor.createRequest(method); - assertRequestLineEquals(httpMethod, + assertRequestLineEquals(request, "GET https://accesspoint.atmosonline.com/rest/namespace HTTP/1.1"); - assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + ": text/xml\n"); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, HttpHeaders.ACCEPT + ": text/xml\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, + assertResponseParserClassEquals(method, request, ParseDirectoryListFromContentAndHeaders.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testListDirectory() throws SecurityException, NoSuchMethodException, IOException { Method method = AtmosStorageAsyncClient.class.getMethod("listDirectory", String.class, Array .newInstance(ListOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - "directory"); + HttpRequest request = processor.createRequest(method, "directory"); - assertRequestLineEquals(httpMethod, + assertRequestLineEquals(request, "GET https://accesspoint.atmosonline.com/rest/namespace/directory/ HTTP/1.1"); - assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + ": text/xml\n"); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, HttpHeaders.ACCEPT + ": text/xml\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, + assertResponseParserClassEquals(method, request, ParseDirectoryListFromContentAndHeaders.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, ThrowContainerNotFoundOn404.class); - checkFilters(httpMethod); + checkFilters(request); } public void testListDirectoriesOptions() throws SecurityException, NoSuchMethodException, IOException { Method method = AtmosStorageAsyncClient.class.getMethod("listDirectories", Array.newInstance( ListOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - new ListOptions().limit(1).token("asda")); + HttpRequest request = processor.createRequest(method, new ListOptions().limit(1) + .token("asda")); - assertRequestLineEquals(httpMethod, + assertRequestLineEquals(request, "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"); - assertPayloadEquals(httpMethod, null); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, + assertResponseParserClassEquals(method, request, ParseDirectoryListFromContentAndHeaders.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testListDirectoryOptions() throws SecurityException, NoSuchMethodException, IOException { Method method = AtmosStorageAsyncClient.class.getMethod("listDirectory", String.class, Array .newInstance(ListOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - "directory", new ListOptions().limit(1).token("asda")); + HttpRequest request = processor.createRequest(method, "directory", new ListOptions().limit(1) + .token("asda")); - assertRequestLineEquals(httpMethod, + assertRequestLineEquals(request, "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"); - assertPayloadEquals(httpMethod, null); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, + assertResponseParserClassEquals(method, request, ParseDirectoryListFromContentAndHeaders.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, ThrowContainerNotFoundOn404.class); - checkFilters(httpMethod); + checkFilters(request); } public void testCreateDirectory() throws SecurityException, NoSuchMethodException, IOException { Method method = AtmosStorageAsyncClient.class.getMethod("createDirectory", String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - "dir"); + HttpRequest request = processor.createRequest(method, "dir"); - assertRequestLineEquals(httpMethod, + assertRequestLineEquals(request, "POST https://accesspoint.atmosonline.com/rest/namespace/dir/ HTTP/1.1"); - assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + ": */*\n"); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, HttpHeaders.ACCEPT + ": */*\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, - ParseURIFromListOrLocationHeaderIf20x.class); + assertResponseParserClassEquals(method, request, ParseURIFromListOrLocationHeaderIf20x.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, ReturnEndpointIfAlreadyExists.class); - checkFilters(httpMethod); + checkFilters(request); } public void testCreateFile() throws SecurityException, NoSuchMethodException, IOException { Method method = AtmosStorageAsyncClient.class.getMethod("createFile", String.class, AtmosObject.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - "dir", blobToObject.apply(BindBlobToMultipartFormTest.TEST_BLOB)); + HttpRequest request = processor.createRequest(method, "dir", blobToObject + .apply(BindBlobToMultipartFormTest.TEST_BLOB)); - assertRequestLineEquals(httpMethod, + assertRequestLineEquals(request, "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"); - assertPayloadEquals(httpMethod, "hello"); + assertPayloadEquals(request, "hello"); - assertResponseParserClassEquals(method, httpMethod, - ParseURIFromListOrLocationHeaderIf20x.class); + assertResponseParserClassEquals(method, request, ParseURIFromListOrLocationHeaderIf20x.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testUpdateFile() throws SecurityException, NoSuchMethodException, IOException { Method method = AtmosStorageAsyncClient.class.getMethod("updateFile", String.class, AtmosObject.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - "dir", blobToObject.apply(BindBlobToMultipartFormTest.TEST_BLOB)); + HttpRequest request = processor.createRequest(method, "dir", blobToObject + .apply(BindBlobToMultipartFormTest.TEST_BLOB)); - assertRequestLineEquals(httpMethod, + assertRequestLineEquals(request, "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"); - assertPayloadEquals(httpMethod, "hello"); + assertPayloadEquals(request, "hello"); - assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); + assertResponseParserClassEquals(method, request, CloseContentAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, ThrowKeyNotFoundOn404.class); - checkFilters(httpMethod); + checkFilters(request); } public void testReadFile() throws SecurityException, NoSuchMethodException, IOException { Method method = AtmosStorageAsyncClient.class.getMethod("readFile", String.class, Array .newInstance(GetOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - "dir/file"); + HttpRequest request = processor.createRequest(method, "dir/file"); - assertRequestLineEquals(httpMethod, + assertRequestLineEquals(request, "GET https://accesspoint.atmosonline.com/rest/namespace/dir/file HTTP/1.1"); - assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + ": */*\n"); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, HttpHeaders.ACCEPT + ": */*\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, - ParseObjectFromHeadersAndHttpContent.class); + assertResponseParserClassEquals(method, request, ParseObjectFromHeadersAndHttpContent.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - checkFilters(httpMethod); + checkFilters(request); } public void testGetSystemMetadata() throws SecurityException, NoSuchMethodException, IOException { Method method = AtmosStorageAsyncClient.class.getMethod("getSystemMetadata", String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - "dir/file"); + HttpRequest request = processor.createRequest(method, "dir/file"); - assertRequestLineEquals(httpMethod, + assertRequestLineEquals(request, "HEAD https://accesspoint.atmosonline.com/rest/namespace/dir/file HTTP/1.1"); - assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + ": */*\n"); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, HttpHeaders.ACCEPT + ": */*\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSystemMetadataFromHeaders.class); + assertResponseParserClassEquals(method, request, ParseSystemMetadataFromHeaders.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - checkFilters(httpMethod); + checkFilters(request); } public void testDeletePath() throws SecurityException, NoSuchMethodException, IOException { Method method = AtmosStorageAsyncClient.class.getMethod("deletePath", String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - "dir/file"); + HttpRequest request = processor.createRequest(method, "dir/file"); - assertRequestLineEquals(httpMethod, + assertRequestLineEquals(request, "DELETE https://accesspoint.atmosonline.com/rest/namespace/dir/file HTTP/1.1"); - assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + ": */*\n"); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, HttpHeaders.ACCEPT + ": */*\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); + assertResponseParserClassEquals(method, request, CloseContentAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class); - checkFilters(httpMethod); + checkFilters(request); } public void testNewObject() throws SecurityException, NoSuchMethodException, IOException { @@ -264,9 +256,9 @@ public class AtmosStorageAsyncClientTest extends RestClientTest httpMethod) { - assertEquals(httpMethod.getFilters().size(), 1); - assertEquals(httpMethod.getFilters().get(0).getClass(), SignRequest.class); + protected void checkFilters(HttpRequest request) { + assertEquals(request.getFilters().size(), 1); + assertEquals(request.getFilters().get(0).getClass(), SignRequest.class); } @Override diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindBlockDeviceMappingToIndexedFormParams.java b/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindBlockDeviceMappingToIndexedFormParams.java index 0d2c04d3f8..5e3d6f2c38 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindBlockDeviceMappingToIndexedFormParams.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindBlockDeviceMappingToIndexedFormParams.java @@ -1,53 +1,67 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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; +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.RunningInstance; import org.jclouds.http.HttpRequest; import org.jclouds.rest.Binder; -import org.jclouds.rest.internal.GeneratedHttpRequest; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static java.lang.String.format; /** * @author Oleksiy Yarmula */ public class BindBlockDeviceMappingToIndexedFormParams implements Binder { - private final String deviceNamePattern = "BlockDeviceMapping.%d.DeviceName"; - private final String volumeIdPattern = "BlockDeviceMapping.%d.Ebs.VolumeId"; - private final String deleteOnTerminationPattern = "BlockDeviceMapping.%d.Ebs.DeleteOnTermination"; + private final String deviceNamePattern = "BlockDeviceMapping.%d.DeviceName"; + private final String volumeIdPattern = "BlockDeviceMapping.%d.Ebs.VolumeId"; + private final String deleteOnTerminationPattern = "BlockDeviceMapping.%d.Ebs.DeleteOnTermination"; - @SuppressWarnings("unchecked") - 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, - "this binder is only valid for BlockDeviceMapping"); - BlockDeviceMapping blockDeviceMapping = (BlockDeviceMapping) input; - GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request; + public void bindToRequest(HttpRequest request, Object input) { + checkArgument(checkNotNull(input, "input") instanceof BlockDeviceMapping, + "this binder is only valid for BlockDeviceMapping"); + BlockDeviceMapping blockDeviceMapping = (BlockDeviceMapping) input; - int amazonOneBasedIndex = 1; //according to docs, counters must start with 1 - for(String ebsBlockDeviceName : blockDeviceMapping.getEbsBlockDevices().keySet()) { - for(RunningInstance.EbsBlockDevice ebsBlockDevice : blockDeviceMapping.getEbsBlockDevices().get(ebsBlockDeviceName)) { + int amazonOneBasedIndex = 1; // according to docs, counters must start with 1 + for (String ebsBlockDeviceName : blockDeviceMapping.getEbsBlockDevices().keySet()) { + for (RunningInstance.EbsBlockDevice ebsBlockDevice : blockDeviceMapping + .getEbsBlockDevices().get(ebsBlockDeviceName)) { - //not null by contract - generatedRequest.addFormParam(format(volumeIdPattern, amazonOneBasedIndex), - ebsBlockDevice.getVolumeId()); + // not null by contract + addFormParamTo(request, format(volumeIdPattern, amazonOneBasedIndex), ebsBlockDevice + .getVolumeId()); - if(ebsBlockDeviceName != null) { - generatedRequest.addFormParam(format(deviceNamePattern, amazonOneBasedIndex), - ebsBlockDeviceName); - } - generatedRequest.addFormParam(format(deleteOnTerminationPattern, amazonOneBasedIndex), - String.valueOf(ebsBlockDevice.isDeleteOnTermination())); - - - amazonOneBasedIndex++; + if (ebsBlockDeviceName != null) { + addFormParamTo(request, format(deviceNamePattern, amazonOneBasedIndex), + ebsBlockDeviceName); } - } + addFormParamTo(request, format(deleteOnTerminationPattern, amazonOneBasedIndex), String + .valueOf(ebsBlockDevice.isDeleteOnTermination())); - } + amazonOneBasedIndex++; + } + } + + } } diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindGroupNameToIndexedFormParams.java b/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindGroupNameToIndexedFormParams.java index f95d343529..bdca20b3b9 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindGroupNameToIndexedFormParams.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindGroupNameToIndexedFormParams.java @@ -18,15 +18,12 @@ */ package org.jclouds.aws.ec2.binders; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.aws.ec2.util.EC2Utils.indexStringArrayToFormValuesWithPrefix; import javax.inject.Singleton; -import org.jclouds.aws.ec2.util.EC2Utils; import org.jclouds.http.HttpRequest; import org.jclouds.rest.Binder; -import org.jclouds.rest.internal.GeneratedHttpRequest; /** * Binds the String [] to query parameters named with GroupName.index @@ -36,11 +33,8 @@ import org.jclouds.rest.internal.GeneratedHttpRequest; @Singleton public class BindGroupNameToIndexedFormParams implements Binder { - @SuppressWarnings("unchecked") public void bindToRequest(HttpRequest request, Object input) { - checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest, - "this binder is only valid for GeneratedHttpRequests!"); - EC2Utils.indexStringArrayToFormValuesWithPrefix((GeneratedHttpRequest) request, "GroupName", input); + indexStringArrayToFormValuesWithPrefix(request, "GroupName", input); } } \ No newline at end of file diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindInstanceIdsToIndexedFormParams.java b/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindInstanceIdsToIndexedFormParams.java index 28db46735e..cbd3a86e0c 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindInstanceIdsToIndexedFormParams.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindInstanceIdsToIndexedFormParams.java @@ -18,15 +18,12 @@ */ package org.jclouds.aws.ec2.binders; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.aws.ec2.util.EC2Utils.indexStringArrayToFormValuesWithPrefix; import javax.inject.Singleton; -import org.jclouds.aws.ec2.util.EC2Utils; import org.jclouds.http.HttpRequest; import org.jclouds.rest.Binder; -import org.jclouds.rest.internal.GeneratedHttpRequest; /** * Binds the String [] to form parameters named with InstanceId.index @@ -36,11 +33,8 @@ import org.jclouds.rest.internal.GeneratedHttpRequest; @Singleton public class BindInstanceIdsToIndexedFormParams implements Binder { - @SuppressWarnings("unchecked") public void bindToRequest(HttpRequest request, Object input) { - checkArgument(checkNotNull(request, "input") instanceof GeneratedHttpRequest, - "this binder is only valid for GeneratedHttpRequests!"); - EC2Utils.indexStringArrayToFormValuesWithPrefix((GeneratedHttpRequest) request, "InstanceId", input); + indexStringArrayToFormValuesWithPrefix(request, "InstanceId", input); } } \ No newline at end of file diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindKeyNameToIndexedFormParams.java b/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindKeyNameToIndexedFormParams.java index 41d54628ff..c750200dec 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindKeyNameToIndexedFormParams.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindKeyNameToIndexedFormParams.java @@ -18,15 +18,12 @@ */ package org.jclouds.aws.ec2.binders; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.aws.ec2.util.EC2Utils.indexStringArrayToFormValuesWithPrefix; import javax.inject.Singleton; -import org.jclouds.aws.ec2.util.EC2Utils; import org.jclouds.http.HttpRequest; import org.jclouds.rest.Binder; -import org.jclouds.rest.internal.GeneratedHttpRequest; /** * Binds the String [] to query parameters named with KeyName.index @@ -36,11 +33,8 @@ import org.jclouds.rest.internal.GeneratedHttpRequest; @Singleton public class BindKeyNameToIndexedFormParams implements Binder { - @SuppressWarnings("unchecked") public void bindToRequest(HttpRequest request, Object input) { - checkArgument(checkNotNull(request, "input") instanceof GeneratedHttpRequest, - "this binder is only valid for GeneratedHttpRequests!"); - EC2Utils.indexStringArrayToFormValuesWithPrefix((GeneratedHttpRequest) request, "KeyName", input); + indexStringArrayToFormValuesWithPrefix(request, "KeyName", input); } } \ No newline at end of file diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindProductCodesToIndexedFormParams.java b/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindProductCodesToIndexedFormParams.java index c3ffbe698c..fe8a206757 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindProductCodesToIndexedFormParams.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindProductCodesToIndexedFormParams.java @@ -18,15 +18,12 @@ */ package org.jclouds.aws.ec2.binders; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.aws.ec2.util.EC2Utils.indexIterableToFormValuesWithPrefix; import javax.inject.Singleton; -import org.jclouds.aws.ec2.util.EC2Utils; import org.jclouds.http.HttpRequest; import org.jclouds.rest.Binder; -import org.jclouds.rest.internal.GeneratedHttpRequest; /** * Binds the String [] to form parameters named with ProductCode.index @@ -36,11 +33,8 @@ import org.jclouds.rest.internal.GeneratedHttpRequest; @Singleton public class BindProductCodesToIndexedFormParams implements Binder { - @SuppressWarnings("unchecked") public void bindToRequest(HttpRequest request, Object input) { - checkArgument(checkNotNull(request, "input") instanceof GeneratedHttpRequest, - "this binder is only valid for GeneratedHttpRequests!"); - EC2Utils.indexIterableToFormValuesWithPrefix((GeneratedHttpRequest) request, "ProductCode", input); + indexIterableToFormValuesWithPrefix(request, "ProductCode", input); } } \ No newline at end of file diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindPublicIpsToIndexedFormParams.java b/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindPublicIpsToIndexedFormParams.java index 3d69ede8ef..236ca9aff8 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindPublicIpsToIndexedFormParams.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindPublicIpsToIndexedFormParams.java @@ -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.checkNotNull; +import static org.jclouds.aws.ec2.util.EC2Utils.indexStringArrayToFormValuesWithPrefix; import javax.inject.Singleton; -import org.jclouds.aws.ec2.util.EC2Utils; import org.jclouds.http.HttpRequest; import org.jclouds.rest.Binder; -import org.jclouds.rest.internal.GeneratedHttpRequest; /** * Binds the String [] to form parameters named with InstanceId.index @@ -36,15 +35,10 @@ import org.jclouds.rest.internal.GeneratedHttpRequest; @Singleton public class BindPublicIpsToIndexedFormParams implements Binder { - @SuppressWarnings("unchecked") 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[], "this binder is only valid for String[] : " + input.getClass()); String[] addressStrings = (String[]) input; - EC2Utils.indexStringArrayToFormValuesWithPrefix((GeneratedHttpRequest) request, - "PublicIp", addressStrings); + indexStringArrayToFormValuesWithPrefix(request, "PublicIp", addressStrings); } - } \ No newline at end of file diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindUserGroupsToIndexedFormParams.java b/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindUserGroupsToIndexedFormParams.java index 9d691e3bfb..26ce8fbc0e 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindUserGroupsToIndexedFormParams.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindUserGroupsToIndexedFormParams.java @@ -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.checkNotNull; +import static org.jclouds.aws.ec2.util.EC2Utils.indexIterableToFormValuesWithPrefix; import javax.inject.Singleton; -import org.jclouds.aws.ec2.util.EC2Utils; import org.jclouds.http.HttpRequest; import org.jclouds.rest.Binder; -import org.jclouds.rest.internal.GeneratedHttpRequest; import com.google.common.collect.Iterables; @@ -38,15 +37,11 @@ import com.google.common.collect.Iterables; @Singleton public class BindUserGroupsToIndexedFormParams implements Binder { - @SuppressWarnings("unchecked") 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, "this binder is only valid for Iterable: " + input.getClass()); checkValidUserGroup(input); - EC2Utils.indexIterableToFormValuesWithPrefix((GeneratedHttpRequest) request, "UserGroup", - input); + indexIterableToFormValuesWithPrefix(request, "UserGroup", input); } private void checkValidUserGroup(Object input) { diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindUserIdGroupPairToSourceSecurityGroupFormParams.java b/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindUserIdGroupPairToSourceSecurityGroupFormParams.java index fcdcb020f1..5a52d9d1c4 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindUserIdGroupPairToSourceSecurityGroupFormParams.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindUserIdGroupPairToSourceSecurityGroupFormParams.java @@ -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.checkNotNull; +import static org.jclouds.http.HttpUtils.addFormParamTo; import javax.inject.Singleton; import org.jclouds.aws.ec2.domain.UserIdGroupPair; import org.jclouds.http.HttpRequest; import org.jclouds.rest.Binder; -import org.jclouds.rest.internal.GeneratedHttpRequest; /** * Binds the String [] to query parameters named with GroupName.index @@ -36,15 +36,11 @@ import org.jclouds.rest.internal.GeneratedHttpRequest; @Singleton public class BindUserIdGroupPairToSourceSecurityGroupFormParams implements Binder { - @SuppressWarnings("unchecked") 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, "this binder is only valid for UserIdGroupPair!"); UserIdGroupPair pair = (UserIdGroupPair) input; - GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request; - generatedRequest.addFormParam("SourceSecurityGroupOwnerId", pair.getUserId()); - generatedRequest.addFormParam("SourceSecurityGroupName", pair.getGroupName()); + addFormParamTo(request, "SourceSecurityGroupOwnerId", pair.getUserId()); + addFormParamTo(request, "SourceSecurityGroupName", pair.getGroupName()); } } \ No newline at end of file diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindUserIdsToIndexedFormParams.java b/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindUserIdsToIndexedFormParams.java index 4c814cce18..edbba3466b 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindUserIdsToIndexedFormParams.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindUserIdsToIndexedFormParams.java @@ -18,15 +18,12 @@ */ package org.jclouds.aws.ec2.binders; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.aws.ec2.util.EC2Utils.indexIterableToFormValuesWithPrefix; import javax.inject.Singleton; -import org.jclouds.aws.ec2.util.EC2Utils; import org.jclouds.http.HttpRequest; import org.jclouds.rest.Binder; -import org.jclouds.rest.internal.GeneratedHttpRequest; /** * Binds the String [] to form parameters named with UserId.index @@ -35,13 +32,8 @@ import org.jclouds.rest.internal.GeneratedHttpRequest; */ @Singleton public class BindUserIdsToIndexedFormParams implements Binder { - - @SuppressWarnings("unchecked") public void bindToRequest(HttpRequest request, Object input) { - checkArgument(checkNotNull(request, "input") instanceof GeneratedHttpRequest, - "this binder is only valid for GeneratedHttpRequests!"); - EC2Utils.indexIterableToFormValuesWithPrefix((GeneratedHttpRequest) request, "UserId", - input); + indexIterableToFormValuesWithPrefix(request, "UserId", input); } } \ No newline at end of file diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindVolumeIdsToIndexedFormParams.java b/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindVolumeIdsToIndexedFormParams.java index 1bbcf269bf..3b8fcf543a 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindVolumeIdsToIndexedFormParams.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/binders/BindVolumeIdsToIndexedFormParams.java @@ -18,15 +18,12 @@ */ package org.jclouds.aws.ec2.binders; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.aws.ec2.util.EC2Utils.indexStringArrayToFormValuesWithPrefix; import javax.inject.Singleton; -import org.jclouds.aws.ec2.util.EC2Utils; import org.jclouds.http.HttpRequest; import org.jclouds.rest.Binder; -import org.jclouds.rest.internal.GeneratedHttpRequest; /** * Binds the String [] to form parameters named with VolumeId.index @@ -36,12 +33,8 @@ import org.jclouds.rest.internal.GeneratedHttpRequest; @Singleton public class BindVolumeIdsToIndexedFormParams implements Binder { - @SuppressWarnings("unchecked") public void bindToRequest(HttpRequest request, Object input) { - checkArgument(checkNotNull(request, "input") instanceof GeneratedHttpRequest, - "this binder is only valid for GeneratedHttpRequests!"); - EC2Utils.indexStringArrayToFormValuesWithPrefix((GeneratedHttpRequest) request, - "VolumeId", input); + indexStringArrayToFormValuesWithPrefix(request, "VolumeId", input); } } \ No newline at end of file diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/binders/IfNotNullBindAvailabilityZoneToFormParam.java b/aws/core/src/main/java/org/jclouds/aws/ec2/binders/IfNotNullBindAvailabilityZoneToFormParam.java index f4e4ebd055..5609ecdc1b 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/binders/IfNotNullBindAvailabilityZoneToFormParam.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/binders/IfNotNullBindAvailabilityZoneToFormParam.java @@ -19,13 +19,12 @@ package org.jclouds.aws.ec2.binders; 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 org.jclouds.http.HttpRequest; import org.jclouds.rest.Binder; -import org.jclouds.rest.internal.GeneratedHttpRequest; /** * Binds the AvailabilityZone to a form parameter if set. @@ -34,16 +33,10 @@ import org.jclouds.rest.internal.GeneratedHttpRequest; */ @Singleton public class IfNotNullBindAvailabilityZoneToFormParam implements Binder { - - @SuppressWarnings("unchecked") public void bindToRequest(HttpRequest request, Object input) { if (input != null) { - checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest, - "this binder is only valid for GeneratedHttpRequests!"); - checkArgument(input instanceof String, - "this binder is only valid for AvailabilityZone!"); - ((GeneratedHttpRequest) request).addFormParam("Placement.AvailabilityZone", - (String) input); + checkArgument(input instanceof String, "this binder is only valid for AvailabilityZone!"); + addFormParamTo(request, "Placement.AvailabilityZone", (String) input); } } diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/util/EC2Utils.java b/aws/core/src/main/java/org/jclouds/aws/ec2/util/EC2Utils.java index 070f650f3d..b2811eb9f0 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/util/EC2Utils.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/util/EC2Utils.java @@ -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.checkNotNull; +import static org.jclouds.http.HttpUtils.addFormParamTo; import java.util.Map; 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.domain.Location; import org.jclouds.domain.LocationScope; +import org.jclouds.http.HttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest; import com.google.common.base.Function; @@ -53,13 +55,14 @@ public class EC2Utils { } } - public static void indexStringArrayToFormValuesWithPrefix(GeneratedHttpRequest request, - String prefix, Object input) { + public static void indexStringArrayToFormValuesWithPrefix(HttpRequest request, String prefix, + Object input) { checkArgument(checkNotNull(input, "input") instanceof String[], "this binder is only valid for String[] : " + input.getClass()); String[] values = (String[]) input; 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 + "]")); } } @@ -75,14 +78,14 @@ public class EC2Utils { return parts; } - public static void indexIterableToFormValuesWithPrefix(GeneratedHttpRequest request, - String prefix, Object input) { + public static void indexIterableToFormValuesWithPrefix(HttpRequest request, String prefix, + Object input) { checkArgument(checkNotNull(input, "input") instanceof Iterable, "this binder is only valid for Iterable: " + input.getClass()); Iterable values = (Iterable) input; int i = 0; for (Object o : values) { - request.addFormParam(prefix + "." + (i++ + 1), checkNotNull(o.toString(), prefix + addFormParamTo(request, prefix + "." + (i++ + 1), checkNotNull(o.toString(), prefix .toLowerCase() + "s[" + i + "]")); } @@ -116,13 +119,13 @@ public class EC2Utils { return null; } - public static void indexStringArrayToFormValuesWithStringFormat(GeneratedHttpRequest request, + public static void indexStringArrayToFormValuesWithStringFormat(HttpRequest request, String format, Object input) { checkArgument(checkNotNull(input, "input") instanceof String[], "this binder is only valid for String[] : " + input.getClass()); String[] values = (String[]) input; 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() + "s[" + i + "]")); } diff --git a/aws/core/src/main/java/org/jclouds/aws/elb/binders/BindELBInstanceIdsToIndexedFormParams.java b/aws/core/src/main/java/org/jclouds/aws/elb/binders/BindELBInstanceIdsToIndexedFormParams.java index 5700552cad..6593462f44 100644 --- a/aws/core/src/main/java/org/jclouds/aws/elb/binders/BindELBInstanceIdsToIndexedFormParams.java +++ b/aws/core/src/main/java/org/jclouds/aws/elb/binders/BindELBInstanceIdsToIndexedFormParams.java @@ -18,15 +18,12 @@ */ package org.jclouds.aws.elb.binders; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.aws.ec2.util.EC2Utils.indexStringArrayToFormValuesWithStringFormat; import javax.inject.Singleton; -import org.jclouds.aws.ec2.util.EC2Utils; import org.jclouds.http.HttpRequest; import org.jclouds.rest.Binder; -import org.jclouds.rest.internal.GeneratedHttpRequest; /** * Binds the String [] to form parameters named with InstanceId.index @@ -36,11 +33,8 @@ import org.jclouds.rest.internal.GeneratedHttpRequest; @Singleton public class BindELBInstanceIdsToIndexedFormParams implements Binder { - @SuppressWarnings("unchecked") public void bindToRequest(HttpRequest request, Object input) { - checkArgument(checkNotNull(request, "input") instanceof GeneratedHttpRequest, - "this binder is only valid for GeneratedHttpRequests!"); - EC2Utils.indexStringArrayToFormValuesWithStringFormat((GeneratedHttpRequest) request, "Instances.member.%s.InstanceId", input); + indexStringArrayToFormValuesWithStringFormat(request, "Instances.member.%s.InstanceId", input); } } \ No newline at end of file diff --git a/aws/core/src/main/java/org/jclouds/aws/filters/FormSigner.java b/aws/core/src/main/java/org/jclouds/aws/filters/FormSigner.java index 89d7ccb686..ab0bed8754 100755 --- a/aws/core/src/main/java/org/jclouds/aws/filters/FormSigner.java +++ b/aws/core/src/main/java/org/jclouds/aws/filters/FormSigner.java @@ -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.TIMESTAMP; 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.Comparator; @@ -46,12 +49,9 @@ import org.jclouds.encryption.EncryptionService; import org.jclouds.http.HttpException; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequestFilter; -import org.jclouds.http.HttpUtils; import org.jclouds.http.internal.SignatureWire; import org.jclouds.logging.Logger; import org.jclouds.rest.RequestSigner; -import org.jclouds.rest.internal.GeneratedHttpRequest; -import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.util.Utils; import com.google.common.annotations.VisibleForTesting; @@ -92,12 +92,11 @@ public class FormSigner implements HttpRequestFilter, RequestSigner { this.encryptionService = encryptionService; } - public void filter(HttpRequest in) throws HttpException { - GeneratedHttpRequest request = (GeneratedHttpRequest) in; + public void filter(HttpRequest request) throws HttpException { checkNotNull(request.getFirstHeaderOrNull(HttpHeaders.HOST), "request is not ready to sign; host not present"); - Multimap decodedParams = RestAnnotationProcessor.parseQueryToMap(request - .getPayload().getRawContent().toString()); + Multimap decodedParams = parseQueryToMap(request.getPayload().getRawContent() + .toString()); request.getHeaders().removeAll(HttpHeaders.CONTENT_LENGTH); addSigningParams(decodedParams); validateParams(decodedParams); @@ -105,7 +104,7 @@ public class FormSigner implements HttpRequestFilter, RequestSigner { String signature = sign(stringToSign); addSignature(decodedParams, signature); setPayload(request, decodedParams); - HttpUtils.logRequest(signatureLog, request, "<<"); + logRequest(signatureLog, request, "<<"); } String[] sortForSigning(String queryLine) { @@ -123,19 +122,16 @@ public class FormSigner implements HttpRequestFilter, RequestSigner { return parts; } - void setPayload(GeneratedHttpRequest request, Multimap decodedParams) { - request.setPayload(RestAnnotationProcessor.makeQueryLine(decodedParams, - new Comparator>() { - public int compare(Entry o1, Entry o2) { - if (o1.getKey().startsWith("Action") - || o2.getKey().startsWith("AWSAccessKeyId")) - return -1; - if (o1.getKey().startsWith("AWSAccessKeyId") - || o2.getKey().startsWith("Action")) - return 1; - return o1.getKey().compareTo(o2.getKey()); - } - })); + void setPayload(HttpRequest request, Multimap decodedParams) { + request.setPayload(makeQueryLine(decodedParams, new Comparator>() { + public int compare(Entry o1, Entry o2) { + if (o1.getKey().startsWith("Action") || o2.getKey().startsWith("AWSAccessKeyId")) + return -1; + if (o1.getKey().startsWith("AWSAccessKeyId") || o2.getKey().startsWith("Action")) + return 1; + return o1.getKey().compareTo(o2.getKey()); + } + })); } @VisibleForTesting @@ -166,7 +162,7 @@ public class FormSigner implements HttpRequestFilter, RequestSigner { @VisibleForTesting public String createStringToSign(HttpRequest request, Multimap decodedParams) { - HttpUtils.logRequest(signatureLog, request, ">>"); + logRequest(signatureLog, request, ">>"); StringBuilder stringToSign = new StringBuilder(); // StringToSign = HTTPVerb + "\n" + stringToSign.append(request.getMethod()).append("\n"); @@ -184,14 +180,13 @@ public class FormSigner implements HttpRequestFilter, RequestSigner { @VisibleForTesting String buildCanonicalizedString(Multimap decodedParams) { - return RestAnnotationProcessor.makeQueryLine(decodedParams, - new Comparator>() { - public int compare(Map.Entry o1, Map.Entry o2) { - if (o1.getKey().startsWith("AWSAccessKeyId")) - return -1; - return o1.getKey().compareTo(o2.getKey()); - } - }); + return makeQueryLine(decodedParams, new Comparator>() { + public int compare(Map.Entry o1, Map.Entry o2) { + if (o1.getKey().startsWith("AWSAccessKeyId")) + return -1; + return o1.getKey().compareTo(o2.getKey()); + } + }); } @VisibleForTesting @@ -204,8 +199,8 @@ public class FormSigner implements HttpRequestFilter, RequestSigner { } public String createStringToSign(HttpRequest input) { - return createStringToSign(input, RestAnnotationProcessor.parseQueryToMap(input.getPayload() - .getRawContent().toString())); + return createStringToSign(input, parseQueryToMap(input.getPayload().getRawContent() + .toString())); } } diff --git a/aws/core/src/main/java/org/jclouds/aws/handlers/AWSRedirectionRetryHandler.java b/aws/core/src/main/java/org/jclouds/aws/handlers/AWSRedirectionRetryHandler.java index 1134af5108..f9a1cb877b 100755 --- a/aws/core/src/main/java/org/jclouds/aws/handlers/AWSRedirectionRetryHandler.java +++ b/aws/core/src/main/java/org/jclouds/aws/handlers/AWSRedirectionRetryHandler.java @@ -18,8 +18,13 @@ */ 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.Provider; +import javax.inject.Singleton; import javax.ws.rs.HttpMethod; import javax.ws.rs.core.HttpHeaders; 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.HttpException; import org.jclouds.http.HttpResponse; -import org.jclouds.http.HttpUtils; import org.jclouds.http.handlers.BackoffLimitedRetryHandler; import org.jclouds.http.handlers.RedirectionRetryHandler; @@ -38,6 +42,7 @@ import org.jclouds.http.handlers.RedirectionRetryHandler; * * @author Adrian Cole */ +@Singleton public class AWSRedirectionRetryHandler extends RedirectionRetryHandler { private final AWSUtils utils; @@ -52,9 +57,9 @@ public class AWSRedirectionRetryHandler extends RedirectionRetryHandler { public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) { if (response.getFirstHeaderOrNull(HttpHeaders.LOCATION) == null && (response.getStatusCode() == 301 || response.getStatusCode() == 307)) { - byte[] content = HttpUtils.closeClientButKeepContentStream(response); + byte[] content = closeClientButKeepContentStream(response); if (command.getRequest().getMethod() == HttpMethod.HEAD) { - command.changeToGETRequest(); + changeToGETRequest(command.getRequest()); return true; } else { command.incrementRedirectCount(); @@ -68,8 +73,9 @@ public class AWSRedirectionRetryHandler extends RedirectionRetryHandler { // http://developer.amazonwebservices.com/connect/thread.jspa?messageID=72287𑩟 return backoffHandler.shouldRetryRequest(command, response); } else { - command.changeSchemeHostAndPortTo(command.getRequest().getEndpoint() - .getScheme(), host, command.getRequest().getEndpoint().getPort()); + changeSchemeHostAndPortTo(command.getRequest(), command.getRequest() + .getEndpoint().getScheme(), host, command.getRequest().getEndpoint() + .getPort(), uriBuilderProvider.get()); } return true; } else { diff --git a/aws/core/src/main/java/org/jclouds/aws/s3/filters/RequestAuthorizeSignature.java b/aws/core/src/main/java/org/jclouds/aws/s3/filters/RequestAuthorizeSignature.java index e7b9f29554..e4366b1bd2 100755 --- a/aws/core/src/main/java/org/jclouds/aws/s3/filters/RequestAuthorizeSignature.java +++ b/aws/core/src/main/java/org/jclouds/aws/s3/filters/RequestAuthorizeSignature.java @@ -19,6 +19,7 @@ package org.jclouds.aws.s3.filters; import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.http.HttpUtils.logRequest; import static org.jclouds.util.Patterns.NEWLINE_PATTERN; import java.util.Collection; @@ -40,7 +41,6 @@ import org.jclouds.encryption.EncryptionService; import org.jclouds.http.HttpException; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequestFilter; -import org.jclouds.http.HttpUtils; import org.jclouds.http.internal.SignatureWire; import org.jclouds.logging.Logger; import org.jclouds.rest.RequestSigner; @@ -99,11 +99,11 @@ public class RequestAuthorizeSignature implements HttpRequestFilter, RequestSign replaceDateHeader(request); String toSign = createStringToSign(request); calculateAndReplaceAuthHeader(request, toSign); - HttpUtils.logRequest(signatureLog, request, "<<"); + logRequest(signatureLog, request, "<<"); } public String createStringToSign(HttpRequest request) { - HttpUtils.logRequest(signatureLog, request, ">>"); + logRequest(signatureLog, request, ">>"); StringBuilder buffer = new StringBuilder(); // re-sign the request appendMethod(request, buffer); diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/EC2AsyncClientTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/EC2AsyncClientTest.java index d712dbb74e..f5cb4b3698 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/EC2AsyncClientTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/EC2AsyncClientTest.java @@ -4,7 +4,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; 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.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -61,7 +61,7 @@ public class EC2AsyncClientTest extends BaseEC2AsyncClientTest { } @Override - protected void checkFilters(GeneratedHttpRequest httpMethod) { + protected void checkFilters(HttpRequest request) { } diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/AMIAsyncClientTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/AMIAsyncClientTest.java index fc530b6c0d..bab574ef04 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/AMIAsyncClientTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/AMIAsyncClientTest.java @@ -33,9 +33,9 @@ import org.jclouds.aws.ec2.xml.DescribeImagesResponseHandler; import org.jclouds.aws.ec2.xml.ImageIdHandler; import org.jclouds.aws.ec2.xml.PermissionHandler; import org.jclouds.aws.ec2.xml.ProductCodesHandler; +import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.ParseSax; -import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; @@ -54,20 +54,19 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest { Method method = AMIAsyncClient.class.getMethod("createImageInRegion", String.class, String.class, String.class, Array.newInstance(CreateImageOptions.class, 0) .getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - "name", "instanceId"); + HttpRequest request = processor.createRequest(method, null, "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( - httpMethod, + request, "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"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, ImageIdHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testCreateImageOptions() throws SecurityException, NoSuchMethodException, @@ -75,87 +74,84 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest { Method method = AMIAsyncClient.class.getMethod("createImageInRegion", String.class, String.class, String.class, Array.newInstance(CreateImageOptions.class, 0) .getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - "name", "instanceId", new CreateImageOptions().withDescription("description") - .noReboot()); + HttpRequest request = processor.createRequest(method, null, "name", "instanceId", + new CreateImageOptions().withDescription("description").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( - httpMethod, + request, "Content-Length: 107\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); assertPayloadEquals( - httpMethod, + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testDescribeImages() throws SecurityException, NoSuchMethodException, IOException { Method method = AMIAsyncClient.class.getMethod("describeImagesInRegion", String.class, Array .newInstance(DescribeImagesOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - (String) null); + HttpRequest request = processor.createRequest(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, + request, "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"); - filter.filter(httpMethod); + assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeImages"); + filter.filter(request); 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"); - - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, DescribeImagesResponseHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testDescribeImagesOptions() throws SecurityException, NoSuchMethodException, IOException { Method method = AMIAsyncClient.class.getMethod("describeImagesInRegion", String.class, Array .newInstance(DescribeImagesOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - executableBy("me").ownedBy("fred", "nancy").imageIds("1", "2")); + HttpRequest request = processor.createRequest(method, null, executableBy("me").ownedBy( + "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( - httpMethod, + request, "Content-Length: 107\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); assertPayloadEquals( - httpMethod, + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testDeregisterImage() throws SecurityException, NoSuchMethodException, IOException { Method method = AMIAsyncClient.class.getMethod("deregisterImageInRegion", String.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - "imageId"); + HttpRequest request = processor.createRequest(method, null, "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( - httpMethod, + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testRegisterImageFromManifest() throws SecurityException, NoSuchMethodException, @@ -163,20 +159,19 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest { Method method = AMIAsyncClient.class.getMethod("registerImageFromManifestInRegion", String.class, String.class, String.class, Array.newInstance( RegisterImageOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - "name", "pathToManifest"); + HttpRequest request = processor.createRequest(method, null, "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( - httpMethod, + request, "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"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, ImageIdHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testRegisterImageFromManifestOptions() throws SecurityException, @@ -184,22 +179,22 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest { Method method = AMIAsyncClient.class.getMethod("registerImageFromManifestInRegion", String.class, String.class, String.class, Array.newInstance( RegisterImageOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - "name", "pathToManifest", new RegisterImageOptions().withDescription("description")); + HttpRequest request = processor.createRequest(method, null, "name", "pathToManifest", + 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( - httpMethod, + request, "Content-Length: 102\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); assertPayloadEquals( - httpMethod, + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testRegisterImageBackedByEBS() throws SecurityException, NoSuchMethodException, @@ -207,21 +202,20 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest { Method method = AMIAsyncClient.class.getMethod("registerUnixImageBackedByEbsInRegion", String.class, String.class, String.class, Array.newInstance( RegisterImageBackedByEbsOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - "imageName", "snapshotId"); + HttpRequest request = processor.createRequest(method, null, "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( - httpMethod, + request, "Content-Length: 176\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); assertPayloadEquals( - httpMethod, + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testRegisterImageBackedByEBSOptions() throws SecurityException, @@ -229,198 +223,194 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest { Method method = AMIAsyncClient.class.getMethod("registerUnixImageBackedByEbsInRegion", String.class, String.class, String.class, Array.newInstance( RegisterImageBackedByEbsOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - "imageName", "snapshotId", new RegisterImageBackedByEbsOptions().withDescription( - "description").addBlockDeviceFromSnapshot("/dev/device", null, "snapshot") + HttpRequest request = processor.createRequest(method, null, "imageName", "snapshotId", + new RegisterImageBackedByEbsOptions().withDescription("description") + .addBlockDeviceFromSnapshot("/dev/device", null, "snapshot") .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( - httpMethod, + request, "Content-Length: 528\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); 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"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, ImageIdHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testGetProductCodesForImage() throws SecurityException, NoSuchMethodException, IOException { Method method = AMIAsyncClient.class.getMethod("getProductCodesForImageInRegion", String.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - "imageId"); + HttpRequest request = processor.createRequest(method, null, "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( - httpMethod, + request, "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"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, ProductCodesHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testGetBlockDeviceMappingsForImage() throws SecurityException, NoSuchMethodException, IOException { Method method = AMIAsyncClient.class.getMethod("getBlockDeviceMappingsForImageInRegion", String.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - "imageId"); + HttpRequest request = processor.createRequest(method, null, "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( - httpMethod, + request, "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"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, BlockDeviceMappingHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testGetLaunchPermissionForImage() throws SecurityException, NoSuchMethodException, IOException { Method method = AMIAsyncClient.class.getMethod("getLaunchPermissionForImageInRegion", String.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - "imageId"); + HttpRequest request = processor.createRequest(method, null, "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( - httpMethod, + request, "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"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, PermissionHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testAddLaunchPermissionsToImage() throws SecurityException, NoSuchMethodException, IOException { Method method = AMIAsyncClient.class.getMethod("addLaunchPermissionsToImageInRegion", String.class, Iterable.class, Iterable.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - ImmutableList.of("bob", "sue"), ImmutableList.of("all"), "imageId"); + HttpRequest request = processor.createRequest(method, null, ImmutableList.of("bob", "sue"), + 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( - httpMethod, + request, "Content-Length: 107\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); assertPayloadEquals( - httpMethod, + request, "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( - 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"); - assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); + assertResponseParserClassEquals(method, request, CloseContentAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testRemoveLaunchPermissionsFromImage() throws SecurityException, NoSuchMethodException, IOException { Method method = AMIAsyncClient.class.getMethod("removeLaunchPermissionsFromImageInRegion", String.class, Iterable.class, Iterable.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - ImmutableList.of("bob", "sue"), ImmutableList.of("all"), "imageId"); + HttpRequest request = processor.createRequest(method, null, ImmutableList.of("bob", "sue"), + 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( - httpMethod, + request, "Content-Length: 110\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); assertPayloadEquals( - httpMethod, + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testResetLaunchPermissionsOnImage() throws SecurityException, NoSuchMethodException, IOException { Method method = AMIAsyncClient.class.getMethod("resetLaunchPermissionsOnImageInRegion", String.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - "imageId"); + HttpRequest request = processor.createRequest(method, null, "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( - httpMethod, + request, "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"); - assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); + assertResponseParserClassEquals(method, request, CloseContentAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testAddProductCodesToImage() throws SecurityException, NoSuchMethodException, IOException { Method method = AMIAsyncClient.class.getMethod("addProductCodesToImageInRegion", String.class, Iterable.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - ImmutableList.of("code1", "code2"), "imageId"); + HttpRequest request = processor.createRequest(method, null, ImmutableList + .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( - httpMethod, + request, "Content-Length: 103\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); assertPayloadEquals( - httpMethod, + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testRemoveProductCodesFromImage() throws SecurityException, NoSuchMethodException, IOException { Method method = AMIAsyncClient.class.getMethod("removeProductCodesFromImageInRegion", String.class, Iterable.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - ImmutableList.of("code1", "code2"), "imageId"); + HttpRequest request = processor.createRequest(method, null, ImmutableList + .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( - httpMethod, + request, "Content-Length: 106\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); assertPayloadEquals( - httpMethod, + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } @Override diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/AvailabilityZoneAndRegionAsyncClientTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/AvailabilityZoneAndRegionAsyncClientTest.java index 6629705412..73a8df05bc 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/AvailabilityZoneAndRegionAsyncClientTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/AvailabilityZoneAndRegionAsyncClientTest.java @@ -31,8 +31,8 @@ import org.jclouds.aws.ec2.options.DescribeAvailabilityZonesOptions; import org.jclouds.aws.ec2.options.DescribeRegionsOptions; import org.jclouds.aws.ec2.xml.DescribeAvailabilityZonesResponseHandler; import org.jclouds.aws.ec2.xml.DescribeRegionsResponseHandler; +import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.ParseSax; -import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; @@ -52,20 +52,19 @@ public class AvailabilityZoneAndRegionAsyncClientTest extends Method method = AvailabilityZoneAndRegionAsyncClient.class.getMethod( "describeAvailabilityZonesInRegion", String.class, Array.newInstance( DescribeAvailabilityZonesOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor - .createRequest(method, Region.US_WEST_1); + HttpRequest request = processor.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( - httpMethod, + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testDescribeAvailabilityZonesOptions() throws SecurityException, @@ -73,62 +72,60 @@ public class AvailabilityZoneAndRegionAsyncClientTest extends Method method = AvailabilityZoneAndRegionAsyncClient.class.getMethod( "describeAvailabilityZonesInRegion", String.class, Array.newInstance( DescribeAvailabilityZonesOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor - .createRequest(method, Region.US_EAST_1, availabilityZones( - AvailabilityZone.US_EAST_1A, AvailabilityZone.US_EAST_1B)); + HttpRequest request = processor.createRequest(method, Region.US_EAST_1, availabilityZones( + 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( - httpMethod, + request, "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"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, DescribeAvailabilityZonesResponseHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testDescribeRegions() throws SecurityException, NoSuchMethodException, IOException { Method method = AvailabilityZoneAndRegionAsyncClient.class.getMethod("describeRegions", Array .newInstance(DescribeRegionsOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor - .createRequest(method); + HttpRequest request = processor.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( - httpMethod, + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testDescribeRegionsOptions() throws SecurityException, NoSuchMethodException, IOException { Method method = AvailabilityZoneAndRegionAsyncClient.class.getMethod("describeRegions", Array .newInstance(DescribeRegionsOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor - .createRequest(method, regions(Region.US_EAST_1, Region.US_WEST_1)); + HttpRequest request = processor.createRequest(method, regions(Region.US_EAST_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( - httpMethod, + request, "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"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, DescribeRegionsResponseHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } @Override diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/BaseEC2AsyncClientTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/BaseEC2AsyncClientTest.java index 4cc4226c22..94071dec03 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/BaseEC2AsyncClientTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/BaseEC2AsyncClientTest.java @@ -34,12 +34,12 @@ import org.jclouds.aws.ec2.config.EC2RestClientModule; import org.jclouds.aws.ec2.domain.AvailabilityZone; import org.jclouds.aws.filters.FormSigner; import org.jclouds.date.DateService; +import org.jclouds.http.HttpRequest; import org.jclouds.http.RequiresHttp; import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory.ContextSpec; -import org.jclouds.rest.internal.GeneratedHttpRequest; import org.testng.annotations.BeforeTest; import com.google.common.collect.ImmutableMap; @@ -80,9 +80,9 @@ public abstract class BaseEC2AsyncClientTest extends RestClientTest { protected FormSigner filter; @Override - protected void checkFilters(GeneratedHttpRequest httpMethod) { - assertEquals(httpMethod.getFilters().size(), 1); - assertEquals(httpMethod.getFilters().get(0).getClass(), FormSigner.class); + protected void checkFilters(HttpRequest request) { + assertEquals(request.getFilters().size(), 1); + assertEquals(request.getFilters().get(0).getClass(), FormSigner.class); } public BaseEC2AsyncClientTest() { diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticBlockStoreAsyncClientTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticBlockStoreAsyncClientTest.java index 3c282c4465..1f7caf2707 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticBlockStoreAsyncClientTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticBlockStoreAsyncClientTest.java @@ -36,9 +36,9 @@ import org.jclouds.aws.ec2.xml.DescribeSnapshotsResponseHandler; import org.jclouds.aws.ec2.xml.DescribeVolumesResponseHandler; import org.jclouds.aws.ec2.xml.PermissionHandler; import org.jclouds.aws.ec2.xml.SnapshotHandler; +import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.ParseSax; -import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; @@ -57,158 +57,156 @@ public class ElasticBlockStoreAsyncClientTest extends public void testCreateVolume() throws SecurityException, NoSuchMethodException, IOException { Method method = ElasticBlockStoreAsyncClient.class.getMethod( "createVolumeInAvailabilityZone", String.class, int.class); - GeneratedHttpRequest httpMethod = processor.createRequest( - method, AvailabilityZone.US_EAST_1A, 20); + HttpRequest request = processor.createRequest(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( - httpMethod, + request, "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"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, CreateVolumeResponseHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testCreateVolumeFromSnapShot() throws SecurityException, NoSuchMethodException, IOException { Method method = ElasticBlockStoreAsyncClient.class.getMethod( "createVolumeFromSnapshotInAvailabilityZone", String.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest( - method, AvailabilityZone.US_EAST_1A, "snapshotId"); + HttpRequest request = processor.createRequest(method, AvailabilityZone.US_EAST_1A, + "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, + request, "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"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, CreateVolumeResponseHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testCreateVolumeFromSnapShotWithSize() throws SecurityException, NoSuchMethodException, IOException { Method method = ElasticBlockStoreAsyncClient.class.getMethod( "createVolumeFromSnapshotInAvailabilityZone", String.class, int.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest( - method, AvailabilityZone.US_EAST_1A, 15, "snapshotId"); + HttpRequest request = processor.createRequest(method, AvailabilityZone.US_EAST_1A, 15, + "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, + request, "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"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, CreateVolumeResponseHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testDeleteVolume() throws SecurityException, NoSuchMethodException, IOException { Method method = ElasticBlockStoreAsyncClient.class.getMethod("deleteVolumeInRegion", String.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest( - method, null, "id"); + HttpRequest request = processor.createRequest(method, null, "id"); - assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); - assertHeadersEqual(httpMethod, + assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); + assertHeadersEqual( + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testDescribeVolumes() throws SecurityException, NoSuchMethodException, IOException { Method method = ElasticBlockStoreAsyncClient.class.getMethod("describeVolumesInRegion", String.class, Array.newInstance(String.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest( - method, (String) null); + HttpRequest request = processor.createRequest(method, (String) null); - assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); - assertHeadersEqual(httpMethod, + assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); + assertHeadersEqual( + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testDescribeVolumesArgs() throws SecurityException, NoSuchMethodException, IOException { Method method = ElasticBlockStoreAsyncClient.class.getMethod("describeVolumesInRegion", String.class, Array.newInstance(String.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest( - method, null, "1", "2"); + HttpRequest request = processor.createRequest(method, null, "1", "2"); - assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); - assertHeadersEqual(httpMethod, + assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); + assertHeadersEqual( + request, "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"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, DescribeVolumesResponseHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testAttachVolume() throws SecurityException, NoSuchMethodException, IOException { Method method = ElasticBlockStoreAsyncClient.class.getMethod("attachVolumeInRegion", String.class, String.class, String.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest( - method, null, "id", "instanceId", "/device"); + HttpRequest request = processor.createRequest(method, null, "id", "instanceId", "/device"); - assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); - assertHeadersEqual(httpMethod, + assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); + assertHeadersEqual( + request, "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"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, AttachmentHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testDetachVolume() throws SecurityException, NoSuchMethodException, IOException { Method method = ElasticBlockStoreAsyncClient.class.getMethod("detachVolumeInRegion", String.class, String.class, boolean.class, Array.newInstance( DetachVolumeOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest( - method, null, "id", false); + HttpRequest request = processor.createRequest(method, null, "id", false); - assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); - assertHeadersEqual(httpMethod, + assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); + assertHeadersEqual( + request, "Content-Length: 62\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); - assertPayloadEquals(httpMethod, - "Version=2009-11-30&Action=DetachVolume&Force=false&VolumeId=id"); + assertPayloadEquals(request, "Version=2009-11-30&Action=DetachVolume&Force=false&VolumeId=id"); - assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); + assertResponseParserClassEquals(method, request, CloseContentAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, ReturnVoidOnVolumeAvailable.class); - checkFilters(httpMethod); + checkFilters(request); } public void testDetachVolumeOptions() throws SecurityException, NoSuchMethodException, @@ -216,40 +214,41 @@ public class ElasticBlockStoreAsyncClientTest extends Method method = ElasticBlockStoreAsyncClient.class.getMethod("detachVolumeInRegion", String.class, String.class, boolean.class, Array.newInstance( DetachVolumeOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest( - method, null, "id", true, fromInstance("instanceId").fromDevice("/device")); + HttpRequest request = processor.createRequest(method, null, "id", true, fromInstance( + "instanceId").fromDevice("/device")); - assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); - assertHeadersEqual(httpMethod, + assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); + assertHeadersEqual( + request, "Content-Length: 100\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); assertPayloadEquals( - httpMethod, + request, "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); assertExceptionParserClassEquals(method, ReturnVoidOnVolumeAvailable.class); - checkFilters(httpMethod); + checkFilters(request); } public void testCreateSnapshot() throws SecurityException, NoSuchMethodException, IOException { Method method = ElasticBlockStoreAsyncClient.class.getMethod("createSnapshotInRegion", String.class, String.class, Array.newInstance(CreateSnapshotOptions.class, 0) .getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest( - method, null, "volumeId"); + HttpRequest request = processor.createRequest(method, null, "volumeId"); - assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); - assertHeadersEqual(httpMethod, + assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); + assertHeadersEqual( + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testCreateSnapshotOptions() throws SecurityException, NoSuchMethodException, @@ -257,81 +256,82 @@ public class ElasticBlockStoreAsyncClientTest extends Method method = ElasticBlockStoreAsyncClient.class.getMethod("createSnapshotInRegion", String.class, String.class, Array.newInstance(CreateSnapshotOptions.class, 0) .getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest( - method, null, "volumeId", CreateSnapshotOptions.Builder - .withDescription("description")); + HttpRequest request = processor.createRequest(method, null, "volumeId", + CreateSnapshotOptions.Builder.withDescription("description")); - assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); - assertHeadersEqual(httpMethod, + assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); + assertHeadersEqual( + request, "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"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, SnapshotHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testDescribeSnapshots() throws SecurityException, NoSuchMethodException, IOException { Method method = ElasticBlockStoreAsyncClient.class.getMethod("describeSnapshotsInRegion", String.class, Array.newInstance(DescribeSnapshotsOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest( - method, (String) null); + HttpRequest request = processor.createRequest(method, (String) null); - assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); - assertHeadersEqual(httpMethod, + assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); + assertHeadersEqual( + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testDescribeSnapshotsArgs() throws SecurityException, NoSuchMethodException, IOException { Method method = ElasticBlockStoreAsyncClient.class.getMethod("describeSnapshotsInRegion", String.class, Array.newInstance(DescribeSnapshotsOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest( - method, null, ownedBy("o1", "o2").restorableBy("r1", "r2").snapshotIds("s1", "s2")); + HttpRequest request = processor.createRequest(method, null, ownedBy("o1", "o2").restorableBy( + "r1", "r2").snapshotIds("s1", "s2")); - assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); - assertHeadersEqual(httpMethod, + assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); + assertHeadersEqual( + request, "Content-Length: 133\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); 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"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, DescribeSnapshotsResponseHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testGetCreateVolumePermissionForSnapshot() throws SecurityException, NoSuchMethodException, IOException { Method method = ElasticBlockStoreAsyncClient.class.getMethod( "getCreateVolumePermissionForSnapshotInRegion", String.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest( - method, null, "snapshotId"); + HttpRequest request = processor.createRequest(method, null, "snapshotId"); - assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); - assertHeadersEqual(httpMethod, + assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); + assertHeadersEqual( + request, "Content-Length: 106\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); assertPayloadEquals( - httpMethod, + request, "Version=2009-11-30&Action=DescribeSnapshotAttribute&Attribute=createVolumePermission&SnapshotId=snapshotId"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, PermissionHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testAddCreateVolumePermissionsToSnapshot() throws SecurityException, @@ -339,21 +339,22 @@ public class ElasticBlockStoreAsyncClientTest extends Method method = ElasticBlockStoreAsyncClient.class.getMethod( "addCreateVolumePermissionsToSnapshotInRegion", String.class, Iterable.class, Iterable.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest( - method, null, ImmutableList.of("bob", "sue"), ImmutableList.of("all"), "snapshotId"); + HttpRequest request = processor.createRequest(method, null, ImmutableList.of("bob", "sue"), + ImmutableList.of("all"), "snapshotId"); - assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); - assertHeadersEqual(httpMethod, + assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); + assertHeadersEqual( + request, "Content-Length: 122\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); assertPayloadEquals( - httpMethod, + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testRemoveCreateVolumePermissionsFromSnapshot() throws SecurityException, @@ -361,40 +362,41 @@ public class ElasticBlockStoreAsyncClientTest extends Method method = ElasticBlockStoreAsyncClient.class.getMethod( "removeCreateVolumePermissionsFromSnapshotInRegion", String.class, Iterable.class, Iterable.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest( - method, null, ImmutableList.of("bob", "sue"), ImmutableList.of("all"), "snapshotId"); + HttpRequest request = processor.createRequest(method, null, ImmutableList.of("bob", "sue"), + ImmutableList.of("all"), "snapshotId"); - assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); - assertHeadersEqual(httpMethod, + assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); + assertHeadersEqual( + request, "Content-Length: 125\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); assertPayloadEquals( - httpMethod, + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testResetCreateVolumePermissionsOnSnapshot() throws SecurityException, NoSuchMethodException, IOException { Method method = ElasticBlockStoreAsyncClient.class.getMethod( "resetCreateVolumePermissionsOnSnapshotInRegion", String.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest( - method, null, "snapshotId"); + HttpRequest request = processor.createRequest(method, null, "snapshotId"); - assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); - assertHeadersEqual(httpMethod, + assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); + assertHeadersEqual( + request, "Content-Length: 103\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); assertPayloadEquals( - httpMethod, + request, "Version=2009-11-30&Action=ResetSnapshotAttribute&Attribute=createVolumePermission&SnapshotId=snapshotId"); - assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); + assertResponseParserClassEquals(method, request, CloseContentAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } @Override diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticIPAddressAsyncClientTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticIPAddressAsyncClientTest.java index e0b43e9380..9c4611f661 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticIPAddressAsyncClientTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticIPAddressAsyncClientTest.java @@ -24,9 +24,9 @@ import java.lang.reflect.Method; import org.jclouds.aws.ec2.xml.AllocateAddressResponseHandler; import org.jclouds.aws.ec2.xml.DescribeAddressesResponseHandler; +import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.ParseSax; -import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; @@ -45,99 +45,94 @@ public class ElasticIPAddressAsyncClientTest extends IOException { Method method = ElasticIPAddressAsyncClient.class.getMethod("disassociateAddressInRegion", String.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest( - method, null, "127.0.0.1"); + HttpRequest request = processor.createRequest(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( - httpMethod, + request, "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"); - assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); + assertResponseParserClassEquals(method, request, CloseContentAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testAssociateAddress() throws SecurityException, NoSuchMethodException, IOException { Method method = ElasticIPAddressAsyncClient.class.getMethod("associateAddressInRegion", String.class, String.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest( - method, null, "127.0.0.1", "me"); + HttpRequest request = processor.createRequest(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( - httpMethod, + request, "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"); - assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); + assertResponseParserClassEquals(method, request, CloseContentAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testReleaseAddress() throws SecurityException, NoSuchMethodException, IOException { Method method = ElasticIPAddressAsyncClient.class.getMethod("releaseAddressInRegion", String.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest( - method, null, "127.0.0.1"); + HttpRequest request = processor.createRequest(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( - httpMethod, + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testDescribeAddresses() throws SecurityException, NoSuchMethodException, IOException { Method method = ElasticIPAddressAsyncClient.class.getMethod("describeAddressesInRegion", String.class, Array.newInstance(String.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest( - method, null, "127.0.0.1"); + HttpRequest request = processor.createRequest(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( - httpMethod, + request, "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"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, DescribeAddressesResponseHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testAllocateAddress() throws SecurityException, NoSuchMethodException, IOException { Method method = ElasticIPAddressAsyncClient.class.getMethod("allocateAddressInRegion", String.class); - GeneratedHttpRequest httpMethod = processor.createRequest( - method, (String) null); + HttpRequest request = processor.createRequest(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, + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } @Override diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/InstanceAsyncClientTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/InstanceAsyncClientTest.java index 0df8add45b..a131b92ca3 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/InstanceAsyncClientTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/InstanceAsyncClientTest.java @@ -38,9 +38,9 @@ import org.jclouds.aws.ec2.xml.InstanceTypeHandler; import org.jclouds.aws.ec2.xml.RunInstancesResponseHandler; import org.jclouds.aws.ec2.xml.StringValueHandler; import org.jclouds.aws.ec2.xml.UnencodeStringValueHandler; +import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.ParseSax; -import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; @@ -56,83 +56,79 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest httpMethod = processor.createRequest(method, - (String) null); + HttpRequest request = processor.createRequest(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, + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testDescribeInstancesArgs() throws SecurityException, NoSuchMethodException, IOException { Method method = InstanceAsyncClient.class.getMethod("describeInstancesInRegion", String.class, Array.newInstance(String.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - "1", "2"); + HttpRequest request = processor.createRequest(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, + request, "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"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, DescribeInstancesResponseHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testTerminateInstances() throws SecurityException, NoSuchMethodException, IOException { Method method = InstanceAsyncClient.class.getMethod("terminateInstancesInRegion", String.class, Array.newInstance(String.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - "1", "2"); + HttpRequest request = processor.createRequest(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, + request, "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"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, InstanceStateChangeHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testRunInstances() throws SecurityException, NoSuchMethodException, IOException { Method method = InstanceAsyncClient.class.getMethod("runInstancesInRegion", String.class, String.class, String.class, int.class, int.class, Array.newInstance( RunInstancesOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - null, "ami-voo", 1, 1); + HttpRequest request = processor.createRequest(method, null, 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( - httpMethod, + request, "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"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, RunInstancesResponseHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testRunInstancesOptions() throws SecurityException, NoSuchMethodException, @@ -140,210 +136,201 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest httpMethod = processor.createRequest(method, - Region.EU_WEST_1, AvailabilityZone.EU_WEST_1A, "ami-voo", 1, 5, - new RunInstancesOptions().withKernelId("kernelId").enableMonitoring() - .withSecurityGroups("group1", "group2")); + HttpRequest request = processor.createRequest(method, Region.EU_WEST_1, + AvailabilityZone.EU_WEST_1A, "ami-voo", 1, 5, new RunInstancesOptions() + .withKernelId("kernelId").enableMonitoring().withSecurityGroups("group1", + "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( - httpMethod, + request, "Content-Length: 164\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.eu-west-1.amazonaws.com\n"); 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"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, RunInstancesResponseHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testStopInstances() throws SecurityException, NoSuchMethodException, IOException { Method method = InstanceAsyncClient.class.getMethod("stopInstancesInRegion", String.class, boolean.class, Array.newInstance(String.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - true, "1", "2"); + HttpRequest request = processor.createRequest(method, null, 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( - httpMethod, + request, "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"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, InstanceStateChangeHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testRebootInstances() throws SecurityException, NoSuchMethodException, IOException { Method method = InstanceAsyncClient.class.getMethod("rebootInstancesInRegion", String.class, Array.newInstance(String.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - "1", "2"); + HttpRequest request = processor.createRequest(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, + request, "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"); - assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); + assertResponseParserClassEquals(method, request, CloseContentAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testStartInstances() throws SecurityException, NoSuchMethodException, IOException { Method method = InstanceAsyncClient.class.getMethod("startInstancesInRegion", String.class, Array.newInstance(String.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - "1", "2"); + HttpRequest request = processor.createRequest(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, + request, "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"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, InstanceStateChangeHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testGetUserDataForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException { Method method = InstanceAsyncClient.class.getMethod("getUserDataForInstanceInRegion", String.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - "1"); + HttpRequest request = processor.createRequest(method, null, "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( - httpMethod, + request, "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"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, UnencodeStringValueHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testGetRootDeviceNameForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException { Method method = InstanceAsyncClient.class.getMethod("getRootDeviceNameForInstanceInRegion", String.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - "1"); + HttpRequest request = processor.createRequest(method, null, "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( - httpMethod, + request, "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"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, StringValueHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testGetRamdiskForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException { Method method = InstanceAsyncClient.class.getMethod("getRamdiskForInstanceInRegion", String.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - "1"); + HttpRequest request = processor.createRequest(method, null, "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( - httpMethod, + request, "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"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, StringValueHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testGetDisableApiTerminationForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException { Method method = InstanceAsyncClient.class.getMethod( "isApiTerminationDisabledForInstanceInRegion", String.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - "1"); + HttpRequest request = processor.createRequest(method, null, "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( - httpMethod, + request, "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"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, BooleanValueHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testGetKernelForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException { Method method = InstanceAsyncClient.class.getMethod("getKernelForInstanceInRegion", String.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - "1"); + HttpRequest request = processor.createRequest(method, null, "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( - httpMethod, + request, "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"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, StringValueHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testGetInstanceTypeForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException { Method method = InstanceAsyncClient.class.getMethod("getInstanceTypeForInstanceInRegion", String.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - "1"); + HttpRequest request = processor.createRequest(method, null, "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( - httpMethod, + request, "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"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, InstanceTypeHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testGetInstanceInitiatedShutdownBehaviorForInstanceInRegion() @@ -351,109 +338,104 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest httpMethod = processor.createRequest(method, null, - "1"); + HttpRequest request = processor.createRequest(method, null, "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( - httpMethod, + request, "Content-Length: 108\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); assertPayloadEquals( - httpMethod, + request, "Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=instanceInitiatedShutdownBehavior&InstanceId=1"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, InstanceInitiatedShutdownBehaviorHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testGetBlockDeviceMappingForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException { Method method = InstanceAsyncClient.class.getMethod( "getBlockDeviceMappingForInstanceInRegion", String.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - "1"); + HttpRequest request = processor.createRequest(method, null, "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( - httpMethod, + request, "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"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, BlockDeviceMappingHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testSetUserDataForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException { Method method = InstanceAsyncClient.class.getMethod("setUserDataForInstanceInRegion", String.class, String.class, Array.newInstance(byte.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - "1", "test".getBytes()); + HttpRequest request = processor.createRequest(method, null, "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( - httpMethod, + request, "Content-Length: 100\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); assertPayloadEquals( - httpMethod, + request, "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( - 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"); - assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); + assertResponseParserClassEquals(method, request, CloseContentAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testSetRamdiskForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException { Method method = InstanceAsyncClient.class.getMethod("setRamdiskForInstanceInRegion", String.class, String.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - "1", "test"); + HttpRequest request = processor.createRequest(method, null, "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( - httpMethod, + request, "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"); - assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); + assertResponseParserClassEquals(method, request, CloseContentAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testSetKernelForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException { Method method = InstanceAsyncClient.class.getMethod("setKernelForInstanceInRegion", String.class, String.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - "1", "test"); + HttpRequest request = processor.createRequest(method, null, "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( - httpMethod, + request, "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"); - assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); + assertResponseParserClassEquals(method, request, CloseContentAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testSetApiTerminationDisabledForInstanceInRegion() throws SecurityException, @@ -461,44 +443,42 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest httpMethod = processor.createRequest(method, null, - "1", true); + HttpRequest request = processor.createRequest(method, null, "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( - httpMethod, + request, "Content-Length: 105\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); assertPayloadEquals( - httpMethod, + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testSetInstanceTypeForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException { Method method = InstanceAsyncClient.class.getMethod("setInstanceTypeForInstanceInRegion", String.class, String.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - "1", InstanceType.C1_MEDIUM); + HttpRequest request = processor.createRequest(method, null, "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( - httpMethod, + request, "Content-Length: 101\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); assertPayloadEquals( - httpMethod, + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testSetInstanceInitiatedShutdownBehaviorForInstanceInRegion() @@ -506,22 +486,22 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest httpMethod = processor.createRequest(method, null, - "1", InstanceInitiatedShutdownBehavior.TERMINATE); + HttpRequest request = processor.createRequest(method, null, "1", + 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( - httpMethod, + request, "Content-Length: 122\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); assertPayloadEquals( - httpMethod, + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testSetBlockDeviceMappingForInstanceInRegion() throws SecurityException, @@ -533,25 +513,24 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest httpMethod = processor.createRequest(method, null, - "1", blockDeviceMapping); + HttpRequest request = processor.createRequest(method, null, "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( - httpMethod, + request, "Content-Length: 62\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); 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"); - filter.filter(httpMethod);// ensure encoding worked properly + filter.filter(request);// ensure encoding worked properly 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"); - assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); + assertResponseParserClassEquals(method, request, CloseContentAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } @Override diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/KeyPairAsyncClientTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/KeyPairAsyncClientTest.java index c6aa6039a7..110a55aa72 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/KeyPairAsyncClientTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/KeyPairAsyncClientTest.java @@ -23,9 +23,9 @@ import java.lang.reflect.Array; import java.lang.reflect.Method; import org.jclouds.aws.ec2.xml.DescribeKeyPairsResponseHandler; +import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.ParseSax; -import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; @@ -42,60 +42,57 @@ public class KeyPairAsyncClientTest extends BaseEC2AsyncClientTest httpMethod = processor.createRequest(method, null, - "mykey"); + HttpRequest request = processor.createRequest(method, null, "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( - httpMethod, + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testDescribeKeyPairs() throws SecurityException, NoSuchMethodException, IOException { Method method = KeyPairAsyncClient.class.getMethod("describeKeyPairsInRegion", String.class, Array.newInstance(String.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - (String) null); + HttpRequest request = processor.createRequest(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, + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testDescribeKeyPairsArgs() throws SecurityException, NoSuchMethodException, IOException { Method method = KeyPairAsyncClient.class.getMethod("describeKeyPairsInRegion", String.class, Array.newInstance(String.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - "1", "2"); + HttpRequest request = processor.createRequest(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, + request, "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"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, DescribeKeyPairsResponseHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } @Override diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/MonitoringAsyncClientTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/MonitoringAsyncClientTest.java index 7fa460a706..b3e25fd414 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/MonitoringAsyncClientTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/MonitoringAsyncClientTest.java @@ -23,8 +23,8 @@ import java.lang.reflect.Array; import java.lang.reflect.Method; import org.jclouds.aws.ec2.xml.MonitoringStateHandler; +import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.ParseSax; -import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; @@ -42,41 +42,39 @@ public class MonitoringAsyncClientTest extends BaseEC2AsyncClientTest httpMethod = processor.createRequest(method, - null, "instance1", "instance2"); + HttpRequest request = processor.createRequest(method, 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( - httpMethod, + request, "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"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, MonitoringStateHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testMonitorInstances() throws SecurityException, NoSuchMethodException, IOException { Method method = MonitoringAsyncClient.class.getMethod("monitorInstancesInRegion", String.class, String.class, Array.newInstance(String.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - null, "instance1", "instance2"); + HttpRequest request = processor.createRequest(method, 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( - httpMethod, + request, "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"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, MonitoringStateHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } @Override diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/SecurityGroupAsyncClientTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/SecurityGroupAsyncClientTest.java index 87d775dd90..8c43527e0e 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/SecurityGroupAsyncClientTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/SecurityGroupAsyncClientTest.java @@ -26,9 +26,9 @@ import org.jclouds.aws.ec2.domain.IpProtocol; import org.jclouds.aws.ec2.domain.UserIdGroupPair; import org.jclouds.aws.ec2.functions.ReturnVoidOnGroupNotFound; import org.jclouds.aws.ec2.xml.DescribeSecurityGroupsResponseHandler; +import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.ParseSax; -import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; @@ -46,79 +46,78 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest httpMethod = processor.createRequest(method, - null, "name"); + HttpRequest request = processor.createRequest(method, null, "name"); - assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); - assertHeadersEqual(httpMethod, + assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); + assertHeadersEqual( + request, "Content-Length: 60\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); - assertPayloadEquals(httpMethod, - "Version=2009-11-30&Action=DeleteSecurityGroup&GroupName=name"); + assertPayloadEquals(request, "Version=2009-11-30&Action=DeleteSecurityGroup&GroupName=name"); - assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); + assertResponseParserClassEquals(method, request, CloseContentAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, ReturnVoidOnGroupNotFound.class); - checkFilters(httpMethod); + checkFilters(request); } public void testCreateSecurityGroup() throws SecurityException, NoSuchMethodException, IOException { Method method = SecurityGroupAsyncClient.class.getMethod("createSecurityGroupInRegion", String.class, String.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - null, "name", "description"); + HttpRequest request = processor.createRequest(method, null, "name", "description"); - assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); - assertHeadersEqual(httpMethod, + assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); + assertHeadersEqual( + request, "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"); - assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); + assertResponseParserClassEquals(method, request, CloseContentAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testDescribeSecurityGroups() throws SecurityException, NoSuchMethodException, IOException { Method method = SecurityGroupAsyncClient.class.getMethod("describeSecurityGroupsInRegion", String.class, Array.newInstance(String.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - (String) null); + HttpRequest request = processor.createRequest(method, (String) null); - assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); - assertHeadersEqual(httpMethod, + assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); + assertHeadersEqual( + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testDescribeSecurityGroupsArgs() throws SecurityException, NoSuchMethodException, IOException { Method method = SecurityGroupAsyncClient.class.getMethod("describeSecurityGroupsInRegion", String.class, Array.newInstance(String.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - null, "1", "2"); + HttpRequest request = processor.createRequest(method, null, "1", "2"); - assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); - assertHeadersEqual(httpMethod, + assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); + assertHeadersEqual( + request, "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"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, DescribeSecurityGroupsResponseHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testAuthorizeSecurityGroupIngressGroup() throws SecurityException, @@ -126,21 +125,22 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest httpMethod = processor.createRequest(method, - null, "group", new UserIdGroupPair("sourceUser", "sourceGroup")); + HttpRequest request = processor.createRequest(method, null, "group", new UserIdGroupPair( + "sourceUser", "sourceGroup")); - assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); - assertHeadersEqual(httpMethod, + assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); + assertHeadersEqual( + request, "Content-Length: 71\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); assertPayloadEquals( - httpMethod, + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testAuthorizeSecurityGroupIngressCidr() throws SecurityException, @@ -148,21 +148,22 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest httpMethod = processor.createRequest(method, - null, "group", IpProtocol.TCP, 6000, 7000, "0.0.0.0/0"); + HttpRequest request = processor.createRequest(method, null, "group", IpProtocol.TCP, 6000, + 7000, "0.0.0.0/0"); - assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); - assertHeadersEqual(httpMethod, + assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); + assertHeadersEqual( + request, "Content-Length: 131\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); assertPayloadEquals( - httpMethod, + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testRevokeSecurityGroupIngressGroup() throws SecurityException, @@ -170,21 +171,22 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest httpMethod = processor.createRequest(method, - null, "group", new UserIdGroupPair("sourceUser", "sourceGroup")); + HttpRequest request = processor.createRequest(method, null, "group", new UserIdGroupPair( + "sourceUser", "sourceGroup")); - assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); - assertHeadersEqual(httpMethod, + assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); + assertHeadersEqual( + request, "Content-Length: 68\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); assertPayloadEquals( - httpMethod, + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testRevokeSecurityGroupIngressCidr() throws SecurityException, @@ -192,21 +194,22 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest httpMethod = processor.createRequest(method, - null, "group", IpProtocol.TCP, 6000, 7000, "0.0.0.0/0"); + HttpRequest request = processor.createRequest(method, null, "group", IpProtocol.TCP, 6000, + 7000, "0.0.0.0/0"); - assertRequestLineEquals(httpMethod, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); - assertHeadersEqual(httpMethod, + assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); + assertHeadersEqual( + request, "Content-Length: 128\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n"); assertPayloadEquals( - httpMethod, + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } @Override diff --git a/aws/core/src/test/java/org/jclouds/aws/elb/ELBAsyncClientTest.java b/aws/core/src/test/java/org/jclouds/aws/elb/ELBAsyncClientTest.java index 5d2d439824..0d295052b4 100644 --- a/aws/core/src/test/java/org/jclouds/aws/elb/ELBAsyncClientTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/elb/ELBAsyncClientTest.java @@ -28,17 +28,16 @@ import javax.inject.Named; import org.jclouds.Constants; import org.jclouds.aws.ec2.xml.RegisterInstancesWithLoadBalancerResponseHandler; -import org.jclouds.aws.elb.ELBAsyncClient; import org.jclouds.aws.elb.config.ELBRestClientModule; import org.jclouds.aws.filters.FormSigner; import org.jclouds.date.DateService; +import org.jclouds.http.HttpRequest; import org.jclouds.http.RequiresHttp; import org.jclouds.http.functions.ParseSax; import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory.ContextSpec; -import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; @@ -55,28 +54,26 @@ public class ELBAsyncClientTest extends RestClientTest { public void testRegisterInstancesWithLoadBalancer() throws SecurityException, NoSuchMethodException, IOException { - Method method = ELBAsyncClient.class.getMethod( - "registerInstancesWithLoadBalancerInRegion", String.class, String.class, - String[].class); + Method method = ELBAsyncClient.class.getMethod("registerInstancesWithLoadBalancerInRegion", + String.class, String.class, String[].class); - GeneratedHttpRequest httpMethod = processor.createRequest( - method, null, "ReferenceAP1", "i-6055fa09"); + HttpRequest request = processor.createRequest(method, null, "ReferenceAP1", "i-6055fa09"); - assertRequestLineEquals(httpMethod, + assertRequestLineEquals(request, "POST https://elasticloadbalancing.us-east-1.amazonaws.com/ HTTP/1.1"); assertHeadersEqual( - httpMethod, + request, "Content-Length: 89\nContent-Type: application/x-www-form-urlencoded\nHost: elasticloadbalancing.us-east-1.amazonaws.com\n"); assertPayloadEquals( - httpMethod, + request, "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, RegisterInstancesWithLoadBalancerResponseHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } @Override @@ -84,7 +81,7 @@ public class ELBAsyncClientTest extends RestClientTest { return new TypeLiteral>() { }; } - + @RequiresHttp @ConfiguresRestClient private static final class TestELBRestClientModule extends ELBRestClientModule { @@ -99,6 +96,7 @@ public class ELBAsyncClientTest extends RestClientTest { return "2009-11-08T15:54:08.897Z"; } } + @Override protected Module createModule() { return new TestELBRestClientModule(); @@ -111,9 +109,9 @@ public class ELBAsyncClientTest extends RestClientTest { } @Override - protected void checkFilters(GeneratedHttpRequest httpMethod) { - assertEquals(httpMethod.getFilters().size(), 1); - assertEquals(httpMethod.getFilters().get(0).getClass(), FormSigner.class); + protected void checkFilters(HttpRequest request) { + assertEquals(request.getFilters().size(), 1); + assertEquals(request.getFilters().get(0).getClass(), FormSigner.class); } } diff --git a/aws/core/src/test/java/org/jclouds/aws/s3/S3AsyncClientTest.java b/aws/core/src/test/java/org/jclouds/aws/s3/S3AsyncClientTest.java index 164d031df6..9e705574c9 100644 --- a/aws/core/src/test/java/org/jclouds/aws/s3/S3AsyncClientTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/s3/S3AsyncClientTest.java @@ -59,6 +59,7 @@ import org.jclouds.blobstore.functions.ReturnNullOnKeyNotFound; import org.jclouds.blobstore.functions.ThrowContainerNotFoundOn404; import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404; import org.jclouds.date.TimeStamp; +import org.jclouds.http.HttpRequest; import org.jclouds.http.RequiresHttp; import org.jclouds.http.functions.CloseContentAndReturn; 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.ContextSpec; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; -import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.util.Utils; import org.testng.annotations.BeforeClass; @@ -99,115 +99,112 @@ public class S3AsyncClientTest extends RestClientTest { public void testGetBucketLocation() throws SecurityException, NoSuchMethodException, IOException { Method method = S3AsyncClient.class.getMethod("getBucketLocation", String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, "bucket"); + HttpRequest request = processor.createRequest(method, "bucket"); - assertRequestLineEquals(httpMethod, "GET https://bucket.s3.amazonaws.com/?location HTTP/1.1"); - assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n"); - assertPayloadEquals(httpMethod, null); + assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/?location HTTP/1.1"); + assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n"); + 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( - httpMethod, + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testGetBucketPayer() throws SecurityException, NoSuchMethodException, IOException { Method method = S3AsyncClient.class.getMethod("getBucketPayer", String.class); - GeneratedHttpRequest 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"); - assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n"); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, PayerHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testSetBucketPayerOwner() throws SecurityException, NoSuchMethodException, IOException { Method method = S3AsyncClient.class.getMethod("setBucketPayer", String.class, Payer.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, "bucket", - Payer.BUCKET_OWNER); + HttpRequest request = processor.createRequest(method, "bucket", Payer.BUCKET_OWNER); - assertRequestLineEquals(httpMethod, + assertRequestLineEquals(request, "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"); assertPayloadEquals( - httpMethod, + request, "BucketOwner"); - assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); + assertResponseParserClassEquals(method, request, CloseContentAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testSetBucketPayerRequester() throws SecurityException, NoSuchMethodException, IOException { Method method = S3AsyncClient.class.getMethod("setBucketPayer", String.class, Payer.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, "bucket", - Payer.REQUESTER); + HttpRequest request = processor.createRequest(method, "bucket", Payer.REQUESTER); - assertRequestLineEquals(httpMethod, + assertRequestLineEquals(request, "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"); assertPayloadEquals( - httpMethod, + request, "Requester"); - assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); + assertResponseParserClassEquals(method, request, CloseContentAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testListBucket() throws SecurityException, NoSuchMethodException, IOException { Method method = S3AsyncClient.class.getMethod("listBucket", String.class, Array.newInstance( ListBucketOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, "bucket"); + HttpRequest request = processor.createRequest(method, "bucket"); - assertRequestLineEquals(httpMethod, "GET https://bucket.s3.amazonaws.com/ HTTP/1.1"); - assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n"); - assertPayloadEquals(httpMethod, null); + assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/ HTTP/1.1"); + assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, ListBucketHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testBucketExists() throws SecurityException, NoSuchMethodException, IOException { Method method = S3AsyncClient.class.getMethod("bucketExists", String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, "bucket"); + HttpRequest request = processor.createRequest(method, "bucket"); - assertRequestLineEquals(httpMethod, - "HEAD https://bucket.s3.amazonaws.com/?max-keys=0 HTTP/1.1"); - assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n"); - assertPayloadEquals(httpMethod, null); + assertRequestLineEquals(request, "HEAD https://bucket.s3.amazonaws.com/?max-keys=0 HTTP/1.1"); + assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ReturnTrueIf2xx.class); + assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, ReturnFalseOnContainerNotFound.class); - checkFilters(httpMethod); + checkFilters(request); } @Test(expectedExceptions = IllegalArgumentException.class) @@ -226,154 +223,148 @@ public class S3AsyncClientTest extends RestClientTest { Method method = S3AsyncClient.class .getMethod("copyObject", String.class, String.class, String.class, String.class, Array.newInstance(CopyObjectOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - "sourceBucket", "sourceObject", "destinationbucket", "destinationObject"); + HttpRequest request = processor.createRequest(method, "sourceBucket", "sourceObject", + "destinationbucket", "destinationObject"); - assertRequestLineEquals(httpMethod, + assertRequestLineEquals(request, "PUT https://destinationbucket.s3.amazonaws.com/destinationObject HTTP/1.1"); assertHeadersEqual( - httpMethod, + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testDeleteBucketIfEmpty() throws SecurityException, NoSuchMethodException, IOException { Method method = S3AsyncClient.class.getMethod("deleteBucketIfEmpty", String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, "bucket"); + HttpRequest request = processor.createRequest(method, "bucket"); - assertRequestLineEquals(httpMethod, "DELETE https://bucket.s3.amazonaws.com/ HTTP/1.1"); - assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n"); - assertPayloadEquals(httpMethod, null); + assertRequestLineEquals(request, "DELETE https://bucket.s3.amazonaws.com/ HTTP/1.1"); + assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ReturnTrueIf2xx.class); + assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, ReturnTrueOn404OrNotFoundFalseIfNotEmpty.class); - checkFilters(httpMethod); + checkFilters(request); } public void testDeleteObject() throws SecurityException, NoSuchMethodException, IOException { Method method = S3AsyncClient.class.getMethod("deleteObject", String.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, "bucket", - "object"); + HttpRequest request = processor.createRequest(method, "bucket", "object"); - assertRequestLineEquals(httpMethod, "DELETE https://bucket.s3.amazonaws.com/object HTTP/1.1"); - assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n"); - assertPayloadEquals(httpMethod, null); + assertRequestLineEquals(request, "DELETE https://bucket.s3.amazonaws.com/object HTTP/1.1"); + assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); + assertResponseParserClassEquals(method, request, CloseContentAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class); - checkFilters(httpMethod); + checkFilters(request); } public void testGetBucketACL() throws SecurityException, NoSuchMethodException, IOException { Method method = S3AsyncClient.class.getMethod("getBucketACL", String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, "bucket"); + HttpRequest request = processor.createRequest(method, "bucket"); - assertRequestLineEquals(httpMethod, "GET https://bucket.s3.amazonaws.com/?acl HTTP/1.1"); - assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n"); - assertPayloadEquals(httpMethod, null); + assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/?acl HTTP/1.1"); + assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, AccessControlListHandler.class); assertExceptionParserClassEquals(method, ThrowContainerNotFoundOn404.class); - checkFilters(httpMethod); + checkFilters(request); } public void testGetObject() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException, NoSuchMethodException, IOException { Method method = S3AsyncClient.class.getMethod("getObject", String.class, String.class, Array .newInstance(GetOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, "bucket", - "object"); + HttpRequest request = processor.createRequest(method, "bucket", "object"); - assertRequestLineEquals(httpMethod, "GET https://bucket.s3.amazonaws.com/object HTTP/1.1"); - assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n"); - assertPayloadEquals(httpMethod, null); + assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/object HTTP/1.1"); + assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, - ParseObjectFromHeadersAndHttpContent.class); + assertResponseParserClassEquals(method, request, ParseObjectFromHeadersAndHttpContent.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, ReturnNullOnKeyNotFound.class); - checkFilters(httpMethod); + checkFilters(request); } public void testGetObjectACL() throws SecurityException, NoSuchMethodException, IOException { Method method = S3AsyncClient.class.getMethod("getObjectACL", String.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, "bucket", - "object"); + HttpRequest request = processor.createRequest(method, "bucket", "object"); - assertRequestLineEquals(httpMethod, "GET https://bucket.s3.amazonaws.com/object?acl HTTP/1.1"); - assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n"); - assertPayloadEquals(httpMethod, null); + assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/object?acl HTTP/1.1"); + assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, AccessControlListHandler.class); assertExceptionParserClassEquals(method, ThrowKeyNotFoundOn404.class); - checkFilters(httpMethod); + checkFilters(request); } public void testObjectExists() throws SecurityException, NoSuchMethodException, IOException { Method method = S3AsyncClient.class.getMethod("objectExists", String.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, "bucket", - "object"); + HttpRequest request = processor.createRequest(method, "bucket", "object"); - assertRequestLineEquals(httpMethod, "HEAD https://bucket.s3.amazonaws.com/object HTTP/1.1"); - assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n"); - assertPayloadEquals(httpMethod, null); + assertRequestLineEquals(request, "HEAD https://bucket.s3.amazonaws.com/object HTTP/1.1"); + assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ReturnTrueIf2xx.class); + assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, ReturnFalseOnKeyNotFound.class); - checkFilters(httpMethod); + checkFilters(request); } public void testHeadObject() throws SecurityException, NoSuchMethodException, IOException { Method method = S3AsyncClient.class.getMethod("headObject", String.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, "bucket", - "object"); + HttpRequest request = processor.createRequest(method, "bucket", "object"); - assertRequestLineEquals(httpMethod, "HEAD https://bucket.s3.amazonaws.com/object HTTP/1.1"); - assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n"); - assertPayloadEquals(httpMethod, null); + assertRequestLineEquals(request, "HEAD https://bucket.s3.amazonaws.com/object HTTP/1.1"); + assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseObjectMetadataFromHeaders.class); + assertResponseParserClassEquals(method, request, ParseObjectMetadataFromHeaders.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, ReturnNullOnKeyNotFound.class); - checkFilters(httpMethod); + checkFilters(request); } public void testListOwnedBuckets() throws SecurityException, NoSuchMethodException, IOException { Method method = S3AsyncClient.class.getMethod("listOwnedBuckets"); - GeneratedHttpRequest httpMethod = processor.createRequest(method); + HttpRequest request = processor.createRequest(method); - assertRequestLineEquals(httpMethod, "GET https://s3.amazonaws.com/ HTTP/1.1"); - assertHeadersEqual(httpMethod, "Host: s3.amazonaws.com\n"); - assertPayloadEquals(httpMethod, null); + assertRequestLineEquals(request, "GET https://s3.amazonaws.com/ HTTP/1.1"); + assertHeadersEqual(request, "Host: s3.amazonaws.com\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, ListAllMyBucketsHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testNewS3Object() throws SecurityException, NoSuchMethodException, IOException { @@ -384,60 +375,58 @@ public class S3AsyncClientTest extends RestClientTest { public void testPutBucketACL() throws SecurityException, NoSuchMethodException, IOException { Method method = S3AsyncClient.class.getMethod("putBucketACL", String.class, AccessControlList.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, "bucket", - AccessControlList.fromCannedAccessPolicy(CannedAccessPolicy.PRIVATE, "1234")); + HttpRequest request = processor.createRequest(method, "bucket", AccessControlList + .fromCannedAccessPolicy(CannedAccessPolicy.PRIVATE, "1234")); - assertRequestLineEquals(httpMethod, "PUT https://bucket.s3.amazonaws.com/?acl HTTP/1.1"); - assertHeadersEqual(httpMethod, + assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/?acl HTTP/1.1"); + assertHeadersEqual(request, "Content-Length: 321\nContent-Type: text/xml\nHost: bucket.s3.amazonaws.com\n"); assertPayloadEquals( - httpMethod, + request, "12341234FULL_CONTROL"); - assertResponseParserClassEquals(method, httpMethod, ReturnTrueIf2xx.class); + assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testPutBucketDefault() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException, NoSuchMethodException, IOException { Method method = S3AsyncClient.class.getMethod("putBucketInRegion", String.class, String.class, Array.newInstance(PutBucketOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - (String) null, "bucket"); + HttpRequest request = processor.createRequest(method, (String) null, "bucket"); - assertRequestLineEquals(httpMethod, "PUT https://bucket.s3.amazonaws.com/ HTTP/1.1"); - assertHeadersEqual(httpMethod, "Content-Length: 0\nHost: bucket.s3.amazonaws.com\n"); - assertPayloadEquals(httpMethod, null); + assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/ HTTP/1.1"); + assertHeadersEqual(request, "Content-Length: 0\nHost: bucket.s3.amazonaws.com\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ReturnTrueIf2xx.class); + assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, ReturnFalseIfBucketAlreadyOwnedByYou.class); - checkFilters(httpMethod); + checkFilters(request); } public void testPutBucketEu() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException, NoSuchMethodException, IOException { Method method = S3AsyncClient.class.getMethod("putBucketInRegion", String.class, String.class, Array.newInstance(PutBucketOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, "EU", - "bucket"); + HttpRequest request = processor.createRequest(method, "EU", "bucket"); - assertRequestLineEquals(httpMethod, "PUT https://bucket.s3.amazonaws.com/ HTTP/1.1"); - assertHeadersEqual(httpMethod, + assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/ HTTP/1.1"); + assertHeadersEqual(request, "Content-Length: 98\nContent-Type: application/unknown\nHost: bucket.s3.amazonaws.com\n"); assertPayloadEquals( - httpMethod, + request, "EU"); - assertResponseParserClassEquals(method, httpMethod, ReturnTrueIf2xx.class); + assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, ReturnFalseIfBucketAlreadyOwnedByYou.class); - checkFilters(httpMethod); + checkFilters(request); } public void testPutObject() throws ArrayIndexOutOfBoundsException, SecurityException, @@ -445,102 +434,102 @@ public class S3AsyncClientTest extends RestClientTest { Method method = S3AsyncClient.class.getMethod("putObject", String.class, S3Object.class, Array.newInstance(PutObjectOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, "bucket", - blobToS3Object.apply(BindBlobToMultipartFormTest.TEST_BLOB)); + HttpRequest request = processor.createRequest(method, "bucket", blobToS3Object + .apply(BindBlobToMultipartFormTest.TEST_BLOB)); - assertRequestLineEquals(httpMethod, "PUT https://bucket.s3.amazonaws.com/hello HTTP/1.1"); - assertHeadersEqual(httpMethod, + assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/hello HTTP/1.1"); + assertHeadersEqual(request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testPutObjectACL() throws SecurityException, NoSuchMethodException, IOException { Method method = S3AsyncClient.class.getMethod("putObjectACL", String.class, String.class, AccessControlList.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, "bucket", - "key", AccessControlList.fromCannedAccessPolicy(CannedAccessPolicy.PRIVATE, "1234")); + HttpRequest request = processor.createRequest(method, "bucket", "key", AccessControlList + .fromCannedAccessPolicy(CannedAccessPolicy.PRIVATE, "1234")); - assertRequestLineEquals(httpMethod, "PUT https://bucket.s3.amazonaws.com/key?acl HTTP/1.1"); - assertHeadersEqual(httpMethod, + assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/key?acl HTTP/1.1"); + assertHeadersEqual(request, "Content-Length: 321\nContent-Type: text/xml\nHost: bucket.s3.amazonaws.com\n"); assertPayloadEquals( - httpMethod, + request, "12341234FULL_CONTROL"); - assertResponseParserClassEquals(method, httpMethod, ReturnTrueIf2xx.class); + assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testGetBucketLogging() throws SecurityException, NoSuchMethodException, IOException { Method method = S3AsyncClient.class.getMethod("getBucketLogging", String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, "bucket"); + HttpRequest request = processor.createRequest(method, "bucket"); - assertRequestLineEquals(httpMethod, "GET https://bucket.s3.amazonaws.com/?logging HTTP/1.1"); - assertHeadersEqual(httpMethod, "Host: bucket.s3.amazonaws.com\n"); - assertPayloadEquals(httpMethod, null); + assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/?logging HTTP/1.1"); + assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, BucketLoggingHandler.class); assertExceptionParserClassEquals(method, ThrowContainerNotFoundOn404.class); - checkFilters(httpMethod); + checkFilters(request); } public void testDisableBucketLogging() throws SecurityException, NoSuchMethodException, IOException { Method method = S3AsyncClient.class.getMethod("disableBucketLogging", String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, "bucket"); + HttpRequest request = processor.createRequest(method, "bucket"); - assertRequestLineEquals(httpMethod, "PUT https://bucket.s3.amazonaws.com/?logging HTTP/1.1"); - assertHeadersEqual(httpMethod, + assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/?logging HTTP/1.1"); + assertHeadersEqual(request, "Content-Length: 70\nContent-Type: text/xml\nHost: bucket.s3.amazonaws.com\n"); - assertPayloadEquals(httpMethod, + assertPayloadEquals(request, ""); - assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); + assertResponseParserClassEquals(method, request, CloseContentAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testEnableBucketLoggingOwner() throws SecurityException, NoSuchMethodException, IOException { Method method = S3AsyncClient.class.getMethod("enableBucketLogging", String.class, BucketLogging.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, "bucket", - new BucketLogging("mylogs", "access_log-", ImmutableSet. of(new Grant( - new EmailAddressGrantee("adrian@jclouds.org"), Permission.FULL_CONTROL)))); + HttpRequest request = processor.createRequest(method, "bucket", new BucketLogging("mylogs", + "access_log-", ImmutableSet. of(new Grant(new EmailAddressGrantee( + "adrian@jclouds.org"), Permission.FULL_CONTROL)))); - assertRequestLineEquals(httpMethod, "PUT https://bucket.s3.amazonaws.com/?logging HTTP/1.1"); - assertHeadersEqual(httpMethod, + assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/?logging HTTP/1.1"); + assertHeadersEqual(request, "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"))); - assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); + assertResponseParserClassEquals(method, request, CloseContentAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } BlobToObject blobToS3Object; RequestAuthorizeSignature filter; @Override - protected void checkFilters(GeneratedHttpRequest httpMethod) { - assertEquals(httpMethod.getFilters().size(), 1); - assertEquals(httpMethod.getFilters().get(0).getClass(), RequestAuthorizeSignature.class); + protected void checkFilters(HttpRequest request) { + assertEquals(request.getFilters().size(), 1); + assertEquals(request.getFilters().get(0).getClass(), RequestAuthorizeSignature.class); } @Override diff --git a/aws/core/src/test/java/org/jclouds/aws/sqs/SQSAsyncClientTest.java b/aws/core/src/test/java/org/jclouds/aws/sqs/SQSAsyncClientTest.java index 91794ae546..4e895db3ef 100644 --- a/aws/core/src/test/java/org/jclouds/aws/sqs/SQSAsyncClientTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/sqs/SQSAsyncClientTest.java @@ -38,12 +38,12 @@ import org.jclouds.aws.sqs.options.ListQueuesOptions; import org.jclouds.aws.sqs.xml.RegexListQueuesResponseHandler; import org.jclouds.aws.sqs.xml.RegexQueueHandler; import org.jclouds.date.DateService; +import org.jclouds.http.HttpRequest; import org.jclouds.http.RequiresHttp; import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory.ContextSpec; -import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; @@ -78,81 +78,79 @@ public class SQSAsyncClientTest extends RestClientTest { IOException { Method method = SQSAsyncClient.class.getMethod("listQueuesInRegion", String.class, Array .newInstance(ListQueuesOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - (String) null); + HttpRequest request = processor.createRequest(method, (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( - httpMethod, + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testListQueuesInRegionOptions() throws SecurityException, NoSuchMethodException, IOException { Method method = SQSAsyncClient.class.getMethod("listQueuesInRegion", String.class, Array .newInstance(ListQueuesOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - ListQueuesOptions.Builder.queuePrefix("prefix")); + HttpRequest request = processor.createRequest(method, null, ListQueuesOptions.Builder + .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( - httpMethod, + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testCreateQueueInRegion() throws SecurityException, NoSuchMethodException, IOException { Method method = SQSAsyncClient.class.getMethod("createQueueInRegion", String.class, String.class, Array.newInstance(CreateQueueOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - "queueName"); + HttpRequest request = processor.createRequest(method, null, "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( - httpMethod, + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testCreateQueueInRegionOptions() throws SecurityException, NoSuchMethodException, IOException { Method method = SQSAsyncClient.class.getMethod("createQueueInRegion", String.class, String.class, Array.newInstance(CreateQueueOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, null, - "queueName", CreateQueueOptions.Builder.defaultVisibilityTimeout(45)); + HttpRequest request = processor.createRequest(method, null, "queueName", + 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( - httpMethod, + request, "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"); - assertResponseParserClassEquals(method, httpMethod, RegexQueueHandler.class); + assertResponseParserClassEquals(method, request, RegexQueueHandler.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testAllRegions() throws SecurityException, NoSuchMethodException, IOException { @@ -164,9 +162,9 @@ public class SQSAsyncClientTest extends RestClientTest { } @Override - protected void checkFilters(GeneratedHttpRequest httpMethod) { - assertEquals(httpMethod.getFilters().size(), 1); - assertEquals(httpMethod.getFilters().get(0).getClass(), FormSigner.class); + protected void checkFilters(HttpRequest request) { + assertEquals(request.getFilters().size(), 1); + assertEquals(request.getFilters().get(0).getClass(), FormSigner.class); } @Override diff --git a/azure/src/test/java/org/jclouds/azure/storage/blob/AzureBlobAsyncClientTest.java b/azure/src/test/java/org/jclouds/azure/storage/blob/AzureBlobAsyncClientTest.java index 6b528f04f7..390f11b970 100644 --- a/azure/src/test/java/org/jclouds/azure/storage/blob/AzureBlobAsyncClientTest.java +++ b/azure/src/test/java/org/jclouds/azure/storage/blob/AzureBlobAsyncClientTest.java @@ -38,6 +38,7 @@ import org.jclouds.azure.storage.blob.options.ListBlobsOptions; import org.jclouds.azure.storage.filters.SharedKeyLiteAuthentication; import org.jclouds.azure.storage.options.ListOptions; import org.jclouds.blobstore.functions.ReturnNullOnContainerNotFound; +import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.ParseSax; 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.functions.MapHttp4xxCodesToExceptions; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; -import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; @@ -67,16 +67,15 @@ public class AzureBlobAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] {}); - assertEquals(httpMethod.getEndpoint().getHost(), "identity.blob.core.windows.net"); - assertEquals(httpMethod.getEndpoint().getPath(), "/"); - assertEquals(httpMethod.getEndpoint().getQuery(), "comp=list"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 1); - assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections + HttpRequest request = processor.createRequest(method, new Object[] {}); + assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net"); + assertEquals(request.getEndpoint().getPath(), "/"); + assertEquals(request.getEndpoint().getQuery(), "comp=list"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 1); + assertEquals(request.getHeaders().get("x-ms-version"), Collections .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 assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), @@ -87,19 +86,19 @@ public class AzureBlobAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { maxResults(1).marker("marker").prefix("prefix") }); - assertEquals(httpMethod.getEndpoint().getHost(), "identity.blob.core.windows.net"); - assertEquals(httpMethod.getEndpoint().getPath(), "/"); - assert httpMethod.getEndpoint().getQuery().contains("comp=list"); - assert httpMethod.getEndpoint().getQuery().contains("marker=marker"); - assert httpMethod.getEndpoint().getQuery().contains("maxresults=1"); - assert httpMethod.getEndpoint().getQuery().contains("prefix=prefix"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 1); - assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections + HttpRequest request = processor.createRequest(method, new Object[] { maxResults(1).marker( + "marker").prefix("prefix") }); + assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net"); + assertEquals(request.getEndpoint().getPath(), "/"); + assert request.getEndpoint().getQuery().contains("comp=list"); + assert request.getEndpoint().getQuery().contains("marker=marker"); + assert request.getEndpoint().getQuery().contains("maxresults=1"); + assert request.getEndpoint().getQuery().contains("prefix=prefix"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 1); + assertEquals(request.getHeaders().get("x-ms-version"), Collections .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 assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), @@ -110,17 +109,16 @@ public class AzureBlobAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { "container" }); - assertEquals(httpMethod.getEndpoint().getHost(), "identity.blob.core.windows.net"); - assertEquals(httpMethod.getEndpoint().getPath(), "/container"); - assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container"); - assertEquals(httpMethod.getMethod(), HttpMethod.PUT); - assertEquals(httpMethod.getHeaders().size(), 2); - assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections + HttpRequest request = processor.createRequest(method, new Object[] { "container" }); + assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net"); + assertEquals(request.getEndpoint().getPath(), "/container"); + assertEquals(request.getEndpoint().getQuery(), "restype=container"); + assertEquals(request.getMethod(), HttpMethod.PUT); + assertEquals(request.getHeaders().size(), 2); + assertEquals(request.getHeaders().get("x-ms-version"), Collections .singletonList("2009-09-19")); - assertEquals(httpMethod.getHeaders().get("Content-Length"), Collections.singletonList("0")); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + assertEquals(request.getHeaders().get("Content-Length"), Collections.singletonList("0")); + assertEquals(processor.createResponseParser(method, request).getClass(), ReturnTrueIf2xx.class); // TODO check generic type of response parser assertEquals(processor @@ -131,16 +129,15 @@ public class AzureBlobAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { "container" }); - assertEquals(httpMethod.getEndpoint().getHost(), "identity.blob.core.windows.net"); - assertEquals(httpMethod.getEndpoint().getPath(), "/container"); - assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container"); - assertEquals(httpMethod.getMethod(), HttpMethod.DELETE); - assertEquals(httpMethod.getHeaders().size(), 1); - assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections + HttpRequest request = processor.createRequest(method, new Object[] { "container" }); + assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net"); + assertEquals(request.getEndpoint().getPath(), "/container"); + assertEquals(request.getEndpoint().getQuery(), "restype=container"); + assertEquals(request.getMethod(), HttpMethod.DELETE); + assertEquals(request.getHeaders().size(), 1); + assertEquals(request.getHeaders().get("x-ms-version"), Collections .singletonList("2009-09-19")); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + assertEquals(processor.createResponseParser(method, request).getClass(), CloseContentAndReturn.class); // TODO check generic type of response parser assertEquals(processor @@ -152,21 +149,20 @@ public class AzureBlobAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { "container", - withPublicAcl().withMetadata(ImmutableMultimap.of("foo", "bar")) }); - assertEquals(httpMethod.getEndpoint().getHost(), "identity.blob.core.windows.net"); - assertEquals(httpMethod.getEndpoint().getPath(), "/container"); - assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container"); - assertEquals(httpMethod.getMethod(), HttpMethod.PUT); - assertEquals(httpMethod.getHeaders().size(), 4); - assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections + HttpRequest request = processor.createRequest(method, new Object[] { "container", + withPublicAcl().withMetadata(ImmutableMultimap.of("foo", "bar")) }); + assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net"); + assertEquals(request.getEndpoint().getPath(), "/container"); + assertEquals(request.getEndpoint().getQuery(), "restype=container"); + assertEquals(request.getMethod(), HttpMethod.PUT); + assertEquals(request.getHeaders().size(), 4); + assertEquals(request.getHeaders().get("x-ms-version"), Collections .singletonList("2009-09-19")); - assertEquals(httpMethod.getHeaders().get("x-ms-meta-foo"), Collections.singletonList("bar")); - assertEquals(httpMethod.getHeaders().get("x-ms-prop-publicaccess"), Collections + assertEquals(request.getHeaders().get("x-ms-meta-foo"), Collections.singletonList("bar")); + assertEquals(request.getHeaders().get("x-ms-prop-publicaccess"), Collections .singletonList("true")); - assertEquals(httpMethod.getHeaders().get("Content-Length"), Collections.singletonList("0")); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + assertEquals(request.getHeaders().get("Content-Length"), Collections.singletonList("0")); + assertEquals(processor.createResponseParser(method, request).getClass(), ReturnTrueIf2xx.class); // TODO check generic type of response parser assertEquals(processor @@ -178,17 +174,16 @@ public class AzureBlobAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] {}); - assertEquals(httpMethod.getEndpoint().getHost(), "identity.blob.core.windows.net"); - assertEquals(httpMethod.getEndpoint().getPath(), "/$root"); - assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container"); - assertEquals(httpMethod.getMethod(), HttpMethod.PUT); - assertEquals(httpMethod.getHeaders().size(), 2); - assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections + HttpRequest request = processor.createRequest(method, new Object[] {}); + assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net"); + assertEquals(request.getEndpoint().getPath(), "/$root"); + assertEquals(request.getEndpoint().getQuery(), "restype=container"); + assertEquals(request.getMethod(), HttpMethod.PUT); + assertEquals(request.getHeaders().size(), 2); + assertEquals(request.getHeaders().get("x-ms-version"), Collections .singletonList("2009-09-19")); - assertEquals(httpMethod.getHeaders().get("Content-Length"), Collections.singletonList("0")); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + assertEquals(request.getHeaders().get("Content-Length"), Collections.singletonList("0")); + assertEquals(processor.createResponseParser(method, request).getClass(), ReturnTrueIf2xx.class); // TODO check generic type of response parser assertEquals(processor @@ -199,16 +194,15 @@ public class AzureBlobAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] {}); - assertEquals(httpMethod.getEndpoint().getHost(), "identity.blob.core.windows.net"); - assertEquals(httpMethod.getEndpoint().getPath(), "/$root"); - assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container"); - assertEquals(httpMethod.getMethod(), HttpMethod.DELETE); - assertEquals(httpMethod.getHeaders().size(), 1); - assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections + HttpRequest request = processor.createRequest(method, new Object[] {}); + assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net"); + assertEquals(request.getEndpoint().getPath(), "/$root"); + assertEquals(request.getEndpoint().getQuery(), "restype=container"); + assertEquals(request.getMethod(), HttpMethod.DELETE); + assertEquals(request.getHeaders().size(), 1); + assertEquals(request.getHeaders().get("x-ms-version"), Collections .singletonList("2009-09-19")); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + assertEquals(processor.createResponseParser(method, request).getClass(), CloseContentAndReturn.class); // TODO check generic type of response parser assertEquals(processor @@ -220,20 +214,20 @@ public class AzureBlobAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { withPublicAcl().withMetadata(ImmutableMultimap.of("foo", "bar")) }); - assertEquals(httpMethod.getEndpoint().getHost(), "identity.blob.core.windows.net"); - assertEquals(httpMethod.getEndpoint().getPath(), "/$root"); - assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container"); - assertEquals(httpMethod.getMethod(), HttpMethod.PUT); - assertEquals(httpMethod.getHeaders().size(), 4); - assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections + HttpRequest request = processor.createRequest(method, new Object[] { withPublicAcl() + .withMetadata(ImmutableMultimap.of("foo", "bar")) }); + assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net"); + assertEquals(request.getEndpoint().getPath(), "/$root"); + assertEquals(request.getEndpoint().getQuery(), "restype=container"); + assertEquals(request.getMethod(), HttpMethod.PUT); + assertEquals(request.getHeaders().size(), 4); + assertEquals(request.getHeaders().get("x-ms-version"), Collections .singletonList("2009-09-19")); - assertEquals(httpMethod.getHeaders().get("x-ms-meta-foo"), Collections.singletonList("bar")); - assertEquals(httpMethod.getHeaders().get("x-ms-prop-publicaccess"), Collections + assertEquals(request.getHeaders().get("x-ms-meta-foo"), Collections.singletonList("bar")); + assertEquals(request.getHeaders().get("x-ms-prop-publicaccess"), Collections .singletonList("true")); - assertEquals(httpMethod.getHeaders().get("Content-Length"), Collections.singletonList("0")); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + assertEquals(request.getHeaders().get("Content-Length"), Collections.singletonList("0")); + assertEquals(processor.createResponseParser(method, request).getClass(), ReturnTrueIf2xx.class); // TODO check generic type of response parser assertEquals(processor @@ -245,16 +239,15 @@ public class AzureBlobAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { "container" }); - assertEquals(httpMethod.getEndpoint().getHost(), "identity.blob.core.windows.net"); - assertEquals(httpMethod.getEndpoint().getPath(), "/container"); - assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container&comp=list"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 1); - assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections + HttpRequest request = processor.createRequest(method, new Object[] { "container" }); + assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net"); + assertEquals(request.getEndpoint().getPath(), "/container"); + assertEquals(request.getEndpoint().getQuery(), "restype=container&comp=list"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 1); + assertEquals(request.getHeaders().get("x-ms-version"), Collections .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 assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), @@ -265,16 +258,15 @@ public class AzureBlobAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] {}); - assertEquals(httpMethod.getEndpoint().getHost(), "identity.blob.core.windows.net"); - assertEquals(httpMethod.getEndpoint().getPath(), "/$root"); - assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container&comp=list"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 1); - assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections + HttpRequest request = processor.createRequest(method, new Object[] {}); + assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net"); + assertEquals(request.getEndpoint().getPath(), "/$root"); + assertEquals(request.getEndpoint().getQuery(), "restype=container&comp=list"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 1); + assertEquals(request.getHeaders().get("x-ms-version"), Collections .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 assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), @@ -284,16 +276,15 @@ public class AzureBlobAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { "container" }); - assertEquals(httpMethod.getEndpoint().getHost(), "identity.blob.core.windows.net"); - assertEquals(httpMethod.getEndpoint().getPath(), "/container"); - assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container"); - assertEquals(httpMethod.getMethod(), HttpMethod.HEAD); - assertEquals(httpMethod.getHeaders().size(), 1); - assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections + HttpRequest request = processor.createRequest(method, new Object[] { "container" }); + assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net"); + assertEquals(request.getEndpoint().getPath(), "/container"); + assertEquals(request.getEndpoint().getQuery(), "restype=container"); + assertEquals(request.getMethod(), HttpMethod.HEAD); + assertEquals(request.getHeaders().size(), 1); + assertEquals(request.getHeaders().get("x-ms-version"), Collections .singletonList("2009-09-19")); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + assertEquals(processor.createResponseParser(method, request).getClass(), ParseContainerPropertiesFromHeaders.class); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), @@ -304,20 +295,20 @@ public class AzureBlobAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { "container", ImmutableMap.of("key", "value") }); - assertEquals(httpMethod.getEndpoint().getHost(), "identity.blob.core.windows.net"); - assertEquals(httpMethod.getEndpoint().getPath(), "/container"); - assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container&comp=metadata"); - assertEquals(httpMethod.getMethod(), HttpMethod.PUT); - assertEquals(httpMethod.getHeaders().size(), 3); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections + HttpRequest request = processor.createRequest(method, new Object[] { "container", + ImmutableMap.of("key", "value") }); + assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net"); + assertEquals(request.getEndpoint().getPath(), "/container"); + assertEquals(request.getEndpoint().getQuery(), "restype=container&comp=metadata"); + assertEquals(request.getMethod(), HttpMethod.PUT); + assertEquals(request.getHeaders().size(), 3); + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections .singletonList("0")); - assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections + assertEquals(request.getHeaders().get("x-ms-version"), Collections .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); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), @@ -327,20 +318,20 @@ public class AzureBlobAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { "container", "blob", ImmutableMap.of("key", "value") }); - assertEquals(httpMethod.getEndpoint().getHost(), "identity.blob.core.windows.net"); - assertEquals(httpMethod.getEndpoint().getPath(), "/container/blob"); - assertEquals(httpMethod.getEndpoint().getQuery(), "comp=metadata"); - assertEquals(httpMethod.getMethod(), HttpMethod.PUT); - assertEquals(httpMethod.getHeaders().size(), 3); - assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections + HttpRequest request = processor.createRequest(method, new Object[] { "container", "blob", + ImmutableMap.of("key", "value") }); + assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net"); + assertEquals(request.getEndpoint().getPath(), "/container/blob"); + assertEquals(request.getEndpoint().getQuery(), "comp=metadata"); + assertEquals(request.getMethod(), HttpMethod.PUT); + assertEquals(request.getHeaders().size(), 3); + assertEquals(request.getHeaders().get("x-ms-version"), Collections .singletonList("2009-09-19")); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections .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); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), @@ -348,9 +339,9 @@ public class AzureBlobAsyncClientTest extends RestClientTest httpMethod) { - assertEquals(httpMethod.getFilters().size(), 1); - assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class); + protected void checkFilters(HttpRequest request) { + assertEquals(request.getFilters().size(), 1); + assertEquals(request.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class); } @Override diff --git a/azure/src/test/java/org/jclouds/azure/storage/queue/AzureQueueAsyncClientTest.java b/azure/src/test/java/org/jclouds/azure/storage/queue/AzureQueueAsyncClientTest.java index 7d56c5dea5..227d1b1f84 100644 --- a/azure/src/test/java/org/jclouds/azure/storage/queue/AzureQueueAsyncClientTest.java +++ b/azure/src/test/java/org/jclouds/azure/storage/queue/AzureQueueAsyncClientTest.java @@ -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.xml.AccountNameEnumerationResultsHandler; import org.jclouds.azure.storage.queue.xml.QueueMessagesListHandler; +import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ReturnTrueIf2xx; import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory.ContextSpec; -import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; @@ -59,91 +59,88 @@ public class AzureQueueAsyncClientTest extends RestClientTest httpRequest = processor.createRequest(method, - "myqueue"); + HttpRequest request = processor.createRequest(method, "myqueue"); - assertRequestLineEquals(httpRequest, + assertRequestLineEquals(request, "GET https://identity.queue.core.windows.net/myqueue/messages HTTP/1.1"); - assertHeadersEqual(httpRequest, "x-ms-version: 2009-09-19\n"); - assertPayloadEquals(httpRequest, null); + assertHeadersEqual(request, "x-ms-version: 2009-09-19\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpRequest, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, QueueMessagesListHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpRequest); + checkFilters(request); } public void testGetMessagesOptions() throws SecurityException, NoSuchMethodException, IOException { Method method = AzureQueueAsyncClient.class.getMethod("getMessages", String.class, GetOptions[].class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, - "myqueue", maxMessages(1).visibilityTimeout(30)); + HttpRequest request = processor.createRequest(method, "myqueue", maxMessages(1) + .visibilityTimeout(30)); assertRequestLineEquals( - httpRequest, + request, "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"); - assertPayloadEquals(httpRequest, null); + assertHeadersEqual(request, "x-ms-version: 2009-09-19\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpRequest, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, QueueMessagesListHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpRequest); + checkFilters(request); } public void testListQueues() throws SecurityException, NoSuchMethodException, IOException { Method method = AzureQueueAsyncClient.class.getMethod("listQueues", ListOptions[].class); - GeneratedHttpRequest 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"); - assertHeadersEqual(httpRequest, "x-ms-version: 2009-09-19\n"); - assertPayloadEquals(httpRequest, null); + assertHeadersEqual(request, "x-ms-version: 2009-09-19\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpRequest, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, AccountNameEnumerationResultsHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpRequest); + checkFilters(request); } public void testListQueuesOptions() throws SecurityException, NoSuchMethodException, IOException { Method method = AzureQueueAsyncClient.class.getMethod("listQueues", ListOptions[].class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, - maxResults(1).marker("marker").prefix("prefix")); + HttpRequest request = processor.createRequest(method, maxResults(1).marker("marker").prefix( + "prefix")); assertRequestLineEquals( - httpRequest, + request, "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"); - assertPayloadEquals(httpRequest, null); + assertHeadersEqual(request, "x-ms-version: 2009-09-19\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpRequest, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, AccountNameEnumerationResultsHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpRequest); + checkFilters(request); } public void testCreateQueue() throws SecurityException, NoSuchMethodException, IOException { Method method = AzureQueueAsyncClient.class.getMethod("createQueue", String.class, CreateOptions[].class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, - "queue"); + HttpRequest request = processor.createRequest(method, "queue"); - assertRequestLineEquals(httpRequest, - "PUT https://identity.queue.core.windows.net/queue HTTP/1.1"); - assertHeadersEqual(httpRequest, "Content-Length: 0\nx-ms-version: 2009-09-19\n"); - assertPayloadEquals(httpRequest, null); + assertRequestLineEquals(request, "PUT https://identity.queue.core.windows.net/queue HTTP/1.1"); + assertHeadersEqual(request, "Content-Length: 0\nx-ms-version: 2009-09-19\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpRequest, ReturnTrueIf2xx.class); + assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpRequest); + checkFilters(request); } public void testCreateQueueOptions() throws SecurityException, NoSuchMethodException, @@ -151,38 +148,36 @@ public class AzureQueueAsyncClientTest extends RestClientTest httpRequest = processor.createRequest(method, - "queue", withMetadata(ImmutableMultimap.of("foo", "bar"))); + HttpRequest request = processor.createRequest(method, "queue", withMetadata(ImmutableMultimap + .of("foo", "bar"))); - assertRequestLineEquals(httpRequest, - "PUT https://identity.queue.core.windows.net/queue HTTP/1.1"); - assertHeadersEqual(httpRequest, + assertRequestLineEquals(request, "PUT https://identity.queue.core.windows.net/queue HTTP/1.1"); + assertHeadersEqual(request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpRequest); + checkFilters(request); } public void testDeleteQueue() throws SecurityException, NoSuchMethodException, IOException { Method method = AzureQueueAsyncClient.class.getMethod("deleteQueue", String.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, - "queue"); + HttpRequest request = processor.createRequest(method, "queue"); - assertRequestLineEquals(httpRequest, + assertRequestLineEquals(request, "DELETE https://identity.queue.core.windows.net/queue HTTP/1.1"); - assertHeadersEqual(httpRequest, "x-ms-version: 2009-09-19\n"); - assertPayloadEquals(httpRequest, null); + assertHeadersEqual(request, "x-ms-version: 2009-09-19\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpRequest, CloseContentAndReturn.class); + assertResponseParserClassEquals(method, request, CloseContentAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpRequest); + checkFilters(request); } @@ -190,66 +185,63 @@ public class AzureQueueAsyncClientTest extends RestClientTest httpRequest = processor.createRequest(method, - "queue", "message"); + HttpRequest request = processor.createRequest(method, "queue", "message"); - assertRequestLineEquals(httpRequest, + assertRequestLineEquals(request, "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"); - assertPayloadEquals(httpRequest, + assertPayloadEquals(request, "message"); - assertResponseParserClassEquals(method, httpRequest, CloseContentAndReturn.class); + assertResponseParserClassEquals(method, request, CloseContentAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpRequest); + checkFilters(request); } public void testPutMessageOptions() throws SecurityException, NoSuchMethodException, IOException { Method method = AzureQueueAsyncClient.class.getMethod("putMessage", String.class, String.class, PutMessageOptions[].class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, - "queue", "message", withTTL(3)); + HttpRequest request = processor.createRequest(method, "queue", "message", withTTL(3)); - assertRequestLineEquals(httpRequest, + assertRequestLineEquals(request, "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"); - assertPayloadEquals(httpRequest, + assertPayloadEquals(request, "message"); - assertResponseParserClassEquals(method, httpRequest, CloseContentAndReturn.class); + assertResponseParserClassEquals(method, request, CloseContentAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpRequest); + checkFilters(request); } public void testClearMessages() throws SecurityException, NoSuchMethodException, IOException { Method method = AzureQueueAsyncClient.class.getMethod("clearMessages", String.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, - "queue"); + HttpRequest request = processor.createRequest(method, "queue"); - assertRequestLineEquals(httpRequest, + assertRequestLineEquals(request, "DELETE https://identity.queue.core.windows.net/queue/messages HTTP/1.1"); - assertHeadersEqual(httpRequest, "x-ms-version: 2009-09-19\n"); - assertPayloadEquals(httpRequest, null); + assertHeadersEqual(request, "x-ms-version: 2009-09-19\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpRequest, CloseContentAndReturn.class); + assertResponseParserClassEquals(method, request, CloseContentAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpRequest); + checkFilters(request); } @Override - protected void checkFilters(GeneratedHttpRequest httpMethod) { - assertEquals(httpMethod.getFilters().size(), 1); - assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class); + protected void checkFilters(HttpRequest request) { + assertEquals(request.getFilters().size(), 1); + assertEquals(request.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class); } @Override diff --git a/blobstore/src/main/java/org/jclouds/blobstore/TransientAsyncBlobStore.java b/blobstore/src/main/java/org/jclouds/blobstore/TransientAsyncBlobStore.java index a908e421f4..af3b595f04 100755 --- a/blobstore/src/main/java/org/jclouds/blobstore/TransientAsyncBlobStore.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/TransientAsyncBlobStore.java @@ -111,8 +111,7 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore { ConcurrentMap containerToLocation, HttpGetOptionsListToGetOptions httpGetOptionsConverter, IfDirectoryReturnNameStrategy ifDirectoryReturnName, Blob.Factory blobFactory, - BlobUtils blobUtils, - @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, + BlobUtils blobUtils, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Location defaultLocation, Set locations) { super(context, blobUtils, service, defaultLocation, locations); this.blobFactory = blobFactory; @@ -446,12 +445,6 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore { return false; } - public void changeSchemeHostAndPortTo(String scheme, String host, int port) { - } - - public void changeToGETRequest() { - } - public Exception getException() { return null; } @@ -472,9 +465,6 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore { } - @Override - public void changePathTo(String newPath) { - } }, response); } diff --git a/boxdotnet/src/test/java/org/jclouds/boxdotnet/BoxDotNetAsyncClientTest.java b/boxdotnet/src/test/java/org/jclouds/boxdotnet/BoxDotNetAsyncClientTest.java index 6fa4dc2d78..ef9694ed8d 100644 --- a/boxdotnet/src/test/java/org/jclouds/boxdotnet/BoxDotNetAsyncClientTest.java +++ b/boxdotnet/src/test/java/org/jclouds/boxdotnet/BoxDotNetAsyncClientTest.java @@ -29,6 +29,7 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.lang.reflect.Method; +import org.jclouds.http.HttpRequest; import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.ReturnStringIf200; @@ -51,7 +52,6 @@ import com.google.inject.TypeLiteral; @Test(groups = "unit", testName = "boxdotnet.BoxDotNetAsyncClientTest") public class BoxDotNetAsyncClientTest extends RestClientTest { - public void testList() throws SecurityException, NoSuchMethodException, IOException { Method method = BoxDotNetAsyncClient.class.getMethod("list"); GeneratedHttpRequest httpRequest = processor.createRequest(method); @@ -66,7 +66,8 @@ public class BoxDotNetAsyncClientTest extends RestClientTest httpRequest = processor.createRequest( - method, 1); + GeneratedHttpRequest httpRequest = processor.createRequest(method, 1); assertRequestLineEquals(httpRequest, "DELETE https://www.box.net/api/1.0/rest/items/1 HTTP/1.1"); @@ -113,10 +113,11 @@ public class BoxDotNetAsyncClientTest extends RestClientTest httpRequest) { - assertEquals(httpRequest.getFilters().size(), 1); - assertEquals(httpRequest.getFilters().get(0).getClass(), BasicAuthentication.class); + protected void checkFilters(HttpRequest request) { + assertEquals(request.getFilters().size(), 1); + assertEquals(request.getFilters().get(0).getClass(), BasicAuthentication.class); } @Override @@ -127,7 +128,7 @@ public class BoxDotNetAsyncClientTest extends RestClientTest createContextSpec() { - return contextSpec("boxdotnet", "https://www.box.net/api/1.0/rest", "1.0", "identity", "credential", - BoxDotNetClient.class, BoxDotNetAsyncClient.class); + return contextSpec("boxdotnet", "https://www.box.net/api/1.0/rest", "1.0", "identity", + "credential", BoxDotNetClient.class, BoxDotNetAsyncClient.class); } } diff --git a/chef/src/main/java/org/jclouds/chef/filters/SignedHeaderAuth.java b/chef/src/main/java/org/jclouds/chef/filters/SignedHeaderAuth.java index 6350112436..bfb1a87929 100644 --- a/chef/src/main/java/org/jclouds/chef/filters/SignedHeaderAuth.java +++ b/chef/src/main/java/org/jclouds/chef/filters/SignedHeaderAuth.java @@ -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) { - 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:") .append(contentHash).append("\n").append("X-Ops-Timestamp:").append(timestamp) .append("\n").append("X-Ops-UserId:").append(userId).toString(); diff --git a/chef/src/test/java/org/jclouds/chef/ChefAsyncClientTest.java b/chef/src/test/java/org/jclouds/chef/ChefAsyncClientTest.java index 47304da292..d0b1ca62c2 100644 --- a/chef/src/test/java/org/jclouds/chef/ChefAsyncClientTest.java +++ b/chef/src/test/java/org/jclouds/chef/ChefAsyncClientTest.java @@ -39,6 +39,7 @@ import org.jclouds.chef.functions.ParseKeyFromJson; import org.jclouds.chef.functions.ParseKeySetFromJson; import org.jclouds.chef.functions.ParseSandboxFromJson; import org.jclouds.date.TimeStamp; +import org.jclouds.http.HttpRequest; import org.jclouds.http.RequiresHttp; import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.ReturnStringIf200; @@ -67,27 +68,22 @@ import com.google.inject.TypeLiteral; @Test(groups = "unit", testName = "chef.ChefAsyncClientTest") public class ChefAsyncClientTest extends RestClientTest { - public void testGetUploadUrisForContent() throws SecurityException, - NoSuchMethodException, IOException { - Method method = ChefAsyncClient.class.getMethod( - "getUploadUrisForContent", Set.class); - GeneratedHttpRequest httpRequest = processor - .createRequest(method, ImmutableSet.of( - "0189e76ccc476701d6b374e5a1a27347", - "0c5ecd7788cf4f6c7de2a57193897a6c", - "1dda05ed139664f1f89b9dec482b77c0")); + public void testGetUploadUrisForContent() throws SecurityException, NoSuchMethodException, + IOException { + Method method = ChefAsyncClient.class.getMethod("getUploadUrisForContent", Set.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, + ImmutableSet.of("0189e76ccc476701d6b374e5a1a27347", + "0c5ecd7788cf4f6c7de2a57193897a6c", "1dda05ed139664f1f89b9dec482b77c0")); - assertRequestLineEquals(httpRequest, - "POST http://localhost:4000/sandboxes HTTP/1.1"); + assertRequestLineEquals(httpRequest, "POST http://localhost:4000/sandboxes HTTP/1.1"); assertHeadersEqual( - httpRequest, - "Accept: application/json\nContent-Length: 135\nContent-Type: application/json\nX-Chef-Version: 0.9.0\n"); + httpRequest, + "Accept: application/json\nContent-Length: 135\nContent-Type: application/json\nX-Chef-Version: 0.9.0\n"); assertPayloadEquals( - httpRequest, - "{\"checksums\":{\"0189e76ccc476701d6b374e5a1a27347\":null,\"0c5ecd7788cf4f6c7de2a57193897a6c\":null,\"1dda05ed139664f1f89b9dec482b77c0\":null}}"); + httpRequest, + "{\"checksums\":{\"0189e76ccc476701d6b374e5a1a27347\":null,\"0c5ecd7788cf4f6c7de2a57193897a6c\":null,\"1dda05ed139664f1f89b9dec482b77c0\":null}}"); - assertResponseParserClassEquals(method, httpRequest, - ParseSandboxFromJson.class); + assertResponseParserClassEquals(method, httpRequest, ParseSandboxFromJson.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); @@ -95,20 +91,16 @@ public class ChefAsyncClientTest extends RestClientTest { } - public void testGetCookbook() throws SecurityException, - NoSuchMethodException, IOException { - Method method = ChefAsyncClient.class.getMethod("getCookbook", - String.class, String.class); - GeneratedHttpRequest httpRequest = processor - .createRequest(method, "cookbook", "1.0.0"); + public void testGetCookbook() throws SecurityException, NoSuchMethodException, IOException { + Method method = ChefAsyncClient.class.getMethod("getCookbook", String.class, String.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, + "cookbook", "1.0.0"); assertRequestLineEquals(httpRequest, - "GET http://localhost:4000/cookbooks/cookbook/1.0.0 HTTP/1.1"); - assertHeadersEqual(httpRequest, - "Accept: application/json\nX-Chef-Version: 0.9.0\n"); + "GET http://localhost:4000/cookbooks/cookbook/1.0.0 HTTP/1.1"); + assertHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.0\n"); assertPayloadEquals(httpRequest, null); - assertResponseParserClassEquals(method, httpRequest, - ParseCookbookFromJson.class); + assertResponseParserClassEquals(method, httpRequest, ParseCookbookFromJson.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); @@ -116,20 +108,16 @@ public class ChefAsyncClientTest extends RestClientTest { } - public void testDeleteCookbook() throws SecurityException, - NoSuchMethodException, IOException { - Method method = ChefAsyncClient.class.getMethod("deleteCookbook", - String.class, String.class); - GeneratedHttpRequest httpRequest = processor - .createRequest(method, "cookbook", "1.0.0"); + public void testDeleteCookbook() throws SecurityException, NoSuchMethodException, IOException { + Method method = ChefAsyncClient.class.getMethod("deleteCookbook", String.class, String.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, + "cookbook", "1.0.0"); assertRequestLineEquals(httpRequest, - "DELETE http://localhost:4000/cookbooks/cookbook/1.0.0 HTTP/1.1"); - assertHeadersEqual(httpRequest, - "Accept: application/json\nX-Chef-Version: 0.9.0\n"); + "DELETE http://localhost:4000/cookbooks/cookbook/1.0.0 HTTP/1.1"); + assertHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.0\n"); assertPayloadEquals(httpRequest, null); - assertResponseParserClassEquals(method, httpRequest, - CloseContentAndReturn.class); + assertResponseParserClassEquals(method, httpRequest, CloseContentAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class); @@ -137,24 +125,22 @@ public class ChefAsyncClientTest extends RestClientTest { } - public void testUpdateCookbook() throws SecurityException, - NoSuchMethodException, IOException { - Method method = ChefAsyncClient.class.getMethod("updateCookbook", - String.class, String.class, Cookbook.class); - GeneratedHttpRequest httpRequest = processor - .createRequest(method, "cookbook", "1.0.1", new Cookbook()); + public void testUpdateCookbook() throws SecurityException, NoSuchMethodException, IOException { + Method method = ChefAsyncClient.class.getMethod("updateCookbook", String.class, String.class, + Cookbook.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, + "cookbook", "1.0.1", new Cookbook()); 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"); assertHeadersEqual( - httpRequest, - "Accept: application/json\nContent-Length: 134\nContent-Type: application/json\nX-Chef-Version: 0.9.0\n"); + httpRequest, + "Accept: application/json\nContent-Length: 134\nContent-Type: application/json\nX-Chef-Version: 0.9.0\n"); assertPayloadEquals( - httpRequest, - "{\"definitions\":[],\"attributes\":[],\"files\":[],\"providers\":[],\"resources\":[],\"templates\":[],\"libraries\":[],\"recipes\":[],\"root_files\":[]}"); + httpRequest, + "{\"definitions\":[],\"attributes\":[],\"files\":[],\"providers\":[],\"resources\":[],\"templates\":[],\"libraries\":[],\"recipes\":[],\"root_files\":[]}"); - assertResponseParserClassEquals(method, httpRequest, - CloseContentAndReturn.class); + assertResponseParserClassEquals(method, httpRequest, CloseContentAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); @@ -162,20 +148,15 @@ public class ChefAsyncClientTest extends RestClientTest { } - public void testListCookbooks() throws SecurityException, - NoSuchMethodException, IOException { + public void testListCookbooks() throws SecurityException, NoSuchMethodException, IOException { Method method = ChefAsyncClient.class.getMethod("listCookbooks"); - GeneratedHttpRequest httpRequest = processor - .createRequest(method); + GeneratedHttpRequest httpRequest = processor.createRequest(method); - assertRequestLineEquals(httpRequest, - "GET http://localhost:4000/cookbooks HTTP/1.1"); - assertHeadersEqual(httpRequest, - "Accept: application/json\nX-Chef-Version: 0.9.0\n"); + assertRequestLineEquals(httpRequest, "GET http://localhost:4000/cookbooks HTTP/1.1"); + assertHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.0\n"); assertPayloadEquals(httpRequest, null); - assertResponseParserClassEquals(method, httpRequest, - ParseKeySetFromJson.class); + assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); @@ -183,20 +164,14 @@ public class ChefAsyncClientTest extends RestClientTest { } - public void testClientExists() throws SecurityException, - NoSuchMethodException, IOException { - Method method = ChefAsyncClient.class.getMethod("clientExists", - String.class); - GeneratedHttpRequest httpRequest = processor - .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"); + public void testClientExists() throws SecurityException, NoSuchMethodException, IOException { + Method method = ChefAsyncClient.class.getMethod("clientExists", String.class); + GeneratedHttpRequest httpRequest = processor.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); - assertResponseParserClassEquals(method, httpRequest, - ReturnTrueIf2xx.class); + assertResponseParserClassEquals(method, httpRequest, ReturnTrueIf2xx.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, ReturnFalseOnNotFoundOr404.class); @@ -204,20 +179,14 @@ public class ChefAsyncClientTest extends RestClientTest { } - public void testDeleteClient() throws SecurityException, - NoSuchMethodException, IOException { - Method method = ChefAsyncClient.class.getMethod("deleteClient", - String.class); - GeneratedHttpRequest httpRequest = processor - .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"); + public void testDeleteClient() throws SecurityException, NoSuchMethodException, IOException { + Method method = ChefAsyncClient.class.getMethod("deleteClient", String.class); + GeneratedHttpRequest httpRequest = processor.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); - assertResponseParserClassEquals(method, httpRequest, - ReturnStringIf200.class); + assertResponseParserClassEquals(method, httpRequest, ReturnStringIf200.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); @@ -225,22 +194,17 @@ public class ChefAsyncClientTest extends RestClientTest { } - public void testGenerateKeyForClient() throws SecurityException, - NoSuchMethodException, IOException { - Method method = ChefAsyncClient.class.getMethod("generateKeyForClient", - String.class); - GeneratedHttpRequest httpRequest = processor - .createRequest(method, "client"); - assertRequestLineEquals(httpRequest, - "PUT http://localhost:4000/clients/client HTTP/1.1"); + public void testGenerateKeyForClient() throws SecurityException, NoSuchMethodException, + IOException { + Method method = ChefAsyncClient.class.getMethod("generateKeyForClient", String.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, "client"); + assertRequestLineEquals(httpRequest, "PUT http://localhost:4000/clients/client HTTP/1.1"); assertHeadersEqual( - httpRequest, - "Accept: application/json\nContent-Length: 44\nContent-Type: application/json\nX-Chef-Version: 0.9.0\n"); - assertPayloadEquals(httpRequest, - "{\"clientname\":\"client\", \"private_key\": true}"); + httpRequest, + "Accept: application/json\nContent-Length: 44\nContent-Type: application/json\nX-Chef-Version: 0.9.0\n"); + assertPayloadEquals(httpRequest, "{\"clientname\":\"client\", \"private_key\": true}"); - assertResponseParserClassEquals(method, httpRequest, - ParseKeyFromJson.class); + assertResponseParserClassEquals(method, httpRequest, ParseKeyFromJson.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); @@ -248,22 +212,17 @@ public class ChefAsyncClientTest extends RestClientTest { } - public void testCreateClient() throws SecurityException, - NoSuchMethodException, IOException { - Method method = ChefAsyncClient.class.getMethod("createClient", - String.class); - GeneratedHttpRequest httpRequest = processor - .createRequest(method, "client"); + public void testCreateClient() throws SecurityException, NoSuchMethodException, IOException { + Method method = ChefAsyncClient.class.getMethod("createClient", String.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, "client"); - assertRequestLineEquals(httpRequest, - "POST http://localhost:4000/clients HTTP/1.1"); + assertRequestLineEquals(httpRequest, "POST http://localhost:4000/clients HTTP/1.1"); assertHeadersEqual( - httpRequest, - "Accept: application/json\nContent-Length: 23\nContent-Type: application/json\nX-Chef-Version: 0.9.0\n"); + httpRequest, + "Accept: application/json\nContent-Length: 23\nContent-Type: application/json\nX-Chef-Version: 0.9.0\n"); assertPayloadEquals(httpRequest, "{\"clientname\":\"client\"}"); - assertResponseParserClassEquals(method, httpRequest, - ParseKeyFromJson.class); + assertResponseParserClassEquals(method, httpRequest, ParseKeyFromJson.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); @@ -271,20 +230,15 @@ public class ChefAsyncClientTest extends RestClientTest { } - public void testListClients() throws SecurityException, - NoSuchMethodException, IOException { + public void testListClients() throws SecurityException, NoSuchMethodException, IOException { Method method = ChefAsyncClient.class.getMethod("listClients"); - GeneratedHttpRequest httpRequest = processor - .createRequest(method); + GeneratedHttpRequest httpRequest = processor.createRequest(method); - assertRequestLineEquals(httpRequest, - "GET http://localhost:4000/clients HTTP/1.1"); - assertHeadersEqual(httpRequest, - "Accept: application/json\nX-Chef-Version: 0.9.0\n"); + assertRequestLineEquals(httpRequest, "GET http://localhost:4000/clients HTTP/1.1"); + assertHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.0\n"); assertPayloadEquals(httpRequest, null); - assertResponseParserClassEquals(method, httpRequest, - ParseKeySetFromJson.class); + assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); @@ -293,10 +247,9 @@ public class ChefAsyncClientTest extends RestClientTest { } @Override - protected void checkFilters(GeneratedHttpRequest httpRequest) { - assertEquals(httpRequest.getFilters().size(), 1); - assertEquals(httpRequest.getFilters().get(0).getClass(), - SignedHeaderAuth.class); + protected void checkFilters(HttpRequest request) { + assertEquals(request.getFilters().size(), 1); + assertEquals(request.getFilters().get(0).getClass(), SignedHeaderAuth.class); } @Override @@ -323,6 +276,6 @@ public class ChefAsyncClientTest extends RestClientTest { @Override public ContextSpec createContextSpec() { return new RestContextFactory().createContextSpec("chef", "user", - SignedHeaderAuthTest.PRIVATE_KEY, new Properties()); + SignedHeaderAuthTest.PRIVATE_KEY, new Properties()); } } diff --git a/chef/src/test/java/org/jclouds/chef/ChefClientLiveTest.java b/chef/src/test/java/org/jclouds/chef/ChefClientLiveTest.java index 51b8654d76..858b72f386 100644 --- a/chef/src/test/java/org/jclouds/chef/ChefClientLiveTest.java +++ b/chef/src/test/java/org/jclouds/chef/ChefClientLiveTest.java @@ -32,14 +32,17 @@ import java.util.Properties; import java.util.Set; import org.jclouds.chef.domain.Cookbook; +import org.jclouds.chef.domain.Resource; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContextFactory; +import org.jclouds.util.Utils; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.base.Charsets; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.io.Files; import com.google.inject.Module; @@ -52,8 +55,6 @@ import com.google.inject.Module; @Test(groups = "live", testName = "chef.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 validatorConnection; private RestContext clientConnection; private RestContext adminConnection; @@ -62,48 +63,40 @@ public class ChefClientLiveTest { private String endpoint; private String validator; private String user; - private byte[] cookbookContent; - private File cookbookFile; - public static final String PREFIX = System.getProperty("user.name") - + "-jcloudstest"; + public static final String PREFIX = System.getProperty("user.name") + "-jcloudstest"; @BeforeClass(groups = { "live" }) public void setupClient() throws IOException { - endpoint = checkNotNull(System.getProperty("jclouds.test.endpoint"), - "jclouds.test.endpoint"); + endpoint = checkNotNull(System.getProperty("jclouds.test.endpoint"), "jclouds.test.endpoint"); validator = System.getProperty("jclouds.test.validator"); if (validator == null || validator.equals("")) validator = "chef-validator"; String validatorKey = System.getProperty("jclouds.test.validator.key"); if (validatorKey == null || validatorKey.equals("")) - validatorKey = System.getProperty("user.home") - + "/.chef/validation.pem"; - user = checkNotNull(System.getProperty("jclouds.test.identity"), - "jclouds.test.identity"); + validatorKey = System.getProperty("user.home") + "/.chef/validation.pem"; + user = checkNotNull(System.getProperty("jclouds.test.identity"), "jclouds.test.identity"); String keyfile = System.getProperty("jclouds.test.credential"); if (keyfile == null || keyfile.equals("")) keyfile = System.getProperty("user.home") + "/.chef/" + user + ".pem"; - validatorConnection = createConnection(validator, Files.toString( - new File(validatorKey), Charsets.UTF_8)); - adminConnection = createConnection(user, Files.toString( - new File(keyfile), Charsets.UTF_8)); + validatorConnection = createConnection(validator, Files.toString(new File(validatorKey), + Charsets.UTF_8)); + adminConnection = createConnection(user, Files.toString(new File(keyfile), Charsets.UTF_8)); } - private RestContext createConnection( - String identity, String key) throws IOException { + private RestContext createConnection(String identity, String key) + throws IOException { Properties props = new Properties(); props.setProperty("chef.endpoint", endpoint); - return new RestContextFactory().createContext("chef", identity, key, - ImmutableSet. of(new Log4JLoggingModule()), props); + return new RestContextFactory().createContext("chef", identity, key, ImmutableSet + . of(new Log4JLoggingModule()), props); } @Test public void testListClients() throws Exception { Set clients = validatorConnection.getApi().listClients(); assertNotNull(clients); - assert clients.contains(validator) : "validator: " + validator - + " not in: " + clients; + assert clients.contains(validator) : "validator: " + validator + " not in: " + clients; } @Test(dependsOnMethods = "testListClients") @@ -133,22 +126,30 @@ public class ChefClientLiveTest { @Test public void testListCookbooks() throws Exception { for (String cookbook : adminConnection.getApi().listCookbooks()) - for (String version : adminConnection.getApi().getVersionsOfCookbook( - cookbook)) { + for (String version : adminConnection.getApi().getVersionsOfCookbook(cookbook)) { System.err.printf("%s/%s:%n", cookbook, version); - System.err.printf("%s%n", adminConnection.getApi().getCookbook( - cookbook, version)); + Cookbook cookbookO = adminConnection.getApi().getCookbook(cookbook, version); + for (Resource resource : ImmutableList. 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") public void testUpdateCookbook() throws Exception { for (String cookbook : adminConnection.getApi().listCookbooks()) - for (String version : adminConnection.getApi().getVersionsOfCookbook( - cookbook)) { + for (String version : adminConnection.getApi().getVersionsOfCookbook(cookbook)) { System.err.printf("%s/%s:%n", cookbook, version); - Cookbook cook = adminConnection.getApi().getCookbook(cookbook, - version); + Cookbook cook = adminConnection.getApi().getCookbook(cookbook, version); adminConnection.getApi().updateCookbook(cookbook, version, cook); } @@ -157,14 +158,12 @@ public class ChefClientLiveTest { @Test(dependsOnMethods = "testUpdateCookbook") public void testCreateCookbook() throws Exception { for (String cookbook : adminConnection.getApi().listCookbooks()) - for (String version : adminConnection.getApi().getVersionsOfCookbook( - cookbook)) { + for (String version : adminConnection.getApi().getVersionsOfCookbook(cookbook)) { System.err.printf("%s/%s:%n", cookbook, version); - Cookbook cook = adminConnection.getApi().getCookbook(cookbook, - version); + Cookbook cook = adminConnection.getApi().getCookbook(cookbook, version); adminConnection.getApi().deleteCookbook(cookbook, version); assert adminConnection.getApi().getCookbook(cookbook, version) == null : cookbook - + version; + + version; adminConnection.getApi().updateCookbook(cookbook, version, cook); } diff --git a/core/src/main/java/org/jclouds/http/HttpCommand.java b/core/src/main/java/org/jclouds/http/HttpCommand.java index c926968ce7..f90902f3ca 100644 --- a/core/src/main/java/org/jclouds/http/HttpCommand.java +++ b/core/src/main/java/org/jclouds/http/HttpCommand.java @@ -45,23 +45,6 @@ public interface HttpCommand { */ 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. * diff --git a/core/src/main/java/org/jclouds/http/HttpRequest.java b/core/src/main/java/org/jclouds/http/HttpRequest.java index 3e368359f4..3528a1df2d 100644 --- a/core/src/main/java/org/jclouds/http/HttpRequest.java +++ b/core/src/main/java/org/jclouds/http/HttpRequest.java @@ -24,6 +24,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.io.File; import java.io.InputStream; import java.net.URI; +import java.util.Arrays; import java.util.List; import javax.ws.rs.core.HttpHeaders; @@ -44,6 +45,7 @@ public class HttpRequest extends HttpMessage { private String method; private URI endpoint; 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 */ 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.setEndpoint(checkNotNull(endpoint, "endpoint")); checkArgument(endpoint.getHost() != null, String.format("endpoint.getHost() is null for %s", 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() { return endpoint; } @@ -167,11 +185,12 @@ public class HttpRequest extends HttpMessage { @Override public int hashCode() { final int prime = 31; - int result = 1; + int result = super.hashCode(); result = prime * result + ((endpoint == null) ? 0 : endpoint.hashCode()); result = prime * result + ((method == null) ? 0 : method.hashCode()); result = prime * result + ((payload == null) ? 0 : payload.hashCode()); result = prime * result + ((requestFilters == null) ? 0 : requestFilters.hashCode()); + result = prime * result + Arrays.hashCode(skips); return result; } @@ -179,7 +198,7 @@ public class HttpRequest extends HttpMessage { public boolean equals(Object obj) { if (this == obj) return true; - if (obj == null) + if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; @@ -204,12 +223,14 @@ public class HttpRequest extends HttpMessage { return false; } else if (!requestFilters.equals(other.requestFilters)) return false; + if (!Arrays.equals(skips, other.skips)) + return false; return true; } @Override public String toString() { - return "[method=" + method + ", endpoint=" + endpoint + ", headers=" + headers - + "]"; + return "[method=" + method + ", endpoint=" + endpoint + ", headers=" + headers + "]"; } + } diff --git a/core/src/main/java/org/jclouds/http/HttpUtils.java b/core/src/main/java/org/jclouds/http/HttpUtils.java index 2582307a7a..0172c25206 100644 --- a/core/src/main/java/org/jclouds/http/HttpUtils.java +++ b/core/src/main/java/org/jclouds/http/HttpUtils.java @@ -19,6 +19,8 @@ package org.jclouds.http; 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.PATTERN_THAT_BREAKS_URI; import static org.jclouds.util.Patterns.PLUS_PATTERN; @@ -35,11 +37,21 @@ import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URLDecoder; import java.net.URLEncoder; +import java.util.Collection; +import java.util.Comparator; +import java.util.Iterator; import java.util.List; +import java.util.Map; +import java.util.SortedSet; import java.util.Map.Entry; import java.util.regex.Matcher; +import javax.annotation.Nullable; 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.logging.Logger; @@ -48,17 +60,20 @@ import org.jclouds.util.Utils; import com.google.common.base.Joiner; import com.google.common.base.Splitter; 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.Multimap; +import com.google.common.collect.Sets; import com.google.common.collect.SortedSetMultimap; import com.google.common.collect.TreeMultimap; -import com.google.common.io.ByteStreams; import com.google.common.io.Closeables; import com.google.inject.Inject; /** * @author Adrian Cole */ +@Singleton public class HttpUtils { @Inject(optional = true) @Named(Constants.PROPERTY_RELAX_HOSTNAME) @@ -201,7 +216,7 @@ public class HttpUtils { public static void consumeContent(HttpResponse response) { if (response.getContent() != null) { try { - ByteStreams.toByteArray(response.getContent()); + toByteArray(response.getContent()); } catch (IOException e) { Throwables.propagate(e); } finally { @@ -216,7 +231,7 @@ public class HttpUtils { public static byte[] closeClientButKeepContentStream(HttpResponse response) { if (response.getContent() != null) { try { - byte[] data = ByteStreams.toByteArray(response.getContent()); + byte[] data = toByteArray(response.getContent()); response.setContent(new ByteArrayInputStream(data)); return data; } 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 * 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 - * are curly braces. + * class, and we could simply use URI.create("uri").getUserData(); Also, URI breaks if there are + * curly braces. * */ public static URI createUri(String uriPath) { List onQuery = Lists.newArrayList(Splitter.on('?').split(uriPath)); - if (onQuery.size() == 2){ - onQuery.add(urlEncode(onQuery.remove(1), '=','&')); + if (onQuery.size() == 2) { + onQuery.add(urlEncode(onQuery.remove(1), '=', '&')); uriPath = Joiner.on('?').join(onQuery); } if (uriPath.indexOf('@') != 1) { @@ -274,7 +289,7 @@ public class HttpUtils { parts.add(urlEncode(path, ':')); uriPath = Joiner.on('/').join(parts); } - + if (PATTERN_THAT_BREAKS_URI.matcher(uriPath).matches()) { // Compile and use regular expression Matcher matcher = URI_PATTERN.matcher(uriPath); @@ -341,4 +356,132 @@ public class HttpUtils { 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. 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 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. of(value)); + + } + + public static void addFormParamTo(HttpRequest request, String key, Iterable values) { + Multimap map = parseQueryToMap(request.getPayload().toString()); + for (Object o : values) + map.put(key, o.toString()); + request.setPayload(makeQueryLine(map, null)); + } + + public static Multimap parseQueryToMap(String in) { + Multimap 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 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> sortEntries( + Collection> in, Comparator> sorter) { + SortedSet> entries = Sets.newTreeSet(sorter); + entries.addAll(in); + return entries; + } + + public static String makeQueryLine(Multimap params, + @Nullable Comparator> sorter, char... skips) { + + Iterator> pairs = ((sorter == null) ? params.entries() + : sortEntries(params.entries(), sorter)).iterator(); + StringBuilder formBuilder = new StringBuilder(); + while (pairs.hasNext()) { + Map.Entry 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(); + } } diff --git a/core/src/main/java/org/jclouds/http/TransformingHttpCommandImpl.java b/core/src/main/java/org/jclouds/http/TransformingHttpCommandImpl.java index 514f896d54..8453d804a4 100644 --- a/core/src/main/java/org/jclouds/http/TransformingHttpCommandImpl.java +++ b/core/src/main/java/org/jclouds/http/TransformingHttpCommandImpl.java @@ -18,18 +18,12 @@ */ package org.jclouds.http; -import java.util.Collections; import java.util.concurrent.ExecutionException; import javax.annotation.Resource; 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.rest.internal.GeneratedHttpRequest; import com.google.common.base.Function; import com.google.common.util.concurrent.ListenableFuture; @@ -46,9 +40,8 @@ public class TransformingHttpCommandImpl implements TransformingHttpCommand transformer; - private final Provider uriBuilderProvider; - private GeneratedHttpRequest request; + private HttpRequest request; private volatile int failureCount; @Resource @@ -58,10 +51,8 @@ public class TransformingHttpCommandImpl implements TransformingHttpCommand uriBuilderProvider, - TransformingHttpCommandExecutorService executorService, - GeneratedHttpRequest request, Function transformer) { - this.uriBuilderProvider = uriBuilderProvider; + public TransformingHttpCommandImpl(TransformingHttpCommandExecutorService executorService, + HttpRequest request, Function transformer) { this.request = request; this.executorService = executorService; this.transformer = transformer; @@ -82,30 +73,6 @@ public class TransformingHttpCommandImpl implements TransformingHttpCommand - * 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) { this.exception = exception; } @@ -130,11 +97,6 @@ public class TransformingHttpCommandImpl implements TransformingHttpCommand uriBuilderProvider) { - BackoffLimitedRetryHandler backOff = new BackoffLimitedRetryHandler(); + public DelegatingRetryHandler(BackoffLimitedRetryHandler backOff, + RedirectionRetryHandler redirectionRetryHandler) { this.serverErrorRetryHandler = backOff; - this.redirectionRetryHandler = new RedirectionRetryHandler(uriBuilderProvider, backOff); + this.redirectionRetryHandler = redirectionRetryHandler; this.clientErrorRetryHandler = HttpRetryHandler.NEVER_RETRY; } diff --git a/core/src/main/java/org/jclouds/http/handlers/RedirectionRetryHandler.java b/core/src/main/java/org/jclouds/http/handlers/RedirectionRetryHandler.java index 6409514227..08f6ff05d7 100644 --- a/core/src/main/java/org/jclouds/http/handlers/RedirectionRetryHandler.java +++ b/core/src/main/java/org/jclouds/http/handlers/RedirectionRetryHandler.java @@ -18,6 +18,9 @@ */ 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.IOException; import java.net.URI; @@ -25,6 +28,7 @@ import java.net.URI; import javax.annotation.Resource; import javax.inject.Named; import javax.inject.Provider; +import javax.inject.Singleton; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.UriBuilder; @@ -44,6 +48,7 @@ import com.google.inject.Inject; * * @author Adrian Cole */ +@Singleton public class RedirectionRetryHandler implements HttpRetryHandler { @Inject(optional = true) @Named(Constants.PROPERTY_MAX_REDIRECTS) @@ -53,10 +58,10 @@ public class RedirectionRetryHandler implements HttpRetryHandler { protected Logger logger = Logger.NULL; protected final BackoffLimitedRetryHandler backoffHandler; - private final Provider uriBuilderProvider; + protected final Provider uriBuilderProvider; @Inject - public RedirectionRetryHandler(Provider uriBuilderProvider, + protected RedirectionRetryHandler(Provider uriBuilderProvider, BackoffLimitedRetryHandler backoffHandler) { this.backoffHandler = backoffHandler; this.uriBuilderProvider = uriBuilderProvider; @@ -72,13 +77,14 @@ public class RedirectionRetryHandler implements HttpRetryHandler { && redirectionUrl.getHost().equals(command.getRequest().getEndpoint().getHost()) && redirectionUrl.getPort() == command.getRequest().getEndpoint().getPort()) { if (!redirectionUrl.getPath().equals(command.getRequest().getEndpoint().getPath())) { - command.changePathTo(redirectionUrl.getPath()); + changePathTo(command.getRequest(), redirectionUrl.getPath(), uriBuilderProvider + .get()); } else { return backoffHandler.shouldRetryRequest(command, response); } } else { - command.changeSchemeHostAndPortTo(redirectionUrl.getScheme(), redirectionUrl.getHost(), - redirectionUrl.getPort()); + changeSchemeHostAndPortTo(command.getRequest(), redirectionUrl.getScheme(), + redirectionUrl.getHost(), redirectionUrl.getPort(), uriBuilderProvider.get()); } return true; } else { diff --git a/core/src/main/java/org/jclouds/rest/binders/BindMapToMatrixParams.java b/core/src/main/java/org/jclouds/rest/binders/BindMapToMatrixParams.java index 7a671f4e10..a297c32098 100644 --- a/core/src/main/java/org/jclouds/rest/binders/BindMapToMatrixParams.java +++ b/core/src/main/java/org/jclouds/rest/binders/BindMapToMatrixParams.java @@ -20,31 +20,38 @@ package org.jclouds.rest.binders; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.http.HttpUtils.replaceMatrixParam; import java.util.Map; 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.rest.Binder; -import org.jclouds.rest.internal.GeneratedHttpRequest; /** * Binds the map to matrix parameters. * * @author Adrian Cole - * @since 4.0 */ public class BindMapToMatrixParams implements Binder { + private final Provider builder; + + @Inject + BindMapToMatrixParams(Provider builder) { + this.builder = builder; + } @SuppressWarnings("unchecked") 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, "this binder is only valid for Maps!"); Map map = (Map) input; for (Entry entry : map.entrySet()) { - ((GeneratedHttpRequest) request).replaceMatrixParam(entry.getKey(), entry.getValue()); + replaceMatrixParam(request, entry.getKey(), entry.getValue(), builder.get()); } } diff --git a/core/src/main/java/org/jclouds/rest/config/RestModule.java b/core/src/main/java/org/jclouds/rest/config/RestModule.java index 79ddcbee5d..0fbe551c09 100755 --- a/core/src/main/java/org/jclouds/rest/config/RestModule.java +++ b/core/src/main/java/org/jclouds/rest/config/RestModule.java @@ -22,11 +22,11 @@ import java.util.concurrent.ConcurrentMap; import javax.inject.Inject; import javax.inject.Named; -import javax.inject.Provider; import javax.inject.Singleton; import javax.ws.rs.core.UriBuilder; import org.jboss.resteasy.specimpl.UriBuilderImpl; +import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.http.TransformingHttpCommand; import org.jclouds.http.TransformingHttpCommandExecutorService; @@ -37,7 +37,6 @@ import org.jclouds.rest.AsyncClientFactory; import org.jclouds.rest.HttpAsyncClient; import org.jclouds.rest.HttpClient; import org.jclouds.rest.internal.AsyncRestClientProxy; -import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import com.google.common.base.Function; @@ -109,14 +108,11 @@ public class RestModule extends AbstractModule { private static class Factory implements AsyncRestClientProxy.Factory { @Inject private TransformingHttpCommandExecutorService executorService; - @Inject - private Provider uriBuilderProvider; @SuppressWarnings("unchecked") - public TransformingHttpCommand create(GeneratedHttpRequest request, + public TransformingHttpCommand create(HttpRequest request, Function transformer) { - return new TransformingHttpCommandImpl(uriBuilderProvider, executorService, request, - transformer); + return new TransformingHttpCommandImpl(executorService, request, transformer); } } diff --git a/core/src/main/java/org/jclouds/rest/internal/AsyncRestClientProxy.java b/core/src/main/java/org/jclouds/rest/internal/AsyncRestClientProxy.java index 987e1ef500..74a7ee9cb4 100755 --- a/core/src/main/java/org/jclouds/rest/internal/AsyncRestClientProxy.java +++ b/core/src/main/java/org/jclouds/rest/internal/AsyncRestClientProxy.java @@ -34,6 +34,7 @@ import javax.inject.Singleton; import org.jclouds.Constants; import org.jclouds.concurrent.FutureExceptionParser; +import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.http.TransformingHttpCommand; import org.jclouds.internal.ClassMethodArgs; @@ -107,11 +108,11 @@ public class AsyncRestClientProxy implements InvocationHandler { if (exceptionParser instanceof InvocationContext) { ((InvocationContext) exceptionParser).setContext(null); } - GeneratedHttpRequest request; + HttpRequest request; try { request = annotationProcessor.createRequest(method, args); if (exceptionParser instanceof InvocationContext) { - ((InvocationContext) exceptionParser).setContext(request); + ((InvocationContext) exceptionParser).setContext((GeneratedHttpRequest) request); } } catch (RuntimeException e) { if (exceptionParser != null) { @@ -143,7 +144,7 @@ public class AsyncRestClientProxy implements InvocationHandler { } public static interface Factory { - public TransformingHttpCommand create(GeneratedHttpRequest request, + public TransformingHttpCommand create(HttpRequest request, Function transformer); } diff --git a/core/src/main/java/org/jclouds/rest/internal/GeneratedHttpRequest.java b/core/src/main/java/org/jclouds/rest/internal/GeneratedHttpRequest.java index 6373ecc821..8af7975674 100644 --- a/core/src/main/java/org/jclouds/rest/internal/GeneratedHttpRequest.java +++ b/core/src/main/java/org/jclouds/rest/internal/GeneratedHttpRequest.java @@ -20,17 +20,9 @@ package org.jclouds.rest.internal; import java.lang.reflect.Method; 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 com.google.inject.internal.Nullable; - /** * Represents a request generated from annotations * @@ -40,15 +32,15 @@ public class GeneratedHttpRequest extends HttpRequest { private final Class declaring; private final Method javaMethod; private final Object[] args; - private final RestAnnotationProcessor processor; - private final Provider uriBuilderProvider; - GeneratedHttpRequest(Provider uriBuilderProvider, String method, URI endpoint, - RestAnnotationProcessor processor, Class declaring, Method javaMethod, + GeneratedHttpRequest(String method, URI endpoint, Class declaring, Method javaMethod, Object... args) { - super(method, endpoint); - this.uriBuilderProvider = uriBuilderProvider; - this.processor = processor; + this(method, endpoint, new char[] {}, declaring, javaMethod, args); + } + + GeneratedHttpRequest(String method, URI endpoint, char[] skips, Class declaring, + Method javaMethod, Object... args) { + super(method, endpoint, skips); this.declaring = declaring; this.javaMethod = javaMethod; this.args = args; @@ -66,73 +58,4 @@ public class GeneratedHttpRequest extends HttpRequest { return args; } - public RestAnnotationProcessor 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> 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; - } } diff --git a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java index 676a2023ef..641fa45f96 100755 --- a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java +++ b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java @@ -20,6 +20,8 @@ package org.jclouds.rest.internal; import static com.google.common.base.Preconditions.checkArgument; 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 java.io.InputStream; @@ -32,11 +34,9 @@ import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.SortedSet; import java.util.Map.Entry; import javax.annotation.Nullable; @@ -224,9 +224,9 @@ public class RestAnnotationProcessor { @Inject private InputParamValidator inputParamValidator; + @SuppressWarnings("unchecked") @VisibleForTesting - public Function createResponseParser(Method method, - GeneratedHttpRequest request) { + public Function createResponseParser(Method method, HttpRequest request) { Function transformer; Class> handler = getSaxResponseParserClassOrNull(method); if (handler != null) { @@ -235,7 +235,7 @@ public class RestAnnotationProcessor { transformer = injector.getInstance(getParserOrThrowException(method)); } if (transformer instanceof InvocationContext) { - ((InvocationContext) transformer).setContext(request); + ((InvocationContext) transformer).setContext((GeneratedHttpRequest) request); } return transformer; } @@ -421,8 +421,8 @@ public class RestAnnotationProcessor { throw new IllegalStateException(e); } - GeneratedHttpRequest request = new GeneratedHttpRequest(uriBuilderProvider, httpMethod, - endpoint, this, declaring, method, args); + GeneratedHttpRequest request = new GeneratedHttpRequest(httpMethod, endpoint, skips, + declaring, method, args); addHostHeaderIfAnnotatedWithVirtualHost(headers, request.getEndpoint().getHost(), method); addFiltersIfAnnotated(method, request); @@ -488,83 +488,6 @@ public class RestAnnotationProcessor { return builder.build(); } - public URI addQueryParam(URI in, String key, String[] values) { - return addQueryParam(uriBuilderProvider, in, key, values, skips); - } - - public static URI addQueryParam(Provider uriBuilderProvider, URI in, String key, - String[] values, char... skips) { - UriBuilder builder = uriBuilderProvider.get().uri(in); - Multimap 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 map = parseQueryToMap(in); - map.putAll(key, Arrays.asList(values)); - return makeQueryLine(map, null, skips); - } - - public static Multimap parseQueryToMap(String in) { - Multimap 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 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> sortEntries( - Collection> in, Comparator> sorter) { - SortedSet> entries = Sets.newTreeSet(sorter); - entries.addAll(in); - return entries; - } - - public static String makeQueryLine(Multimap params, - @Nullable Comparator> sorter, char... skips) { - - Iterator> pairs = ((sorter == null) ? params.entries() - : sortEntries(params.entries(), sorter)).iterator(); - StringBuilder formBuilder = new StringBuilder(); - while (pairs.hasNext()) { - Map.Entry 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> tokenValues, Method method, Object... args) { if (declaring.isAnnotationPresent(MatrixParams.class)) { @@ -819,13 +742,13 @@ public class RestAnnotationProcessor { } public String getHttpMethodOrConstantOrThrowException(Method method) { - Set httpMethods = IsHttpMethod.getHttpMethods(method); - if (httpMethods == null || httpMethods.size() != 1) { + Set requests = IsHttpMethod.getHttpMethods(method); + if (requests == null || requests.size() != 1) { throw new IllegalStateException( "You must use at least one, but no more than one http method or pathparam annotation on: " + method.toString()); } - return httpMethods.iterator().next(); + return requests.iterator().next(); } public void addHostHeaderIfAnnotatedWithVirtualHost(Multimap headers, diff --git a/core/src/test/java/org/jclouds/http/TransformingHttpCommandImplTest.java b/core/src/test/java/org/jclouds/http/TransformingHttpCommandImplTest.java index 3f25e6f68d..66e5149e3a 100644 --- a/core/src/test/java/org/jclouds/http/TransformingHttpCommandImplTest.java +++ b/core/src/test/java/org/jclouds/http/TransformingHttpCommandImplTest.java @@ -18,53 +18,13 @@ */ 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 com.google.common.collect.HashMultimap; -import com.google.common.collect.Multimap; - /** * * @author Adrian Cole */ public class TransformingHttpCommandImplTest { - Provider uriBuilderProvider = new Provider() { - - @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 headers = HashMultimap.create(); - expect(request.getHeaders()).andReturn(headers); - replay(request); - command.changeSchemeHostAndPortTo("https", "remotehost", 443); - assertEquals(headers.get(HttpHeaders.HOST), Collections.singletonList("remotehost")); - } @Test public void testTransformingHttpCommandImpl() { diff --git a/core/src/test/java/org/jclouds/http/handlers/BackoffLimitedRetryHandlerTest.java b/core/src/test/java/org/jclouds/http/handlers/BackoffLimitedRetryHandlerTest.java index 1ce815d806..071ffc055c 100644 --- a/core/src/test/java/org/jclouds/http/handlers/BackoffLimitedRetryHandlerTest.java +++ b/core/src/test/java/org/jclouds/http/handlers/BackoffLimitedRetryHandlerTest.java @@ -98,14 +98,18 @@ public class BackoffLimitedRetryHandlerTest { } }; + private HttpUtils utils; @BeforeTest void setupExecutorService() throws Exception { 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( - execService, new DelegatingRetryHandler(uriBuilderProvider), + execService, new DelegatingRetryHandler(backoff, retry), new BackoffLimitedRetryHandler(), new DelegatingErrorHandler(), new HttpWire(), - new HttpUtils(0, 500, 1, 1), null); + utils, null); executorService = new TransformingHttpCommandExecutorServiceImpl(httpService); } @@ -161,8 +165,8 @@ public class BackoffLimitedRetryHandlerTest { private HttpCommand createCommand() throws SecurityException, NoSuchMethodException { Method method = IntegrationTestAsyncClient.class.getMethod("download", String.class); - return new TransformingHttpCommandImpl(uriBuilderProvider, executorService, processor - .createRequest(method, "1"), new ReturnStringIf200()); + return new TransformingHttpCommandImpl(executorService, processor.createRequest( + method, "1"), new ReturnStringIf200()); } @Test diff --git a/core/src/test/java/org/jclouds/rest/RestClientTest.java b/core/src/test/java/org/jclouds/rest/RestClientTest.java index a25044f640..1a01dca2d2 100644 --- a/core/src/test/java/org/jclouds/rest/RestClientTest.java +++ b/core/src/test/java/org/jclouds/rest/RestClientTest.java @@ -29,13 +29,13 @@ import java.lang.reflect.Method; import org.jclouds.concurrent.config.ConfiguresExecutorService; import org.jclouds.concurrent.config.ExecutorServiceModule; +import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpUtils; import org.jclouds.http.TransformingHttpCommandExecutorService; import org.jclouds.http.config.ConfiguresHttpCommandExecutorService; import org.jclouds.logging.config.NullLoggingModule; import org.jclouds.rest.RestContextFactory.ContextSpec; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; -import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.util.Utils; import org.testng.annotations.BeforeClass; @@ -66,7 +66,7 @@ public abstract class RestClientTest { protected Injector injector; - protected abstract void checkFilters(GeneratedHttpRequest httpMethod); + protected abstract void checkFilters(HttpRequest request); protected abstract TypeLiteral> createTypeLiteral(); @@ -101,22 +101,21 @@ public abstract class RestClientTest { } } - protected void assertPayloadEquals(GeneratedHttpRequest httpMethod, String toMatch) - throws IOException { - if (httpMethod.getPayload() == null) { + protected void assertPayloadEquals(HttpRequest request, String toMatch) throws IOException { + if (request.getPayload() == null) { assertNull(toMatch); } else { - String payload = Utils.toStringAndClose(httpMethod.getPayload().getInput()); + String payload = Utils.toStringAndClose(request.getPayload().getInput()); assertEquals(payload, toMatch); } } - protected void assertHeadersEqual(GeneratedHttpRequest httpMethod, String toMatch) { - assertEquals(HttpUtils.sortAndConcatHeadersIntoString(httpMethod.getHeaders()), toMatch); + protected void assertHeadersEqual(HttpRequest request, String toMatch) { + assertEquals(HttpUtils.sortAndConcatHeadersIntoString(request.getHeaders()), toMatch); } - protected void assertRequestLineEquals(GeneratedHttpRequest httpMethod, String toMatch) { - assertEquals(httpMethod.getRequestLine(), toMatch); + protected void assertRequestLineEquals(HttpRequest request, String toMatch) { + assertEquals(request.getRequestLine(), toMatch); } protected void assertExceptionParserClassEquals(Method method, @Nullable Class parserClass) { @@ -133,8 +132,8 @@ public abstract class RestClientTest { } protected void assertResponseParserClassEquals(Method method, - GeneratedHttpRequest httpMethod, @Nullable Class parserClass) { - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), parserClass); + HttpRequest request, @Nullable Class parserClass) { + assertEquals(processor.createResponseParser(method, request).getClass(), parserClass); } } \ No newline at end of file diff --git a/core/src/test/java/org/jclouds/rest/binders/BindMapToMatrixParamsTest.java b/core/src/test/java/org/jclouds/rest/binders/BindMapToMatrixParamsTest.java index 5f1a4f8f24..a0d7aa5ee0 100644 --- a/core/src/test/java/org/jclouds/rest/binders/BindMapToMatrixParamsTest.java +++ b/core/src/test/java/org/jclouds/rest/binders/BindMapToMatrixParamsTest.java @@ -18,14 +18,19 @@ */ package org.jclouds.rest.binders; +import static org.easymock.EasyMock.expect; import static org.easymock.classextension.EasyMock.createMock; import static org.easymock.classextension.EasyMock.replay; +import static org.easymock.classextension.EasyMock.verify; import java.io.File; import java.net.URI; +import javax.inject.Provider; 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.rest.internal.GeneratedHttpRequest; import org.testng.annotations.Test; @@ -40,27 +45,41 @@ import com.google.common.collect.ImmutableMap; @Test(groups = "unit", testName = "rest.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() { + + @Override + public UriBuilder get() { + return new UriBuilderImpl(); + } + + }); + + binder.bindToRequest(request, ImmutableMap.of("imageName", "foo", "serverId", "2")); + + verify(request); + + } + @Test(expectedExceptions = IllegalArgumentException.class) public void testMustBeMap() { - BindMapToMatrixParams binder = new BindMapToMatrixParams(); + BindMapToMatrixParams binder = new BindMapToMatrixParams(null); HttpRequest request = new HttpRequest(HttpMethod.POST, URI.create("http://localhost")); 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 }) public void testNullIsBad() { - BindMapToMatrixParams binder = new BindMapToMatrixParams(); + BindMapToMatrixParams binder = new BindMapToMatrixParams(null); GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); binder.bindToRequest(request, null); } diff --git a/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java b/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java index 9a5b0a62bd..48e09f0326 100755 --- a/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java +++ b/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java @@ -130,9 +130,7 @@ import com.google.common.base.Function; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; import com.google.common.collect.LinkedHashMultimap; -import com.google.common.collect.LinkedListMultimap; import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; import com.google.common.io.Files; @@ -399,34 +397,34 @@ public class RestAnnotationProcessorTest { public void testQuery() throws SecurityException, NoSuchMethodException { Method method = TestQuery.class.getMethod("foo"); - GeneratedHttpRequest httpMethod = factory(TestQuery.class).createRequest(method, + HttpRequest request = factory(TestQuery.class).createRequest(method, new Object[] {}); - assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); - assertEquals(httpMethod.getEndpoint().getPath(), ""); - assertEquals(httpMethod.getEndpoint().getQuery(), "x-ms-version=2009-07-17&x-ms-rubbish=bin"); - assertEquals(httpMethod.getMethod(), "FOO"); + assertEquals(request.getEndpoint().getHost(), "localhost"); + assertEquals(request.getEndpoint().getPath(), ""); + assertEquals(request.getEndpoint().getQuery(), "x-ms-version=2009-07-17&x-ms-rubbish=bin"); + assertEquals(request.getMethod(), "FOO"); } public void testQuery2() throws SecurityException, NoSuchMethodException { Method method = TestQuery.class.getMethod("foo2"); - GeneratedHttpRequest httpMethod = factory(TestQuery.class).createRequest(method, + HttpRequest request = factory(TestQuery.class).createRequest(method, new Object[] {}); - assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); - assertEquals(httpMethod.getEndpoint().getPath(), ""); - assertEquals(httpMethod.getEndpoint().getQuery(), + assertEquals(request.getEndpoint().getHost(), "localhost"); + assertEquals(request.getEndpoint().getPath(), ""); + assertEquals(request.getEndpoint().getQuery(), "x-ms-version=2009-07-17&foo=bar&fooble=baz"); - assertEquals(httpMethod.getMethod(), "FOO"); + assertEquals(request.getMethod(), "FOO"); } public void testQuery3() throws SecurityException, NoSuchMethodException { 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" }); - assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); - assertEquals(httpMethod.getEndpoint().getPath(), ""); - assertEquals(httpMethod.getEndpoint().getQuery(), + assertEquals(request.getEndpoint().getHost(), "localhost"); + assertEquals(request.getEndpoint().getPath(), ""); + assertEquals(request.getEndpoint().getQuery(), "x-ms-version=2009-07-17&foo=bar&fooble=baz&robbie=wonder"); - assertEquals(httpMethod.getMethod(), "FOO"); + assertEquals(request.getMethod(), "FOO"); } public interface TestPayloadParamVarargs { @@ -450,7 +448,7 @@ public class RestAnnotationProcessorTest { } private void verifyTestPostOptions(Method method) { - GeneratedHttpRequest httpMethod = factory(TestPayloadParamVarargs.class).createRequest( + HttpRequest request = factory(TestPayloadParamVarargs.class).createRequest( method, new Object[] { new HttpRequestOptions() { public Multimap buildMatrixParameters() { @@ -478,15 +476,15 @@ public class RestAnnotationProcessorTest { } } }); - assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); - assertEquals(httpMethod.getEndpoint().getPath(), ""); - assertEquals(httpMethod.getMethod(), HttpMethod.POST); - assertEquals(httpMethod.getHeaders().size(), 2); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections + assertEquals(request.getEndpoint().getHost(), "localhost"); + assertEquals(request.getEndpoint().getPath(), ""); + assertEquals(request.getMethod(), HttpMethod.POST); + assertEquals(request.getHeaders().size(), 2); + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections .singletonList("application/unknown")); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections .singletonList("fooya".getBytes().length + "")); - assertEquals(httpMethod.getPayload().toString(), "fooya"); + assertEquals(request.getPayload().toString(), "fooya"); } public class TestCustomMethod { @@ -497,11 +495,11 @@ public class RestAnnotationProcessorTest { public void testCustomMethod() throws SecurityException, NoSuchMethodException { Method method = TestCustomMethod.class.getMethod("foo"); - GeneratedHttpRequest httpMethod = factory(TestCustomMethod.class).createRequest(method, + HttpRequest request = factory(TestCustomMethod.class).createRequest(method, new Object[] {}); - assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); - assertEquals(httpMethod.getEndpoint().getPath(), ""); - assertEquals(httpMethod.getMethod(), "FOO"); + assertEquals(request.getEndpoint().getHost(), "localhost"); + assertEquals(request.getEndpoint().getPath(), ""); + assertEquals(request.getMethod(), "FOO"); } public interface Parent { @@ -516,11 +514,11 @@ public class RestAnnotationProcessorTest { public void testOverriddenMethod() throws SecurityException, NoSuchMethodException { Method method = TestOverridden.class.getMethod("foo"); - GeneratedHttpRequest httpMethod = factory(TestOverridden.class).createRequest(method, + HttpRequest request = factory(TestOverridden.class).createRequest(method, new Object[] {}); - assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); - assertEquals(httpMethod.getEndpoint().getPath(), ""); - assertEquals(httpMethod.getMethod(), "POST"); + assertEquals(request.getEndpoint().getHost(), "localhost"); + assertEquals(request.getEndpoint().getPath(), ""); + assertEquals(request.getMethod(), "POST"); } public class TestOverriddenEndpoint implements Parent { @@ -537,22 +535,22 @@ public class RestAnnotationProcessorTest { public void testOverriddenEndpointMethod() throws SecurityException, NoSuchMethodException { Method method = TestOverriddenEndpoint.class.getMethod("foo"); - GeneratedHttpRequest httpMethod = factory(TestOverriddenEndpoint.class).createRequest( + HttpRequest request = factory(TestOverriddenEndpoint.class).createRequest( method, new Object[] {}); - assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); - assertEquals(httpMethod.getEndpoint().getPort(), 1111); - assertEquals(httpMethod.getEndpoint().getPath(), ""); - assertEquals(httpMethod.getMethod(), "POST"); + assertEquals(request.getEndpoint().getHost(), "localhost"); + assertEquals(request.getEndpoint().getPort(), 1111); + assertEquals(request.getEndpoint().getPath(), ""); + assertEquals(request.getMethod(), "POST"); } public void testOverriddenEndpointParameter() throws SecurityException, NoSuchMethodException { 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") }); - assertEquals(httpMethod.getEndpoint().getHost(), "wowsa"); - assertEquals(httpMethod.getEndpoint().getPort(), 8001); - assertEquals(httpMethod.getEndpoint().getPath(), ""); - assertEquals(httpMethod.getMethod(), "POST"); + assertEquals(request.getEndpoint().getHost(), "wowsa"); + assertEquals(request.getEndpoint().getPort(), 8001); + assertEquals(request.getEndpoint().getPath(), ""); + assertEquals(request.getMethod(), "POST"); } public class TestPost { @@ -579,49 +577,49 @@ public class RestAnnotationProcessorTest { public void testCreatePostRequest() throws SecurityException, NoSuchMethodException { Method method = TestPost.class.getMethod("post", String.class); - GeneratedHttpRequest httpMethod = factory(TestPost.class).createRequest(method, "data"); - assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); - assertEquals(httpMethod.getEndpoint().getPath(), ""); - assertEquals(httpMethod.getMethod(), HttpMethod.POST); - assertEquals(httpMethod.getHeaders().size(), 2); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections + HttpRequest request = factory(TestPost.class).createRequest(method, "data"); + assertEquals(request.getEndpoint().getHost(), "localhost"); + assertEquals(request.getEndpoint().getPath(), ""); + assertEquals(request.getMethod(), HttpMethod.POST); + assertEquals(request.getHeaders().size(), 2); + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections .singletonList("application/unknown")); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections .singletonList("data".getBytes().length + "")); - assertEquals(httpMethod.getPayload().toString(), "data"); + assertEquals(request.getPayload().toString(), "data"); } public void testCreatePostRequestNullOk() throws SecurityException, NoSuchMethodException { 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 }); - assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); - assertEquals(httpMethod.getEndpoint().getPath(), ""); - assertEquals(httpMethod.getMethod(), HttpMethod.POST); - assertEquals(httpMethod.getHeaders().size(), 0); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE).size(), 0); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH).size(), 0); - assertEquals(httpMethod.getPayload(), null); + assertEquals(request.getEndpoint().getHost(), "localhost"); + assertEquals(request.getEndpoint().getPath(), ""); + assertEquals(request.getMethod(), HttpMethod.POST); + assertEquals(request.getHeaders().size(), 0); + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE).size(), 0); + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH).size(), 0); + assertEquals(request.getPayload(), null); } public void testCreatePostJsonRequest() throws SecurityException, NoSuchMethodException { 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" }); - assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); - assertEquals(httpMethod.getEndpoint().getPath(), ""); - assertEquals(httpMethod.getMethod(), HttpMethod.POST); - assertEquals(httpMethod.getHeaders().size(), 2); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections + assertEquals(request.getEndpoint().getHost(), "localhost"); + assertEquals(request.getEndpoint().getPath(), ""); + assertEquals(request.getMethod(), HttpMethod.POST); + assertEquals(request.getHeaders().size(), 2); + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections .singletonList("application/json")); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections .singletonList("\"data\"".getBytes().length + "")); - assertEquals(httpMethod.getPayload().toString(), "\"data\""); + assertEquals(request.getPayload().toString(), "\"data\""); } public void testCreatePostWithPathRequest() throws SecurityException, NoSuchMethodException { 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() { public void bindToRequest(HttpRequest request, Map postParams) { request.setPayload(postParams.get("fooble")); @@ -631,27 +629,27 @@ public class RestAnnotationProcessorTest { throw new RuntimeException("this shouldn't be used in POST"); } } }); - assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); - assertEquals(httpMethod.getEndpoint().getPath(), "/data"); - assertEquals(httpMethod.getMethod(), HttpMethod.POST); - assertEquals(httpMethod.getHeaders().size(), 1); - assertEquals(httpMethod.getPayload().toString(), "data"); + assertEquals(request.getEndpoint().getHost(), "localhost"); + assertEquals(request.getEndpoint().getPath(), "/data"); + assertEquals(request.getMethod(), HttpMethod.POST); + assertEquals(request.getHeaders().size(), 1); + assertEquals(request.getPayload().toString(), "data"); } public void testCreatePostWithMethodBinder() throws SecurityException, NoSuchMethodException { 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", }); - assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); - assertEquals(httpMethod.getEndpoint().getPath(), "/data"); - assertEquals(httpMethod.getMethod(), HttpMethod.POST); - assertEquals(httpMethod.getHeaders().size(), 2); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections + assertEquals(request.getEndpoint().getHost(), "localhost"); + assertEquals(request.getEndpoint().getPath(), "/data"); + assertEquals(request.getMethod(), HttpMethod.POST); + assertEquals(request.getHeaders().size(), 2); + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections .singletonList("application/json")); String expected = "{\"fooble\":\"data\"}"; - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections .singletonList(expected.getBytes().length + "")); - assertEquals(httpMethod.getPayload().toString(), expected); + assertEquals(request.getPayload().toString(), expected); } static interface TestMultipartForm { @@ -827,51 +825,51 @@ public class RestAnnotationProcessorTest { public void testCreatePutWithMethodBinder() throws SecurityException, NoSuchMethodException { 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", }); - assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); - assertEquals(httpMethod.getEndpoint().getPath(), "/data"); - assertEquals(httpMethod.getMethod(), HttpMethod.PUT); - assertEquals(httpMethod.getHeaders().size(), 2); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections + assertEquals(request.getEndpoint().getHost(), "localhost"); + assertEquals(request.getEndpoint().getPath(), "/data"); + assertEquals(request.getMethod(), HttpMethod.PUT); + assertEquals(request.getHeaders().size(), 2); + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections .singletonList("application/json")); String expected = "{\"fooble\":\"data\"}"; - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections .singletonList(expected.getBytes().length + "")); - assertEquals(httpMethod.getPayload().toString(), expected); + assertEquals(request.getPayload().toString(), expected); } public void testCreatePutWithMethodProduces() throws SecurityException, NoSuchMethodException { 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", }); - assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); - assertEquals(httpMethod.getEndpoint().getPath(), "/data"); - assertEquals(httpMethod.getMethod(), HttpMethod.PUT); - assertEquals(httpMethod.getHeaders().size(), 2); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections + assertEquals(request.getEndpoint().getHost(), "localhost"); + assertEquals(request.getEndpoint().getPath(), "/data"); + assertEquals(request.getMethod(), HttpMethod.PUT); + assertEquals(request.getHeaders().size(), 2); + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections .singletonList("text/plain")); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections .singletonList("data".getBytes().length + "")); - assertEquals(httpMethod.getPayload().toString(), "data"); + assertEquals(request.getPayload().toString(), "data"); } public void testCreatePutWithMethodConsumes() throws SecurityException, NoSuchMethodException { 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", }); - assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); - assertEquals(httpMethod.getEndpoint().getPath(), "/data"); - assertEquals(httpMethod.getMethod(), HttpMethod.PUT); - assertEquals(httpMethod.getHeaders().size(), 3); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections + assertEquals(request.getEndpoint().getHost(), "localhost"); + assertEquals(request.getEndpoint().getPath(), "/data"); + assertEquals(request.getMethod(), HttpMethod.PUT); + assertEquals(request.getHeaders().size(), 3); + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections .singletonList("application/json")); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.ACCEPT), Collections + assertEquals(request.getHeaders().get(HttpHeaders.ACCEPT), Collections .singletonList("application/json")); String expected = "{\"fooble\":\"data\"}"; - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections .singletonList(expected.getBytes().length + "")); - assertEquals(httpMethod.getPayload().toString(), expected); + assertEquals(request.getPayload().toString(), expected); } static class TestRequestFilter1 implements HttpRequestFilter { @@ -901,19 +899,19 @@ public class RestAnnotationProcessorTest { @Test public void testRequestFilter() throws SecurityException, NoSuchMethodException { Method method = TestRequestFilter.class.getMethod("get"); - GeneratedHttpRequest httpMethod = factory(TestRequestFilter.class).createRequest(method, + HttpRequest request = factory(TestRequestFilter.class).createRequest(method, new Object[] {}); - assertEquals(httpMethod.getFilters().size(), 2); - assertEquals(httpMethod.getFilters().get(0).getClass(), TestRequestFilter1.class); - assertEquals(httpMethod.getFilters().get(1).getClass(), TestRequestFilter2.class); + assertEquals(request.getFilters().size(), 2); + assertEquals(request.getFilters().get(0).getClass(), TestRequestFilter1.class); + assertEquals(request.getFilters().get(1).getClass(), TestRequestFilter2.class); } public void testRequestFilterOverride() throws SecurityException, NoSuchMethodException { Method method = TestRequestFilter.class.getMethod("getOverride"); - GeneratedHttpRequest httpMethod = factory(TestRequestFilter.class).createRequest(method, + HttpRequest request = factory(TestRequestFilter.class).createRequest(method, new Object[] {}); - assertEquals(httpMethod.getFilters().size(), 1); - assertEquals(httpMethod.getFilters().get(0).getClass(), TestRequestFilter2.class); + assertEquals(request.getFilters().size(), 1); + assertEquals(request.getFilters().get(0).getClass(), TestRequestFilter2.class); } @SkipEncoding('/') @@ -927,21 +925,21 @@ public class RestAnnotationProcessorTest { @Test public void testSkipEncoding() throws SecurityException, NoSuchMethodException { 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" }); - assertEquals(httpMethod.getEndpoint().getPath(), "/1/localhost"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 0); + assertEquals(request.getEndpoint().getPath(), "/1/localhost"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 0); } @Test public void testEncodingPath() throws SecurityException, NoSuchMethodException { 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" }); - assertEquals(httpMethod.getEndpoint().getPath(), "///localhost"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 0); + assertEquals(request.getEndpoint().getPath(), "///localhost"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 0); } @SkipEncoding('/') @@ -959,12 +957,12 @@ public class RestAnnotationProcessorTest { @Test(enabled = false) public void testConstantPathParam() throws SecurityException, NoSuchMethodException, IOException { 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" }); - assertRequestLineEquals(httpMethod, + assertRequestLineEquals(request, "GET http://localhost:9999/v1/ralphie/1/localhost HTTP/1.1"); - assertHeadersEqual(httpMethod, ""); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, ""); + assertPayloadEquals(request, null); } public class TestPath { @@ -1020,55 +1018,55 @@ public class RestAnnotationProcessorTest { public void testPathParamExtractor() throws SecurityException, NoSuchMethodException, IOException { 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" }); - assertRequestLineEquals(httpMethod, "GET http://localhost:9999/l HTTP/1.1"); - assertHeadersEqual(httpMethod, ""); - assertPayloadEquals(httpMethod, null); + assertRequestLineEquals(request, "GET http://localhost:9999/l HTTP/1.1"); + assertHeadersEqual(request, ""); + assertPayloadEquals(request, null); } @Test public void testQueryParamExtractor() throws SecurityException, NoSuchMethodException, IOException { Method method = TestPath.class.getMethod("oneQueryParamExtractor", String.class); - GeneratedHttpRequest httpMethod = factory(TestPath.class).createRequest(method, + HttpRequest request = factory(TestPath.class).createRequest(method, "localhost"); - assertRequestLineEquals(httpMethod, "GET http://localhost:9999/?one=l HTTP/1.1"); - assertHeadersEqual(httpMethod, ""); - assertPayloadEquals(httpMethod, null); + assertRequestLineEquals(request, "GET http://localhost:9999/?one=l HTTP/1.1"); + assertHeadersEqual(request, ""); + assertPayloadEquals(request, null); } @Test public void testMatrixParamExtractor() throws SecurityException, NoSuchMethodException, IOException { 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" }); - assertRequestLineEquals(httpMethod, "GET http://localhost:9999/;one=l HTTP/1.1"); - assertHeadersEqual(httpMethod, ""); - assertPayloadEquals(httpMethod, null); + assertRequestLineEquals(request, "GET http://localhost:9999/;one=l HTTP/1.1"); + assertHeadersEqual(request, ""); + assertPayloadEquals(request, null); } @Test public void testFormParamExtractor() throws SecurityException, NoSuchMethodException, IOException { 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" }); - assertRequestLineEquals(httpMethod, "POST http://localhost:9999/ HTTP/1.1"); - assertHeadersEqual(httpMethod, + assertRequestLineEquals(request, "POST http://localhost:9999/ HTTP/1.1"); + assertHeadersEqual(request, "Content-Length: 5\nContent-Type: application/x-www-form-urlencoded\n"); - assertPayloadEquals(httpMethod, "one=l"); + assertPayloadEquals(request, "one=l"); } @Test public void testParamExtractorMethod() throws SecurityException, NoSuchMethodException { 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" }); - assertEquals(httpMethod.getEndpoint().getPath(), "/l"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 0); + assertEquals(request.getEndpoint().getPath(), "/l"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 0); } static class FirstCharacter implements Function { @@ -1181,31 +1179,6 @@ public class RestAnnotationProcessorTest { assertEquals(query, "x-amz-copy-source=/robot"); } - @Test - public void testParseQueryToMapSingleParam() { - Multimap 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 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 { @POST @Path("objects/{id}/action/{action}") @@ -1218,25 +1191,12 @@ public class RestAnnotationProcessorTest { UnsupportedEncodingException { Method method = TestMapMatrixParams.class.getMethod("action", String.class, String.class, Map.class); - GeneratedHttpRequest httpMethod = factory(TestMapMatrixParams.class) + HttpRequest request = factory(TestMapMatrixParams.class) .createRequest(method, 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"); - assertEquals(httpMethod.getHeaders().size(), 0); - } - - public void testParseBase64InForm() { - Multimap 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")); + assertEquals(request.getHeaders().size(), 0); } @SkipEncoding('/') @@ -1451,13 +1411,13 @@ public class RestAnnotationProcessorTest { public void testPutPayload() throws SecurityException, NoSuchMethodException { 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")); - assertEquals(httpMethod.getRequestLine(), + assertEquals(request.getRequestLine(), "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"))); - assertEquals(httpMethod.getPayload().getRawContent(), "whoops"); + assertEquals(request.getPayload().getRawContent(), "whoops"); } @SuppressWarnings("static-access") @@ -1513,8 +1473,7 @@ public class RestAnnotationProcessorTest { RestAnnotationProcessor processor = factory(TestTransformers.class); Method method = TestTransformers.class.getMethod("oneTransformerWithContext"); GeneratedHttpRequest request = new GeneratedHttpRequest( - uriBuilderProvider, "GET", URI.create("http://localhost"), processor, - TestTransformers.class, method); + "GET", URI.create("http://localhost"), TestTransformers.class, method); Function transformer = processor.createResponseParser(method, request); assertEquals(transformer.getClass(), ReturnStringIf200Context.class); assertEquals(((ReturnStringIf200Context) transformer).request, request); @@ -1579,15 +1538,15 @@ public class RestAnnotationProcessorTest { GetOptions options = GetOptions.Builder.ifModifiedSince(date); HttpRequestOptions[] optionsHolder = new HttpRequestOptions[] {}; 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 }); - assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); - assertEquals(httpMethod.getEndpoint().getPath(), "/1"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 2); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.HOST), Collections + assertEquals(request.getEndpoint().getHost(), "localhost"); + assertEquals(request.getEndpoint().getPath(), "/1"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 2); + assertEquals(request.getHeaders().get(HttpHeaders.HOST), Collections .singletonList("localhost")); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.IF_MODIFIED_SINCE), Collections + assertEquals(request.getHeaders().get(HttpHeaders.IF_MODIFIED_SINCE), Collections .singletonList(dateService.rfc822DateFormat(date))); } @@ -1596,15 +1555,15 @@ public class RestAnnotationProcessorTest { Date date = new Date(); GetOptions options = GetOptions.Builder.ifModifiedSince(date); 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 }); - assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); - assertEquals(httpMethod.getEndpoint().getPath(), "/1"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 2); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.HOST), Collections + assertEquals(request.getEndpoint().getHost(), "localhost"); + assertEquals(request.getEndpoint().getPath(), "/1"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 2); + assertEquals(request.getHeaders().get(HttpHeaders.HOST), Collections .singletonList("localhost")); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.IF_MODIFIED_SINCE), Collections + assertEquals(request.getHeaders().get(HttpHeaders.IF_MODIFIED_SINCE), Collections .singletonList(dateService.rfc822DateFormat(date))); } @@ -1619,33 +1578,33 @@ public class RestAnnotationProcessorTest { NoSuchMethodException, IOException { PrefixOptions options = new PrefixOptions().withPrefix("1"); 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 }); - assertRequestLineEquals(httpMethod, "GET http://localhost:9999/1?prefix=1 HTTP/1.1"); - assertHeadersEqual(httpMethod, "Host: localhost\n"); - assertPayloadEquals(httpMethod, null); + assertRequestLineEquals(request, "GET http://localhost:9999/1?prefix=1 HTTP/1.1"); + assertHeadersEqual(request, "Host: localhost\n"); + assertPayloadEquals(request, null); } public void testCreateGetQuery() throws SecurityException, NoSuchMethodException { 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" }); - assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); - assertEquals(httpMethod.getEndpoint().getPath(), "/1"); - assertEquals(httpMethod.getEndpoint().getQuery(), "max-keys=0"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 0); + assertEquals(request.getEndpoint().getHost(), "localhost"); + assertEquals(request.getEndpoint().getPath(), "/1"); + assertEquals(request.getEndpoint().getQuery(), "max-keys=0"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 0); } public void testCreateGetQueryNull() throws SecurityException, NoSuchMethodException { 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" }); - assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); - assertEquals(httpMethod.getEndpoint().getPath(), "/1"); - assertEquals(httpMethod.getEndpoint().getQuery(), "acl"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 0); + assertEquals(request.getEndpoint().getHost(), "localhost"); + assertEquals(request.getEndpoint().getPath(), "/1"); + assertEquals(request.getEndpoint().getQuery(), "acl"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 0); } public class PayloadOptions extends BaseHttpRequestOptions { @@ -1660,18 +1619,18 @@ public class RestAnnotationProcessorTest { PayloadOptions options = new PayloadOptions(); Method method = TestRequest.class.getMethod("putOptions", String.class, HttpRequestOptions.class); - GeneratedHttpRequest httpMethod = factory(TestRequest.class).createRequest(method, + HttpRequest request = factory(TestRequest.class).createRequest(method, new Object[] { "1", options }); - assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); - assertEquals(httpMethod.getEndpoint().getPath(), "/1"); - assertEquals(httpMethod.getMethod(), HttpMethod.PUT); - assertEquals(httpMethod.getHeaders().size(), 3); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.HOST), Collections + assertEquals(request.getEndpoint().getHost(), "localhost"); + assertEquals(request.getEndpoint().getPath(), "/1"); + assertEquals(request.getMethod(), HttpMethod.PUT); + assertEquals(request.getHeaders().size(), 3); + assertEquals(request.getHeaders().get(HttpHeaders.HOST), Collections .singletonList("localhost")); - assertEquals(httpMethod.getPayload().toString(), "foo"); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections + assertEquals(request.getPayload().toString(), "foo"); + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections .singletonList("application/unknown")); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections .singletonList("foo".getBytes().length + "")); } @@ -1684,47 +1643,47 @@ public class RestAnnotationProcessorTest { public void testCreateGetRequest(String key) throws SecurityException, NoSuchMethodException, UnsupportedEncodingException { 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" }); - assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); + assertEquals(request.getEndpoint().getHost(), "localhost"); String expectedPath = "/" + URLEncoder.encode(key, "UTF-8").replaceAll("\\+", "%20"); - assertEquals(httpMethod.getEndpoint().getRawPath(), expectedPath); - assertEquals(httpMethod.getEndpoint().getPath(), "/" + key); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 1); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.HOST), Collections + assertEquals(request.getEndpoint().getRawPath(), expectedPath); + assertEquals(request.getEndpoint().getPath(), "/" + key); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 1); + assertEquals(request.getHeaders().get(HttpHeaders.HOST), Collections .singletonList("localhost")); } public void testCreatePutRequest() throws SecurityException, NoSuchMethodException { 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" }); - assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); - assertEquals(httpMethod.getEndpoint().getPath(), "/1"); - assertEquals(httpMethod.getMethod(), HttpMethod.PUT); - assertEquals(httpMethod.getHeaders().size(), 2); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections + assertEquals(request.getEndpoint().getHost(), "localhost"); + assertEquals(request.getEndpoint().getPath(), "/1"); + assertEquals(request.getMethod(), HttpMethod.PUT); + assertEquals(request.getHeaders().size(), 2); + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections .singletonList("application/unknown")); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections .singletonList("data".getBytes().length + "")); - assertEquals(httpMethod.getPayload().toString(), "data"); + assertEquals(request.getPayload().toString(), "data"); } public void testCreatePutHeader() throws SecurityException, NoSuchMethodException { 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" }); - assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); - assertEquals(httpMethod.getEndpoint().getPath(), "/1"); - assertEquals(httpMethod.getMethod(), HttpMethod.PUT); - assertEquals(httpMethod.getHeaders().size(), 3); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections + assertEquals(request.getEndpoint().getHost(), "localhost"); + assertEquals(request.getEndpoint().getPath(), "/1"); + assertEquals(request.getMethod(), HttpMethod.PUT); + assertEquals(request.getHeaders().size(), 3); + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections .singletonList("application/unknown")); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections .singletonList("data".getBytes().length + "")); - assertEquals(httpMethod.getHeaders().get("foo"), Collections.singletonList("--1--")); - assertEquals(httpMethod.getPayload().toString(), "data"); + assertEquals(request.getHeaders().get("foo"), Collections.singletonList("--1--")); + assertEquals(request.getPayload().toString(), "data"); } public class TestVirtualHostMethod { @@ -1739,13 +1698,13 @@ public class RestAnnotationProcessorTest { @Test public void testVirtualHostMethod() throws SecurityException, NoSuchMethodException { 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" }); - assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); - assertEquals(httpMethod.getEndpoint().getPath(), "/1"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 1); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.HOST), Collections + assertEquals(request.getEndpoint().getHost(), "localhost"); + assertEquals(request.getEndpoint().getPath(), "/1"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 1); + assertEquals(request.getHeaders().get(HttpHeaders.HOST), Collections .singletonList("localhost")); } @@ -1775,36 +1734,36 @@ public class RestAnnotationProcessorTest { @Test public void testVirtualHost() throws SecurityException, NoSuchMethodException { 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" }); - assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); - assertEquals(httpMethod.getEndpoint().getPath(), "/1"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 1); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.HOST), Collections + assertEquals(request.getEndpoint().getHost(), "localhost"); + assertEquals(request.getEndpoint().getPath(), "/1"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 1); + assertEquals(request.getHeaders().get(HttpHeaders.HOST), Collections .singletonList("localhost")); } @Test public void testHostPrefix() throws SecurityException, NoSuchMethodException { 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" }); - assertEquals(httpMethod.getEndpoint().getHost(), "holylocalhost"); - assertEquals(httpMethod.getEndpoint().getPath(), "/1"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 0); + assertEquals(request.getEndpoint().getHost(), "holylocalhost"); + assertEquals(request.getEndpoint().getPath(), "/1"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 0); } @Test public void testHostPrefixDot() throws SecurityException, NoSuchMethodException { 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" }); - assertEquals(httpMethod.getEndpoint().getHost(), "holy.localhost"); - assertEquals(httpMethod.getEndpoint().getPath(), "/1"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 0); + assertEquals(request.getEndpoint().getHost(), "holy.localhost"); + assertEquals(request.getEndpoint().getPath(), "/1"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 0); } @Test(expectedExceptions = IllegalArgumentException.class) @@ -1897,9 +1856,8 @@ public class RestAnnotationProcessorTest { public void testPut() throws SecurityException, NoSuchMethodException { RestAnnotationProcessor processor = factory(TestPayload.class); Method method = TestPayload.class.getMethod("put", String.class); - GeneratedHttpRequest request = new GeneratedHttpRequest( - uriBuilderProvider, "GET", URI.create("http://localhost"), processor, - TestPayload.class, method, "test"); + GeneratedHttpRequest request = new GeneratedHttpRequest("GET", URI + .create("http://localhost"), TestPayload.class, method, "test"); processor.decorateRequest(request); assertEquals(request.getPayload().toString(), "test"); assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections @@ -1915,9 +1873,8 @@ public class RestAnnotationProcessorTest { RestAnnotationProcessor processor = factory(TestPayload.class); Method method = TestPayload.class.getMethod("putWithPath", String.class, String.class); - GeneratedHttpRequest request = new GeneratedHttpRequest( - uriBuilderProvider, "GET", URI.create("http://localhost"), processor, - TestPayload.class, method, "rabble", "test"); + GeneratedHttpRequest request = new GeneratedHttpRequest("GET", URI + .create("http://localhost"), TestPayload.class, method, "rabble", "test"); processor.decorateRequest(request); assertEquals(request.getPayload().toString(), "test"); 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 { - if (httpMethod.getPayload() == null) { + if (request.getPayload() == null) { assertNull(toMatch); } else { - String payload = Utils.toStringAndClose(httpMethod.getPayload().getInput()); + String payload = Utils.toStringAndClose(request.getPayload().getInput()); assertEquals(payload, toMatch); } } - protected void assertHeadersEqual(GeneratedHttpRequest httpMethod, String toMatch) { - assertEquals(HttpUtils.sortAndConcatHeadersIntoString(httpMethod.getHeaders()), toMatch); + protected void assertHeadersEqual(HttpRequest request, String toMatch) { + assertEquals(HttpUtils.sortAndConcatHeadersIntoString(request.getHeaders()), toMatch); } - protected void assertRequestLineEquals(GeneratedHttpRequest httpMethod, String toMatch) { - assertEquals(httpMethod.getRequestLine(), toMatch); + protected void assertRequestLineEquals(HttpRequest request, String toMatch) { + assertEquals(request.getRequestLine(), toMatch); } } diff --git a/core/src/test/java/org/jclouds/util/HttpUtilsTest.java b/core/src/test/java/org/jclouds/util/HttpUtilsTest.java index acefd48074..c64b902bc3 100644 --- a/core/src/test/java/org/jclouds/util/HttpUtilsTest.java +++ b/core/src/test/java/org/jclouds/util/HttpUtilsTest.java @@ -18,14 +18,31 @@ */ 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 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.http.HttpRequest; import org.jclouds.http.HttpUtils; 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. * @@ -33,6 +50,62 @@ import org.testng.annotations.Test; */ @Test(groups = "performance", sequential = true, testName = "jclouds.HttpUtils") public class HttpUtilsTest extends PerformanceTest { + Provider uriBuilderProvider = new Provider() { + + @Override + public UriBuilder get() { + return new UriBuilderImpl(); + } + + }; + + public void testParseBase64InForm() { + Multimap 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 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 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 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() { assert HttpUtils.isUrlEncoded("/read-tests/%73%6f%6d%65%20%66%69%6c%65"); @@ -44,7 +117,7 @@ public class HttpUtilsTest extends PerformanceTest { "/read-tests/%73%6f%6d%65%20%66%69%6c%65"); assertEquals(HttpUtils.urlEncode("/read-tests/ tep", '/'), "/read-tests/%20tep"); } - + public void testIBM() { URI ibm = HttpUtils .createUri("https://www-180.ibm.com/cloud/enterprise/beta/ram/assetDetail/generalDetails.faces?guid={A31FF849-0E97-431A-0324-097385A46298}&v=1.2"); diff --git a/gogrid/src/main/java/org/jclouds/gogrid/binders/BindIdsToQueryParams.java b/gogrid/src/main/java/org/jclouds/gogrid/binders/BindIdsToQueryParams.java index afb1221926..63c7ce646b 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/binders/BindIdsToQueryParams.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/binders/BindIdsToQueryParams.java @@ -23,20 +23,34 @@ */ package org.jclouds.gogrid.binders; -import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.gogrid.reference.GoGridQueryParams.ID_KEY; +import 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.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 * * @author Oleksiy Yarmula */ +@Singleton public class BindIdsToQueryParams implements Binder { + private final Provider builder; + + @Inject + BindIdsToQueryParams(Provider builder) { + this.builder = builder; + } /** * Binds the ids to query parameters. The pattern, as specified by GoGrid's specification, is: @@ -50,22 +64,17 @@ public class BindIdsToQueryParams implements Binder { */ @Override public void bindToRequest(HttpRequest request, Object input) { - checkArgument(checkNotNull(request, "request is null") instanceof GeneratedHttpRequest, - "this binder is only valid for GeneratedHttpRequests!"); - GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request; - - if (checkNotNull(input, "input is null") instanceof Long[]){ + + if (checkNotNull(input, "input is null") instanceof Long[]) { Long[] names = (Long[]) input; - for (long id : names) - generatedRequest.addQueryParam(ID_KEY, id + ""); + addQueryParamTo(request, ID_KEY, ImmutableList.copyOf(names), builder.get()); } else if (input instanceof long[]) { long[] names = (long[]) input; - - for (long id : names) - generatedRequest.addQueryParam(ID_KEY, id + ""); + addQueryParamTo(request, ID_KEY, Longs.asList(names), builder.get()); } 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()); } - + } } diff --git a/gogrid/src/main/java/org/jclouds/gogrid/binders/BindNamesToQueryParams.java b/gogrid/src/main/java/org/jclouds/gogrid/binders/BindNamesToQueryParams.java index c68183d07b..c69d829026 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/binders/BindNamesToQueryParams.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/binders/BindNamesToQueryParams.java @@ -26,10 +26,16 @@ package org.jclouds.gogrid.binders; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.gogrid.reference.GoGridQueryParams.NAME_KEY; +import 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.rest.Binder; -import org.jclouds.rest.internal.GeneratedHttpRequest; + +import com.google.common.collect.ImmutableList; /** * Binds names to corresponding query parameters @@ -37,6 +43,12 @@ import org.jclouds.rest.internal.GeneratedHttpRequest; * @author Oleksiy Yarmula */ public class BindNamesToQueryParams implements Binder { + private final Provider builder; + + @Inject + BindNamesToQueryParams(Provider builder) { + this.builder = builder; + } /** * 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 public void bindToRequest(HttpRequest request, Object input) { - checkArgument(checkNotNull(request, "request is null") instanceof GeneratedHttpRequest, - "this binder is only valid for GeneratedHttpRequests!"); checkArgument(checkNotNull(input, "input is null") instanceof String[], "this binder is only valid for String[] arguments"); - String[] names = (String[]) input; - GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request; - - for (String name : names) { - generatedRequest.addQueryParam(NAME_KEY, name); - } - + addQueryParamTo(request, NAME_KEY, ImmutableList.copyOf(names), builder.get()); } } diff --git a/gogrid/src/main/java/org/jclouds/gogrid/binders/BindObjectNameToGetJobsRequestQueryParams.java b/gogrid/src/main/java/org/jclouds/gogrid/binders/BindObjectNameToGetJobsRequestQueryParams.java index 54a7bd91f0..0ca8c3c898 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/binders/BindObjectNameToGetJobsRequestQueryParams.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/binders/BindObjectNameToGetJobsRequestQueryParams.java @@ -21,10 +21,14 @@ package org.jclouds.gogrid.binders; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.gogrid.reference.GoGridQueryParams.OBJECT_KEY; +import 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.rest.Binder; -import org.jclouds.rest.internal.GeneratedHttpRequest; /** * @@ -33,6 +37,12 @@ import org.jclouds.rest.internal.GeneratedHttpRequest; * @author Oleksiy Yarmula */ public class BindObjectNameToGetJobsRequestQueryParams implements Binder { + private final Provider builder; + + @Inject + BindObjectNameToGetJobsRequestQueryParams(Provider builder) { + this.builder = builder; + } /** * Maps the object's name to the input of , - "this binder is only valid for GeneratedHttpRequests!"); checkArgument(checkNotNull(input, "input is null") instanceof String, "this binder is only valid for String arguments"); String serverName = (String) input; - GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request; - - generatedRequest.addQueryParam(OBJECT_KEY, serverName); + addQueryParamTo(request, OBJECT_KEY, serverName, builder.get()); } } diff --git a/gogrid/src/main/java/org/jclouds/gogrid/binders/BindRealIpPortPairsToQueryParams.java b/gogrid/src/main/java/org/jclouds/gogrid/binders/BindRealIpPortPairsToQueryParams.java index f19d1af8f1..2da0b3dfba 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/binders/BindRealIpPortPairsToQueryParams.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/binders/BindRealIpPortPairsToQueryParams.java @@ -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.checkState; import static org.jclouds.gogrid.reference.GoGridQueryParams.REAL_IP_LIST_KEY; +import static org.jclouds.http.HttpUtils.addQueryParamTo; 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.http.HttpRequest; import org.jclouds.rest.Binder; -import org.jclouds.rest.internal.GeneratedHttpRequest; /** * Binds a list of real IPs to the request. @@ -38,17 +42,20 @@ import org.jclouds.rest.internal.GeneratedHttpRequest; * @author Oleksiy Yarmula */ public class BindRealIpPortPairsToQueryParams implements Binder { + private final Provider builder; + + @Inject + BindRealIpPortPairsToQueryParams(Provider builder) { + this.builder = builder; + } @SuppressWarnings( { "unchecked" }) @Override public void bindToRequest(HttpRequest request, Object input) { - checkArgument(checkNotNull(request, "request is null") instanceof GeneratedHttpRequest, - "this binder is only valid for GeneratedHttpRequests!"); checkArgument(checkNotNull(input, "input is null") instanceof List, "this binder is only valid for a List argument"); List ipPortPairs = (List) input; - GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request; int i = 0; for (IpPortPair ipPortPair : ipPortPairs) { @@ -57,9 +64,10 @@ public class BindRealIpPortPairsToQueryParams implements Binder { "There must be an IP address defined in Ip object"); checkState(ipPortPair.getPort() > 0, "The port number must be a positive integer"); - generatedRequest.addQueryParam(REAL_IP_LIST_KEY + i + ".ip", ipPortPair.getIp().getIp()); - generatedRequest.addQueryParam(REAL_IP_LIST_KEY + i + ".port", String.valueOf(ipPortPair - .getPort())); + addQueryParamTo(request, REAL_IP_LIST_KEY + i + ".ip", ipPortPair.getIp().getIp(), builder + .get()); + addQueryParamTo(request, REAL_IP_LIST_KEY + i + ".port", String.valueOf(ipPortPair + .getPort()), builder.get()); i++; } } diff --git a/gogrid/src/main/java/org/jclouds/gogrid/binders/BindVirtualIpPortPairToQueryParams.java b/gogrid/src/main/java/org/jclouds/gogrid/binders/BindVirtualIpPortPairToQueryParams.java index c3a0e86fde..2ccd2eb969 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/binders/BindVirtualIpPortPairToQueryParams.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/binders/BindVirtualIpPortPairToQueryParams.java @@ -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.checkState; 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.http.HttpRequest; import org.jclouds.rest.Binder; -import org.jclouds.rest.internal.GeneratedHttpRequest; /** * Binds a virtual IP to the request. @@ -36,22 +40,26 @@ import org.jclouds.rest.internal.GeneratedHttpRequest; * @author Oleksiy Yarmula */ public class BindVirtualIpPortPairToQueryParams implements Binder { + private final Provider builder; + + @Inject + BindVirtualIpPortPairToQueryParams(Provider builder) { + this.builder = builder; + } @Override public void bindToRequest(HttpRequest request, Object input) { - checkArgument(checkNotNull(request, "request is null") instanceof GeneratedHttpRequest, - "this binder is only valid for GeneratedHttpRequests!"); checkArgument(checkNotNull(input, "input is null") instanceof IpPortPair, "this binder is only valid for a IpPortPair argument"); IpPortPair ipPortPair = (IpPortPair) input; - GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request; checkNotNull(ipPortPair.getIp(), "There must be an IP address defined"); checkNotNull(ipPortPair.getIp().getIp(), "There must be an IP address defined in Ip object"); checkState(ipPortPair.getPort() > 0, "The port number must be a positive integer"); - generatedRequest.addQueryParam(VIRTUAL_IP_KEY + "ip", ipPortPair.getIp().getIp()); - generatedRequest.addQueryParam(VIRTUAL_IP_KEY + "port", String.valueOf(ipPortPair.getPort())); + addQueryParamTo(request, VIRTUAL_IP_KEY + "ip", ipPortPair.getIp().getIp(), builder.get()); + addQueryParamTo(request, VIRTUAL_IP_KEY + "port", String.valueOf(ipPortPair.getPort()), + builder.get()); } } diff --git a/gogrid/src/main/java/org/jclouds/gogrid/filters/SharedKeyLiteAuthentication.java b/gogrid/src/main/java/org/jclouds/gogrid/filters/SharedKeyLiteAuthentication.java index 53ece4b652..da813bea80 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/filters/SharedKeyLiteAuthentication.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/filters/SharedKeyLiteAuthentication.java @@ -23,11 +23,12 @@ */ 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 org.jclouds.Constants.PROPERTY_CREDENTIAL; 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; @@ -40,10 +41,7 @@ import org.jclouds.date.TimeStamp; import org.jclouds.encryption.EncryptionService; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequestFilter; -import org.jclouds.http.HttpUtils; 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.Multimap; @@ -72,25 +70,23 @@ public class SharedKeyLiteAuthentication implements HttpRequestFilter { } public void filter(HttpRequest request) { - checkArgument(checkNotNull(request, "input") instanceof GeneratedHttpRequest, - "this decorator is only valid for GeneratedHttpRequests!"); String toSign = createStringToSign(); String signatureMd5 = getMd5For(toSign); String query = request.getEndpoint().getQuery(); - Multimap decodedParams = RestAnnotationProcessor.parseQueryToMap(query); + Multimap decodedParams = parseQueryToMap(query); decodedParams.replaceValues("sig", ImmutableSet.of(signatureMd5)); decodedParams.replaceValues("api_key", ImmutableSet.of(apiKey)); - String updatedQuery = RestAnnotationProcessor.makeQueryLine(decodedParams, null); + String updatedQuery = makeQueryLine(decodedParams, null); String requestBasePart = request.getEndpoint().toASCIIString(); String updatedEndpoint = requestBasePart.substring(0, requestBasePart.indexOf("?") + 1) + updatedQuery; request.setEndpoint(URI.create(updatedEndpoint)); - HttpUtils.logRequest(signatureLog, request, "<<"); + logRequest(signatureLog, request, "<<"); } private String createStringToSign() { diff --git a/gogrid/src/test/java/org/jclouds/gogrid/binders/BindIdsToQueryParamsTest.java b/gogrid/src/test/java/org/jclouds/gogrid/binders/BindIdsToQueryParamsTest.java index 83a76b002b..5c47904861 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/binders/BindIdsToQueryParamsTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/binders/BindIdsToQueryParamsTest.java @@ -18,10 +18,15 @@ */ package org.jclouds.gogrid.binders; -import static org.easymock.classextension.EasyMock.createMock; -import static org.easymock.classextension.EasyMock.replay; +import static org.testng.Assert.assertEquals; -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; /** @@ -32,32 +37,39 @@ import org.testng.annotations.Test; public class BindIdsToQueryParamsTest { @Test - public void testBinding() { - GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); - Long[] input = { 123L, 456L }; + public void testWithWrapper() throws SecurityException, NoSuchMethodException { - BindIdsToQueryParams binder = new BindIdsToQueryParams(); + HttpRequest request = new HttpRequest("GET", URI.create("http://momma/")); - request.addQueryParam("id", "123"); - request.addQueryParam("id", "456"); - replay(request); + BindIdsToQueryParams binder = new BindIdsToQueryParams(new Provider() { - 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 - public void testBinding2() { - GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); - long[] input = { 123L, 456L }; + public void testWithPrimitive() { + HttpRequest request = new HttpRequest("GET", URI.create("http://momma/")); - BindIdsToQueryParams binder = new BindIdsToQueryParams(); + BindIdsToQueryParams binder = new BindIdsToQueryParams(new Provider() { - request.addQueryParam("id", "123"); - request.addQueryParam("id", "456"); - replay(request); + @Override + public UriBuilder get() { + 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"); } } diff --git a/gogrid/src/test/java/org/jclouds/gogrid/binders/BindNamesToQueryParamsTest.java b/gogrid/src/test/java/org/jclouds/gogrid/binders/BindNamesToQueryParamsTest.java index cf5b013841..1a02e0aa90 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/binders/BindNamesToQueryParamsTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/binders/BindNamesToQueryParamsTest.java @@ -18,32 +18,42 @@ */ package org.jclouds.gogrid.binders; -import org.jclouds.rest.internal.GeneratedHttpRequest; +import static org.testng.Assert.assertEquals; + +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 static org.easymock.classextension.EasyMock.createMock; -import static org.easymock.classextension.EasyMock.replay; - /** - * Tests that name bindings are proper for request - * + * Tests that name bindings are proper for request + * * @author Oleksiy Yarmula */ public class BindNamesToQueryParamsTest { - @Test - public void testBinding() { - GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); - String[] input = {"hello", "world"}; + @Test + public void testBinding() { + String[] input = { "hello", "world" }; - BindNamesToQueryParams binder = new BindNamesToQueryParams(); + HttpRequest request = new HttpRequest("GET", URI.create("http://momma/")); - request.addQueryParam("name", "hello"); - request.addQueryParam("name", "world"); - replay(request); + BindNamesToQueryParams binder = new BindNamesToQueryParams(new Provider() { - binder.bindToRequest(request, input); + @Override + public UriBuilder get() { + return new UriBuilderImpl(); + } - } + }); + + binder.bindToRequest(request, input); + + assertEquals(request.getRequestLine(), "GET http://momma/?name=hello&name=world HTTP/1.1"); + } } diff --git a/gogrid/src/test/java/org/jclouds/gogrid/mock/HttpCommandMock.java b/gogrid/src/test/java/org/jclouds/gogrid/mock/HttpCommandMock.java index 48b1b98f46..dbb42a320f 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/mock/HttpCommandMock.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/mock/HttpCommandMock.java @@ -48,18 +48,6 @@ public class HttpCommandMock implements HttpCommand { return false; } - @Override - public void changeSchemeHostAndPortTo(String scheme, String host, int port) { - } - - @Override - public void changeToGETRequest() { - } - - @Override - public void changePathTo(String newPath) { - } - @Override public int incrementFailureCount() { return 0; diff --git a/gogrid/src/test/java/org/jclouds/gogrid/services/BaseGoGridAsyncClientTest.java b/gogrid/src/test/java/org/jclouds/gogrid/services/BaseGoGridAsyncClientTest.java index 69fc142b69..af34f535cb 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/services/BaseGoGridAsyncClientTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/services/BaseGoGridAsyncClientTest.java @@ -25,12 +25,12 @@ import java.util.Properties; import org.jclouds.date.TimeStamp; import org.jclouds.gogrid.config.GoGridRestClientModule; import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication; +import org.jclouds.http.HttpRequest; import org.jclouds.http.RequiresHttp; import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory.ContextSpec; -import org.jclouds.rest.internal.GeneratedHttpRequest; import com.google.common.base.Supplier; import com.google.inject.Module; @@ -41,9 +41,9 @@ import com.google.inject.Module; */ public abstract class BaseGoGridAsyncClientTest extends RestClientTest { @Override - protected void checkFilters(GeneratedHttpRequest httpMethod) { - assertEquals(httpMethod.getFilters().size(), 1); - assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class); + protected void checkFilters(HttpRequest request) { + assertEquals(request.getFilters().size(), 1); + assertEquals(request.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class); } @RequiresHttp diff --git a/ibmdev/src/test/java/org/jclouds/ibmdev/IBMDeveloperCloudAsyncClientTest.java b/ibmdev/src/test/java/org/jclouds/ibmdev/IBMDeveloperCloudAsyncClientTest.java index fd43d99e50..3930574584 100644 --- a/ibmdev/src/test/java/org/jclouds/ibmdev/IBMDeveloperCloudAsyncClientTest.java +++ b/ibmdev/src/test/java/org/jclouds/ibmdev/IBMDeveloperCloudAsyncClientTest.java @@ -30,6 +30,7 @@ import java.lang.reflect.Method; import java.util.Date; import java.util.Properties; +import org.jclouds.http.HttpRequest; import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.ParseSax; @@ -663,9 +664,9 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest httpRequest) { - assertEquals(httpRequest.getFilters().size(), 1); - assertEquals(httpRequest.getFilters().get(0).getClass(), BasicAuthentication.class); + protected void checkFilters(HttpRequest request) { + assertEquals(request.getFilters().size(), 1); + assertEquals(request.getFilters().get(0).getClass(), BasicAuthentication.class); } @Override diff --git a/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSAsyncClientTest.java b/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSAsyncClientTest.java index 864c6449a7..cb2c9916cd 100644 --- a/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSAsyncClientTest.java +++ b/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSAsyncClientTest.java @@ -33,6 +33,7 @@ import javax.ws.rs.core.HttpHeaders; import org.jclouds.blobstore.binders.BindBlobToMultipartFormTest; import org.jclouds.blobstore.functions.ReturnNullOnKeyNotFound; +import org.jclouds.http.HttpRequest; import org.jclouds.http.RequiresHttp; import org.jclouds.http.filters.BasicAuthentication; 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.functions.MapHttp4xxCodesToExceptions; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; -import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -73,50 +73,47 @@ public class PCSAsyncClientTest extends RestClientTest { public void testList() throws SecurityException, NoSuchMethodException, IOException { Method method = PCSAsyncClient.class.getMethod("list"); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - new Object[] {}); + HttpRequest request = processor.createRequest(method, new Object[] {}); - assertRequestLineEquals(httpMethod, "GET http://root HTTP/1.1"); - assertHeadersEqual(httpMethod, "X-Cloud-Depth: 2\n"); - assertPayloadEquals(httpMethod, null); + assertRequestLineEquals(request, "GET http://root HTTP/1.1"); + assertHeadersEqual(request, "X-Cloud-Depth: 2\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, ContainerHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testCreateContainer() throws SecurityException, NoSuchMethodException, IOException { Method method = PCSAsyncClient.class.getMethod("createContainer", String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - new Object[] { "container" }); + HttpRequest request = processor.createRequest(method, new Object[] { "container" }); - assertRequestLineEquals(httpMethod, "POST http://root/contents HTTP/1.1"); - assertHeadersEqual(httpMethod, + assertRequestLineEquals(request, "POST http://root/contents HTTP/1.1"); + assertHeadersEqual(request, "Content-Length: 45\nContent-Type: application/vnd.csp.container-info+xml\n"); - assertPayloadEquals(httpMethod, "container"); + assertPayloadEquals(request, "container"); - assertResponseParserClassEquals(method, httpMethod, - ParseURIFromListOrLocationHeaderIf20x.class); + assertResponseParserClassEquals(method, request, ParseURIFromListOrLocationHeaderIf20x.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testDeleteContainer() throws SecurityException, NoSuchMethodException { Method method = PCSAsyncClient.class.getMethod("deleteContainer", URI.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - new Object[] { URI.create("http://localhost/container/1234") }); - assertEquals(httpMethod.getRequestLine(), "DELETE http://localhost/container/1234 HTTP/1.1"); - assertEquals(httpMethod.getHeaders().size(), 0); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + HttpRequest request = processor.createRequest(method, new Object[] { URI + .create("http://localhost/container/1234") }); + assertEquals(request.getRequestLine(), "DELETE http://localhost/container/1234 HTTP/1.1"); + assertEquals(request.getHeaders().size(), 0); + assertEquals(processor.createResponseParser(method, request).getClass(), CloseContentAndReturn.class); assertEquals(RestAnnotationProcessor.getSaxResponseParserClassOrNull(method), null); - assertEquals(httpMethod.getFilters().size(), 1); - assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class); + assertEquals(request.getFilters().size(), 1); + assertEquals(request.getFilters().get(0).getClass(), BasicAuthentication.class); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnVoidOnNotFoundOr404.class); @@ -124,16 +121,16 @@ public class PCSAsyncClientTest extends RestClientTest { public void testListURI() throws SecurityException, NoSuchMethodException { Method method = PCSAsyncClient.class.getMethod("list", URI.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - new Object[] { URI.create("http://localhost/mycontainer") }); - assertEquals(httpMethod.getRequestLine(), "GET http://localhost/mycontainer HTTP/1.1"); - assertEquals(httpMethod.getHeaders().size(), 1); - assertEquals(httpMethod.getHeaders().get("X-Cloud-Depth"), Collections.singletonList("2")); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseSax.class); + HttpRequest request = processor.createRequest(method, new Object[] { URI + .create("http://localhost/mycontainer") }); + assertEquals(request.getRequestLine(), "GET http://localhost/mycontainer HTTP/1.1"); + assertEquals(request.getHeaders().size(), 1); + assertEquals(request.getHeaders().get("X-Cloud-Depth"), Collections.singletonList("2")); + assertEquals(processor.createResponseParser(method, request).getClass(), ParseSax.class); assertEquals(RestAnnotationProcessor.getSaxResponseParserClassOrNull(method), ContainerHandler.class); - assertEquals(httpMethod.getFilters().size(), 1); - assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class); + assertEquals(request.getFilters().size(), 1); + assertEquals(request.getFilters().get(0).getClass(), BasicAuthentication.class); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), MapHttp4xxCodesToExceptions.class); @@ -141,16 +138,16 @@ public class PCSAsyncClientTest extends RestClientTest { public void testGetFileInfo() throws SecurityException, NoSuchMethodException { Method method = PCSAsyncClient.class.getMethod("getFileInfo", URI.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - new Object[] { URI.create("http://localhost/myfile") }); - assertEquals(httpMethod.getRequestLine(), "GET http://localhost/myfile HTTP/1.1"); - assertEquals(httpMethod.getHeaders().size(), 1); - assertEquals(httpMethod.getHeaders().get("X-Cloud-Depth"), Collections.singletonList("2")); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseSax.class); + HttpRequest request = processor.createRequest(method, new Object[] { URI + .create("http://localhost/myfile") }); + assertEquals(request.getRequestLine(), "GET http://localhost/myfile HTTP/1.1"); + assertEquals(request.getHeaders().size(), 1); + assertEquals(request.getHeaders().get("X-Cloud-Depth"), Collections.singletonList("2")); + assertEquals(processor.createResponseParser(method, request).getClass(), ParseSax.class); assertEquals(RestAnnotationProcessor.getSaxResponseParserClassOrNull(method), FileHandler.class); - assertEquals(httpMethod.getFilters().size(), 1); - assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class); + assertEquals(request.getFilters().size(), 1); + assertEquals(request.getFilters().get(0).getClass(), BasicAuthentication.class); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnNullOnKeyNotFound.class); @@ -158,70 +155,69 @@ public class PCSAsyncClientTest extends RestClientTest { public void testUploadFile() throws SecurityException, NoSuchMethodException, IOException { Method method = PCSAsyncClient.class.getMethod("uploadFile", URI.class, PCSFile.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - new Object[] { URI.create("http://localhost/mycontainer"), - blobToPCSFile.apply(BindBlobToMultipartFormTest.TEST_BLOB) }); + HttpRequest request = processor.createRequest(method, new Object[] { + URI.create("http://localhost/mycontainer"), + blobToPCSFile.apply(BindBlobToMultipartFormTest.TEST_BLOB) }); - assertRequestLineEquals(httpMethod, "POST http://localhost/mycontainer/contents HTTP/1.1"); - assertHeadersEqual(httpMethod, + assertRequestLineEquals(request, "POST http://localhost/mycontainer/contents HTTP/1.1"); + assertHeadersEqual(request, "Content-Length: 113\nContent-Type: multipart/form-data; boundary=--JCLOUDS--\n"); - assertPayloadEquals(httpMethod, BindBlobToMultipartFormTest.EXPECTS); + assertPayloadEquals(request, BindBlobToMultipartFormTest.EXPECTS); - assertResponseParserClassEquals(method, httpMethod, - ParseURIFromListOrLocationHeaderIf20x.class); + assertResponseParserClassEquals(method, request, ParseURIFromListOrLocationHeaderIf20x.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testUploadBlock() throws SecurityException, NoSuchMethodException, IOException { Method method = PCSAsyncClient.class.getMethod("uploadBlock", URI.class, PCSFile.class, Array .newInstance(PutBlockOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - new Object[] { URI.create("http://localhost/mycontainer"), - blobToPCSFile.apply(BindBlobToMultipartFormTest.TEST_BLOB) }); + HttpRequest request = processor.createRequest(method, new Object[] { + URI.create("http://localhost/mycontainer"), + blobToPCSFile.apply(BindBlobToMultipartFormTest.TEST_BLOB) }); - assertRequestLineEquals(httpMethod, "PUT http://localhost/mycontainer/content HTTP/1.1"); - assertHeadersEqual(httpMethod, "Content-Length: 5\n"); - assertPayloadEquals(httpMethod, "hello"); + assertRequestLineEquals(request, "PUT http://localhost/mycontainer/content HTTP/1.1"); + assertHeadersEqual(request, "Content-Length: 5\n"); + assertPayloadEquals(request, "hello"); - assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); + assertResponseParserClassEquals(method, request, CloseContentAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testDownloadFile() throws SecurityException, NoSuchMethodException, IOException { Method method = PCSAsyncClient.class.getMethod("downloadFile", URI.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - new Object[] { URI.create("http://localhost/container") }); + HttpRequest request = processor.createRequest(method, new Object[] { URI + .create("http://localhost/container") }); - assertRequestLineEquals(httpMethod, "GET http://localhost/container/content HTTP/1.1"); - assertHeadersEqual(httpMethod, ""); - assertPayloadEquals(httpMethod, null); + assertRequestLineEquals(request, "GET http://localhost/container/content HTTP/1.1"); + assertHeadersEqual(request, ""); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ReturnInputStream.class); + assertResponseParserClassEquals(method, request, ReturnInputStream.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, ReturnNullOnKeyNotFound.class); - checkFilters(httpMethod); + checkFilters(request); } public void testDeleteFile() throws SecurityException, NoSuchMethodException, IOException { Method method = PCSAsyncClient.class.getMethod("deleteFile", URI.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - new Object[] { URI.create("http://localhost/contents/file") }); - assertEquals(httpMethod.getRequestLine(), "DELETE http://localhost/contents/file HTTP/1.1"); - assertEquals(httpMethod.getHeaders().size(), 0); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + HttpRequest request = processor.createRequest(method, new Object[] { URI + .create("http://localhost/contents/file") }); + assertEquals(request.getRequestLine(), "DELETE http://localhost/contents/file HTTP/1.1"); + assertEquals(request.getHeaders().size(), 0); + assertEquals(processor.createResponseParser(method, request).getClass(), CloseContentAndReturn.class); assertEquals(RestAnnotationProcessor.getSaxResponseParserClassOrNull(method), null); - assertEquals(httpMethod.getFilters().size(), 1); - assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class); + assertEquals(request.getFilters().size(), 1); + assertEquals(request.getFilters().get(0).getClass(), BasicAuthentication.class); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnVoidOnNotFoundOr404.class); @@ -230,21 +226,21 @@ public class PCSAsyncClientTest extends RestClientTest { public void testPutMetadata() throws SecurityException, NoSuchMethodException { Method method = PCSAsyncClient.class.getMethod("putMetadataItem", URI.class, String.class, String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - new Object[] { URI.create("http://localhost/contents/file"), "pow", "bar" }); - assertEquals(httpMethod.getRequestLine(), + HttpRequest request = processor.createRequest(method, new Object[] { + URI.create("http://localhost/contents/file"), "pow", "bar" }); + assertEquals(request.getRequestLine(), "PUT http://localhost/contents/file/metadata/pow HTTP/1.1"); - assertEquals(httpMethod.getMethod(), HttpMethod.PUT); - assertEquals(httpMethod.getHeaders().size(), 2); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections - .singletonList(httpMethod.getPayload().toString().getBytes().length + "")); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections + assertEquals(request.getMethod(), HttpMethod.PUT); + assertEquals(request.getHeaders().size(), 2); + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections + .singletonList(request.getPayload().toString().getBytes().length + "")); + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections .singletonList("application/unknown")); - assertEquals("bar", httpMethod.getPayload().getRawContent()); + assertEquals("bar", request.getPayload().getRawContent()); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), MapHttp4xxCodesToExceptions.class); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + assertEquals(processor.createResponseParser(method, request).getClass(), CloseContentAndReturn.class); } @@ -252,25 +248,24 @@ public class PCSAsyncClientTest extends RestClientTest { Method method = PCSAsyncClient.class.getMethod("addMetadataItemToMap", URI.class, String.class, Map.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - new Object[] { URI.create("http://localhost/pow"), "newkey", - ImmutableMap.of("key", "value") }); - assertEquals(httpMethod.getRequestLine(), "GET http://localhost/pow/metadata/newkey HTTP/1.1"); + HttpRequest request = processor.createRequest(method, new Object[] { + URI.create("http://localhost/pow"), "newkey", ImmutableMap.of("key", "value") }); + assertEquals(request.getRequestLine(), "GET http://localhost/pow/metadata/newkey HTTP/1.1"); - assertEquals(httpMethod.getHeaders().size(), 0); + assertEquals(request.getHeaders().size(), 0); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), MapHttp4xxCodesToExceptions.class); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + assertEquals(processor.createResponseParser(method, request).getClass(), AddMetadataItemIntoMap.class); } private BlobToPCSFile blobToPCSFile; @Override - protected void checkFilters(GeneratedHttpRequest httpMethod) { - assertEquals(httpMethod.getFilters().size(), 1); - assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class); + protected void checkFilters(HttpRequest request) { + assertEquals(request.getFilters().size(), 1); + assertEquals(request.getFilters().get(0).getClass(), BasicAuthentication.class); } @Override @@ -300,9 +295,10 @@ public class PCSAsyncClientTest extends RestClientTest { } @Override - protected Response provideCloudResponse(AsyncClientFactory factory){ + protected Response provideCloudResponse(AsyncClientFactory factory) { return null; } + @Override protected URI provideRootContainerUrl(Response response) { return URI.create("http://root"); @@ -311,10 +307,10 @@ public class PCSAsyncClientTest extends RestClientTest { @Override public ContextSpec createContextSpec() { - Properties properties = new Properties(); - properties.setProperty("pcs.apiversion","foo"); - properties.setProperty("pcs.endpoint","http://goo"); - return new RestContextFactory().createContextSpec("pcs", "identity", "credential", - properties); + Properties properties = new Properties(); + properties.setProperty("pcs.apiversion", "foo"); + properties.setProperty("pcs.endpoint", "http://goo"); + return new RestContextFactory() + .createContextSpec("pcs", "identity", "credential", properties); } } diff --git a/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSCloudTest.java b/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSCloudTest.java index eb6a74ca16..b35978e6b3 100644 --- a/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSCloudTest.java +++ b/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSCloudTest.java @@ -25,6 +25,7 @@ import java.lang.reflect.Method; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; +import org.jclouds.http.HttpRequest; import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.http.functions.ParseSax; 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.RestContextFactory.ContextSpec; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; -import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; @@ -48,14 +48,14 @@ public class PCSCloudTest extends RestClientTest { public void testAuthenticate() throws SecurityException, NoSuchMethodException { Method method = PCSCloudAsyncClient.class.getMethod("authenticate"); - GeneratedHttpRequest httpMethod = processor.createRequest(method); - assertEquals(httpMethod.getRequestLine(), "GET http://localhost:8080/ HTTP/1.1"); - assertEquals(httpMethod.getHeaders().size(), 0); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), ParseSax.class); + HttpRequest request = processor.createRequest(method); + assertEquals(request.getRequestLine(), "GET http://localhost:8080/ HTTP/1.1"); + assertEquals(request.getHeaders().size(), 0); + assertEquals(processor.createResponseParser(method, request).getClass(), ParseSax.class); assertEquals(RestAnnotationProcessor.getSaxResponseParserClassOrNull(method), CloudXlinkHandler.class); - assertEquals(httpMethod.getFilters().size(), 1); - assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class); + assertEquals(request.getFilters().size(), 1); + assertEquals(request.getFilters().get(0).getClass(), BasicAuthentication.class); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), MapHttp4xxCodesToExceptions.class); @@ -74,7 +74,7 @@ public class PCSCloudTest extends RestClientTest { } @Override - protected void checkFilters(GeneratedHttpRequest httpMethod) { + protected void checkFilters(HttpRequest request) { } diff --git a/nirvanix/sdn/core/src/main/java/org/jclouds/nirvanix/sdn/binders/BindMetadataToQueryParams.java b/nirvanix/sdn/core/src/main/java/org/jclouds/nirvanix/sdn/binders/BindMetadataToQueryParams.java index cdcc05174e..937da5db23 100644 --- a/nirvanix/sdn/core/src/main/java/org/jclouds/nirvanix/sdn/binders/BindMetadataToQueryParams.java +++ b/nirvanix/sdn/core/src/main/java/org/jclouds/nirvanix/sdn/binders/BindMetadataToQueryParams.java @@ -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.checkNotNull; +import static org.jclouds.http.HttpUtils.addQueryParamTo; import java.util.List; import java.util.Map; 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.rest.Binder; -import org.jclouds.rest.internal.GeneratedHttpRequest; import com.google.common.collect.Lists; +@Singleton public class BindMetadataToQueryParams implements Binder { + private final Provider builder; + + @Inject + BindMetadataToQueryParams(Provider builder) { + this.builder = builder; + } @SuppressWarnings("unchecked") 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, "this binder is only valid for Maps!"); Map userMetadata = (Map) input; @@ -44,6 +54,6 @@ public class BindMetadataToQueryParams implements Binder { for (Entry entry : userMetadata.entrySet()) { 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()); } } diff --git a/nirvanix/sdn/core/src/main/java/org/jclouds/nirvanix/sdn/filters/AddSessionTokenToRequest.java b/nirvanix/sdn/core/src/main/java/org/jclouds/nirvanix/sdn/filters/AddSessionTokenToRequest.java index 4d853c9a6f..c641459fdc 100644 --- a/nirvanix/sdn/core/src/main/java/org/jclouds/nirvanix/sdn/filters/AddSessionTokenToRequest.java +++ b/nirvanix/sdn/core/src/main/java/org/jclouds/nirvanix/sdn/filters/AddSessionTokenToRequest.java @@ -18,8 +18,7 @@ */ package org.jclouds.nirvanix.sdn.filters; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.http.HttpUtils.addQueryParamTo; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; @@ -27,13 +26,13 @@ import java.util.concurrent.atomic.AtomicReference; import javax.inject.Inject; import javax.inject.Provider; import javax.inject.Singleton; +import javax.ws.rs.core.UriBuilder; import org.jclouds.http.HttpException; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequestFilter; import org.jclouds.nirvanix.sdn.SessionToken; 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 @@ -46,6 +45,7 @@ import org.jclouds.rest.internal.GeneratedHttpRequest; public class AddSessionTokenToRequest implements HttpRequestFilter { private final Provider authTokenProvider; + private final Provider builder; public final long BILLION = 1000000000; public final long MINUTES = 60 * BILLION; @@ -80,17 +80,15 @@ public class AddSessionTokenToRequest implements HttpRequestFilter { } @Inject - public AddSessionTokenToRequest(@SessionToken Provider authTokenProvider) { + public AddSessionTokenToRequest(@SessionToken Provider authTokenProvider, + Provider builder) { + this.builder = builder; this.authTokenProvider = authTokenProvider; authToken = new AtomicReference(); } public void filter(HttpRequest request) throws HttpException { - checkArgument(checkNotNull(request, "input") instanceof GeneratedHttpRequest, - "this decorator is only valid for GeneratedHttpRequests!"); - ((GeneratedHttpRequest) request).addQueryParam(SDNQueryParams.SESSIONTOKEN, - getSessionToken()); - + addQueryParamTo(request, SDNQueryParams.SESSIONTOKEN, getSessionToken(), builder.get()); } } \ No newline at end of file diff --git a/nirvanix/sdn/core/src/main/java/org/jclouds/nirvanix/sdn/filters/InsertUserContextIntoPath.java b/nirvanix/sdn/core/src/main/java/org/jclouds/nirvanix/sdn/filters/InsertUserContextIntoPath.java index fcccb68b2c..b1d585bf05 100644 --- a/nirvanix/sdn/core/src/main/java/org/jclouds/nirvanix/sdn/filters/InsertUserContextIntoPath.java +++ b/nirvanix/sdn/core/src/main/java/org/jclouds/nirvanix/sdn/filters/InsertUserContextIntoPath.java @@ -18,18 +18,18 @@ */ package org.jclouds.nirvanix.sdn.filters; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.http.HttpUtils.changePathTo; import javax.inject.Inject; import javax.inject.Named; +import javax.inject.Provider; import javax.inject.Singleton; +import javax.ws.rs.core.UriBuilder; import org.jclouds.http.HttpException; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequestFilter; 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 @@ -43,18 +43,18 @@ public class InsertUserContextIntoPath implements HttpRequestFilter { private final AddSessionTokenToRequest sessionManager; private final String pathPrefix; + private final Provider builder; @Inject public InsertUserContextIntoPath(AddSessionTokenToRequest sessionManager, @Named(SDNConstants.PROPERTY_SDN_APPNAME) String appname, - @Named(SDNConstants.PROPERTY_SDN_USERNAME) String username) { + @Named(SDNConstants.PROPERTY_SDN_USERNAME) String username, Provider builder) { + this.builder = builder; this.sessionManager = sessionManager; this.pathPrefix = String.format("/%s/%s/", appname, username); } public void filter(HttpRequest request) throws HttpException { - checkArgument(checkNotNull(request, "input") instanceof GeneratedHttpRequest, - "this decorator is only valid for GeneratedHttpRequests!"); String sessionToken = sessionManager.getSessionToken(); int prefixIndex = request.getEndpoint().getPath().indexOf(pathPrefix); String path; @@ -63,8 +63,7 @@ public class InsertUserContextIntoPath implements HttpRequestFilter { } else { // replace token path = "/" + sessionToken + request.getEndpoint().getPath().substring(prefixIndex); } - ((GeneratedHttpRequest) request).replacePath(path); - + changePathTo(request, path, builder.get()); } } \ No newline at end of file diff --git a/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNAsyncClientTest.java b/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNAsyncClientTest.java index 79f015802d..6a3e449950 100644 --- a/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNAsyncClientTest.java +++ b/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNAsyncClientTest.java @@ -28,6 +28,7 @@ import java.util.Properties; import org.jclouds.blobstore.binders.BindBlobToMultipartFormTest; import org.jclouds.blobstore.domain.Blob; +import org.jclouds.http.HttpRequest; import org.jclouds.http.RequiresHttp; import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.ReturnStringIf200; @@ -41,7 +42,6 @@ import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory.ContextSpec; -import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; @@ -60,20 +60,19 @@ public class SDNAsyncClientTest extends RestClientTest { public void testGetStorageNode() throws SecurityException, NoSuchMethodException, IOException { Method method = SDNAsyncClient.class.getMethod("getStorageNode", String.class, long.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - "adriansmovies", 734859264); + HttpRequest request = processor.createRequest(method, "adriansmovies", 734859264); assertRequestLineEquals( - httpMethod, + request, "GET http://services.nirvanix.com/ws/IMFS/GetStorageNode.ashx?output=json&destFolderPath=adriansmovies&sizeBytes=734859264 HTTP/1.1"); - assertHeadersEqual(httpMethod, ""); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, ""); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseUploadInfoFromJsonResponse.class); + assertResponseParserClassEquals(method, request, ParseUploadInfoFromJsonResponse.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } @@ -81,13 +80,13 @@ public class SDNAsyncClientTest extends RestClientTest { Method method = SDNAsyncClient.class.getMethod("upload", URI.class, String.class, String.class, Blob.class); Blob blob = BindBlobToMultipartFormTest.TEST_BLOB; - GeneratedHttpRequest httpMethod = processor.createRequest(method, URI - .create("http://uploader"), "token", "adriansmovies", blob); + HttpRequest request = processor.createRequest(method, URI.create("http://uploader"), "token", + "adriansmovies", blob); assertRequestLineEquals( - httpMethod, + request, "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"); StringBuffer expects = new StringBuffer(); expects.append("----JCLOUDS--\r\n"); @@ -96,74 +95,72 @@ public class SDNAsyncClientTest extends RestClientTest { expects.append("hello\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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testSetMetadata() throws SecurityException, NoSuchMethodException, IOException { Method method = SDNAsyncClient.class.getMethod("setMetadata", String.class, Map.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - "adriansmovies/sushi.avi", ImmutableMap.of("Chef", "Kawasaki")); + HttpRequest request = processor.createRequest(method, "adriansmovies/sushi.avi", ImmutableMap + .of("Chef", "Kawasaki")); assertRequestLineEquals( - httpMethod, + request, "GET http://services.nirvanix.com/ws/Metadata/SetMetadata.ashx?output=json&path=adriansmovies/sushi.avi&metadata=chef:Kawasaki HTTP/1.1"); - assertHeadersEqual(httpMethod, ""); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, ""); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); + assertResponseParserClassEquals(method, request, CloseContentAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testGetMetadata() throws SecurityException, NoSuchMethodException, IOException { Method method = SDNAsyncClient.class.getMethod("getMetadata", String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - "adriansmovies/sushi.avi"); + HttpRequest request = processor.createRequest(method, "adriansmovies/sushi.avi"); assertRequestLineEquals( - httpMethod, + request, "GET http://services.nirvanix.com/ws/Metadata/GetMetadata.ashx?output=json&path=adriansmovies/sushi.avi HTTP/1.1"); - assertHeadersEqual(httpMethod, ""); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, ""); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseMetadataFromJsonResponse.class); + assertResponseParserClassEquals(method, request, ParseMetadataFromJsonResponse.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testGetFile() throws SecurityException, NoSuchMethodException, IOException { Method method = SDNAsyncClient.class.getMethod("getFile", String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - "adriansmovies/sushi.avi"); + HttpRequest request = processor.createRequest(method, "adriansmovies/sushi.avi"); - assertRequestLineEquals(httpMethod, + assertRequestLineEquals(request, "GET http://services.nirvanix.com/adriansmovies/sushi.avi?output=json HTTP/1.1"); - assertHeadersEqual(httpMethod, ""); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, ""); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ReturnStringIf200.class); + assertResponseParserClassEquals(method, request, ReturnStringIf200.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - assertEquals(httpMethod.getFilters().size(), 1); - assertEquals(httpMethod.getFilters().get(0).getClass(), InsertUserContextIntoPath.class); + assertEquals(request.getFilters().size(), 1); + assertEquals(request.getFilters().get(0).getClass(), InsertUserContextIntoPath.class); } @Override - protected void checkFilters(GeneratedHttpRequest httpMethod) { - assertEquals(httpMethod.getFilters().size(), 1); - assertEquals(httpMethod.getFilters().get(0).getClass(), AddSessionTokenToRequest.class); + protected void checkFilters(HttpRequest request) { + assertEquals(request.getFilters().size(), 1); + assertEquals(request.getFilters().get(0).getClass(), AddSessionTokenToRequest.class); } @Override diff --git a/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNAuthAsyncClientTest.java b/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNAuthAsyncClientTest.java index b40426abe7..c13272f151 100755 --- a/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNAuthAsyncClientTest.java +++ b/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNAuthAsyncClientTest.java @@ -30,7 +30,6 @@ import org.jclouds.nirvanix.sdn.SDNAuthenticationLiveTest.SDNAuthClient; import org.jclouds.nirvanix.sdn.functions.ParseSessionTokenFromJsonResponse; import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestContextFactory.ContextSpec; -import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; @@ -47,20 +46,19 @@ public class SDNAuthAsyncClientTest extends RestClientTest { public void testAuthenticate() throws SecurityException, NoSuchMethodException { Method method = SDNAuthAsyncClient.class.getMethod("authenticate", String.class, String.class, String.class); - HttpRequest httpMethod = processor.createRequest(method, - new Object[] { "apple", "foo", "bar" }); - assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); - assertEquals(httpMethod.getEndpoint().getPath(), "/ws/Authentication/Login.ashx"); - assertEquals(httpMethod.getEndpoint().getQuery(), + HttpRequest request = processor.createRequest(method, new Object[] { "apple", "foo", "bar" }); + assertEquals(request.getEndpoint().getHost(), "localhost"); + assertEquals(request.getEndpoint().getPath(), "/ws/Authentication/Login.ashx"); + assertEquals(request.getEndpoint().getQuery(), "output=json&appKey=apple&password=bar&username=foo"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 0); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 0); assertEquals(RestAnnotationProcessor.getParserOrThrowException(method), ParseSessionTokenFromJsonResponse.class); } @Override - protected void checkFilters(GeneratedHttpRequest httpMethod) { + protected void checkFilters(HttpRequest request) { } diff --git a/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/binders/BindMetadataToQueryParamsTest.java b/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/binders/BindMetadataToQueryParamsTest.java index 327315a74c..1be903322b 100644 --- a/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/binders/BindMetadataToQueryParamsTest.java +++ b/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/binders/BindMetadataToQueryParamsTest.java @@ -19,13 +19,16 @@ package org.jclouds.nirvanix.sdn.binders; 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.net.URI; +import javax.inject.Provider; 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.rest.internal.GeneratedHttpRequest; import org.testng.annotations.Test; @@ -42,24 +45,34 @@ public class BindMetadataToQueryParamsTest { @Test(expectedExceptions = IllegalArgumentException.class) public void testMustBeMap() { - BindMetadataToQueryParams binder = new BindMetadataToQueryParams(); - HttpRequest request = new HttpRequest(HttpMethod.POST, URI.create("http://localhost")); + BindMetadataToQueryParams binder = new BindMetadataToQueryParams(null); + HttpRequest request = new HttpRequest(HttpMethod.POST, URI.create("http://localhost"), new char[]{ '/', ':' }); binder.bindToRequest(request, new File("foo")); } @Test public void testCorrect() throws SecurityException, NoSuchMethodException { - BindMetadataToQueryParams binder = new BindMetadataToQueryParams(); - GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); - request.addQueryParam("metadata", "imagename:foo", "serverid:2"); - replay(request); + HttpRequest request = new HttpRequest("GET", URI.create("http://momma/"), new char[]{ '/', ':' }); + + BindMetadataToQueryParams binder = new BindMetadataToQueryParams(new Provider() { + + @Override + public UriBuilder get() { + return new UriBuilderImpl(); + } + + }); + 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 }) public void testNullIsBad() { - BindMetadataToQueryParams binder = new BindMetadataToQueryParams(); + BindMetadataToQueryParams binder = new BindMetadataToQueryParams(null); GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); binder.bindToRequest(request, null); } diff --git a/opscodeplatform/src/test/java/org/jclouds/opscodeplatform/OpscodePlatformAsyncClientTest.java b/opscodeplatform/src/test/java/org/jclouds/opscodeplatform/OpscodePlatformAsyncClientTest.java index 6b5238f303..1c9e14b6ef 100644 --- a/opscodeplatform/src/test/java/org/jclouds/opscodeplatform/OpscodePlatformAsyncClientTest.java +++ b/opscodeplatform/src/test/java/org/jclouds/opscodeplatform/OpscodePlatformAsyncClientTest.java @@ -44,6 +44,7 @@ import org.jclouds.chef.functions.ParseUserFromJson; import org.jclouds.concurrent.config.ConfiguresExecutorService; import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.date.TimeStamp; +import org.jclouds.http.HttpRequest; import org.jclouds.http.RequiresHttp; import org.jclouds.http.TransformingHttpCommandExecutorService; import org.jclouds.http.config.ConfiguresHttpCommandExecutorService; @@ -278,9 +279,9 @@ public class OpscodePlatformAsyncClientTest extends RestClientTest httpRequest) { - assertEquals(httpRequest.getFilters().size(), 1); - assertEquals(httpRequest.getFilters().get(0).getClass(), SignedHeaderAuth.class); + protected void checkFilters(HttpRequest request) { + assertEquals(request.getFilters().size(), 1); + assertEquals(request.getFilters().get(0).getClass(), SignedHeaderAuth.class); } @Override diff --git a/rackspace/src/main/java/org/jclouds/rackspace/filters/AddTimestampQuery.java b/rackspace/src/main/java/org/jclouds/rackspace/filters/AddTimestampQuery.java index beaf0ae384..367e50b6f5 100644 --- a/rackspace/src/main/java/org/jclouds/rackspace/filters/AddTimestampQuery.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/filters/AddTimestampQuery.java @@ -18,16 +18,19 @@ */ package org.jclouds.rackspace.filters; +import static org.jclouds.http.HttpUtils.addQueryParamTo; + import java.util.Date; import javax.inject.Inject; +import javax.inject.Provider; import javax.inject.Singleton; +import javax.ws.rs.core.UriBuilder; import org.jclouds.date.TimeStamp; import org.jclouds.http.HttpException; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequestFilter; -import org.jclouds.rest.internal.GeneratedHttpRequest; import com.google.common.base.Supplier; @@ -40,15 +43,16 @@ import com.google.common.base.Supplier; @Singleton public class AddTimestampQuery implements HttpRequestFilter { private final Supplier dateProvider; + private final Provider builder; @Inject - public AddTimestampQuery(@TimeStamp Supplier dateProvider) { + public AddTimestampQuery(@TimeStamp Supplier dateProvider, Provider builder) { + this.builder = builder; this.dateProvider = dateProvider; } - public void filter(HttpRequest in) throws HttpException { - GeneratedHttpRequest request = (GeneratedHttpRequest) in; - request.addQueryParam("now", dateProvider.get().getTime() + ""); + public void filter(HttpRequest request) throws HttpException { + addQueryParamTo(request, "now", dateProvider.get().getTime() + "", builder.get()); } } \ No newline at end of file diff --git a/rackspace/src/test/java/org/jclouds/rackspace/RackspaceAuthAsyncClientTest.java b/rackspace/src/test/java/org/jclouds/rackspace/RackspaceAuthAsyncClientTest.java index 35af5e43e1..ab77ca9778 100755 --- a/rackspace/src/test/java/org/jclouds/rackspace/RackspaceAuthAsyncClientTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/RackspaceAuthAsyncClientTest.java @@ -32,7 +32,6 @@ import org.jclouds.rackspace.functions.ParseAuthenticationResponseFromHeaders; import org.jclouds.rackspace.reference.RackspaceHeaders; import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestContextFactory.ContextSpec; -import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; @@ -49,14 +48,14 @@ public class RackspaceAuthAsyncClientTest extends RestClientTest httpMethod) { + protected void checkFilters(HttpRequest request) { } @Override diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersAsyncClientTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersAsyncClientTest.java index 03d23c1f96..6d9ccf78f1 100755 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersAsyncClientTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersAsyncClientTest.java @@ -38,6 +38,7 @@ import javax.ws.rs.HttpMethod; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; +import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.ReturnFalseOn404; import org.jclouds.http.functions.ReturnTrueIf2xx; @@ -70,7 +71,6 @@ import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; -import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; @@ -94,48 +94,46 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { "ralphie", 2, 1 }); - assertEquals("{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1}}", httpMethod + HttpRequest request = processor.createRequest(method, new Object[] { "ralphie", 2, 1 }); + assertEquals("{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1}}", request .getPayload().getRawContent()); - validateCreateServer(method, httpMethod, null); + validateCreateServer(method, request, null); } public void testCreateServerWithIpGroup() throws SecurityException, NoSuchMethodException { Method method = CloudServersAsyncClient.class.getMethod("createServer", String.class, int.class, int.class, createServerOptionsVarargsClass); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - new Object[] { "ralphie", 2, 1, withSharedIpGroup(2) }); + HttpRequest request = processor.createRequest(method, new Object[] { "ralphie", 2, 1, + withSharedIpGroup(2) }); assertEquals( "{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"sharedIpGroupId\":2}}", - httpMethod.getPayload().getRawContent()); - validateCreateServer(method, httpMethod, null); + request.getPayload().getRawContent()); + validateCreateServer(method, request, null); } public void testCreateServerWithFile() throws SecurityException, NoSuchMethodException { Method method = CloudServersAsyncClient.class.getMethod("createServer", String.class, int.class, int.class, createServerOptionsVarargsClass); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - new Object[] { "ralphie", 2, 1, - new CreateServerOptions[] { withFile("/etc/jclouds", "foo".getBytes()) } }); + HttpRequest request = processor.createRequest(method, new Object[] { "ralphie", 2, 1, + new CreateServerOptions[] { withFile("/etc/jclouds", "foo".getBytes()) } }); assertEquals( "{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"personality\":[{\"path\":\"/etc/jclouds\",\"contents\":\"Zm9v\"}]}}", - httpMethod.getPayload().getRawContent()); - validateCreateServer(method, httpMethod, null); + request.getPayload().getRawContent()); + validateCreateServer(method, request, null); } public void testCreateServerWithMetadata() throws SecurityException, NoSuchMethodException { Method method = CloudServersAsyncClient.class.getMethod("createServer", String.class, int.class, int.class, createServerOptionsVarargsClass); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - new Object[] { "ralphie", 2, 1, withMetadata(ImmutableMap.of("foo", "bar")) }); + HttpRequest request = processor.createRequest(method, new Object[] { "ralphie", 2, 1, + withMetadata(ImmutableMap.of("foo", "bar")) }); assertEquals( "{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"metadata\":{\"foo\":\"bar\"}}}", - httpMethod.getPayload().getRawContent()); - validateCreateServer(method, httpMethod, null); + request.getPayload().getRawContent()); + validateCreateServer(method, request, null); } public void testCreateServerWithIpGroupAndSharedIp() throws SecurityException, @@ -143,27 +141,26 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { "ralphie", 2, 1, withSharedIpGroup(2).withSharedIp("127.0.0.1") }); + HttpRequest request = processor.createRequest(method, new Object[] { "ralphie", 2, 1, + withSharedIpGroup(2).withSharedIp("127.0.0.1") }); assertEquals( "{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"sharedIpGroupId\":2,\"addresses\":{\"public\":[\"127.0.0.1\"]}}}", - httpMethod.getPayload().getRawContent()); - validateCreateServer(method, httpMethod, null); + request.getPayload().getRawContent()); + validateCreateServer(method, request, null); } - private void validateCreateServer(Method method, - GeneratedHttpRequest httpMethod, Object[] args) { - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/servers"); - assertEquals(httpMethod.getEndpoint().getQuery(), "format=json"); - assertEquals(httpMethod.getMethod(), HttpMethod.POST); - assertEquals(httpMethod.getHeaders().size(), 2); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections - .singletonList(httpMethod.getPayload().getRawContent().toString().getBytes().length + private void validateCreateServer(Method method, HttpRequest request, Object[] args) { + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/servers"); + assertEquals(request.getEndpoint().getQuery(), "format=json"); + assertEquals(request.getMethod(), HttpMethod.POST); + assertEquals(request.getHeaders().size(), 2); + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections + .singletonList(request.getPayload().getRawContent().toString().getBytes().length + "")); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections .singletonList(MediaType.APPLICATION_JSON)); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + assertEquals(processor.createResponseParser(method, request).getClass(), ParseServerFromJsonResponse.class); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), @@ -175,16 +172,15 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { 2 }); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/images/2"); - assertEquals(httpMethod.getMethod(), HttpMethod.DELETE); - assertEquals(httpMethod.getHeaders().size(), 0); + HttpRequest request = processor.createRequest(method, new Object[] { 2 }); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/images/2"); + assertEquals(request.getMethod(), HttpMethod.DELETE); + assertEquals(request.getHeaders().size(), 0); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnFalseOnNotFoundOr404.class); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + assertEquals(processor.createResponseParser(method, request).getClass(), ReturnTrueIf2xx.class); } @@ -192,14 +188,13 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] {}); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/servers"); - assertEquals(httpMethod.getEndpoint().getQuery(), "format=json"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 0); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + HttpRequest request = processor.createRequest(method, new Object[] {}); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/servers"); + assertEquals(request.getEndpoint().getQuery(), "format=json"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 0); + assertEquals(processor.createResponseParser(method, request).getClass(), ParseServerListFromJsonResponse.class); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), @@ -212,15 +207,15 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { changesSince(now).maxResults(1).startAt(2) }); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/servers"); - assertEquals(httpMethod.getEndpoint().getQuery(), "format=json&changes-since=" - + now.getTime() / 1000 + "&limit=1&offset=2"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 0); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + HttpRequest request = processor.createRequest(method, new Object[] { changesSince(now) + .maxResults(1).startAt(2) }); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/servers"); + assertEquals(request.getEndpoint().getQuery(), "format=json&changes-since=" + now.getTime() + / 1000 + "&limit=1&offset=2"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 0); + assertEquals(processor.createResponseParser(method, request).getClass(), ParseServerListFromJsonResponse.class); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), @@ -231,14 +226,13 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { withDetails() }); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/servers/detail"); - assertEquals(httpMethod.getEndpoint().getQuery(), "format=json"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 0); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + HttpRequest request = processor.createRequest(method, new Object[] { withDetails() }); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/servers/detail"); + assertEquals(request.getEndpoint().getQuery(), "format=json"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 0); + assertEquals(processor.createResponseParser(method, request).getClass(), ParseServerListFromJsonResponse.class); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), @@ -248,14 +242,13 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { 2 }); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2"); - assertEquals(httpMethod.getEndpoint().getQuery(), "format=json"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 0); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + HttpRequest request = processor.createRequest(method, new Object[] { 2 }); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/servers/2"); + assertEquals(request.getEndpoint().getQuery(), "format=json"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 0); + assertEquals(processor.createResponseParser(method, request).getClass(), ParseServerFromJsonResponse.class); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), @@ -266,14 +259,13 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] {}); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/flavors"); - assertEquals(httpMethod.getEndpoint().getQuery(), "format=json"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 0); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + HttpRequest request = processor.createRequest(method, new Object[] {}); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/flavors"); + assertEquals(request.getEndpoint().getQuery(), "format=json"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 0); + assertEquals(processor.createResponseParser(method, request).getClass(), ParseFlavorListFromJsonResponse.class); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), @@ -284,15 +276,15 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { changesSince(now).maxResults(1).startAt(2) }); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/flavors"); - assertEquals(httpMethod.getEndpoint().getQuery(), "format=json&changes-since=" - + now.getTime() / 1000 + "&limit=1&offset=2"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 0); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + HttpRequest request = processor.createRequest(method, new Object[] { changesSince(now) + .maxResults(1).startAt(2) }); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/flavors"); + assertEquals(request.getEndpoint().getQuery(), "format=json&changes-since=" + now.getTime() + / 1000 + "&limit=1&offset=2"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 0); + assertEquals(processor.createResponseParser(method, request).getClass(), ParseFlavorListFromJsonResponse.class); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), @@ -303,14 +295,13 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { withDetails() }); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/flavors/detail"); - assertEquals(httpMethod.getEndpoint().getQuery(), "format=json"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 0); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + HttpRequest request = processor.createRequest(method, new Object[] { withDetails() }); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/flavors/detail"); + assertEquals(request.getEndpoint().getQuery(), "format=json"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 0); + assertEquals(processor.createResponseParser(method, request).getClass(), ParseFlavorListFromJsonResponse.class); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), @@ -321,15 +312,15 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { withDetails().changesSince(now).maxResults(1).startAt(2) }); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/flavors/detail"); - assertEquals(httpMethod.getEndpoint().getQuery(), "format=json&changes-since=" - + now.getTime() / 1000 + "&limit=1&offset=2"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 0); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + HttpRequest request = processor.createRequest(method, new Object[] { withDetails() + .changesSince(now).maxResults(1).startAt(2) }); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/flavors/detail"); + assertEquals(request.getEndpoint().getQuery(), "format=json&changes-since=" + now.getTime() + / 1000 + "&limit=1&offset=2"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 0); + assertEquals(processor.createResponseParser(method, request).getClass(), ParseFlavorListFromJsonResponse.class); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), @@ -339,14 +330,13 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { 2 }); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/flavors/2"); - assertEquals(httpMethod.getEndpoint().getQuery(), "format=json"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 0); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + HttpRequest request = processor.createRequest(method, new Object[] { 2 }); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/flavors/2"); + assertEquals(request.getEndpoint().getQuery(), "format=json"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 0); + assertEquals(processor.createResponseParser(method, request).getClass(), ParseFlavorFromJsonResponse.class); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), @@ -357,14 +347,13 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] {}); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/images"); - assertEquals(httpMethod.getEndpoint().getQuery(), "format=json"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 0); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + HttpRequest request = processor.createRequest(method, new Object[] {}); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/images"); + assertEquals(request.getEndpoint().getQuery(), "format=json"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 0); + assertEquals(processor.createResponseParser(method, request).getClass(), ParseImageListFromJsonResponse.class); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), @@ -375,14 +364,13 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { withDetails() }); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/images/detail"); - assertEquals(httpMethod.getEndpoint().getQuery(), "format=json"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 0); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + HttpRequest request = processor.createRequest(method, new Object[] { withDetails() }); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/images/detail"); + assertEquals(request.getEndpoint().getQuery(), "format=json"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 0); + assertEquals(processor.createResponseParser(method, request).getClass(), ParseImageListFromJsonResponse.class); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), @@ -393,15 +381,15 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { changesSince(now).maxResults(1).startAt(2) }); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/images"); - assertEquals(httpMethod.getEndpoint().getQuery(), "format=json&changes-since=" - + now.getTime() / 1000 + "&limit=1&offset=2"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 0); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + HttpRequest request = processor.createRequest(method, new Object[] { changesSince(now) + .maxResults(1).startAt(2) }); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/images"); + assertEquals(request.getEndpoint().getQuery(), "format=json&changes-since=" + now.getTime() + / 1000 + "&limit=1&offset=2"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 0); + assertEquals(processor.createResponseParser(method, request).getClass(), ParseImageListFromJsonResponse.class); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), @@ -412,15 +400,15 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { withDetails().changesSince(now).maxResults(1).startAt(2) }); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/images/detail"); - assertEquals(httpMethod.getEndpoint().getQuery(), "format=json&changes-since=" - + now.getTime() / 1000 + "&limit=1&offset=2"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 0); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + HttpRequest request = processor.createRequest(method, new Object[] { withDetails() + .changesSince(now).maxResults(1).startAt(2) }); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/images/detail"); + assertEquals(request.getEndpoint().getQuery(), "format=json&changes-since=" + now.getTime() + / 1000 + "&limit=1&offset=2"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 0); + assertEquals(processor.createResponseParser(method, request).getClass(), ParseImageListFromJsonResponse.class); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), @@ -430,14 +418,13 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { 2 }); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/images/2"); - assertEquals(httpMethod.getEndpoint().getQuery(), "format=json"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 0); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + HttpRequest request = processor.createRequest(method, new Object[] { 2 }); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/images/2"); + assertEquals(request.getEndpoint().getQuery(), "format=json"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 0); + assertEquals(processor.createResponseParser(method, request).getClass(), ParseImageFromJsonResponse.class); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), @@ -447,16 +434,15 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { 2 }); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2"); - assertEquals(httpMethod.getMethod(), HttpMethod.DELETE); - assertEquals(httpMethod.getHeaders().size(), 0); + HttpRequest request = processor.createRequest(method, new Object[] { 2 }); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/servers/2"); + assertEquals(request.getMethod(), HttpMethod.DELETE); + assertEquals(request.getHeaders().size(), 0); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnFalseOnNotFoundOr404.class); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + assertEquals(processor.createResponseParser(method, request).getClass(), ReturnTrueIf2xx.class); } @@ -465,22 +451,22 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, + HttpRequest request = processor.createRequest(method, new Object[] { "127.0.0.1", 2, 3, false }); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/ips/public/127.0.0.1"); - assertEquals(httpMethod.getMethod(), HttpMethod.PUT); - assertEquals(httpMethod.getHeaders().size(), 2); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections - .singletonList(httpMethod.getPayload().getRawContent().toString().getBytes().length + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/servers/2/ips/public/127.0.0.1"); + assertEquals(request.getMethod(), HttpMethod.PUT); + assertEquals(request.getHeaders().size(), 2); + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections + .singletonList(request.getPayload().getRawContent().toString().getBytes().length + "")); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections .singletonList(MediaType.APPLICATION_JSON)); - assertEquals("{\"shareIp\":{\"sharedIpGroupId\":3}}", httpMethod.getPayload().getRawContent()); + assertEquals("{\"shareIp\":{\"sharedIpGroupId\":3}}", request.getPayload().getRawContent()); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), MapHttp4xxCodesToExceptions.class); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + assertEquals(processor.createResponseParser(method, request).getClass(), CloseContentAndReturn.class); } @@ -489,23 +475,23 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, + HttpRequest request = processor.createRequest(method, new Object[] { "127.0.0.1", 2, 3, true }); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/ips/public/127.0.0.1"); - assertEquals(httpMethod.getMethod(), HttpMethod.PUT); - assertEquals(httpMethod.getHeaders().size(), 2); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections - .singletonList(httpMethod.getPayload().getRawContent().toString().getBytes().length + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/servers/2/ips/public/127.0.0.1"); + assertEquals(request.getMethod(), HttpMethod.PUT); + assertEquals(request.getHeaders().size(), 2); + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections + .singletonList(request.getPayload().getRawContent().toString().getBytes().length + "")); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections .singletonList(MediaType.APPLICATION_JSON)); - assertEquals("{\"shareIp\":{\"sharedIpGroupId\":3,\"configureServer\":true}}", httpMethod + assertEquals("{\"shareIp\":{\"sharedIpGroupId\":3,\"configureServer\":true}}", request .getPayload().getRawContent()); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), MapHttp4xxCodesToExceptions.class); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + assertEquals(processor.createResponseParser(method, request).getClass(), CloseContentAndReturn.class); } @@ -513,16 +499,16 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, + HttpRequest request = processor.createRequest(method, new Object[] { "127.0.0.1", 2, 3, false }); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/ips/public/127.0.0.1"); - assertEquals(httpMethod.getMethod(), HttpMethod.DELETE); - assertEquals(httpMethod.getHeaders().size(), 0); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/servers/2/ips/public/127.0.0.1"); + assertEquals(request.getMethod(), HttpMethod.DELETE); + assertEquals(request.getHeaders().size(), 0); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnVoidOnNotFoundOr404.class); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + assertEquals(processor.createResponseParser(method, request).getClass(), CloseContentAndReturn.class); } @@ -530,40 +516,38 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { 2, - new BackupSchedule(WeeklyBackup.MONDAY, DailyBackup.H_0800_1000, true) }); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/backup_schedule"); - assertEquals(httpMethod.getMethod(), HttpMethod.POST); - assertEquals(httpMethod.getHeaders().size(), 2); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections - .singletonList(httpMethod.getPayload().getRawContent().toString().getBytes().length + HttpRequest request = processor.createRequest(method, new Object[] { 2, + new BackupSchedule(WeeklyBackup.MONDAY, DailyBackup.H_0800_1000, true) }); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/servers/2/backup_schedule"); + assertEquals(request.getMethod(), HttpMethod.POST); + assertEquals(request.getHeaders().size(), 2); + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections + .singletonList(request.getPayload().getRawContent().toString().getBytes().length + "")); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections .singletonList(MediaType.APPLICATION_JSON)); - assertEquals(httpMethod.getPayload().getRawContent(), + assertEquals(request.getPayload().getRawContent(), "{\"backupSchedule\":{\"daily\":\"H_0800_1000\",\"enabled\":true,\"weekly\":\"MONDAY\"}}"); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnFalseOn404.class); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + assertEquals(processor.createResponseParser(method, request).getClass(), CloseContentAndReturn.class); } public void testDeleteBackupSchedule() throws SecurityException, NoSuchMethodException { Method method = CloudServersAsyncClient.class.getMethod("deleteBackupSchedule", int.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - new Object[] { 2 }); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/backup_schedule"); - assertEquals(httpMethod.getMethod(), HttpMethod.DELETE); - assertEquals(httpMethod.getHeaders().size(), 0); + HttpRequest request = processor.createRequest(method, new Object[] { 2 }); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/servers/2/backup_schedule"); + assertEquals(request.getMethod(), HttpMethod.DELETE); + assertEquals(request.getHeaders().size(), 0); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnFalseOnNotFoundOr404.class); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + assertEquals(processor.createResponseParser(method, request).getClass(), ReturnTrueIf2xx.class); } @@ -571,22 +555,21 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { 2, "foo" }); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2"); - assertEquals(httpMethod.getMethod(), HttpMethod.PUT); - assertEquals(httpMethod.getHeaders().size(), 2); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections - .singletonList(httpMethod.getPayload().getRawContent().toString().getBytes().length + HttpRequest request = processor.createRequest(method, new Object[] { 2, "foo" }); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/servers/2"); + assertEquals(request.getMethod(), HttpMethod.PUT); + assertEquals(request.getHeaders().size(), 2); + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections + .singletonList(request.getPayload().getRawContent().toString().getBytes().length + "")); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections .singletonList(MediaType.APPLICATION_JSON)); - assertEquals("{\"server\":{\"adminPass\":\"foo\"}}", httpMethod.getPayload().getRawContent()); + assertEquals("{\"server\":{\"adminPass\":\"foo\"}}", request.getPayload().getRawContent()); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), MapHttp4xxCodesToExceptions.class); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + assertEquals(processor.createResponseParser(method, request).getClass(), CloseContentAndReturn.class); } @@ -594,22 +577,21 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { 2, "foo" }); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2"); - assertEquals(httpMethod.getMethod(), HttpMethod.PUT); - assertEquals(httpMethod.getHeaders().size(), 2); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections - .singletonList(httpMethod.getPayload().getRawContent().toString().getBytes().length + HttpRequest request = processor.createRequest(method, new Object[] { 2, "foo" }); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/servers/2"); + assertEquals(request.getMethod(), HttpMethod.PUT); + assertEquals(request.getHeaders().size(), 2); + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections + .singletonList(request.getPayload().getRawContent().toString().getBytes().length + "")); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections .singletonList(MediaType.APPLICATION_JSON)); - assertEquals("{\"server\":{\"name\":\"foo\"}}", httpMethod.getPayload().getRawContent()); + assertEquals("{\"server\":{\"name\":\"foo\"}}", request.getPayload().getRawContent()); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), MapHttp4xxCodesToExceptions.class); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + assertEquals(processor.createResponseParser(method, request).getClass(), CloseContentAndReturn.class); } @@ -617,14 +599,13 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] {}); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/shared_ip_groups"); - assertEquals(httpMethod.getEndpoint().getQuery(), "format=json"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 0); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + HttpRequest request = processor.createRequest(method, new Object[] {}); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/shared_ip_groups"); + assertEquals(request.getEndpoint().getQuery(), "format=json"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 0); + assertEquals(processor.createResponseParser(method, request).getClass(), ParseSharedIpGroupListFromJsonResponse.class); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), @@ -635,15 +616,15 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { changesSince(now).maxResults(1).startAt(2) }); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/shared_ip_groups"); - assertEquals(httpMethod.getEndpoint().getQuery(), "format=json&changes-since=" - + now.getTime() / 1000 + "&limit=1&offset=2"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 0); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + HttpRequest request = processor.createRequest(method, new Object[] { changesSince(now) + .maxResults(1).startAt(2) }); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/shared_ip_groups"); + assertEquals(request.getEndpoint().getQuery(), "format=json&changes-since=" + now.getTime() + / 1000 + "&limit=1&offset=2"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 0); + assertEquals(processor.createResponseParser(method, request).getClass(), ParseSharedIpGroupListFromJsonResponse.class); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), @@ -654,14 +635,13 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { withDetails() }); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/shared_ip_groups/detail"); - assertEquals(httpMethod.getEndpoint().getQuery(), "format=json"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 0); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + HttpRequest request = processor.createRequest(method, new Object[] { withDetails() }); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/shared_ip_groups/detail"); + assertEquals(request.getEndpoint().getQuery(), "format=json"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 0); + assertEquals(processor.createResponseParser(method, request).getClass(), ParseSharedIpGroupListFromJsonResponse.class); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), @@ -673,15 +653,15 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { withDetails().changesSince(now).maxResults(1).startAt(2) }); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/shared_ip_groups/detail"); - assertEquals(httpMethod.getEndpoint().getQuery(), "format=json&changes-since=" - + now.getTime() / 1000 + "&limit=1&offset=2"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 0); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + HttpRequest request = processor.createRequest(method, new Object[] { withDetails() + .changesSince(now).maxResults(1).startAt(2) }); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/shared_ip_groups/detail"); + assertEquals(request.getEndpoint().getQuery(), "format=json&changes-since=" + now.getTime() + / 1000 + "&limit=1&offset=2"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 0); + assertEquals(processor.createResponseParser(method, request).getClass(), ParseSharedIpGroupListFromJsonResponse.class); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), @@ -691,14 +671,13 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { 2 }); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/shared_ip_groups/2"); - assertEquals(httpMethod.getEndpoint().getQuery(), "format=json"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 0); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + HttpRequest request = processor.createRequest(method, new Object[] { 2 }); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/shared_ip_groups/2"); + assertEquals(request.getEndpoint().getQuery(), "format=json"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 0); + assertEquals(processor.createResponseParser(method, request).getClass(), ParseSharedIpGroupFromJsonResponse.class); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), @@ -712,37 +691,35 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { "ralphie" }); - assertEquals("{\"sharedIpGroup\":{\"name\":\"ralphie\"}}", httpMethod.getPayload() + HttpRequest request = processor.createRequest(method, new Object[] { "ralphie" }); + assertEquals("{\"sharedIpGroup\":{\"name\":\"ralphie\"}}", request.getPayload() .getRawContent()); - validateCreateSharedIpGroup(method, httpMethod); + validateCreateSharedIpGroup(method, request); } public void testCreateSharedIpGroupWithIpGroup() throws SecurityException, NoSuchMethodException { Method method = CloudServersAsyncClient.class.getMethod("createSharedIpGroup", String.class, createSharedIpGroupOptionsVarargsClass); - GeneratedHttpRequest httpMethod = processor.createRequest(method, + HttpRequest request = processor.createRequest(method, new Object[] { "ralphie", withServer(2) }); - assertEquals("{\"sharedIpGroup\":{\"name\":\"ralphie\",\"server\":2}}", httpMethod - .getPayload().getRawContent()); - validateCreateSharedIpGroup(method, httpMethod); + assertEquals("{\"sharedIpGroup\":{\"name\":\"ralphie\",\"server\":2}}", request.getPayload() + .getRawContent()); + validateCreateSharedIpGroup(method, request); } - private void validateCreateSharedIpGroup(Method method, - GeneratedHttpRequest httpMethod) { - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/shared_ip_groups"); - assertEquals(httpMethod.getEndpoint().getQuery(), "format=json"); - assertEquals(httpMethod.getMethod(), HttpMethod.POST); - assertEquals(httpMethod.getHeaders().size(), 2); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections - .singletonList(httpMethod.getPayload().getRawContent().toString().getBytes().length + private void validateCreateSharedIpGroup(Method method, HttpRequest request) { + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/shared_ip_groups"); + assertEquals(request.getEndpoint().getQuery(), "format=json"); + assertEquals(request.getMethod(), HttpMethod.POST); + assertEquals(request.getHeaders().size(), 2); + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections + .singletonList(request.getPayload().getRawContent().toString().getBytes().length + "")); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections .singletonList(MediaType.APPLICATION_JSON)); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + assertEquals(processor.createResponseParser(method, request).getClass(), ParseSharedIpGroupFromJsonResponse.class); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), @@ -754,72 +731,67 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { 2 }); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/shared_ip_groups/2"); - assertEquals(httpMethod.getMethod(), HttpMethod.DELETE); - assertEquals(httpMethod.getHeaders().size(), 0); + HttpRequest request = processor.createRequest(method, new Object[] { 2 }); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/shared_ip_groups/2"); + assertEquals(request.getMethod(), HttpMethod.DELETE); + assertEquals(request.getHeaders().size(), 0); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnFalseOnNotFoundOr404.class); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + assertEquals(processor.createResponseParser(method, request).getClass(), ReturnTrueIf2xx.class); } public void testListAddresses() throws SecurityException, NoSuchMethodException { Method method = CloudServersAsyncClient.class.getMethod("getAddresses", int.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - new Object[] { 2 }); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/ips"); - assertEquals(httpMethod.getEndpoint().getQuery(), "format=json"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 0); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + HttpRequest request = processor.createRequest(method, new Object[] { 2 }); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/servers/2/ips"); + assertEquals(request.getEndpoint().getQuery(), "format=json"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 0); + assertEquals(processor.createResponseParser(method, request).getClass(), ParseAddressesFromJsonResponse.class); } public void testListPublicAddresses() throws SecurityException, NoSuchMethodException { Method method = CloudServersAsyncClient.class.getMethod("listPublicAddresses", int.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - new Object[] { 2 }); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/ips/public"); - assertEquals(httpMethod.getEndpoint().getQuery(), "format=json"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 0); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + HttpRequest request = processor.createRequest(method, new Object[] { 2 }); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/servers/2/ips/public"); + assertEquals(request.getEndpoint().getQuery(), "format=json"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 0); + assertEquals(processor.createResponseParser(method, request).getClass(), ParseInetAddressListFromJsonResponse.class); } public void testListPrivateAddresses() throws SecurityException, NoSuchMethodException { Method method = CloudServersAsyncClient.class.getMethod("listPrivateAddresses", int.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - new Object[] { 2 }); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/ips/private"); - assertEquals(httpMethod.getEndpoint().getQuery(), "format=json"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 0); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + HttpRequest request = processor.createRequest(method, new Object[] { 2 }); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/servers/2/ips/private"); + assertEquals(request.getEndpoint().getQuery(), "format=json"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 0); + assertEquals(processor.createResponseParser(method, request).getClass(), ParseInetAddressListFromJsonResponse.class); } public void testListBackupSchedule() throws SecurityException, NoSuchMethodException { Method method = CloudServersAsyncClient.class.getMethod("getBackupSchedule", int.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - new Object[] { 2 }); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/backup_schedule"); - assertEquals(httpMethod.getEndpoint().getQuery(), "format=json"); - assertEquals(httpMethod.getMethod(), HttpMethod.GET); - assertEquals(httpMethod.getHeaders().size(), 0); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + HttpRequest request = processor.createRequest(method, new Object[] { 2 }); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/servers/2/backup_schedule"); + assertEquals(request.getEndpoint().getQuery(), "format=json"); + assertEquals(request.getMethod(), HttpMethod.GET); + assertEquals(request.getHeaders().size(), 0); + assertEquals(processor.createResponseParser(method, request).getClass(), ParseBackupScheduleFromJsonResponse.class); } @@ -827,21 +799,20 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { "ralphie", 2 }); - assertEquals("{\"image\":{\"serverId\":2,\"name\":\"ralphie\"}}", httpMethod.getPayload() + HttpRequest request = processor.createRequest(method, new Object[] { "ralphie", 2 }); + assertEquals("{\"image\":{\"serverId\":2,\"name\":\"ralphie\"}}", request.getPayload() .getRawContent()); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/images"); - assertEquals(httpMethod.getEndpoint().getQuery(), "format=json"); - assertEquals(httpMethod.getMethod(), HttpMethod.POST); - assertEquals(httpMethod.getHeaders().size(), 2); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections - .singletonList(httpMethod.getPayload().getRawContent().toString().getBytes().length + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/images"); + assertEquals(request.getEndpoint().getQuery(), "format=json"); + assertEquals(request.getMethod(), HttpMethod.POST); + assertEquals(request.getHeaders().size(), 2); + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections + .singletonList(request.getPayload().getRawContent().toString().getBytes().length + "")); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections .singletonList(MediaType.APPLICATION_JSON)); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + assertEquals(processor.createResponseParser(method, request).getClass(), ParseImageFromJsonResponse.class); assertNotNull(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method)); @@ -855,38 +826,35 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { 3 }); - assertEquals("{\"rebuild\":{}}", httpMethod.getPayload().getRawContent()); - validateRebuildServer(method, httpMethod); + HttpRequest request = processor.createRequest(method, new Object[] { 3 }); + assertEquals("{\"rebuild\":{}}", request.getPayload().getRawContent()); + validateRebuildServer(method, request); } public void testRebuildServerWithImage() throws SecurityException, NoSuchMethodException { Method method = CloudServersAsyncClient.class.getMethod("rebuildServer", int.class, rebuildServerOptionsVarargsClass); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - new Object[] { 3, withImage(2) }); - assertEquals("{\"rebuild\":{\"imageId\":2}}", httpMethod.getPayload().getRawContent()); - validateRebuildServer(method, httpMethod); + HttpRequest request = processor.createRequest(method, new Object[] { 3, withImage(2) }); + assertEquals("{\"rebuild\":{\"imageId\":2}}", request.getPayload().getRawContent()); + validateRebuildServer(method, request); } - private void validateRebuildServer(Method method, - GeneratedHttpRequest httpMethod) { - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/servers/3/action"); - assertEquals(httpMethod.getEndpoint().getQuery(), "format=json"); - assertEquals(httpMethod.getMethod(), HttpMethod.POST); - assertEquals(httpMethod.getHeaders().size(), 2); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections - .singletonList(httpMethod.getPayload().getRawContent().toString().getBytes().length + private void validateRebuildServer(Method method, HttpRequest request) { + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/servers/3/action"); + assertEquals(request.getEndpoint().getQuery(), "format=json"); + assertEquals(request.getMethod(), HttpMethod.POST); + assertEquals(request.getHeaders().size(), 2); + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections + .singletonList(request.getPayload().getRawContent().toString().getBytes().length + "")); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections .singletonList(MediaType.APPLICATION_JSON)); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), MapHttp4xxCodesToExceptions.class); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + assertEquals(processor.createResponseParser(method, request).getClass(), CloseContentAndReturn.class); assertNotNull(processor.getMapPayloadBinderOrNull(method, new Object[] { "", new RebuildServerOptions[] { withImage(2) } })); @@ -896,87 +864,83 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - new Object[] { 2, RebootType.HARD }); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/action"); - assertEquals(httpMethod.getMethod(), HttpMethod.POST); - assertEquals(httpMethod.getHeaders().size(), 2); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections - .singletonList(httpMethod.getPayload().getRawContent().toString().getBytes().length + HttpRequest request = processor.createRequest(method, new Object[] { 2, RebootType.HARD }); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/servers/2/action"); + assertEquals(request.getMethod(), HttpMethod.POST); + assertEquals(request.getHeaders().size(), 2); + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections + .singletonList(request.getPayload().getRawContent().toString().getBytes().length + "")); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections .singletonList(MediaType.APPLICATION_JSON)); - assertEquals("{\"reboot\":{\"type\":\"HARD\"}}", httpMethod.getPayload().getRawContent()); + assertEquals("{\"reboot\":{\"type\":\"HARD\"}}", request.getPayload().getRawContent()); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), MapHttp4xxCodesToExceptions.class); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + assertEquals(processor.createResponseParser(method, request).getClass(), CloseContentAndReturn.class); } public void testResize() throws SecurityException, NoSuchMethodException { Method method = CloudServersAsyncClient.class.getMethod("resizeServer", int.class, int.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - new Object[] { 2, 3 }); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/action"); - assertEquals(httpMethod.getMethod(), HttpMethod.POST); - assertEquals(httpMethod.getHeaders().size(), 2); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections - .singletonList(httpMethod.getPayload().getRawContent().toString().getBytes().length + HttpRequest request = processor.createRequest(method, new Object[] { 2, 3 }); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/servers/2/action"); + assertEquals(request.getMethod(), HttpMethod.POST); + assertEquals(request.getHeaders().size(), 2); + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections + .singletonList(request.getPayload().getRawContent().toString().getBytes().length + "")); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections .singletonList(MediaType.APPLICATION_JSON)); - assertEquals("{\"resize\":{\"flavorId\":3}}", httpMethod.getPayload().getRawContent()); + assertEquals("{\"resize\":{\"flavorId\":3}}", request.getPayload().getRawContent()); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), MapHttp4xxCodesToExceptions.class); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + assertEquals(processor.createResponseParser(method, request).getClass(), CloseContentAndReturn.class); } public void testConfirmResize() throws SecurityException, NoSuchMethodException { Method method = CloudServersAsyncClient.class.getMethod("confirmResizeServer", int.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - new Object[] { 2 }); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/action"); - assertEquals(httpMethod.getMethod(), HttpMethod.POST); - assertEquals(httpMethod.getHeaders().size(), 2); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections - .singletonList(httpMethod.getPayload().getRawContent().toString().getBytes().length + HttpRequest request = processor.createRequest(method, new Object[] { 2 }); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/servers/2/action"); + assertEquals(request.getMethod(), HttpMethod.POST); + assertEquals(request.getHeaders().size(), 2); + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections + .singletonList(request.getPayload().getRawContent().toString().getBytes().length + "")); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections .singletonList(MediaType.APPLICATION_JSON)); - assertEquals("{\"confirmResize\":null}", httpMethod.getPayload().getRawContent()); + assertEquals("{\"confirmResize\":null}", request.getPayload().getRawContent()); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), MapHttp4xxCodesToExceptions.class); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + assertEquals(processor.createResponseParser(method, request).getClass(), CloseContentAndReturn.class); } public void testRevertResize() throws SecurityException, NoSuchMethodException { Method method = CloudServersAsyncClient.class.getMethod("revertResizeServer", int.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - new Object[] { 2 }); - assertEquals(httpMethod.getEndpoint().getHost(), "serverManagementUrl"); - assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/action"); - assertEquals(httpMethod.getMethod(), HttpMethod.POST); - assertEquals(httpMethod.getHeaders().size(), 2); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections - .singletonList(httpMethod.getPayload().getRawContent().toString().getBytes().length + HttpRequest request = processor.createRequest(method, new Object[] { 2 }); + assertEquals(request.getEndpoint().getHost(), "serverManagementUrl"); + assertEquals(request.getEndpoint().getPath(), "/servers/2/action"); + assertEquals(request.getMethod(), HttpMethod.POST); + assertEquals(request.getHeaders().size(), 2); + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections + .singletonList(request.getPayload().getRawContent().toString().getBytes().length + "")); - assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections + assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections .singletonList(MediaType.APPLICATION_JSON)); - assertEquals("{\"revertResize\":null}", httpMethod.getPayload().getRawContent()); + assertEquals("{\"revertResize\":null}", request.getPayload().getRawContent()); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), MapHttp4xxCodesToExceptions.class); - assertEquals(processor.createResponseParser(method, httpMethod).getClass(), + assertEquals(processor.createResponseParser(method, request).getClass(), CloseContentAndReturn.class); } @@ -987,10 +951,10 @@ public class CloudServersAsyncClientTest extends RestClientTest httpMethod) { - assertEquals(httpMethod.getFilters().size(), 2); - assertEquals(httpMethod.getFilters().get(0).getClass(), AuthenticateRequest.class); - assertEquals(httpMethod.getFilters().get(1).getClass(), AddTimestampQuery.class); + protected void checkFilters(HttpRequest request) { + assertEquals(request.getFilters().size(), 2); + assertEquals(request.getFilters().get(0).getClass(), AuthenticateRequest.class); + assertEquals(request.getFilters().get(1).getClass(), AddTimestampQuery.class); } diff --git a/rackspace/src/test/java/org/jclouds/rackspace/filters/AddTimestampQueryTest.java b/rackspace/src/test/java/org/jclouds/rackspace/filters/AddTimestampQueryTest.java index ceb6449618..75932f711a 100644 --- a/rackspace/src/test/java/org/jclouds/rackspace/filters/AddTimestampQueryTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/filters/AddTimestampQueryTest.java @@ -18,12 +18,16 @@ */ package org.jclouds.rackspace.filters; -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.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 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() { + + @Override + public UriBuilder get() { + return new UriBuilderImpl(); + } + + }); + filter.filter(request); + + assertEquals(request.getRequestLine(), String.format("GET http://momma/?now=%s HTTP/1.1", + date.getTime())); + } } diff --git a/twitter/src/test/java/org/jclouds/twitter/TwitterAsyncClientTest.java b/twitter/src/test/java/org/jclouds/twitter/TwitterAsyncClientTest.java index c7ed84e7ad..e5ccb780dc 100644 --- a/twitter/src/test/java/org/jclouds/twitter/TwitterAsyncClientTest.java +++ b/twitter/src/test/java/org/jclouds/twitter/TwitterAsyncClientTest.java @@ -24,10 +24,10 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.lang.reflect.Method; +import org.jclouds.http.HttpRequest; import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestContextFactory.ContextSpec; -import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.twitter.functions.ParseStatusesFromJsonResponse; import org.testng.annotations.Test; @@ -44,23 +44,23 @@ public class TwitterAsyncClientTest extends RestClientTest { public void testGetMyMentions() throws SecurityException, NoSuchMethodException, IOException { Method method = TwitterAsyncClient.class.getMethod("getMyMentions"); - GeneratedHttpRequest httpMethod = processor.createRequest(method); + HttpRequest request = processor.createRequest(method); - assertRequestLineEquals(httpMethod, "GET http://twitter.com/statuses/mentions.json HTTP/1.1"); - assertHeadersEqual(httpMethod, ""); - assertPayloadEquals(httpMethod, null); + assertRequestLineEquals(request, "GET http://twitter.com/statuses/mentions.json HTTP/1.1"); + assertHeadersEqual(request, ""); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseStatusesFromJsonResponse.class); + assertResponseParserClassEquals(method, request, ParseStatusesFromJsonResponse.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } @Override - protected void checkFilters(GeneratedHttpRequest httpMethod) { - assertEquals(httpMethod.getFilters().size(), 1); - assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class); + protected void checkFilters(HttpRequest request) { + assertEquals(request.getFilters().size(), 1); + assertEquals(request.getFilters().get(0).getClass(), BasicAuthentication.class); } @Override diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java index dd00a0f381..844e26560d 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java @@ -32,6 +32,7 @@ import java.util.Properties; import javax.inject.Named; import javax.inject.Provider; +import org.jclouds.http.HttpRequest; import org.jclouds.http.RequiresHttp; import org.jclouds.http.functions.CloseContentAndReturn; 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.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; -import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.util.Utils; import org.jclouds.vcloud.config.VCloudRestClientModule; @@ -81,22 +81,21 @@ public class VCloudAsyncClientTest extends RestClientTest { Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", String.class, String.class, String.class, Array.newInstance( InstantiateVAppTemplateOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, "1", - "my-vapp", 3 + ""); + HttpRequest request = processor.createRequest(method, "1", "my-vapp", 3 + ""); - assertRequestLineEquals(httpMethod, + assertRequestLineEquals(request, "POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); assertHeadersEqual( - httpMethod, + request, "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"))); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, VAppHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testInstantiateVAppTemplateOptions() throws SecurityException, @@ -104,23 +103,23 @@ public class VCloudAsyncClientTest extends RestClientTest { Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", String.class, String.class, String.class, Array.newInstance( InstantiateVAppTemplateOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, "1", - "my-vapp", 3 + "", processorCount(1).memory(512).disk(1024).fenceMode("allowInOut") - .inNetwork(URI.create("https://vcloud.safesecureweb.com/network/1990"))); + HttpRequest request = processor.createRequest(method, "1", "my-vapp", 3 + "", processorCount( + 1).memory(512).disk(1024).fenceMode("allowInOut").inNetwork( + 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"); assertHeadersEqual( - httpMethod, + request, "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"))); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, VAppHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } @Test(expectedExceptions = IllegalArgumentException.class) @@ -136,44 +135,43 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testCloneVApp() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("cloneVAppInVDC", String.class, String.class, String.class, Array.newInstance(CloneVAppOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, "1", - "4181", "my-vapp"); + HttpRequest request = processor.createRequest(method, "1", "4181", "my-vapp"); - assertRequestLineEquals(httpMethod, + assertRequestLineEquals(request, "POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/cloneVApp HTTP/1.1"); assertHeadersEqual( - httpMethod, + request, "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"))); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, TaskHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testCloneVAppOptions() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("cloneVAppInVDC", String.class, String.class, String.class, Array.newInstance(CloneVAppOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, "1", - "201", "new-linux-server", new CloneVAppOptions().deploy().powerOn() - .withDescription("The description of the new vApp")); + HttpRequest request = processor.createRequest(method, "1", "201", "new-linux-server", + new CloneVAppOptions().deploy().powerOn().withDescription( + "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"); assertHeadersEqual( - httpMethod, + request, "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"))); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, TaskHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } @Test(expectedExceptions = IllegalArgumentException.class) @@ -188,361 +186,360 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testDefaultOrganization() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getDefaultOrganization"); - GeneratedHttpRequest httpMethod = processor.createRequest(method); + HttpRequest request = processor.createRequest(method); - assertRequestLineEquals(httpMethod, - "GET https://vcloud.safesecureweb.com/api/v0.8/org HTTP/1.1"); - assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.org+xml\n"); - assertPayloadEquals(httpMethod, null); + assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/org HTTP/1.1"); + assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.org+xml\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, OrgHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testOrganization() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getOrganization", String.class); - GeneratedHttpRequest 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"); - assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.org+xml\n"); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.org+xml\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, OrgHandler.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - checkFilters(httpMethod); + checkFilters(request); } public void testDefaultCatalog() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getDefaultCatalog"); - GeneratedHttpRequest 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"); - assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.catalog+xml\n"); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalog+xml\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, CatalogHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testCatalog() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getCatalog", String.class); - GeneratedHttpRequest 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"); - assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.catalog+xml\n"); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalog+xml\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, CatalogHandler.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - checkFilters(httpMethod); + checkFilters(request); } public void testNetwork() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getNetwork", String.class); - GeneratedHttpRequest 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"); - assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.network+xml\n"); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.network+xml\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, NetworkHandler.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - checkFilters(httpMethod); + checkFilters(request); } public void testCatalogItem() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getCatalogItem", String.class); - GeneratedHttpRequest 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"); - assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.catalogItem+xml\n"); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalogItem+xml\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, CatalogItemHandler.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - checkFilters(httpMethod); + checkFilters(request); } public void testVAppTemplate() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getVAppTemplate", String.class); - GeneratedHttpRequest 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"); - assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n"); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, VAppTemplateHandler.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - checkFilters(httpMethod); + checkFilters(request); } public void testGetDefaultVDC() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getDefaultVDC"); - GeneratedHttpRequest 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"); - assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.vdc+xml\n"); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, VDCHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testGetVDC() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getVDC", String.class); - GeneratedHttpRequest 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"); - assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.vdc+xml\n"); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, VDCHandler.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - checkFilters(httpMethod); + checkFilters(request); } public void testGetDefaultTasksList() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getDefaultTasksList"); - GeneratedHttpRequest 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"); - assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.tasksList+xml\n"); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.tasksList+xml\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, TasksListHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testGetTasksList() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getTasksList", String.class); - GeneratedHttpRequest 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"); - assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.tasksList+xml\n"); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.tasksList+xml\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, TasksListHandler.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - checkFilters(httpMethod); + checkFilters(request); } public void testDeployVApp() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("deployVApp", String.class); - GeneratedHttpRequest 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"); - assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n"); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, TaskHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testGetVApp() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getVApp", String.class); - GeneratedHttpRequest 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"); - assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.vApp+xml\n"); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, VAppHandler.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - checkFilters(httpMethod); + checkFilters(request); } public void testUndeployVApp() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("undeployVApp", String.class); - GeneratedHttpRequest 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"); - assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n"); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, TaskHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testDeleteVApp() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("deleteVApp", String.class); - GeneratedHttpRequest 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"); - assertHeadersEqual(httpMethod, ""); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, ""); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); + assertResponseParserClassEquals(method, request, CloseContentAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class); - checkFilters(httpMethod); + checkFilters(request); } public void testPowerOn() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("powerOnVApp", String.class); - GeneratedHttpRequest 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"); - assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n"); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, TaskHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testPowerOff() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("powerOffVApp", String.class); - GeneratedHttpRequest 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"); - assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n"); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, TaskHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testReset() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("resetVApp", String.class); - GeneratedHttpRequest 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"); - assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n"); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, TaskHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testSuspend() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("suspendVApp", String.class); - GeneratedHttpRequest 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"); - assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n"); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, TaskHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testShutdown() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("shutdownVApp", String.class); - GeneratedHttpRequest 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"); - assertHeadersEqual(httpMethod, ""); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, ""); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); + assertResponseParserClassEquals(method, request, CloseContentAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testGetTask() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getTask", String.class); - GeneratedHttpRequest 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"); - assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n"); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, TaskHandler.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - checkFilters(httpMethod); + checkFilters(request); } public void testCancelTask() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("cancelTask", String.class); - GeneratedHttpRequest 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"); - assertHeadersEqual(httpMethod, ""); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, ""); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); + assertResponseParserClassEquals(method, request, CloseContentAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } @Override - protected void checkFilters(GeneratedHttpRequest httpMethod) { - assertEquals(httpMethod.getFilters().size(), 1); - assertEquals(httpMethod.getFilters().get(0).getClass(), SetVCloudTokenCookie.class); + protected void checkFilters(HttpRequest request) { + assertEquals(request.getFilters().size(), 1); + assertEquals(request.getFilters().get(0).getClass(), SetVCloudTokenCookie.class); } @Override diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudLoginTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudLoginTest.java index 938990dd35..bc236ecd99 100755 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudLoginTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudLoginTest.java @@ -27,11 +27,11 @@ import java.net.URI; import javax.ws.rs.core.HttpHeaders; +import org.jclouds.http.HttpRequest; import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestContextFactory.ContextSpec; import org.jclouds.rest.annotations.Provider; -import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.vcloud.VCloudLoginLiveTest.VCloudLoginClient; import org.jclouds.vcloud.endpoints.VCloudLogin; @@ -54,24 +54,24 @@ public class VCloudLoginTest extends RestClientTest { public void testLogin() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudLoginAsyncClient.class.getMethod("login"); - GeneratedHttpRequest httpMethod = processor.createRequest(method); + HttpRequest request = processor.createRequest(method); - assertEquals(httpMethod.getRequestLine(), "POST http://localhost:8080/login HTTP/1.1"); - assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + assertEquals(request.getRequestLine(), "POST http://localhost:8080/login HTTP/1.1"); + assertHeadersEqual(request, HttpHeaders.ACCEPT + ": 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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } @Override - protected void checkFilters(GeneratedHttpRequest httpMethod) { - assertEquals(httpMethod.getFilters().size(), 1); - assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class); + protected void checkFilters(HttpRequest request) { + assertEquals(request.getFilters().size(), 1); + assertEquals(request.getFilters().get(0).getClass(), BasicAuthentication.class); } @Override diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudVersionsTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudVersionsTest.java index d1c3fb5552..0fc27d0dd1 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudVersionsTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudVersionsTest.java @@ -24,10 +24,10 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.lang.reflect.Method; +import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.ParseSax; import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestContextFactory.ContextSpec; -import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.vcloud.VCloudVersionsLiveTest.VCloudVersionsClient; import org.jclouds.vcloud.internal.VCloudVersionsAsyncClient; @@ -46,22 +46,22 @@ public class VCloudVersionsTest extends RestClientTest httpMethod = processor.createRequest(method); + HttpRequest request = processor.createRequest(method); - assertEquals(httpMethod.getRequestLine(), "GET http://localhost:8080/versions HTTP/1.1"); - assertHeadersEqual(httpMethod, ""); - assertPayloadEquals(httpMethod, null); + assertEquals(request.getRequestLine(), "GET http://localhost:8080/versions HTTP/1.1"); + assertHeadersEqual(request, ""); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, SupportedVersionsHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } @Override - protected void checkFilters(GeneratedHttpRequest httpMethod) { - assertEquals(httpMethod.getFilters().size(), 0); + protected void checkFilters(HttpRequest request) { + assertEquals(request.getFilters().size(), 0); } @Override diff --git a/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudAsyncClientTest.java b/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudAsyncClientTest.java index 13fd6403a1..27222a4da8 100644 --- a/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudAsyncClientTest.java +++ b/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudAsyncClientTest.java @@ -29,13 +29,13 @@ import java.util.Properties; import javax.inject.Named; +import org.jclouds.http.HttpRequest; import org.jclouds.http.RequiresHttp; import org.jclouds.http.functions.ParseSax; import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory.ContextSpec; -import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.domain.NamedResource; @@ -62,26 +62,25 @@ public class HostingDotComVCloudAsyncClientTest extends RestClientTest { public void testCatalog() throws SecurityException, NoSuchMethodException, IOException { Method method = HostingDotComVCloudAsyncClient.class.getMethod("getDefaultCatalog"); - GeneratedHttpRequest httpMethod = processor - .createRequest(method); + HttpRequest request = processor.createRequest(method); - assertRequestLineEquals(httpMethod, "GET https://catalog HTTP/1.1"); + assertRequestLineEquals(request, "GET https://catalog HTTP/1.1"); assertHeadersEqual( - httpMethod, + request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } @Override - protected void checkFilters(GeneratedHttpRequest httpMethod) { - assertEquals(httpMethod.getFilters().size(), 1); - assertEquals(httpMethod.getFilters().get(0).getClass(), SetVCloudTokenCookie.class); + protected void checkFilters(HttpRequest request) { + assertEquals(request.getFilters().size(), 1); + assertEquals(request.getFilters().get(0).getClass(), SetVCloudTokenCookie.class); } @Override @@ -89,6 +88,7 @@ public class HostingDotComVCloudAsyncClientTest extends return new TypeLiteral>() { }; } + @Override protected Module createModule() { return new HostingDotComVCloudRestClientModuleExtension(); diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/binders/BindNodeConfigurationToXmlPayload.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/binders/BindNodeConfigurationToXmlPayload.java index 5d88411900..6d09e0f8a3 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/binders/BindNodeConfigurationToXmlPayload.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/binders/BindNodeConfigurationToXmlPayload.java @@ -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.checkNotNull; -import static com.google.common.base.Preconditions.checkState; import java.util.Properties; @@ -31,7 +30,6 @@ import javax.xml.transform.TransformerException; import org.jclouds.http.HttpRequest; import org.jclouds.rest.binders.BindToStringPayload; -import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.vcloud.terremark.domain.NodeConfiguration; import com.jamesmurty.utils.XMLBuilder; @@ -44,20 +42,13 @@ import com.jamesmurty.utils.XMLBuilder; @Singleton public class BindNodeConfigurationToXmlPayload extends BindToStringPayload { - @SuppressWarnings("unchecked") @Override public void bindToRequest(HttpRequest request, Object input) { - checkArgument( - checkNotNull(request, "request") instanceof GeneratedHttpRequest, - "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"); + NodeConfiguration nodeConfiguration = (NodeConfiguration) checkNotNull(input, + "nodeConfiguration"); checkArgument(nodeConfiguration.getDescription() != null - || nodeConfiguration.getEnabled() != null - || nodeConfiguration.getName() != null, "no configuration set"); + || nodeConfiguration.getEnabled() != null || nodeConfiguration.getName() != null, + "no configuration set"); try { super.bindToRequest(request, generateXml(nodeConfiguration)); } catch (ParserConfigurationException e) { @@ -71,11 +62,10 @@ public class BindNodeConfigurationToXmlPayload extends BindToStringPayload { } protected String generateXml(NodeConfiguration nodeConfiguration) - throws ParserConfigurationException, FactoryConfigurationError, - TransformerException { + throws ParserConfigurationException, FactoryConfigurationError, TransformerException { XMLBuilder rootBuilder = XMLBuilder.create("NodeService").a("xmlns", - "urn:tmrk:vCloudExpressExtensions-1.6").a("xmlns:i", - "http://www.w3.org/2001/XMLSchema-instance"); + "urn:tmrk:vCloudExpressExtensions-1.6").a("xmlns:i", + "http://www.w3.org/2001/XMLSchema-instance"); if (nodeConfiguration.getDescription() != null) rootBuilder.e("Description").t(nodeConfiguration.getDescription()); if (nodeConfiguration.getName() != null) @@ -83,8 +73,7 @@ public class BindNodeConfigurationToXmlPayload extends BindToStringPayload { if (nodeConfiguration.getEnabled() != null) rootBuilder.e("Enabled").t(nodeConfiguration.getEnabled()); Properties outputProperties = new Properties(); - outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, - "yes"); + outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes"); return rootBuilder.asString(outputProperties); } diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClientTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClientTest.java index 5c841f43ea..41611f2661 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClientTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClientTest.java @@ -31,6 +31,7 @@ import java.util.Properties; import javax.inject.Named; +import org.jclouds.http.HttpRequest; import org.jclouds.http.RequiresHttp; import org.jclouds.http.functions.CloseContentAndReturn; 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.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; -import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.util.Utils; import org.jclouds.vcloud.VCloudClient; @@ -85,49 +85,47 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - "1"); + HttpRequest request = processor.createRequest(method, "1"); - assertRequestLineEquals(httpMethod, "GET https://catalog HTTP/1.1"); - assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.catalog+xml\n"); - assertPayloadEquals(httpMethod, null); + assertRequestLineEquals(request, "GET https://catalog HTTP/1.1"); + assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalog+xml\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, CatalogHandler.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - checkFilters(httpMethod); + checkFilters(request); } public void testGetDefaultVDC() throws SecurityException, NoSuchMethodException, IOException { Method method = TerremarkVCloudAsyncClient.class.getMethod("getDefaultVDC"); - GeneratedHttpRequest httpMethod = processor.createRequest(method); + HttpRequest request = processor.createRequest(method); - assertRequestLineEquals(httpMethod, "GET https://vdc/1 HTTP/1.1"); - assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.vdc+xml\n"); - assertPayloadEquals(httpMethod, null); + assertRequestLineEquals(request, "GET https://vdc/1 HTTP/1.1"); + assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, TerremarkVDCHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testGetVDC() throws SecurityException, NoSuchMethodException, IOException { Method method = TerremarkVCloudAsyncClient.class.getMethod("getVDC", String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - "1"); + HttpRequest request = processor.createRequest(method, "1"); - assertRequestLineEquals(httpMethod, "GET https://vcloud/vdc/1 HTTP/1.1"); - assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.vdc+xml\n"); - assertPayloadEquals(httpMethod, null); + assertRequestLineEquals(request, "GET https://vcloud/vdc/1 HTTP/1.1"); + assertHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, TerremarkVDCHandler.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - checkFilters(httpMethod); + checkFilters(request); } public void testInstantiateVAppTemplate() throws SecurityException, NoSuchMethodException, @@ -135,22 +133,21 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - "1", "name", 3 + ""); + HttpRequest request = processor.createRequest(method, "1", "name", 3 + ""); - assertRequestLineEquals(httpMethod, + assertRequestLineEquals(request, "POST https://vcloud/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); assertHeadersEqual( - httpMethod, + request, "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"))); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, VAppHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testInstantiateVAppTemplateOptions() throws SecurityException, @@ -158,24 +155,24 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - "1", "name", 3 + "", TerremarkInstantiateVAppTemplateOptions.Builder.processorCount( - 2).memory(512).inRow("row").inGroup("group").withPassword("password") - .inNetwork(URI.create("http://network"))); + HttpRequest request = processor.createRequest(method, "1", "name", 3 + "", + TerremarkInstantiateVAppTemplateOptions.Builder.processorCount(2).memory(512).inRow( + "row").inGroup("group").withPassword("password").inNetwork( + URI.create("http://network"))); - assertRequestLineEquals(httpMethod, + assertRequestLineEquals(request, "POST https://vcloud/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); assertHeadersEqual( - httpMethod, + request, "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"))); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, VAppHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testAddInternetService() throws SecurityException, NoSuchMethodException, @@ -183,22 +180,21 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - "1", "name", Protocol.TCP, 22); + HttpRequest request = processor.createRequest(method, "1", "name", Protocol.TCP, 22); - assertRequestLineEquals(httpMethod, + assertRequestLineEquals(request, "POST https://vcloud/extensions/vdc/1/internetServices HTTP/1.1"); assertHeadersEqual( - httpMethod, + request, "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"))); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, InternetServiceHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testAddInternetServiceOptions() throws SecurityException, NoSuchMethodException, @@ -206,79 +202,73 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - "1", "name", Protocol.TCP, 22, disabled().withDescription("yahoo")); + HttpRequest request = processor.createRequest(method, "1", "name", Protocol.TCP, 22, + disabled().withDescription("yahoo")); - assertRequestLineEquals(httpMethod, + assertRequestLineEquals(request, "POST https://vcloud/extensions/vdc/1/internetServices HTTP/1.1"); assertHeadersEqual( - httpMethod, + request, "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"))); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, InternetServiceHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testGetAllInternetServices() throws SecurityException, NoSuchMethodException, IOException { Method method = TerremarkVCloudAsyncClient.class.getMethod("getAllInternetServicesInVDC", String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - "1"); + HttpRequest request = processor.createRequest(method, "1"); - assertRequestLineEquals(httpMethod, + assertRequestLineEquals(request, "GET https://vcloud/extensions/vdc/1/internetServices HTTP/1.1"); - assertHeadersEqual(httpMethod, - "Accept: application/vnd.tmrk.vCloud.internetServicesList+xml\n"); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.internetServicesList+xml\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, InternetServicesHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testGetInternetService() throws SecurityException, NoSuchMethodException, IOException { Method method = TerremarkVCloudAsyncClient.class.getMethod("getInternetService", int.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - 12); + HttpRequest request = processor.createRequest(method, 12); - assertRequestLineEquals(httpMethod, - "GET https://vcloud/extensions/internetService/12 HTTP/1.1"); - assertHeadersEqual(httpMethod, - "Accept: application/vnd.tmrk.vCloud.internetServicesList+xml\n"); - assertPayloadEquals(httpMethod, null); + assertRequestLineEquals(request, "GET https://vcloud/extensions/internetService/12 HTTP/1.1"); + assertHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.internetServicesList+xml\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, InternetServiceHandler.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - checkFilters(httpMethod); + checkFilters(request); } public void testDeleteInternetService() throws SecurityException, NoSuchMethodException, IOException { Method method = TerremarkVCloudAsyncClient.class .getMethod("deleteInternetService", int.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - 12); + HttpRequest request = processor.createRequest(method, 12); - assertRequestLineEquals(httpMethod, + assertRequestLineEquals(request, "DELETE https://vcloud/extensions/internetService/12 HTTP/1.1"); - assertHeadersEqual(httpMethod, ""); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, ""); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); + assertResponseParserClassEquals(method, request, CloseContentAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class); - checkFilters(httpMethod); + checkFilters(request); } public void testAddInternetServiceToExistingIp() throws SecurityException, @@ -286,22 +276,21 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - 12, "name", Protocol.TCP, 22); + HttpRequest request = processor.createRequest(method, 12, "name", Protocol.TCP, 22); - assertRequestLineEquals(httpMethod, + assertRequestLineEquals(request, "POST https://vcloud/extensions/publicIp/12/internetServices HTTP/1.1"); assertHeadersEqual( - httpMethod, + request, "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"))); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, InternetServiceHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testAddInternetServiceToExistingIpOptions() throws SecurityException, @@ -309,203 +298,194 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - 12, "name", Protocol.TCP, 22, disabled().withDescription("yahoo")); + HttpRequest request = processor.createRequest(method, 12, "name", Protocol.TCP, 22, + disabled().withDescription("yahoo")); - assertRequestLineEquals(httpMethod, + assertRequestLineEquals(request, "POST https://vcloud/extensions/publicIp/12/internetServices HTTP/1.1"); assertHeadersEqual( - httpMethod, + request, "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"))); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, InternetServiceHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testAddNode() throws SecurityException, NoSuchMethodException, IOException { Method method = TerremarkVCloudAsyncClient.class.getMethod("addNode", int.class, String.class, String.class, int.class, Array.newInstance(AddNodeOptions.class, 0) .getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - 12, "10.2.2.2", "name", 22); + HttpRequest request = processor.createRequest(method, 12, "10.2.2.2", "name", 22); - assertRequestLineEquals(httpMethod, + assertRequestLineEquals(request, "POST https://vcloud/extensions/internetService/12/nodeServices HTTP/1.1"); assertHeadersEqual( - httpMethod, + request, "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"))); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, NodeHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testAddNodeOptions() throws SecurityException, NoSuchMethodException, IOException { Method method = TerremarkVCloudAsyncClient.class.getMethod("addNode", int.class, String.class, String.class, int.class, Array.newInstance(AddNodeOptions.class, 0) .getClass()); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - 12, "10.2.2.2", "name", 22, AddNodeOptions.Builder.disabled().withDescription( - "yahoo")); + HttpRequest request = processor.createRequest(method, 12, "10.2.2.2", "name", 22, + AddNodeOptions.Builder.disabled().withDescription("yahoo")); - assertRequestLineEquals(httpMethod, + assertRequestLineEquals(request, "POST https://vcloud/extensions/internetService/12/nodeServices HTTP/1.1"); assertHeadersEqual( - httpMethod, + request, "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"))); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, NodeHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testGetKeyPair() throws SecurityException, NoSuchMethodException, IOException { Method method = TerremarkVCloudAsyncClient.class.getMethod("getNode", int.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - 12); + HttpRequest request = processor.createRequest(method, 12); - assertRequestLineEquals(httpMethod, "GET https://vcloud/extensions/nodeService/12 HTTP/1.1"); - assertHeadersEqual(httpMethod, "Accept: application/vnd.tmrk.vCloud.nodeService+xml\n"); - assertPayloadEquals(httpMethod, null); + assertRequestLineEquals(request, "GET https://vcloud/extensions/nodeService/12 HTTP/1.1"); + assertHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.nodeService+xml\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, NodeHandler.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - checkFilters(httpMethod); + checkFilters(request); } public void testConfigureNode() throws SecurityException, NoSuchMethodException, IOException { Method method = TerremarkVCloudAsyncClient.class.getMethod("configureNode", int.class, NodeConfiguration.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - 12, new NodeConfiguration().changeDescriptionTo("eggs")); + HttpRequest request = processor.createRequest(method, 12, new NodeConfiguration() + .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( - httpMethod, + request, "Accept: application/vnd.tmrk.vCloud.nodeService+xml\nContent-Length: 155\nContent-Type: application/vnd.tmrk.vCloud.nodeService+xml\n"); assertPayloadEquals( - httpMethod, + request, "eggs"); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, NodeHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testGetNodes() throws SecurityException, NoSuchMethodException, IOException { Method method = TerremarkVCloudAsyncClient.class.getMethod("getNodes", int.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - 12); + HttpRequest request = processor.createRequest(method, 12); - assertRequestLineEquals(httpMethod, + assertRequestLineEquals(request, "GET https://vcloud/extensions/internetService/12/nodeServices HTTP/1.1"); - assertHeadersEqual(httpMethod, "Accept: application/vnd.tmrk.vCloud.nodeService+xml\n"); - assertPayloadEquals(httpMethod, null); + assertHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.nodeService+xml\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, NodesHandler.class); assertExceptionParserClassEquals(method, ReturnEmptySetOnUnauthorized.class); - checkFilters(httpMethod); + checkFilters(request); } public void testDeleteNode() throws SecurityException, NoSuchMethodException, IOException { Method method = TerremarkVCloudAsyncClient.class.getMethod("deleteNode", int.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - 12); + HttpRequest request = processor.createRequest(method, 12); - assertRequestLineEquals(httpMethod, - "DELETE https://vcloud/extensions/nodeService/12 HTTP/1.1"); - assertHeadersEqual(httpMethod, ""); - assertPayloadEquals(httpMethod, null); + assertRequestLineEquals(request, "DELETE https://vcloud/extensions/nodeService/12 HTTP/1.1"); + assertHeadersEqual(request, ""); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); + assertResponseParserClassEquals(method, request, CloseContentAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class); - checkFilters(httpMethod); + checkFilters(request); } public void testGetCustomizationOptionsOfCatalogItem() throws SecurityException, NoSuchMethodException, IOException { Method method = TerremarkVCloudAsyncClient.class.getMethod( "getCustomizationOptionsOfCatalogItem", String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - 12); + HttpRequest request = processor.createRequest(method, 12); - assertRequestLineEquals(httpMethod, + assertRequestLineEquals(request, "GET https://vcloud/extensions/template/12/options/customization HTTP/1.1"); - assertHeadersEqual(httpMethod, + assertHeadersEqual(request, "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); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testListKeyPairs() throws SecurityException, NoSuchMethodException, IOException { Method method = TerremarkVCloudAsyncClient.class.getMethod("listKeyPairs"); - GeneratedHttpRequest httpMethod = processor.createRequest(method); + HttpRequest request = processor.createRequest(method); - assertRequestLineEquals(httpMethod, "GET https://keysList HTTP/1.1"); - assertHeadersEqual(httpMethod, "Accept: application/vnd.tmrk.vcloudExpress.keysList+xml\n"); - assertPayloadEquals(httpMethod, null); + assertRequestLineEquals(request, "GET https://keysList HTTP/1.1"); + assertHeadersEqual(request, "Accept: application/vnd.tmrk.vcloudExpress.keysList+xml\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, KeyPairsHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testListKeyPairsInOrg() throws SecurityException, NoSuchMethodException, IOException { Method method = TerremarkVCloudAsyncClient.class.getMethod("listKeyPairsInOrg", String.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - "org1"); + HttpRequest request = processor.createRequest(method, "org1"); - assertRequestLineEquals(httpMethod, "GET https://vcloud/extensions/org/org1/keys HTTP/1.1"); - assertHeadersEqual(httpMethod, "Accept: application/vnd.tmrk.vcloudExpress.keysList+xml\n"); - assertPayloadEquals(httpMethod, null); + assertRequestLineEquals(request, "GET https://vcloud/extensions/org/org1/keys HTTP/1.1"); + assertHeadersEqual(request, "Accept: application/vnd.tmrk.vcloudExpress.keysList+xml\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, KeyPairsHandler.class); assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); + checkFilters(request); } public void testGetNode() throws SecurityException, NoSuchMethodException, IOException { Method method = TerremarkVCloudAsyncClient.class.getMethod("getNode", int.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - 12); + HttpRequest request = processor.createRequest(method, 12); - assertRequestLineEquals(httpMethod, "GET https://vcloud/extensions/nodeService/12 HTTP/1.1"); - assertHeadersEqual(httpMethod, "Accept: application/vnd.tmrk.vCloud.nodeService+xml\n"); - assertPayloadEquals(httpMethod, null); + assertRequestLineEquals(request, "GET https://vcloud/extensions/nodeService/12 HTTP/1.1"); + assertHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.nodeService+xml\n"); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, NodeHandler.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - checkFilters(httpMethod); + checkFilters(request); } // TODO @@ -513,45 +493,44 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest httpMethod = processor + // HttpRequest request = processor // .createRequest(method, 12, new KeyPairConfiguration() // .changeDescriptionTo("eggs")); // - // assertRequestLineEquals(httpMethod, + // assertRequestLineEquals(request, // "PUT https://vcloud/extensions/keyPairService/12 HTTP/1.1"); // assertHeadersEqual( - // httpMethod, + // request, // "Accept: application/vnd.tmrk.vCloud.keyPairService+xml\nContent-Length: 155\nContent-Type: application/vnd.tmrk.vCloud.keyPairService+xml\n"); // assertPayloadEquals( - // httpMethod, + // request, // "eggs"); - // assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + // assertResponseParserClassEquals(method, request, ParseSax.class); // assertSaxResponseParserClassEquals(method, KeyPairHandler.class); // assertExceptionParserClassEquals(method, null); // - // checkFilters(httpMethod); + // checkFilters(request); // } public void testDeleteKeyPair() throws SecurityException, NoSuchMethodException, IOException { Method method = TerremarkVCloudAsyncClient.class.getMethod("deleteKeyPair", int.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, - 12); + HttpRequest request = processor.createRequest(method, 12); - assertRequestLineEquals(httpMethod, "DELETE https://vcloud/extensions/key/12 HTTP/1.1"); - assertHeadersEqual(httpMethod, ""); - assertPayloadEquals(httpMethod, null); + assertRequestLineEquals(request, "DELETE https://vcloud/extensions/key/12 HTTP/1.1"); + assertHeadersEqual(request, ""); + assertPayloadEquals(request, null); - assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class); + assertResponseParserClassEquals(method, request, CloseContentAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class); - checkFilters(httpMethod); + checkFilters(request); } @Override - protected void checkFilters(GeneratedHttpRequest httpMethod) { - assertEquals(httpMethod.getFilters().size(), 1); - assertEquals(httpMethod.getFilters().get(0).getClass(), SetVCloudTokenCookie.class); + protected void checkFilters(HttpRequest request) { + assertEquals(request.getFilters().size(), 1); + assertEquals(request.getFilters().get(0).getClass(), SetVCloudTokenCookie.class); } @Override diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/binders/BindNodeConfigurationToXmlPayloadTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/binders/BindNodeConfigurationToXmlPayloadTest.java index 6434fd2cf1..1af2f44840 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/binders/BindNodeConfigurationToXmlPayloadTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/binders/BindNodeConfigurationToXmlPayloadTest.java @@ -28,8 +28,7 @@ import java.io.IOException; import java.net.URI; import java.util.Properties; -import org.jclouds.rest.internal.GeneratedHttpRequest; -import com.google.inject.name.Names; +import org.jclouds.http.HttpRequest; import org.jclouds.vcloud.VCloudPropertiesBuilder; import org.jclouds.vcloud.terremark.domain.NodeConfiguration; import org.testng.annotations.Test; @@ -40,6 +39,7 @@ import com.google.common.collect.Multimaps; import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; +import com.google.inject.name.Names; /** * Tests behavior of {@code BindNodeConfigurationToXmlPayload} @@ -100,8 +100,7 @@ public class BindNodeConfigurationToXmlPayloadTest { .getInstance(BindNodeConfigurationToXmlPayload.class); Multimap headers = Multimaps.synchronizedMultimap(HashMultimap . create()); - GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); - expect(request.getArgs()).andReturn(new Object[] { config }).atLeastOnce(); + HttpRequest request = createMock(HttpRequest.class); expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes(); expect(request.getFirstHeaderOrNull("Content-Type")).andReturn(null).atLeastOnce(); expect(request.getHeaders()).andReturn(headers).atLeastOnce();