loosened dependency on the GeneratedHttpRequest class

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

View File

@ -40,6 +40,7 @@ import org.jclouds.blobstore.binders.BindBlobToMultipartFormTest;
import org.jclouds.blobstore.functions.ThrowContainerNotFoundOn404;
import org.jclouds.blobstore.functions.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<AtmosStorageAsyn
public void testListDirectories() throws SecurityException, NoSuchMethodException, IOException {
Method method = AtmosStorageAsyncClient.class.getMethod("listDirectories", Array.newInstance(
ListOptions.class, 0).getClass());
GeneratedHttpRequest<AtmosStorageAsyncClient> httpMethod = processor.createRequest(method);
HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(httpMethod,
assertRequestLineEquals(request,
"GET https://accesspoint.atmosonline.com/rest/namespace HTTP/1.1");
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<AtmosStorageAsyncClient> 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<AtmosStorageAsyncClient> 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<AtmosStorageAsyncClient> 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<AtmosStorageAsyncClient> 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<AtmosStorageAsyncClient> 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<AtmosStorageAsyncClient> 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<AtmosStorageAsyncClient> 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<AtmosStorageAsyncClient> 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<AtmosStorageAsyncClient> 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<AtmosStorageAsyn
}
@Override
protected void checkFilters(GeneratedHttpRequest<AtmosStorageAsyncClient> 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

View File

@ -1,53 +1,67 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.aws.ec2.binders;
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++;
}
}
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -20,13 +20,12 @@ package org.jclouds.aws.ec2.binders;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.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);
}
}

View File

@ -20,13 +20,12 @@ package org.jclouds.aws.ec2.binders;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.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) {

View File

@ -20,13 +20,13 @@ package org.jclouds.aws.ec2.binders;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.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());
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -20,6 +20,7 @@ package org.jclouds.aws.ec2.util;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.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 + "]"));
}

View File

@ -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);
}
}

View File

@ -27,6 +27,9 @@ import static org.jclouds.aws.ec2.reference.EC2Parameters.SIGNATURE_METHOD;
import static org.jclouds.aws.ec2.reference.EC2Parameters.SIGNATURE_VERSION;
import static org.jclouds.aws.ec2.reference.EC2Parameters.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<String, String> decodedParams = RestAnnotationProcessor.parseQueryToMap(request
.getPayload().getRawContent().toString());
Multimap<String, String> 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<String, String> decodedParams) {
request.setPayload(RestAnnotationProcessor.makeQueryLine(decodedParams,
new Comparator<Map.Entry<String, String>>() {
public int compare(Entry<String, String> o1, Entry<String, String> 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<String, String> decodedParams) {
request.setPayload(makeQueryLine(decodedParams, new Comparator<Map.Entry<String, String>>() {
public int compare(Entry<String, String> o1, Entry<String, String> 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<String, String> 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<String, String> decodedParams) {
return RestAnnotationProcessor.makeQueryLine(decodedParams,
new Comparator<Map.Entry<String, String>>() {
public int compare(Map.Entry<String, String> o1, Map.Entry<String, String> o2) {
if (o1.getKey().startsWith("AWSAccessKeyId"))
return -1;
return o1.getKey().compareTo(o2.getKey());
}
});
return makeQueryLine(decodedParams, new Comparator<Map.Entry<String, String>>() {
public int compare(Map.Entry<String, String> o1, Map.Entry<String, String> 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()));
}
}

View File

@ -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&#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 {

View File

@ -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);

View File

@ -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<EC2AsyncClient> {
}
@Override
protected void checkFilters(GeneratedHttpRequest<EC2AsyncClient> httpMethod) {
protected void checkFilters(HttpRequest request) {
}

View File

@ -33,9 +33,9 @@ import org.jclouds.aws.ec2.xml.DescribeImagesResponseHandler;
import org.jclouds.aws.ec2.xml.ImageIdHandler;
import org.jclouds.aws.ec2.xml.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<AMIAsyncClient> {
Method method = AMIAsyncClient.class.getMethod("createImageInRegion", String.class,
String.class, String.class, Array.newInstance(CreateImageOptions.class, 0)
.getClass());
GeneratedHttpRequest<AMIAsyncClient> 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<AMIAsyncClient> {
Method method = AMIAsyncClient.class.getMethod("createImageInRegion", String.class,
String.class, String.class, Array.newInstance(CreateImageOptions.class, 0)
.getClass());
GeneratedHttpRequest<AMIAsyncClient> 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<AMIAsyncClient> 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<AMIAsyncClient> 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<AMIAsyncClient> 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<AMIAsyncClient> {
Method method = AMIAsyncClient.class.getMethod("registerImageFromManifestInRegion",
String.class, String.class, String.class, Array.newInstance(
RegisterImageOptions.class, 0).getClass());
GeneratedHttpRequest<AMIAsyncClient> 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<AMIAsyncClient> {
Method method = AMIAsyncClient.class.getMethod("registerImageFromManifestInRegion",
String.class, String.class, String.class, Array.newInstance(
RegisterImageOptions.class, 0).getClass());
GeneratedHttpRequest<AMIAsyncClient> 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<AMIAsyncClient> {
Method method = AMIAsyncClient.class.getMethod("registerUnixImageBackedByEbsInRegion",
String.class, String.class, String.class, Array.newInstance(
RegisterImageBackedByEbsOptions.class, 0).getClass());
GeneratedHttpRequest<AMIAsyncClient> 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<AMIAsyncClient> {
Method method = AMIAsyncClient.class.getMethod("registerUnixImageBackedByEbsInRegion",
String.class, String.class, String.class, Array.newInstance(
RegisterImageBackedByEbsOptions.class, 0).getClass());
GeneratedHttpRequest<AMIAsyncClient> 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<AMIAsyncClient> 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<AMIAsyncClient> 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<AMIAsyncClient> 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<AMIAsyncClient> 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<AMIAsyncClient> 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<AMIAsyncClient> 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<AMIAsyncClient> 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<AMIAsyncClient> 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

View File

@ -31,8 +31,8 @@ import org.jclouds.aws.ec2.options.DescribeAvailabilityZonesOptions;
import org.jclouds.aws.ec2.options.DescribeRegionsOptions;
import org.jclouds.aws.ec2.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<AvailabilityZoneAndRegionAsyncClient> 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<AvailabilityZoneAndRegionAsyncClient> 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<AvailabilityZoneAndRegionAsyncClient> 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<AvailabilityZoneAndRegionAsyncClient> 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

View File

@ -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<T> extends RestClientTest<T> {
protected FormSigner filter;
@Override
protected void checkFilters(GeneratedHttpRequest<T> 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() {

View File

@ -36,9 +36,9 @@ import org.jclouds.aws.ec2.xml.DescribeSnapshotsResponseHandler;
import org.jclouds.aws.ec2.xml.DescribeVolumesResponseHandler;
import org.jclouds.aws.ec2.xml.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<ElasticBlockStoreAsyncClient> 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<ElasticBlockStoreAsyncClient> 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<ElasticBlockStoreAsyncClient> 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<ElasticBlockStoreAsyncClient> 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<ElasticBlockStoreAsyncClient> 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<ElasticBlockStoreAsyncClient> 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<ElasticBlockStoreAsyncClient> 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<ElasticBlockStoreAsyncClient> 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<ElasticBlockStoreAsyncClient> 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<ElasticBlockStoreAsyncClient> 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<ElasticBlockStoreAsyncClient> 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<ElasticBlockStoreAsyncClient> 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<ElasticBlockStoreAsyncClient> 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<ElasticBlockStoreAsyncClient> 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<ElasticBlockStoreAsyncClient> 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<ElasticBlockStoreAsyncClient> 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<ElasticBlockStoreAsyncClient> 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

View File

@ -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<ElasticIPAddressAsyncClient> 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<ElasticIPAddressAsyncClient> 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<ElasticIPAddressAsyncClient> 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<ElasticIPAddressAsyncClient> 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<ElasticIPAddressAsyncClient> 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

View File

@ -38,9 +38,9 @@ import org.jclouds.aws.ec2.xml.InstanceTypeHandler;
import org.jclouds.aws.ec2.xml.RunInstancesResponseHandler;
import org.jclouds.aws.ec2.xml.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<InstanceAsyn
public void testDescribeInstances() throws SecurityException, NoSuchMethodException, IOException {
Method method = InstanceAsyncClient.class.getMethod("describeInstancesInRegion",
String.class, Array.newInstance(String.class, 0).getClass());
GeneratedHttpRequest<InstanceAsyncClient> 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<InstanceAsyncClient> 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<InstanceAsyncClient> 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<InstanceAsyncClient> 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<InstanceAsyn
Method method = InstanceAsyncClient.class.getMethod("runInstancesInRegion", String.class,
String.class, String.class, int.class, int.class, Array.newInstance(
RunInstancesOptions.class, 0).getClass());
GeneratedHttpRequest<InstanceAsyncClient> 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<InstanceAsyncClient> 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<InstanceAsyncClient> 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<InstanceAsyncClient> 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<InstanceAsyncClient> 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<InstanceAsyncClient> 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<InstanceAsyncClient> 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<InstanceAsyncClient> 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<InstanceAsyncClient> 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<InstanceAsyncClient> 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<InstanceAsyn
Method method = InstanceAsyncClient.class.getMethod(
"getInstanceInitiatedShutdownBehaviorForInstanceInRegion", String.class,
String.class);
GeneratedHttpRequest<InstanceAsyncClient> 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<InstanceAsyncClient> 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<InstanceAsyncClient> 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<InstanceAsyncClient> 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<InstanceAsyncClient> 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<InstanceAsyn
Method method = InstanceAsyncClient.class.getMethod(
"setApiTerminationDisabledForInstanceInRegion", String.class, String.class,
boolean.class);
GeneratedHttpRequest<InstanceAsyncClient> 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<InstanceAsyncClient> 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<InstanceAsyn
Method method = InstanceAsyncClient.class.getMethod(
"setInstanceInitiatedShutdownBehaviorForInstanceInRegion", String.class,
String.class, InstanceInitiatedShutdownBehavior.class);
GeneratedHttpRequest<InstanceAsyncClient> 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<InstanceAsyn
BlockDeviceMapping blockDeviceMapping = new BlockDeviceMapping();
blockDeviceMapping.addEbsBlockDevice("/dev/sda1", new RunningInstance.EbsBlockDevice(
"vol-test1", true));
GeneratedHttpRequest<InstanceAsyncClient> 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

View File

@ -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<KeyPairAsyncC
public void testDeleteKeyPair() throws SecurityException, NoSuchMethodException, IOException {
Method method = KeyPairAsyncClient.class.getMethod("deleteKeyPairInRegion", String.class,
String.class);
GeneratedHttpRequest<KeyPairAsyncClient> 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<KeyPairAsyncClient> 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<KeyPairAsyncClient> 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

View File

@ -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<Monitoring
IOException {
Method method = MonitoringAsyncClient.class.getMethod("unmonitorInstancesInRegion",
String.class, String.class, Array.newInstance(String.class, 0).getClass());
GeneratedHttpRequest<MonitoringAsyncClient> 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<MonitoringAsyncClient> 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

View File

@ -26,9 +26,9 @@ import org.jclouds.aws.ec2.domain.IpProtocol;
import org.jclouds.aws.ec2.domain.UserIdGroupPair;
import org.jclouds.aws.ec2.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<Securit
IOException {
Method method = SecurityGroupAsyncClient.class.getMethod("deleteSecurityGroupInRegion",
String.class, String.class);
GeneratedHttpRequest<SecurityGroupAsyncClient> 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<SecurityGroupAsyncClient> 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<SecurityGroupAsyncClient> 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<SecurityGroupAsyncClient> 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<Securit
Method method = SecurityGroupAsyncClient.class.getMethod(
"authorizeSecurityGroupIngressInRegion", String.class, String.class,
UserIdGroupPair.class);
GeneratedHttpRequest<SecurityGroupAsyncClient> 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<Securit
Method method = SecurityGroupAsyncClient.class.getMethod(
"authorizeSecurityGroupIngressInRegion", String.class, String.class,
IpProtocol.class, int.class, int.class, String.class);
GeneratedHttpRequest<SecurityGroupAsyncClient> 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<Securit
Method method = SecurityGroupAsyncClient.class.getMethod(
"revokeSecurityGroupIngressInRegion", String.class, String.class,
UserIdGroupPair.class);
GeneratedHttpRequest<SecurityGroupAsyncClient> 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<Securit
Method method = SecurityGroupAsyncClient.class.getMethod(
"revokeSecurityGroupIngressInRegion", String.class, String.class, IpProtocol.class,
int.class, int.class, String.class);
GeneratedHttpRequest<SecurityGroupAsyncClient> 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

View File

@ -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<ELBAsyncClient> {
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<ELBAsyncClient> 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<ELBAsyncClient> {
return new TypeLiteral<RestAnnotationProcessor<ELBAsyncClient>>() {
};
}
@RequiresHttp
@ConfiguresRestClient
private static final class TestELBRestClientModule extends ELBRestClientModule {
@ -99,6 +96,7 @@ public class ELBAsyncClientTest extends RestClientTest<ELBAsyncClient> {
return "2009-11-08T15:54:08.897Z";
}
}
@Override
protected Module createModule() {
return new TestELBRestClientModule();
@ -111,9 +109,9 @@ public class ELBAsyncClientTest extends RestClientTest<ELBAsyncClient> {
}
@Override
protected void checkFilters(GeneratedHttpRequest<ELBAsyncClient> 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);
}
}

View File

@ -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<S3AsyncClient> {
public void testGetBucketLocation() throws SecurityException, NoSuchMethodException, IOException {
Method method = S3AsyncClient.class.getMethod("getBucketLocation", String.class);
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket");
HttpRequest request = processor.createRequest(method, "bucket");
assertRequestLineEquals(httpMethod, "GET https://bucket.s3.amazonaws.com/?location HTTP/1.1");
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<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket");
HttpRequest request = processor.createRequest(method, "bucket");
assertRequestLineEquals(httpMethod,
assertRequestLineEquals(request,
"GET https://bucket.s3.amazonaws.com/?requestPayment HTTP/1.1");
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<S3AsyncClient> 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,
"<RequestPaymentConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Payer>BucketOwner</Payer></RequestPaymentConfiguration>");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
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<S3AsyncClient> 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,
"<RequestPaymentConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Payer>Requester</Payer></RequestPaymentConfiguration>");
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
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<S3AsyncClient> 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<S3AsyncClient> 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<S3AsyncClient> {
Method method = S3AsyncClient.class
.getMethod("copyObject", String.class, String.class, String.class, String.class,
Array.newInstance(CopyObjectOptions.class, 0).getClass());
GeneratedHttpRequest<S3AsyncClient> 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<S3AsyncClient> 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<S3AsyncClient> 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<S3AsyncClient> 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<S3AsyncClient> 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<S3AsyncClient> 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<S3AsyncClient> 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<S3AsyncClient> 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<S3AsyncClient> 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<S3AsyncClient> {
public void testPutBucketACL() throws SecurityException, NoSuchMethodException, IOException {
Method method = S3AsyncClient.class.getMethod("putBucketACL", String.class,
AccessControlList.class);
GeneratedHttpRequest<S3AsyncClient> 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,
"<AccessControlPolicy xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Owner><ID>1234</ID></Owner><AccessControlList><Grant><Grantee xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"CanonicalUser\"><ID>1234</ID></Grantee><Permission>FULL_CONTROL</Permission></Grant></AccessControlList></AccessControlPolicy>");
assertResponseParserClassEquals(method, httpMethod, ReturnTrueIf2xx.class);
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
assertSaxResponseParserClassEquals(method, null);
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<S3AsyncClient> 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<S3AsyncClient> 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,
"<CreateBucketConfiguration><LocationConstraint>EU</LocationConstraint></CreateBucketConfiguration>");
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<S3AsyncClient> {
Method method = S3AsyncClient.class.getMethod("putObject", String.class, S3Object.class,
Array.newInstance(PutObjectOptions.class, 0).getClass());
GeneratedHttpRequest<S3AsyncClient> 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<S3AsyncClient> 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,
"<AccessControlPolicy xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Owner><ID>1234</ID></Owner><AccessControlList><Grant><Grantee xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"CanonicalUser\"><ID>1234</ID></Grantee><Permission>FULL_CONTROL</Permission></Grant></AccessControlList></AccessControlPolicy>");
assertResponseParserClassEquals(method, httpMethod, ReturnTrueIf2xx.class);
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod);
checkFilters(request);
}
public void testGetBucketLogging() throws SecurityException, NoSuchMethodException, IOException {
Method method = S3AsyncClient.class.getMethod("getBucketLogging", String.class);
GeneratedHttpRequest<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket");
HttpRequest request = processor.createRequest(method, "bucket");
assertRequestLineEquals(httpMethod, "GET https://bucket.s3.amazonaws.com/?logging HTTP/1.1");
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<S3AsyncClient> 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,
"<BucketLoggingStatus xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"/>");
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<S3AsyncClient> httpMethod = processor.createRequest(method, "bucket",
new BucketLogging("mylogs", "access_log-", ImmutableSet.<Grant> of(new Grant(
new EmailAddressGrantee("adrian@jclouds.org"), Permission.FULL_CONTROL))));
HttpRequest request = processor.createRequest(method, "bucket", new BucketLogging("mylogs",
"access_log-", ImmutableSet.<Grant> 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<S3AsyncClient> 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

View File

@ -38,12 +38,12 @@ import org.jclouds.aws.sqs.options.ListQueuesOptions;
import org.jclouds.aws.sqs.xml.RegexListQueuesResponseHandler;
import org.jclouds.aws.sqs.xml.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<SQSAsyncClient> {
IOException {
Method method = SQSAsyncClient.class.getMethod("listQueuesInRegion", String.class, Array
.newInstance(ListQueuesOptions.class, 0).getClass());
GeneratedHttpRequest<SQSAsyncClient> 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<SQSAsyncClient> 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<SQSAsyncClient> 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<SQSAsyncClient> 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<SQSAsyncClient> {
}
@Override
protected void checkFilters(GeneratedHttpRequest<SQSAsyncClient> 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

View File

@ -38,6 +38,7 @@ import org.jclouds.azure.storage.blob.options.ListBlobsOptions;
import org.jclouds.azure.storage.filters.SharedKeyLiteAuthentication;
import org.jclouds.azure.storage.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<AzureBlobAsyncClien
Method method = AzureBlobAsyncClient.class.getMethod("listContainers", Array.newInstance(
ListOptions.class, 0).getClass());
GeneratedHttpRequest<AzureBlobAsyncClient> 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<AzureBlobAsyncClien
Method method = AzureBlobAsyncClient.class.getMethod("listContainers", Array.newInstance(
ListOptions.class, 0).getClass());
GeneratedHttpRequest<AzureBlobAsyncClient> 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<AzureBlobAsyncClien
Method method = AzureBlobAsyncClient.class.getMethod("createContainer", String.class, Array
.newInstance(CreateContainerOptions.class, 0).getClass());
GeneratedHttpRequest<AzureBlobAsyncClient> 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<AzureBlobAsyncClien
public void testDeleteContainer() throws SecurityException, NoSuchMethodException {
Method method = AzureBlobAsyncClient.class.getMethod("deleteContainer", String.class);
GeneratedHttpRequest<AzureBlobAsyncClient> 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<AzureBlobAsyncClien
Method method = AzureBlobAsyncClient.class.getMethod("createContainer", String.class, Array
.newInstance(CreateContainerOptions.class, 0).getClass());
GeneratedHttpRequest<AzureBlobAsyncClient> 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<AzureBlobAsyncClien
Method method = AzureBlobAsyncClient.class.getMethod("createRootContainer", Array
.newInstance(CreateContainerOptions.class, 0).getClass());
GeneratedHttpRequest<AzureBlobAsyncClient> 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<AzureBlobAsyncClien
public void testDeleteRootContainer() throws SecurityException, NoSuchMethodException {
Method method = AzureBlobAsyncClient.class.getMethod("deleteRootContainer");
GeneratedHttpRequest<AzureBlobAsyncClient> 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<AzureBlobAsyncClien
Method method = AzureBlobAsyncClient.class.getMethod("createRootContainer", Array
.newInstance(CreateContainerOptions.class, 0).getClass());
GeneratedHttpRequest<AzureBlobAsyncClient> 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<AzureBlobAsyncClien
Method method = AzureBlobAsyncClient.class.getMethod("listBlobs", String.class, Array
.newInstance(ListBlobsOptions.class, 0).getClass());
GeneratedHttpRequest<AzureBlobAsyncClient> 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<AzureBlobAsyncClien
Method method = AzureBlobAsyncClient.class.getMethod("listBlobs", Array.newInstance(
ListBlobsOptions.class, 0).getClass());
GeneratedHttpRequest<AzureBlobAsyncClient> 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<AzureBlobAsyncClien
public void testContainerProperties() throws SecurityException, NoSuchMethodException {
Method method = AzureBlobAsyncClient.class.getMethod("getContainerProperties", String.class);
GeneratedHttpRequest<AzureBlobAsyncClient> 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<AzureBlobAsyncClien
Method method = AzureBlobAsyncClient.class.getMethod("setResourceMetadata", String.class,
Map.class);
GeneratedHttpRequest<AzureBlobAsyncClient> 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<AzureBlobAsyncClien
public void testSetBlobMetadata() throws SecurityException, NoSuchMethodException {
Method method = AzureBlobAsyncClient.class.getMethod("setBlobMetadata", String.class,
String.class, Map.class);
GeneratedHttpRequest<AzureBlobAsyncClient> 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<AzureBlobAsyncClien
}
@Override
protected void checkFilters(GeneratedHttpRequest<AzureBlobAsyncClient> 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

View File

@ -35,13 +35,13 @@ import org.jclouds.azure.storage.queue.options.GetOptions;
import org.jclouds.azure.storage.queue.options.PutMessageOptions;
import org.jclouds.azure.storage.queue.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<AzureQueueAsyncCli
public void testGetMessages() throws SecurityException, NoSuchMethodException, IOException {
Method method = AzureQueueAsyncClient.class.getMethod("getMessages", String.class,
GetOptions[].class);
GeneratedHttpRequest<AzureQueueAsyncClient> 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<AzureQueueAsyncClient> 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<AzureQueueAsyncClient> httpRequest = processor.createRequest(method);
HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(httpRequest,
assertRequestLineEquals(request,
"GET https://identity.queue.core.windows.net/?comp=list HTTP/1.1");
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<AzureQueueAsyncClient> 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<AzureQueueAsyncClient> 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<AzureQueueAsyncCli
Method method = AzureQueueAsyncClient.class.getMethod("createQueue", String.class,
CreateOptions[].class);
GeneratedHttpRequest<AzureQueueAsyncClient> 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<AzureQueueAsyncClient> 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<AzureQueueAsyncCli
Method method = AzureQueueAsyncClient.class.getMethod("putMessage", String.class,
String.class, PutMessageOptions[].class);
GeneratedHttpRequest<AzureQueueAsyncClient> 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,
"<QueueMessage><MessageText>message</MessageText></QueueMessage>");
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<AzureQueueAsyncClient> 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,
"<QueueMessage><MessageText>message</MessageText></QueueMessage>");
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<AzureQueueAsyncClient> 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<AzureQueueAsyncClient> 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

View File

@ -111,8 +111,7 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore {
ConcurrentMap<String, Location> 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<Location> 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);
}

View File

@ -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<BoxDotNetAsyncClient> {
public void testList() throws SecurityException, NoSuchMethodException, IOException {
Method method = BoxDotNetAsyncClient.class.getMethod("list");
GeneratedHttpRequest<BoxDotNetAsyncClient> httpRequest = processor.createRequest(method);
@ -66,7 +66,8 @@ public class BoxDotNetAsyncClientTest extends RestClientTest<BoxDotNetAsyncClien
assertRequestLineEquals(httpRequest, "GET https://www.box.net/api/1.0/rest/items HTTP/1.1");
// for example, using basic authentication, we should get "only one" header
assertHeadersEqual(httpRequest, "Accept: application/json\nAuthorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\n");
assertHeadersEqual(httpRequest,
"Accept: application/json\nAuthorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\n");
assertPayloadEquals(httpRequest, null);
// TODO: insert expected response class, which probably extends ParseJson
@ -98,8 +99,7 @@ public class BoxDotNetAsyncClientTest extends RestClientTest<BoxDotNetAsyncClien
public void testDelete() throws SecurityException, NoSuchMethodException, IOException {
Method method = BoxDotNetAsyncClient.class.getMethod("delete", long.class);
GeneratedHttpRequest<BoxDotNetAsyncClient> httpRequest = processor.createRequest(
method, 1);
GeneratedHttpRequest<BoxDotNetAsyncClient> 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<BoxDotNetAsyncClien
checkFilters(httpRequest);
}
@Override
protected void checkFilters(GeneratedHttpRequest<BoxDotNetAsyncClient> 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<BoxDotNetAsyncClien
@Override
public ContextSpec<BoxDotNetClient, BoxDotNetAsyncClient> 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);
}
}

View File

@ -121,10 +121,10 @@ public class SignedHeaderAuth implements HttpRequestFilter {
}
}
public String createStringToSign(String httpMethod, String hashedPath, String contentHash,
public String createStringToSign(String request, String hashedPath, String contentHash,
String timestamp) {
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();

View File

@ -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<ChefAsyncClient> {
public void testGetUploadUrisForContent() throws SecurityException,
NoSuchMethodException, IOException {
Method method = ChefAsyncClient.class.getMethod(
"getUploadUrisForContent", Set.class);
GeneratedHttpRequest<ChefAsyncClient> 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<ChefAsyncClient> 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<ChefAsyncClient> {
}
public void testGetCookbook() throws SecurityException,
NoSuchMethodException, IOException {
Method method = ChefAsyncClient.class.getMethod("getCookbook",
String.class, String.class);
GeneratedHttpRequest<ChefAsyncClient> 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<ChefAsyncClient> 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<ChefAsyncClient> {
}
public void testDeleteCookbook() throws SecurityException,
NoSuchMethodException, IOException {
Method method = ChefAsyncClient.class.getMethod("deleteCookbook",
String.class, String.class);
GeneratedHttpRequest<ChefAsyncClient> 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<ChefAsyncClient> 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<ChefAsyncClient> {
}
public void testUpdateCookbook() throws SecurityException,
NoSuchMethodException, IOException {
Method method = ChefAsyncClient.class.getMethod("updateCookbook",
String.class, String.class, Cookbook.class);
GeneratedHttpRequest<ChefAsyncClient> 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<ChefAsyncClient> 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<ChefAsyncClient> {
}
public void testListCookbooks() throws SecurityException,
NoSuchMethodException, IOException {
public void testListCookbooks() throws SecurityException, NoSuchMethodException, IOException {
Method method = ChefAsyncClient.class.getMethod("listCookbooks");
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor
.createRequest(method);
GeneratedHttpRequest<ChefAsyncClient> 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<ChefAsyncClient> {
}
public void testClientExists() throws SecurityException,
NoSuchMethodException, IOException {
Method method = ChefAsyncClient.class.getMethod("clientExists",
String.class);
GeneratedHttpRequest<ChefAsyncClient> 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<ChefAsyncClient> 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<ChefAsyncClient> {
}
public void testDeleteClient() throws SecurityException,
NoSuchMethodException, IOException {
Method method = ChefAsyncClient.class.getMethod("deleteClient",
String.class);
GeneratedHttpRequest<ChefAsyncClient> 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<ChefAsyncClient> 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<ChefAsyncClient> {
}
public void testGenerateKeyForClient() throws SecurityException,
NoSuchMethodException, IOException {
Method method = ChefAsyncClient.class.getMethod("generateKeyForClient",
String.class);
GeneratedHttpRequest<ChefAsyncClient> 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<ChefAsyncClient> 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<ChefAsyncClient> {
}
public void testCreateClient() throws SecurityException,
NoSuchMethodException, IOException {
Method method = ChefAsyncClient.class.getMethod("createClient",
String.class);
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor
.createRequest(method, "client");
public void testCreateClient() throws SecurityException, NoSuchMethodException, IOException {
Method method = ChefAsyncClient.class.getMethod("createClient", String.class);
GeneratedHttpRequest<ChefAsyncClient> 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<ChefAsyncClient> {
}
public void testListClients() throws SecurityException,
NoSuchMethodException, IOException {
public void testListClients() throws SecurityException, NoSuchMethodException, IOException {
Method method = ChefAsyncClient.class.getMethod("listClients");
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor
.createRequest(method);
GeneratedHttpRequest<ChefAsyncClient> 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<ChefAsyncClient> {
}
@Override
protected void checkFilters(GeneratedHttpRequest<ChefAsyncClient> 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<ChefAsyncClient> {
@Override
public ContextSpec<ChefClient, ChefAsyncClient> createContextSpec() {
return new RestContextFactory().createContextSpec("chef", "user",
SignedHeaderAuthTest.PRIVATE_KEY, new Properties());
SignedHeaderAuthTest.PRIVATE_KEY, new Properties());
}
}

View File

@ -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<ChefClient, ChefAsyncClient> validatorConnection;
private RestContext<ChefClient, ChefAsyncClient> clientConnection;
private RestContext<ChefClient, ChefAsyncClient> 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<ChefClient, ChefAsyncClient> createConnection(
String identity, String key) throws IOException {
private RestContext<ChefClient, ChefAsyncClient> createConnection(String identity, String key)
throws IOException {
Properties props = new Properties();
props.setProperty("chef.endpoint", endpoint);
return new RestContextFactory().createContext("chef", identity, key,
ImmutableSet.<Module> of(new Log4JLoggingModule()), props);
return new RestContextFactory().createContext("chef", identity, key, ImmutableSet
.<Module> of(new Log4JLoggingModule()), props);
}
@Test
public void testListClients() throws Exception {
Set<String> 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.<Resource> builder().addAll(
cookbookO.getDefinitions()).addAll(cookbookO.getFiles()).addAll(
cookbookO.getLibraries()).addAll(cookbookO.getProviders()).addAll(
cookbookO.getRecipes()).addAll(cookbookO.getResources()).addAll(
cookbookO.getRootFiles()).addAll(cookbookO.getTemplates()).build()) {
try {
Utils.toStringAndClose(adminConnection.utils().http().get(resource.getUrl()));
} catch (NullPointerException e) {
assert false : "resource not found: " + resource;
}
System.err.printf("resource %s ok%n", resource.getName());
}
}
}
@Test(dependsOnMethods = "testListCookbooks")
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);
}

View File

@ -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.
*

View File

@ -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 + "]";
}
}

View File

@ -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<String> 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.<Object> of(value), builder, request.getSkips());
}
public static void addQueryParamTo(HttpRequest request, String key, Iterable<?> values,
UriBuilder builder) {
addQueryParamTo(request, key, values, builder, request.getSkips());
}
public static void addQueryParamTo(HttpRequest request, String key, Iterable<?> values,
UriBuilder builder, char... skips) {
builder.uri(request.getEndpoint());
Multimap<String, String> map = parseQueryToMap(request.getEndpoint().getQuery());
for (Object o : values)
map.put(key, o.toString());
builder.replaceQuery(makeQueryLine(map, null, skips));
request.setEndpoint(builder.build());
}
public static void replaceMatrixParam(HttpRequest request, String name, Object value,
UriBuilder builder) {
replaceMatrixParam(request, name, new Object[] { value }, builder);
}
public static void replaceMatrixParam(HttpRequest request, String name, Object[] values,
UriBuilder builder) {
builder.uri(request.getEndpoint());
builder.replaceMatrixParam(name, values);
request.setEndpoint(builder.build());
}
public static void addFormParamTo(HttpRequest request, String key, String value) {
addFormParamTo(request, key, ImmutableSet.<Object> of(value));
}
public static void addFormParamTo(HttpRequest request, String key, Iterable<?> values) {
Multimap<String, String> map = parseQueryToMap(request.getPayload().toString());
for (Object o : values)
map.put(key, o.toString());
request.setPayload(makeQueryLine(map, null));
}
public static Multimap<String, String> parseQueryToMap(String in) {
Multimap<String, String> map = LinkedListMultimap.create();
if (in == null) {
} else if (in.indexOf('&') == -1) {
if (in.contains("="))
parseKeyValueFromStringToMap(in, map);
else
map.put(in, null);
} else {
String[] parts = HttpUtils.urlDecode(in).split("&");
for (String part : parts) {
parseKeyValueFromStringToMap(part, map);
}
}
return map;
}
public static void parseKeyValueFromStringToMap(String stringToParse,
Multimap<String, String> map) {
// note that '=' can be a valid part of the value
int indexOfFirstEquals = stringToParse.indexOf('=');
String key = indexOfFirstEquals == -1 ? stringToParse : stringToParse.substring(0,
indexOfFirstEquals);
String value = indexOfFirstEquals == -1 ? null : stringToParse
.substring(indexOfFirstEquals + 1);
map.put(key, value);
}
public static SortedSet<Entry<String, String>> sortEntries(
Collection<Map.Entry<String, String>> in, Comparator<Map.Entry<String, String>> sorter) {
SortedSet<Entry<String, String>> entries = Sets.newTreeSet(sorter);
entries.addAll(in);
return entries;
}
public static String makeQueryLine(Multimap<String, String> params,
@Nullable Comparator<Map.Entry<String, String>> sorter, char... skips) {
Iterator<Map.Entry<String, String>> pairs = ((sorter == null) ? params.entries()
: sortEntries(params.entries(), sorter)).iterator();
StringBuilder formBuilder = new StringBuilder();
while (pairs.hasNext()) {
Map.Entry<String, String> pair = pairs.next();
formBuilder.append(HttpUtils.urlEncode(pair.getKey(), skips));
if (pair.getValue() != null && !pair.getValue().equals("")) {
formBuilder.append("=");
formBuilder.append(HttpUtils.urlEncode(pair.getValue(), skips));
}
if (pairs.hasNext())
formBuilder.append("&");
}
return formBuilder.toString();
}
}

View File

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

View File

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

View File

@ -18,9 +18,6 @@
*/
package org.jclouds.http.handlers;
import javax.inject.Provider;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpRetryHandler;
@ -55,10 +52,10 @@ public class DelegatingRetryHandler implements HttpRetryHandler {
HttpRetryHandler serverErrorRetryHandler;
@Inject
public DelegatingRetryHandler(Provider<UriBuilder> 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;
}

View File

@ -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<UriBuilder> uriBuilderProvider;
protected final Provider<UriBuilder> uriBuilderProvider;
@Inject
public RedirectionRetryHandler(Provider<UriBuilder> uriBuilderProvider,
protected RedirectionRetryHandler(Provider<UriBuilder> 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 {

View File

@ -20,31 +20,38 @@ package org.jclouds.rest.binders;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.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<UriBuilder> builder;
@Inject
BindMapToMatrixParams(Provider<UriBuilder> 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<String, String> map = (Map<String, String>) input;
for (Entry<String, String> entry : map.entrySet()) {
((GeneratedHttpRequest) request).replaceMatrixParam(entry.getKey(), entry.getValue());
replaceMatrixParam(request, entry.getKey(), entry.getValue(), builder.get());
}
}

View File

@ -22,11 +22,11 @@ import java.util.concurrent.ConcurrentMap;
import javax.inject.Inject;
import javax.inject.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<UriBuilder> uriBuilderProvider;
@SuppressWarnings("unchecked")
public TransformingHttpCommand<?> create(GeneratedHttpRequest<?> request,
public TransformingHttpCommand<?> create(HttpRequest request,
Function<HttpResponse, ?> transformer) {
return new TransformingHttpCommandImpl(uriBuilderProvider, executorService, request,
transformer);
return new TransformingHttpCommandImpl(executorService, request, transformer);
}
}

View File

@ -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<T> implements InvocationHandler {
if (exceptionParser instanceof InvocationContext) {
((InvocationContext) exceptionParser).setContext(null);
}
GeneratedHttpRequest<T> request;
HttpRequest request;
try {
request = annotationProcessor.createRequest(method, args);
if (exceptionParser instanceof InvocationContext) {
((InvocationContext) exceptionParser).setContext(request);
((InvocationContext) exceptionParser).setContext((GeneratedHttpRequest<T>) request);
}
} catch (RuntimeException e) {
if (exceptionParser != null) {
@ -143,7 +144,7 @@ public class AsyncRestClientProxy<T> implements InvocationHandler {
}
public static interface Factory {
public TransformingHttpCommand<?> create(GeneratedHttpRequest<?> request,
public TransformingHttpCommand<?> create(HttpRequest request,
Function<HttpResponse, ?> transformer);
}

View File

@ -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<T> extends HttpRequest {
private final Class<T> declaring;
private final Method javaMethod;
private final Object[] args;
private final RestAnnotationProcessor<T> processor;
private final Provider<UriBuilder> uriBuilderProvider;
GeneratedHttpRequest(Provider<UriBuilder> uriBuilderProvider, String method, URI endpoint,
RestAnnotationProcessor<T> processor, Class<T> declaring, Method javaMethod,
GeneratedHttpRequest(String method, URI endpoint, Class<T> 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<T> 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<T> extends HttpRequest {
return args;
}
public RestAnnotationProcessor<T> getProcessor() {
return processor;
}
public void replaceMatrixParam(String name, Object... values) {
UriBuilder builder = uriBuilderProvider.get().uri(getEndpoint());
builder.replaceMatrixParam(name, values);
replacePath(builder.build().getPath());
}
public void addQueryParam(String name, String... values) {
setEndpoint(processor.addQueryParam(getEndpoint(), name, values));
}
public void replaceQuery(String query, @Nullable Comparator<Entry<String, String>> sorter) {
setEndpoint(processor.replaceQuery(getEndpoint(), query, sorter));
}
public void replacePath(String path) {
UriBuilder builder = uriBuilderProvider.get().uri(getEndpoint());
builder.replacePath(path);
setEndpoint(builder.build());
}
public void addFormParam(String name, String... values) {
this
.setPayload(processor.addFormParam(getPayload().getRawContent().toString(), name,
values));
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + Arrays.hashCode(args);
result = prime * result + ((declaring == null) ? 0 : declaring.hashCode());
result = prime * result + ((javaMethod == null) ? 0 : javaMethod.hashCode());
result = prime * result + ((processor == null) ? 0 : processor.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
GeneratedHttpRequest<?> other = (GeneratedHttpRequest<?>) obj;
if (!Arrays.equals(args, other.args))
return false;
if (declaring == null) {
if (other.declaring != null)
return false;
} else if (!declaring.equals(other.declaring))
return false;
if (javaMethod == null) {
if (other.javaMethod != null)
return false;
} else if (!javaMethod.equals(other.javaMethod))
return false;
if (processor == null) {
if (other.processor != null)
return false;
} else if (!processor.equals(other.processor))
return false;
return true;
}
}

View File

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

View File

@ -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<UriBuilder> uriBuilderProvider = new Provider<UriBuilder>() {
@Override
public UriBuilder get() {
return new UriBuilderImpl();
}
};
@SuppressWarnings("unchecked")
@Test
public void testChangeSchemeHostAndPortTo() {
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
TransformingHttpCommandImpl<?> command = new TransformingHttpCommandImpl(uriBuilderProvider,
null, request, null);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/mypath"));
request.setEndpoint(URI.create("https://remotehost:443/mypath"));
Multimap<String, String> headers = HashMultimap.create();
expect(request.getHeaders()).andReturn(headers);
replay(request);
command.changeSchemeHostAndPortTo("https", "remotehost", 443);
assertEquals(headers.get(HttpHeaders.HOST), Collections.singletonList("remotehost"));
}
@Test
public void testTransformingHttpCommandImpl() {

View File

@ -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<String>(uriBuilderProvider, executorService, processor
.createRequest(method, "1"), new ReturnStringIf200());
return new TransformingHttpCommandImpl<String>(executorService, processor.createRequest(
method, "1"), new ReturnStringIf200());
}
@Test

View File

@ -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<T> {
protected Injector injector;
protected abstract void checkFilters(GeneratedHttpRequest<T> httpMethod);
protected abstract void checkFilters(HttpRequest request);
protected abstract TypeLiteral<RestAnnotationProcessor<T>> createTypeLiteral();
@ -101,22 +101,21 @@ public abstract class RestClientTest<T> {
}
}
protected void assertPayloadEquals(GeneratedHttpRequest<T> 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<T> 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<T> 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<T> {
}
protected void assertResponseParserClassEquals(Method method,
GeneratedHttpRequest<T> httpMethod, @Nullable Class<?> parserClass) {
assertEquals(processor.createResponseParser(method, httpMethod).getClass(), parserClass);
HttpRequest request, @Nullable Class<?> parserClass) {
assertEquals(processor.createResponseParser(method, request).getClass(), parserClass);
}
}

View File

@ -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<UriBuilder>() {
@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);
}

View File

@ -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<String, String> 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<String, String> 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<Object, String> {
@ -1181,31 +1179,6 @@ public class RestAnnotationProcessorTest {
assertEquals(query, "x-amz-copy-source=/robot");
}
@Test
public void testParseQueryToMapSingleParam() {
Multimap<String, String> parsedMap = RestAnnotationProcessor.parseQueryToMap("v=1.3");
assert parsedMap.keySet().size() == 1 : "Expected 1 key, found: " + parsedMap.keySet().size();
assert parsedMap.keySet().contains("v") : "Expected v to be a part of the keys";
String valueForV = Iterables.getOnlyElement(parsedMap.get("v"));
assert valueForV.equals("1.3") : "Expected the value for 'v' to be '1.3', found: "
+ valueForV;
}
@Test
public void testParseQueryToMapMultiParam() {
Multimap<String, String> parsedMap = RestAnnotationProcessor.parseQueryToMap("v=1.3&sig=123");
assert parsedMap.keySet().size() == 2 : "Expected 2 keys, found: "
+ parsedMap.keySet().size();
assert parsedMap.keySet().contains("v") : "Expected v to be a part of the keys";
assert parsedMap.keySet().contains("sig") : "Expected sig to be a part of the keys";
String valueForV = Iterables.getOnlyElement(parsedMap.get("v"));
assert valueForV.equals("1.3") : "Expected the value for 'v' to be '1.3', found: "
+ valueForV;
String valueForSig = Iterables.getOnlyElement(parsedMap.get("sig"));
assert valueForSig.equals("123") : "Expected the value for 'v' to be '123', found: "
+ valueForSig;
}
private interface TestMapMatrixParams {
@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<TestMapMatrixParams> 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<String, String> expects = LinkedListMultimap.create();
expects.put("Version", "2009-11-30");
expects.put("Action", "ModifyInstanceAttribute");
expects.put("Attribute", "userData");
expects.put("Value", "dGVzdA==");
expects.put("InstanceId", "1");
assertEquals(
expects,
RestAnnotationProcessor
.parseQueryToMap("Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=userData&Value=dGVzdA%3D%3D&InstanceId=1"));
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<TestTransformers> processor = factory(TestTransformers.class);
Method method = TestTransformers.class.getMethod("oneTransformerWithContext");
GeneratedHttpRequest<TestTransformers> request = new GeneratedHttpRequest<TestTransformers>(
uriBuilderProvider, "GET", URI.create("http://localhost"), processor,
TestTransformers.class, method);
"GET", URI.create("http://localhost"), TestTransformers.class, method);
Function<HttpResponse, ?> 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<TestPayload> processor = factory(TestPayload.class);
Method method = TestPayload.class.getMethod("put", String.class);
GeneratedHttpRequest<TestPayload> request = new GeneratedHttpRequest<TestPayload>(
uriBuilderProvider, "GET", URI.create("http://localhost"), processor,
TestPayload.class, method, "test");
GeneratedHttpRequest<TestPayload> request = new GeneratedHttpRequest<TestPayload>("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<TestPayload> processor = factory(TestPayload.class);
Method method = TestPayload.class.getMethod("putWithPath", String.class, String.class);
GeneratedHttpRequest<TestPayload> request = new GeneratedHttpRequest<TestPayload>(
uriBuilderProvider, "GET", URI.create("http://localhost"), processor,
TestPayload.class, method, "rabble", "test");
GeneratedHttpRequest<TestPayload> request = new GeneratedHttpRequest<TestPayload>("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);
}
}

View File

@ -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<UriBuilder> uriBuilderProvider = new Provider<UriBuilder>() {
@Override
public UriBuilder get() {
return new UriBuilderImpl();
}
};
public void testParseBase64InForm() {
Multimap<String, String> expects = LinkedListMultimap.create();
expects.put("Version", "2009-11-30");
expects.put("Action", "ModifyInstanceAttribute");
expects.put("Attribute", "userData");
expects.put("Value", "dGVzdA==");
expects.put("InstanceId", "1");
assertEquals(
expects,
parseQueryToMap("Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=userData&Value=dGVzdA%3D%3D&InstanceId=1"));
}
@Test
public void testParseQueryToMapSingleParam() {
Multimap<String, String> parsedMap = parseQueryToMap("v=1.3");
assert parsedMap.keySet().size() == 1 : "Expected 1 key, found: " + parsedMap.keySet().size();
assert parsedMap.keySet().contains("v") : "Expected v to be a part of the keys";
String valueForV = Iterables.getOnlyElement(parsedMap.get("v"));
assert valueForV.equals("1.3") : "Expected the value for 'v' to be '1.3', found: "
+ valueForV;
}
@Test
public void testParseQueryToMapMultiParam() {
Multimap<String, String> parsedMap = parseQueryToMap("v=1.3&sig=123");
assert parsedMap.keySet().size() == 2 : "Expected 2 keys, found: "
+ parsedMap.keySet().size();
assert parsedMap.keySet().contains("v") : "Expected v to be a part of the keys";
assert parsedMap.keySet().contains("sig") : "Expected sig to be a part of the keys";
String valueForV = Iterables.getOnlyElement(parsedMap.get("v"));
assert valueForV.equals("1.3") : "Expected the value for 'v' to be '1.3', found: "
+ valueForV;
String valueForSig = Iterables.getOnlyElement(parsedMap.get("sig"));
assert valueForSig.equals("123") : "Expected the value for 'v' to be '123', found: "
+ valueForSig;
}
@Test
public void testChangeSchemeHostAndPortTo() {
HttpRequest request = createMock(HttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/mypath"));
request.setEndpoint(URI.create("https://remotehost:443/mypath"));
Multimap<String, String> headers = HashMultimap.create();
expect(request.getHeaders()).andReturn(headers);
replay(request);
changeSchemeHostAndPortTo(request, "https", "remotehost", 443, uriBuilderProvider.get());
assertEquals(headers.get(HttpHeaders.HOST), Collections.singletonList("remotehost"));
}
public void testIsEncoded() {
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");

View File

@ -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<UriBuilder> builder;
@Inject
BindIdsToQueryParams(Provider<UriBuilder> builder) {
this.builder = builder;
}
/**
* Binds the ids to query parameters. The pattern, as specified by GoGrid's specification, is:
@ -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());
}
}
}

View File

@ -26,10 +26,16 @@ package org.jclouds.gogrid.binders;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.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<UriBuilder> builder;
@Inject
BindNamesToQueryParams(Provider<UriBuilder> builder) {
this.builder = builder;
}
/**
* Binds the names to query parameters. The pattern, as specified by GoGrid's specification, is:
@ -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());
}
}

View File

@ -21,10 +21,14 @@ package org.jclouds.gogrid.binders;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.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<UriBuilder> builder;
@Inject
BindObjectNameToGetJobsRequestQueryParams(Provider<UriBuilder> builder) {
this.builder = builder;
}
/**
* Maps the object's name to the input of <a
@ -40,15 +50,11 @@ public class BindObjectNameToGetJobsRequestQueryParams 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 serverName = (String) input;
GeneratedHttpRequest<?> generatedRequest = (GeneratedHttpRequest<?>) request;
generatedRequest.addQueryParam(OBJECT_KEY, serverName);
addQueryParamTo(request, OBJECT_KEY, serverName, builder.get());
}
}

View File

@ -22,13 +22,17 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.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<UriBuilder> builder;
@Inject
BindRealIpPortPairsToQueryParams(Provider<UriBuilder> 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<IpPortPair> ipPortPairs = (List<IpPortPair>) 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++;
}
}

View File

@ -22,11 +22,15 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.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<UriBuilder> builder;
@Inject
BindVirtualIpPortPairToQueryParams(Provider<UriBuilder> 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());
}
}

View File

@ -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<String, String> decodedParams = RestAnnotationProcessor.parseQueryToMap(query);
Multimap<String, String> 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() {

View File

@ -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<UriBuilder>() {
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<UriBuilder>() {
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");
}
}

View File

@ -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<UriBuilder>() {
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");
}
}

View File

@ -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;

View File

@ -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<T> extends RestClientTest<T> {
@Override
protected void checkFilters(GeneratedHttpRequest<T> 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

View File

@ -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<IBMDevelope
}
@Override
protected void checkFilters(GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> 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

View File

@ -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<PCSAsyncClient> {
public void testList() throws SecurityException, NoSuchMethodException, IOException {
Method method = PCSAsyncClient.class.getMethod("list");
GeneratedHttpRequest<PCSAsyncClient> 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<PCSAsyncClient> 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><name>container</name></container>");
assertPayloadEquals(request, "<container><name>container</name></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<PCSAsyncClient> 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<PCSAsyncClient> {
public void testListURI() throws SecurityException, NoSuchMethodException {
Method method = PCSAsyncClient.class.getMethod("list", URI.class);
GeneratedHttpRequest<PCSAsyncClient> 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<PCSAsyncClient> {
public void testGetFileInfo() throws SecurityException, NoSuchMethodException {
Method method = PCSAsyncClient.class.getMethod("getFileInfo", URI.class);
GeneratedHttpRequest<PCSAsyncClient> 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<PCSAsyncClient> {
public void testUploadFile() throws SecurityException, NoSuchMethodException, IOException {
Method method = PCSAsyncClient.class.getMethod("uploadFile", URI.class, PCSFile.class);
GeneratedHttpRequest<PCSAsyncClient> 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<PCSAsyncClient> 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<PCSAsyncClient> 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<PCSAsyncClient> 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<PCSAsyncClient> {
public void testPutMetadata() throws SecurityException, NoSuchMethodException {
Method method = PCSAsyncClient.class.getMethod("putMetadataItem", URI.class, String.class,
String.class);
GeneratedHttpRequest<PCSAsyncClient> 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<PCSAsyncClient> {
Method method = PCSAsyncClient.class.getMethod("addMetadataItemToMap", URI.class,
String.class, Map.class);
GeneratedHttpRequest<PCSAsyncClient> 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<PCSAsyncClient> 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<PCSAsyncClient> {
}
@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<PCSAsyncClient> {
@Override
public ContextSpec<PCSClient, PCSAsyncClient> 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);
}
}

View File

@ -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<PCSCloudAsyncClient> {
public void testAuthenticate() throws SecurityException, NoSuchMethodException {
Method method = PCSCloudAsyncClient.class.getMethod("authenticate");
GeneratedHttpRequest<PCSCloudAsyncClient> 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<PCSCloudAsyncClient> {
}
@Override
protected void checkFilters(GeneratedHttpRequest<PCSCloudAsyncClient> httpMethod) {
protected void checkFilters(HttpRequest request) {
}

View File

@ -20,23 +20,33 @@ package org.jclouds.nirvanix.sdn.binders;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.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<UriBuilder> builder;
@Inject
BindMetadataToQueryParams(Provider<UriBuilder> 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<String, String> userMetadata = (Map<String, String>) input;
@ -44,6 +54,6 @@ public class BindMetadataToQueryParams implements Binder {
for (Entry<String, String> 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());
}
}

View File

@ -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<String> authTokenProvider;
private final Provider<UriBuilder> 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<String> authTokenProvider) {
public AddSessionTokenToRequest(@SessionToken Provider<String> authTokenProvider,
Provider<UriBuilder> builder) {
this.builder = builder;
this.authTokenProvider = authTokenProvider;
authToken = new AtomicReference<String>();
}
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());
}
}

View File

@ -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<UriBuilder> 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<UriBuilder> 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());
}
}

View File

@ -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<SDNAsyncClient> {
public void testGetStorageNode() throws SecurityException, NoSuchMethodException, IOException {
Method method = SDNAsyncClient.class.getMethod("getStorageNode", String.class, long.class);
GeneratedHttpRequest<SDNAsyncClient> 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<SDNAsyncClient> {
Method method = SDNAsyncClient.class.getMethod("upload", URI.class, String.class,
String.class, Blob.class);
Blob blob = BindBlobToMultipartFormTest.TEST_BLOB;
GeneratedHttpRequest<SDNAsyncClient> 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<SDNAsyncClient> {
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<SDNAsyncClient> 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<SDNAsyncClient> 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<SDNAsyncClient> 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<SDNAsyncClient> 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

View File

@ -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<SDNAuthAsyncClient> {
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<SDNAuthAsyncClient> httpMethod) {
protected void checkFilters(HttpRequest request) {
}

View File

@ -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<UriBuilder>() {
@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);
}

View File

@ -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<OpscodePlatfo
}
@Override
protected void checkFilters(GeneratedHttpRequest<OpscodePlatformAsyncClient> 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

View File

@ -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<Date> dateProvider;
private final Provider<UriBuilder> builder;
@Inject
public AddTimestampQuery(@TimeStamp Supplier<Date> dateProvider) {
public AddTimestampQuery(@TimeStamp Supplier<Date> dateProvider, Provider<UriBuilder> 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());
}
}

View File

@ -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<RackspaceAuthAs
public void testAuthenticate() throws SecurityException, NoSuchMethodException {
Method method = RackspaceAuthAsyncClient.class.getMethod("authenticate", String.class,
String.class);
HttpRequest httpMethod = processor.createRequest(method, "foo", "bar");
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/auth");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 2);
assertEquals(httpMethod.getHeaders().get(RackspaceHeaders.AUTH_USER), Collections
HttpRequest request = processor.createRequest(method, "foo", "bar");
assertEquals(request.getEndpoint().getHost(), "localhost");
assertEquals(request.getEndpoint().getPath(), "/auth");
assertEquals(request.getMethod(), HttpMethod.GET);
assertEquals(request.getHeaders().size(), 2);
assertEquals(request.getHeaders().get(RackspaceHeaders.AUTH_USER), Collections
.singletonList("foo"));
assertEquals(httpMethod.getHeaders().get(RackspaceHeaders.AUTH_KEY), Collections
assertEquals(request.getHeaders().get(RackspaceHeaders.AUTH_KEY), Collections
.singletonList("bar"));
assertEquals(RestAnnotationProcessor.getParserOrThrowException(method),
ParseAuthenticationResponseFromHeaders.class);
@ -70,7 +69,7 @@ public class RackspaceAuthAsyncClientTest extends RestClientTest<RackspaceAuthAs
}
@Override
protected void checkFilters(GeneratedHttpRequest<RackspaceAuthAsyncClient> httpMethod) {
protected void checkFilters(HttpRequest request) {
}
@Override

View File

@ -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<UriBuilder>() {
@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()));
}
}

View File

@ -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<TwitterAsyncClient> {
public void testGetMyMentions() throws SecurityException, NoSuchMethodException, IOException {
Method method = TwitterAsyncClient.class.getMethod("getMyMentions");
GeneratedHttpRequest<TwitterAsyncClient> httpMethod = processor.createRequest(method);
HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(httpMethod, "GET http://twitter.com/statuses/mentions.json HTTP/1.1");
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<TwitterAsyncClient> 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

View File

@ -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<VCloudAsyncClient> {
Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC",
String.class, String.class, String.class, Array.newInstance(
InstantiateVAppTemplateOptions.class, 0).getClass());
GeneratedHttpRequest<VCloudAsyncClient> 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<VCloudAsyncClient> {
Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC",
String.class, String.class, String.class, Array.newInstance(
InstantiateVAppTemplateOptions.class, 0).getClass());
GeneratedHttpRequest<VCloudAsyncClient> 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<VCloudAsyncClient> {
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<VCloudAsyncClient> 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<VCloudAsyncClient> 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<VCloudAsyncClient> {
public void testDefaultOrganization() throws SecurityException, NoSuchMethodException,
IOException {
Method method = VCloudAsyncClient.class.getMethod("getDefaultOrganization");
GeneratedHttpRequest<VCloudAsyncClient> 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<VCloudAsyncClient> httpMethod = processor.createRequest(method, "1");
HttpRequest request = processor.createRequest(method, "1");
assertRequestLineEquals(httpMethod,
assertRequestLineEquals(request,
"GET https://vcloud.safesecureweb.com/api/v0.8/org/1 HTTP/1.1");
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<VCloudAsyncClient> httpMethod = processor.createRequest(method);
HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(httpMethod,
assertRequestLineEquals(request,
"GET https://vcloud.safesecureweb.com/api/v0.8/catalog HTTP/1.1");
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<VCloudAsyncClient> httpMethod = processor.createRequest(method, "1");
HttpRequest request = processor.createRequest(method, "1");
assertRequestLineEquals(httpMethod,
assertRequestLineEquals(request,
"GET https://vcloud.safesecureweb.com/api/v0.8/catalog/1 HTTP/1.1");
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<VCloudAsyncClient> httpMethod = processor.createRequest(method, "2");
HttpRequest request = processor.createRequest(method, "2");
assertRequestLineEquals(httpMethod,
assertRequestLineEquals(request,
"GET https://vcloud.safesecureweb.com/api/v0.8/network/2 HTTP/1.1");
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<VCloudAsyncClient> httpMethod = processor.createRequest(method, "2");
HttpRequest request = processor.createRequest(method, "2");
assertRequestLineEquals(httpMethod,
assertRequestLineEquals(request,
"GET https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2 HTTP/1.1");
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<VCloudAsyncClient> httpMethod = processor.createRequest(method, "2");
HttpRequest request = processor.createRequest(method, "2");
assertRequestLineEquals(httpMethod,
assertRequestLineEquals(request,
"GET https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/2 HTTP/1.1");
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<VCloudAsyncClient> httpMethod = processor.createRequest(method);
HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(httpMethod,
assertRequestLineEquals(request,
"GET https://vcloud.safesecureweb.com/api/v0.8/vdc/1 HTTP/1.1");
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<VCloudAsyncClient> httpMethod = processor.createRequest(method, "1");
HttpRequest request = processor.createRequest(method, "1");
assertRequestLineEquals(httpMethod,
assertRequestLineEquals(request,
"GET https://vcloud.safesecureweb.com/api/v0.8/vdc/1 HTTP/1.1");
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<VCloudAsyncClient> httpMethod = processor.createRequest(method);
HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(httpMethod,
assertRequestLineEquals(request,
"GET https://vcloud.safesecureweb.com/api/v0.8/taskslist HTTP/1.1");
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<VCloudAsyncClient> httpMethod = processor.createRequest(method, "1");
HttpRequest request = processor.createRequest(method, "1");
assertRequestLineEquals(httpMethod,
assertRequestLineEquals(request,
"GET https://vcloud.safesecureweb.com/api/v0.8/tasksList/1 HTTP/1.1");
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<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
HttpRequest request = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod,
assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/action/deploy HTTP/1.1");
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<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
HttpRequest request = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod,
assertRequestLineEquals(request,
"GET https://vcloud.safesecureweb.com/api/v0.8/vApp/1 HTTP/1.1");
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<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
HttpRequest request = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod,
assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/action/undeploy HTTP/1.1");
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<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
HttpRequest request = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod,
assertRequestLineEquals(request,
"DELETE https://vcloud.safesecureweb.com/api/v0.8/vApp/1 HTTP/1.1");
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<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
HttpRequest request = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod,
assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/power/action/powerOn HTTP/1.1");
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<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
HttpRequest request = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod,
assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/power/action/powerOff HTTP/1.1");
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<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
HttpRequest request = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod,
assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/power/action/reset HTTP/1.1");
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<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
HttpRequest request = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod,
assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/power/action/suspend HTTP/1.1");
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<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
HttpRequest request = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod,
assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/power/action/shutdown HTTP/1.1");
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<VCloudAsyncClient> httpMethod = processor.createRequest(method, "1");
HttpRequest request = processor.createRequest(method, "1");
assertRequestLineEquals(httpMethod,
assertRequestLineEquals(request,
"GET https://vcloud.safesecureweb.com/api/v0.8/task/1 HTTP/1.1");
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<VCloudAsyncClient> httpMethod = processor.createRequest(method, "1");
HttpRequest request = processor.createRequest(method, "1");
assertRequestLineEquals(httpMethod,
assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/task/1/action/cancel HTTP/1.1");
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<VCloudAsyncClient> 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

View File

@ -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<VCloudLoginAsyncClient> {
public void testLogin() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudLoginAsyncClient.class.getMethod("login");
GeneratedHttpRequest<VCloudLoginAsyncClient> httpMethod = processor.createRequest(method);
HttpRequest request = processor.createRequest(method);
assertEquals(httpMethod.getRequestLine(), "POST http://localhost:8080/login HTTP/1.1");
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<VCloudLoginAsyncClient> 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

View File

@ -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<VCloudVersionsAsyncClient
public void testVersions() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudVersionsAsyncClient.class.getMethod("getSupportedVersions");
GeneratedHttpRequest<VCloudVersionsAsyncClient> httpMethod = processor.createRequest(method);
HttpRequest request = processor.createRequest(method);
assertEquals(httpMethod.getRequestLine(), "GET http://localhost:8080/versions HTTP/1.1");
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<VCloudVersionsAsyncClient> httpMethod) {
assertEquals(httpMethod.getFilters().size(), 0);
protected void checkFilters(HttpRequest request) {
assertEquals(request.getFilters().size(), 0);
}
@Override

View File

@ -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<HostingDotComVCloudAsyncClient> {
public void testCatalog() throws SecurityException, NoSuchMethodException, IOException {
Method method = HostingDotComVCloudAsyncClient.class.getMethod("getDefaultCatalog");
GeneratedHttpRequest<HostingDotComVCloudAsyncClient> 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<HostingDotComVCloudAsyncClient> 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<RestAnnotationProcessor<HostingDotComVCloudAsyncClient>>() {
};
}
@Override
protected Module createModule() {
return new HostingDotComVCloudRestClientModuleExtension();

View File

@ -20,7 +20,6 @@ package org.jclouds.vcloud.terremark.binders;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.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);
}

View File

@ -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<TerremarkVClo
*/
public void testCatalog() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("getCatalog", String.class);
GeneratedHttpRequest<TerremarkVCloudAsyncClient> 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<TerremarkVCloudAsyncClient> 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<TerremarkVCloudAsyncClient> 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<TerremarkVClo
Method method = TerremarkVCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC",
String.class, String.class, String.class, Array.newInstance(
InstantiateVAppTemplateOptions.class, 0).getClass());
GeneratedHttpRequest<TerremarkVCloudAsyncClient> 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<TerremarkVClo
Method method = TerremarkVCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC",
String.class, String.class, String.class, Array.newInstance(
InstantiateVAppTemplateOptions.class, 0).getClass());
GeneratedHttpRequest<TerremarkVCloudAsyncClient> 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<TerremarkVClo
Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetServiceToVDC",
String.class, String.class, Protocol.class, int.class, Array.newInstance(
AddInternetServiceOptions.class, 0).getClass());
GeneratedHttpRequest<TerremarkVCloudAsyncClient> 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<TerremarkVClo
Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetServiceToVDC",
String.class, String.class, Protocol.class, int.class, Array.newInstance(
AddInternetServiceOptions.class, 0).getClass());
GeneratedHttpRequest<TerremarkVCloudAsyncClient> 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<TerremarkVCloudAsyncClient> 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<TerremarkVCloudAsyncClient> 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<TerremarkVCloudAsyncClient> 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<TerremarkVClo
Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetServiceToExistingIp",
int.class, String.class, Protocol.class, int.class, Array.newInstance(
AddInternetServiceOptions.class, 0).getClass());
GeneratedHttpRequest<TerremarkVCloudAsyncClient> 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<TerremarkVClo
Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetServiceToExistingIp",
int.class, String.class, Protocol.class, int.class, Array.newInstance(
AddInternetServiceOptions.class, 0).getClass());
GeneratedHttpRequest<TerremarkVCloudAsyncClient> 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<TerremarkVCloudAsyncClient> 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<TerremarkVCloudAsyncClient> 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<TerremarkVCloudAsyncClient> 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<TerremarkVCloudAsyncClient> 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,
"<NodeService xmlns=\"urn:tmrk:vCloudExpressExtensions-1.6\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><Description>eggs</Description></NodeService>");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, NodeHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod);
checkFilters(request);
}
public void testGetNodes() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("getNodes", int.class);
GeneratedHttpRequest<TerremarkVCloudAsyncClient> 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<TerremarkVCloudAsyncClient> 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<TerremarkVCloudAsyncClient> 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<TerremarkVCloudAsyncClient> 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<TerremarkVCloudAsyncClient> 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<TerremarkVCloudAsyncClient> 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<TerremarkVClo
// NoSuchMethodException, IOException {
// Method method = TerremarkVCloudAsyncClient.class.getMethod(
// "configureKeyPair", int.class, KeyPairConfiguration.class);
// GeneratedHttpRequest<TerremarkVCloudAsyncClient> 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,
// "<KeyPairService xmlns=\"urn:tmrk:vCloudExpressExtensions-1.6\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><Description>eggs</Description></KeyPairService>");
// assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
// assertResponseParserClassEquals(method, request, ParseSax.class);
// assertSaxResponseParserClassEquals(method, KeyPairHandler.class);
// assertExceptionParserClassEquals(method, null);
//
// checkFilters(httpMethod);
// checkFilters(request);
// }
public void testDeleteKeyPair() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("deleteKeyPair", int.class);
GeneratedHttpRequest<TerremarkVCloudAsyncClient> 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<TerremarkVCloudAsyncClient> 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

View File

@ -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<String, String> headers = Multimaps.synchronizedMultimap(HashMultimap
.<String, String> 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();