mirror of https://github.com/apache/jclouds.git
Issue 315: added auto-deserialization of json into java objects and new @Unwrap annotation; Issue 311: fixed template parsing for new cluster instance in ec2; Issue 191: started adding node support to chef
This commit is contained in:
parent
328679799b
commit
1d0949dec5
|
@ -70,17 +70,15 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
|
|||
private BlobToObject blobToObject;
|
||||
|
||||
public void testListDirectories() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AtmosStorageAsyncClient.class.getMethod("listDirectories", Array.newInstance(
|
||||
ListOptions.class, 0).getClass());
|
||||
Method method = AtmosStorageAsyncClient.class.getMethod("listDirectories", Array
|
||||
.newInstance(ListOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://accesspoint.atmosonline.com/rest/namespace HTTP/1.1");
|
||||
assertRequestLineEquals(request, "GET https://accesspoint.atmosonline.com/rest/namespace HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, HttpHeaders.ACCEPT + ": text/xml\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request,
|
||||
ParseDirectoryListFromContentAndHeaders.class);
|
||||
assertResponseParserClassEquals(method, request, ParseDirectoryListFromContentAndHeaders.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -88,59 +86,47 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
|
|||
}
|
||||
|
||||
public void testListDirectory() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AtmosStorageAsyncClient.class.getMethod("listDirectory", String.class, Array
|
||||
.newInstance(ListOptions.class, 0).getClass());
|
||||
Method method = AtmosStorageAsyncClient.class.getMethod("listDirectory", String.class, Array.newInstance(
|
||||
ListOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, "directory");
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://accesspoint.atmosonline.com/rest/namespace/directory/ HTTP/1.1");
|
||||
assertRequestLineEquals(request, "GET https://accesspoint.atmosonline.com/rest/namespace/directory/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, HttpHeaders.ACCEPT + ": text/xml\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request,
|
||||
ParseDirectoryListFromContentAndHeaders.class);
|
||||
assertResponseParserClassEquals(method, request, ParseDirectoryListFromContentAndHeaders.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ThrowContainerNotFoundOn404.class);
|
||||
|
||||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testListDirectoriesOptions() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = AtmosStorageAsyncClient.class.getMethod("listDirectories", Array.newInstance(
|
||||
ListOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, new ListOptions().limit(1)
|
||||
.token("asda"));
|
||||
public void testListDirectoriesOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AtmosStorageAsyncClient.class.getMethod("listDirectories", Array
|
||||
.newInstance(ListOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, new ListOptions().limit(1).token("asda"));
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://accesspoint.atmosonline.com/rest/namespace HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, HttpHeaders.ACCEPT
|
||||
+ ": text/xml\nx-emc-limit: 1\nx-emc-token: asda\n");
|
||||
assertRequestLineEquals(request, "GET https://accesspoint.atmosonline.com/rest/namespace HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, HttpHeaders.ACCEPT + ": text/xml\nx-emc-limit: 1\nx-emc-token: asda\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request,
|
||||
ParseDirectoryListFromContentAndHeaders.class);
|
||||
assertResponseParserClassEquals(method, request, ParseDirectoryListFromContentAndHeaders.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testListDirectoryOptions() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = AtmosStorageAsyncClient.class.getMethod("listDirectory", String.class, Array
|
||||
.newInstance(ListOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, "directory", new ListOptions().limit(1)
|
||||
.token("asda"));
|
||||
public void testListDirectoryOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AtmosStorageAsyncClient.class.getMethod("listDirectory", String.class, Array.newInstance(
|
||||
ListOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, "directory", new ListOptions().limit(1).token("asda"));
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://accesspoint.atmosonline.com/rest/namespace/directory/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, HttpHeaders.ACCEPT
|
||||
+ ": text/xml\nx-emc-limit: 1\nx-emc-token: asda\n");
|
||||
assertRequestLineEquals(request, "GET https://accesspoint.atmosonline.com/rest/namespace/directory/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, HttpHeaders.ACCEPT + ": text/xml\nx-emc-limit: 1\nx-emc-token: asda\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request,
|
||||
ParseDirectoryListFromContentAndHeaders.class);
|
||||
assertResponseParserClassEquals(method, request, ParseDirectoryListFromContentAndHeaders.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ThrowContainerNotFoundOn404.class);
|
||||
|
||||
|
@ -151,8 +137,7 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
|
|||
Method method = AtmosStorageAsyncClient.class.getMethod("createDirectory", String.class);
|
||||
HttpRequest request = processor.createRequest(method, "dir");
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"POST https://accesspoint.atmosonline.com/rest/namespace/dir/ HTTP/1.1");
|
||||
assertRequestLineEquals(request, "POST https://accesspoint.atmosonline.com/rest/namespace/dir/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, HttpHeaders.ACCEPT + ": */*\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -164,15 +149,12 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
|
|||
}
|
||||
|
||||
public void testCreateFile() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AtmosStorageAsyncClient.class.getMethod("createFile", String.class,
|
||||
AtmosObject.class);
|
||||
Method method = AtmosStorageAsyncClient.class.getMethod("createFile", String.class, AtmosObject.class);
|
||||
HttpRequest request = processor.createRequest(method, "dir", blobToObject
|
||||
.apply(BindBlobToMultipartFormTest.TEST_BLOB));
|
||||
.apply(BindBlobToMultipartFormTest.TEST_BLOB));
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"POST https://accesspoint.atmosonline.com/rest/namespace/dir/hello HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, HttpHeaders.ACCEPT
|
||||
+ ": */*\n");
|
||||
assertRequestLineEquals(request, "POST https://accesspoint.atmosonline.com/rest/namespace/dir/hello HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, HttpHeaders.ACCEPT + ": */*\n");
|
||||
assertPayloadEquals(request, "hello", "text/plain", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseURIFromListOrLocationHeaderIf20x.class);
|
||||
|
@ -183,15 +165,12 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
|
|||
}
|
||||
|
||||
public void testUpdateFile() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AtmosStorageAsyncClient.class.getMethod("updateFile", String.class,
|
||||
AtmosObject.class);
|
||||
Method method = AtmosStorageAsyncClient.class.getMethod("updateFile", String.class, AtmosObject.class);
|
||||
HttpRequest request = processor.createRequest(method, "dir", blobToObject
|
||||
.apply(BindBlobToMultipartFormTest.TEST_BLOB));
|
||||
.apply(BindBlobToMultipartFormTest.TEST_BLOB));
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"PUT https://accesspoint.atmosonline.com/rest/namespace/dir/hello HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, HttpHeaders.ACCEPT
|
||||
+ ": */*\n");
|
||||
assertRequestLineEquals(request, "PUT https://accesspoint.atmosonline.com/rest/namespace/dir/hello HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, HttpHeaders.ACCEPT + ": */*\n");
|
||||
assertPayloadEquals(request, "hello", "text/plain", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
|
@ -202,12 +181,11 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
|
|||
}
|
||||
|
||||
public void testReadFile() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AtmosStorageAsyncClient.class.getMethod("readFile", String.class, Array
|
||||
.newInstance(GetOptions.class, 0).getClass());
|
||||
Method method = AtmosStorageAsyncClient.class.getMethod("readFile", String.class, Array.newInstance(
|
||||
GetOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, "dir/file");
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://accesspoint.atmosonline.com/rest/namespace/dir/file HTTP/1.1");
|
||||
assertRequestLineEquals(request, "GET https://accesspoint.atmosonline.com/rest/namespace/dir/file HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, HttpHeaders.ACCEPT + ": */*\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -222,8 +200,7 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
|
|||
Method method = AtmosStorageAsyncClient.class.getMethod("getSystemMetadata", String.class);
|
||||
HttpRequest request = processor.createRequest(method, "dir/file");
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"HEAD https://accesspoint.atmosonline.com/rest/namespace/dir/file HTTP/1.1");
|
||||
assertRequestLineEquals(request, "HEAD https://accesspoint.atmosonline.com/rest/namespace/dir/file HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, HttpHeaders.ACCEPT + ": */*\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -238,8 +215,7 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
|
|||
Method method = AtmosStorageAsyncClient.class.getMethod("deletePath", String.class);
|
||||
HttpRequest request = processor.createRequest(method, "dir/file");
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"DELETE https://accesspoint.atmosonline.com/rest/namespace/dir/file HTTP/1.1");
|
||||
assertRequestLineEquals(request, "DELETE https://accesspoint.atmosonline.com/rest/namespace/dir/file HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, HttpHeaders.ACCEPT + ": */*\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -295,8 +271,7 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
|
|||
|
||||
@Override
|
||||
public ContextSpec<?, ?> createContextSpec() {
|
||||
return new RestContextFactory().createContextSpec("atmosonline", "identity", "credential",
|
||||
new Properties());
|
||||
return new RestContextFactory().createContextSpec("atmosonline", "identity", "credential", new Properties());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -130,39 +130,31 @@ public class EC2ComputeServiceContextModule extends AbstractModule {
|
|||
@Singleton
|
||||
@Named("PRESENT")
|
||||
protected Predicate<RunningInstance> instancePresent(InstancePresent present) {
|
||||
return new RetryablePredicate<RunningInstance>(present, 3000, 200,
|
||||
TimeUnit.MILLISECONDS);
|
||||
return new RetryablePredicate<RunningInstance>(present, 3000, 200, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
install(new ComputeServiceTimeoutsModule());
|
||||
bind(Location.class).toProvider(DefaultLocationProvider.class).in(
|
||||
Scopes.SINGLETON);
|
||||
bind(Location.class).toProvider(DefaultLocationProvider.class).in(Scopes.SINGLETON);
|
||||
bind(TemplateBuilder.class).to(EC2TemplateBuilderImpl.class);
|
||||
bind(TemplateOptions.class).to(EC2TemplateOptions.class);
|
||||
bind(ComputeService.class).to(EC2ComputeService.class);
|
||||
bind(new TypeLiteral<ComputeServiceContext>() {
|
||||
})
|
||||
.to(
|
||||
new TypeLiteral<ComputeServiceContextImpl<EC2Client, EC2AsyncClient>>() {
|
||||
}).in(Scopes.SINGLETON);
|
||||
}).to(new TypeLiteral<ComputeServiceContextImpl<EC2Client, EC2AsyncClient>>() {
|
||||
}).in(Scopes.SINGLETON);
|
||||
bind(new TypeLiteral<RestContext<EC2Client, EC2AsyncClient>>() {
|
||||
}).to(new TypeLiteral<RestContextImpl<EC2Client, EC2AsyncClient>>() {
|
||||
}).in(Scopes.SINGLETON);
|
||||
bind(LoadBalanceNodesStrategy.class)
|
||||
.to(EC2LoadBalanceNodesStrategy.class);
|
||||
bind(DestroyLoadBalancerStrategy.class).to(
|
||||
EC2DestroyLoadBalancerStrategy.class);
|
||||
bind(RunNodesAndAddToSetStrategy.class).to(
|
||||
EC2RunNodesAndAddToSetStrategy.class);
|
||||
bind(LoadBalanceNodesStrategy.class).to(EC2LoadBalanceNodesStrategy.class);
|
||||
bind(DestroyLoadBalancerStrategy.class).to(EC2DestroyLoadBalancerStrategy.class);
|
||||
bind(RunNodesAndAddToSetStrategy.class).to(EC2RunNodesAndAddToSetStrategy.class);
|
||||
bind(ListNodesStrategy.class).to(EC2ListNodesStrategy.class);
|
||||
bind(GetNodeMetadataStrategy.class).to(EC2GetNodeMetadataStrategy.class);
|
||||
bind(RebootNodeStrategy.class).to(EC2RebootNodeStrategy.class);
|
||||
bind(DestroyNodeStrategy.class).to(EC2DestroyNodeStrategy.class);
|
||||
bind(new TypeLiteral<Function<RunningInstance, Map<String, String>>>() {
|
||||
}).annotatedWith(Names.named("volumeMapping")).to(
|
||||
RunningInstanceToStorageMappingUnix.class).in(Scopes.SINGLETON);
|
||||
}).annotatedWith(Names.named("volumeMapping")).to(RunningInstanceToStorageMappingUnix.class).in(Scopes.SINGLETON);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -181,12 +173,10 @@ public class EC2ComputeServiceContextModule extends AbstractModule {
|
|||
|
||||
@Provides
|
||||
@Named("DEFAULT")
|
||||
protected TemplateBuilder provideTemplate(@Region String region,
|
||||
TemplateBuilder template) {
|
||||
return "Eucalyptus".equals(region) ? template.osFamily(CENTOS).smallest()
|
||||
: template.architecture(Architecture.X86_32).osFamily(UBUNTU)
|
||||
.imageNameMatches(".*10\\.?04.*").osDescriptionMatches(
|
||||
"^ubuntu-images.*");
|
||||
protected TemplateBuilder provideTemplate(@Region String region, TemplateBuilder template) {
|
||||
return "Eucalyptus".equals(region) ? template.osFamily(CENTOS).smallest() : template.architecture(
|
||||
Architecture.X86_32).osFamily(UBUNTU).imageNameMatches(".*10\\.?04.*").osDescriptionMatches(
|
||||
"^ubuntu-images.*");
|
||||
}
|
||||
|
||||
// TODO make this more efficient for listNodes(); currently
|
||||
|
@ -204,8 +194,7 @@ public class EC2ComputeServiceContextModule extends AbstractModule {
|
|||
private final ExecutorService executor;
|
||||
|
||||
@Inject
|
||||
protected EC2ListNodesStrategy(EC2Client client,
|
||||
@Region Map<String, URI> regionMap,
|
||||
protected EC2ListNodesStrategy(EC2Client client, @Region Map<String, URI> regionMap,
|
||||
RunningInstanceToNodeMetadata runningInstanceToNodeMetadata,
|
||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
|
||||
this.client = client;
|
||||
|
@ -220,45 +209,37 @@ public class EC2ComputeServiceContextModule extends AbstractModule {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Iterable<? extends NodeMetadata> listDetailsOnNodesMatching(
|
||||
Predicate<ComputeMetadata> filter) {
|
||||
public Iterable<? extends NodeMetadata> listDetailsOnNodesMatching(Predicate<ComputeMetadata> filter) {
|
||||
final Set<NodeMetadata> nodes = Sets.newHashSet();
|
||||
|
||||
Map<String, ListenableFuture<?>> parallelResponses = Maps.newHashMap();
|
||||
|
||||
for (final String region : regionMap.keySet()) {
|
||||
parallelResponses.put(region, ConcurrentUtils.makeListenable(
|
||||
executor.submit(new Callable<Void>() {
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
Iterables.addAll(nodes, Iterables.transform(Iterables
|
||||
.concat(client.getInstanceServices()
|
||||
.describeInstancesInRegion(region)),
|
||||
runningInstanceToNodeMetadata));
|
||||
return null;
|
||||
}
|
||||
}), executor));
|
||||
parallelResponses.put(region, ConcurrentUtils.makeListenable(executor.submit(new Callable<Void>() {
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
Iterables.addAll(nodes, Iterables.transform(Iterables.concat(client.getInstanceServices()
|
||||
.describeInstancesInRegion(region)), runningInstanceToNodeMetadata));
|
||||
return null;
|
||||
}
|
||||
}), executor));
|
||||
}
|
||||
Map<String, Exception> exceptions = awaitCompletion(parallelResponses,
|
||||
executor, null, logger, "nodes");
|
||||
Map<String, Exception> exceptions = awaitCompletion(parallelResponses, executor, null, logger, "nodes");
|
||||
|
||||
if (exceptions.size() > 0)
|
||||
throw new RuntimeException(String.format(
|
||||
"error parsing nodes in regions: %s", exceptions));
|
||||
throw new RuntimeException(String.format("error parsing nodes in regions: %s", exceptions));
|
||||
return Iterables.filter(nodes, filter);
|
||||
}
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class EC2GetNodeMetadataStrategy implements
|
||||
GetNodeMetadataStrategy {
|
||||
public static class EC2GetNodeMetadataStrategy implements GetNodeMetadataStrategy {
|
||||
|
||||
private final EC2Client client;
|
||||
private final RunningInstanceToNodeMetadata runningInstanceToNodeMetadata;
|
||||
|
||||
@Inject
|
||||
protected EC2GetNodeMetadataStrategy(EC2Client client,
|
||||
RunningInstanceToNodeMetadata runningInstanceToNodeMetadata) {
|
||||
protected EC2GetNodeMetadataStrategy(EC2Client client, RunningInstanceToNodeMetadata runningInstanceToNodeMetadata) {
|
||||
this.client = client;
|
||||
this.runningInstanceToNodeMetadata = runningInstanceToNodeMetadata;
|
||||
}
|
||||
|
@ -269,9 +250,8 @@ public class EC2ComputeServiceContextModule extends AbstractModule {
|
|||
String region = parts[0];
|
||||
String instanceId = parts[1];
|
||||
try {
|
||||
RunningInstance runningInstance = Iterables
|
||||
.getOnlyElement(getAllRunningInstancesInRegion(client
|
||||
.getInstanceServices(), region, instanceId));
|
||||
RunningInstance runningInstance = Iterables.getOnlyElement(getAllRunningInstancesInRegion(client
|
||||
.getInstanceServices(), region, instanceId));
|
||||
return runningInstanceToNodeMetadata.apply(runningInstance);
|
||||
} catch (NoSuchElementException e) {
|
||||
return null;
|
||||
|
@ -286,8 +266,7 @@ public class EC2ComputeServiceContextModule extends AbstractModule {
|
|||
private final GetNodeMetadataStrategy getNode;
|
||||
|
||||
@Inject
|
||||
protected EC2RebootNodeStrategy(EC2Client client,
|
||||
GetNodeMetadataStrategy getNode) {
|
||||
protected EC2RebootNodeStrategy(EC2Client client, GetNodeMetadataStrategy getNode) {
|
||||
this.client = client.getInstanceServices();
|
||||
this.getNode = getNode;
|
||||
}
|
||||
|
@ -305,8 +284,7 @@ public class EC2ComputeServiceContextModule extends AbstractModule {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected final Map<RegionAndName, KeyPair> credentialsMap(
|
||||
CreateUniqueKeyPair in) {
|
||||
protected final Map<RegionAndName, KeyPair> credentialsMap(CreateUniqueKeyPair in) {
|
||||
// doesn't seem to clear when someone issues remove(key)
|
||||
// return new MapMaker().makeComputingMap(in);
|
||||
return Maps.newLinkedHashMap();
|
||||
|
@ -314,8 +292,7 @@ public class EC2ComputeServiceContextModule extends AbstractModule {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected final Map<RegionAndName, String> securityGroupMap(
|
||||
CreateSecurityGroupIfNeeded in) {
|
||||
protected final Map<RegionAndName, String> securityGroupMap(CreateSecurityGroupIfNeeded in) {
|
||||
// doesn't seem to clear when someone issues remove(key)
|
||||
// return new MapMaker().makeComputingMap(in);
|
||||
return Maps.newLinkedHashMap();
|
||||
|
@ -334,45 +311,36 @@ public class EC2ComputeServiceContextModule extends AbstractModule {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
Set<? extends Size> provideSizes(Set<? extends Location> locations,
|
||||
@Named(PROPERTY_EC2_CC_AMIs) String[] ccAmis) {
|
||||
Set<? extends Size> provideSizes(Set<? extends Location> locations, @Named(PROPERTY_EC2_CC_AMIs) String[] ccAmis) {
|
||||
Set<Size> sizes = Sets.newHashSet();
|
||||
for (String ccAmi : ccAmis) {
|
||||
final String region = ccAmi.split("/")[0];
|
||||
Location location = Iterables.find(locations,
|
||||
new Predicate<Location>() {
|
||||
Location location = Iterables.find(locations, new Predicate<Location>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(Location input) {
|
||||
return input.getScope() == LocationScope.REGION
|
||||
&& input.getId().equals(region);
|
||||
}
|
||||
@Override
|
||||
public boolean apply(Location input) {
|
||||
return input.getScope() == LocationScope.REGION && input.getId().equals(region);
|
||||
}
|
||||
|
||||
});
|
||||
sizes.add(new EC2Size(location, InstanceType.CC1_4XLARGE, 33.5,
|
||||
23 * 1024, 1690, ccAmis));
|
||||
});
|
||||
sizes.add(new EC2Size(location, InstanceType.CC1_4XLARGE, 33.5, 23 * 1024, 1690, ccAmis));
|
||||
}
|
||||
sizes.addAll(ImmutableSet.<Size> of(EC2Size.C1_MEDIUM, EC2Size.C1_XLARGE,
|
||||
EC2Size.M1_LARGE, EC2Size.M1_SMALL, EC2Size.M1_XLARGE,
|
||||
EC2Size.M2_XLARGE, EC2Size.M2_2XLARGE, EC2Size.M2_4XLARGE));
|
||||
sizes.addAll(ImmutableSet.<Size> of(EC2Size.C1_MEDIUM, EC2Size.C1_XLARGE, EC2Size.M1_LARGE, EC2Size.M1_SMALL,
|
||||
EC2Size.M1_XLARGE, EC2Size.M2_XLARGE, EC2Size.M2_2XLARGE, EC2Size.M2_4XLARGE));
|
||||
return sizes;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
Set<? extends Location> provideLocations(
|
||||
Map<String, String> availabilityZoneToRegionMap,
|
||||
Set<? extends Location> provideLocations(Map<String, String> availabilityZoneToRegionMap,
|
||||
@Provider String providerName) {
|
||||
Location ec2 = new LocationImpl(LocationScope.PROVIDER, providerName,
|
||||
providerName, null);
|
||||
Location ec2 = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
|
||||
Set<Location> locations = Sets.newLinkedHashSet();
|
||||
for (String zone : availabilityZoneToRegionMap.keySet()) {
|
||||
Location region = new LocationImpl(LocationScope.REGION,
|
||||
availabilityZoneToRegionMap.get(zone),
|
||||
Location region = new LocationImpl(LocationScope.REGION, availabilityZoneToRegionMap.get(zone),
|
||||
availabilityZoneToRegionMap.get(zone), ec2);
|
||||
locations.add(region);
|
||||
locations
|
||||
.add(new LocationImpl(LocationScope.ZONE, zone, zone, region));
|
||||
locations.add(new LocationImpl(LocationScope.ZONE, zone, zone, region));
|
||||
}
|
||||
return locations;
|
||||
}
|
||||
|
@ -402,29 +370,24 @@ public class EC2ComputeServiceContextModule extends AbstractModule {
|
|||
}
|
||||
|
||||
@Provides
|
||||
protected Set<? extends Image> provideImages(
|
||||
Map<RegionAndName, ? extends Image> map) {
|
||||
protected Set<? extends Image> provideImages(Map<RegionAndName, ? extends Image> map) {
|
||||
return ImmutableSet.copyOf(map.values());
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected ConcurrentMap<RegionAndName, Image> provideImageMap(
|
||||
RegionAndIdToImage regionAndIdToImage) {
|
||||
protected ConcurrentMap<RegionAndName, Image> provideImageMap(RegionAndIdToImage regionAndIdToImage) {
|
||||
return new MapMaker().makeComputingMap(regionAndIdToImage);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Map<RegionAndName, ? extends Image> provideImages(
|
||||
final EC2Client sync, @Region Map<String, URI> regionMap,
|
||||
final LogHolder holder, Function<ComputeMetadata, String> indexer,
|
||||
@Named(PROPERTY_EC2_CC_AMIs) String[] ccAmis,
|
||||
@Named(PROPERTY_EC2_AMI_OWNERS) final String[] amiOwners,
|
||||
final ImageParser parser,
|
||||
final ConcurrentMap<RegionAndName, Image> images,
|
||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor)
|
||||
throws InterruptedException, ExecutionException, TimeoutException {
|
||||
protected Map<RegionAndName, ? extends Image> provideImages(final EC2Client sync,
|
||||
@Region Map<String, URI> regionMap, final LogHolder holder, Function<ComputeMetadata, String> indexer,
|
||||
@Named(PROPERTY_EC2_CC_AMIs) String[] ccAmis, @Named(PROPERTY_EC2_AMI_OWNERS) final String[] amiOwners,
|
||||
final ImageParser parser, final ConcurrentMap<RegionAndName, Image> images,
|
||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) throws InterruptedException,
|
||||
ExecutionException, TimeoutException {
|
||||
if (amiOwners.length == 0) {
|
||||
holder.logger.debug(">> no owners specified, skipping image parsing");
|
||||
} else {
|
||||
|
@ -437,40 +400,33 @@ public class EC2ComputeServiceContextModule extends AbstractModule {
|
|||
else
|
||||
options = ownedBy(amiOwners);
|
||||
for (final String region : regionMap.keySet()) {
|
||||
parallelResponses.put(region, ConcurrentUtils.makeListenable(
|
||||
executor.submit(new Callable<Void>() {
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
for (final org.jclouds.aws.ec2.domain.Image from : sync
|
||||
.getAMIServices().describeImagesInRegion(region,
|
||||
options)) {
|
||||
Image image = parser.apply(from);
|
||||
if (image != null)
|
||||
images.put(new RegionAndName(region, image
|
||||
.getProviderId()), image);
|
||||
else if (from.getImageType() == ImageType.MACHINE)
|
||||
holder.logger.trace("<< image(%s) didn't parse",
|
||||
from.getId());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}), executor));
|
||||
parallelResponses.put(region, ConcurrentUtils.makeListenable(executor.submit(new Callable<Void>() {
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
Set<org.jclouds.aws.ec2.domain.Image> matchingImages = sync.getAMIServices().describeImagesInRegion(
|
||||
region, options);
|
||||
for (final org.jclouds.aws.ec2.domain.Image from : matchingImages) {
|
||||
Image image = parser.apply(from);
|
||||
if (image != null)
|
||||
images.put(new RegionAndName(region, image.getProviderId()), image);
|
||||
else if (from.getImageType() == ImageType.MACHINE)
|
||||
holder.logger.trace("<< image(%s) didn't parse", from.getId());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}), executor));
|
||||
}
|
||||
Map<String, Exception> exceptions = awaitCompletion(parallelResponses,
|
||||
executor, null, holder.logger, "images");
|
||||
Map<String, Exception> exceptions = awaitCompletion(parallelResponses, executor, null, holder.logger, "images");
|
||||
for (String ccAmi : ccAmis) {
|
||||
String region = ccAmi.split("/")[0];
|
||||
org.jclouds.aws.ec2.domain.Image from = Iterables
|
||||
.getOnlyElement(sync.getAMIServices().describeImagesInRegion(
|
||||
region, imageIds(ccAmi.split("/")[1])));
|
||||
org.jclouds.aws.ec2.domain.Image from = Iterables.getOnlyElement(sync.getAMIServices()
|
||||
.describeImagesInRegion(region, imageIds(ccAmi.split("/")[1])));
|
||||
Image image = parser.apply(from);
|
||||
if (image != null)
|
||||
images.put(new RegionAndName(region, image.getProviderId()),
|
||||
image);
|
||||
images.put(new RegionAndName(region, image.getProviderId()), image);
|
||||
}
|
||||
if (exceptions.size() > 0)
|
||||
throw new RuntimeException(String.format(
|
||||
"error parsing images in regions: %s", exceptions));
|
||||
throw new RuntimeException(String.format("error parsing images in regions: %s", exceptions));
|
||||
|
||||
holder.logger.debug("<< images(%d)", images.size());
|
||||
}
|
||||
|
|
|
@ -1,6 +1,25 @@
|
|||
/**
|
||||
*
|
||||
* 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.compute.internal;
|
||||
|
||||
import java.util.List;
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
@ -18,7 +37,7 @@ import org.jclouds.compute.internal.TemplateBuilderImpl;
|
|||
import org.jclouds.compute.options.TemplateOptions;
|
||||
import org.jclouds.domain.Location;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -29,15 +48,11 @@ public class EC2TemplateBuilderImpl extends TemplateBuilderImpl {
|
|||
private final ConcurrentMap<RegionAndName, Image> imageMap;
|
||||
|
||||
@Inject
|
||||
protected EC2TemplateBuilderImpl(
|
||||
Provider<Set<? extends Location>> locations,
|
||||
Provider<Set<? extends Image>> images,
|
||||
Provider<Set<? extends Size>> sizes, Location defaultLocation,
|
||||
Provider<TemplateOptions> optionsProvider,
|
||||
protected EC2TemplateBuilderImpl(Provider<Set<? extends Location>> locations, Provider<Set<? extends Image>> images,
|
||||
Provider<Set<? extends Size>> sizes, Location defaultLocation, Provider<TemplateOptions> optionsProvider,
|
||||
@Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider,
|
||||
ConcurrentMap<RegionAndName, Image> imageMap) {
|
||||
super(locations, images, sizes, defaultLocation, optionsProvider,
|
||||
defaultTemplateProvider);
|
||||
super(locations, images, sizes, defaultLocation, optionsProvider, defaultTemplateProvider);
|
||||
this.imageMap = imageMap;
|
||||
}
|
||||
|
||||
|
@ -47,37 +62,62 @@ public class EC2TemplateBuilderImpl extends TemplateBuilderImpl {
|
|||
if (from instanceof EC2TemplateOptions) {
|
||||
EC2TemplateOptions eFrom = EC2TemplateOptions.class.cast(from);
|
||||
EC2TemplateOptions eTo = EC2TemplateOptions.class.cast(to);
|
||||
if (eFrom.getGroupIds().size() >0)
|
||||
if (eFrom.getGroupIds().size() > 0)
|
||||
eTo.securityGroups(eFrom.getGroupIds());
|
||||
if (eFrom.getKeyPair() != null)
|
||||
eTo.keyPair(eFrom.getKeyPair());
|
||||
if (!eFrom.shouldAutomaticallyCreateKeyPair())
|
||||
eTo.noKeyPair();
|
||||
if(eFrom.getSubnetId() != null)
|
||||
if (eFrom.getSubnetId() != null)
|
||||
eTo.subnetId(eFrom.getSubnetId());
|
||||
}
|
||||
}
|
||||
|
||||
final Provider<Image> lazyImageProvider = new Provider<Image>() {
|
||||
|
||||
@Override
|
||||
public Image get() {
|
||||
if (imageId != null) {
|
||||
String[] regionName = imageId.split("/");
|
||||
checkArgument(regionName.length == 2,
|
||||
"amazon image ids must include the region. ex. us-east-1/ami-7ea24a17");
|
||||
RegionAndName key = new RegionAndName(regionName[0], regionName[1]);
|
||||
try {
|
||||
return imageMap.get(key);
|
||||
} catch (NullPointerException nex) {
|
||||
throw new NoSuchElementException(String.format("image %s/%s not found", key.getRegion(), key.getName()));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @throws NoSuchElementException
|
||||
* if the image is not found
|
||||
*/
|
||||
@Override
|
||||
protected List<? extends Image> resolveImages() {
|
||||
protected Image resolveImage(Size size) {
|
||||
try {
|
||||
return super.resolveImages();
|
||||
return super.resolveImage(size);
|
||||
} catch (NoSuchElementException e) {
|
||||
if (locationId != null && imageId != null) {
|
||||
RegionAndName key = new RegionAndName(this.locationId, this.imageId);
|
||||
try {
|
||||
return ImmutableList.of(imageMap.get(key));
|
||||
} catch (NullPointerException nex) {
|
||||
throw new NoSuchElementException(String.format(
|
||||
"image %s/%s not found", key.getRegion(), key.getName()));
|
||||
}
|
||||
}
|
||||
Image returnVal = lazyImageProvider.get();
|
||||
if (returnVal != null)
|
||||
return returnVal;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<? extends Image> getImages() {
|
||||
Set<? extends Image> images = this.images.get();
|
||||
if (images.size() == 0) {
|
||||
Image toReturn = lazyImageProvider.get();
|
||||
if (toReturn != null)
|
||||
return ImmutableSet.of(lazyImageProvider.get());
|
||||
}
|
||||
return images;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,7 +21,9 @@ package org.jclouds.aws.ec2.xml;
|
|||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.aws.Region;
|
||||
import org.jclouds.aws.ec2.domain.AvailabilityZoneInfo;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.logging.Logger;
|
||||
|
@ -33,9 +35,9 @@ import com.google.common.collect.Sets;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class DescribeAvailabilityZonesResponseHandler extends
|
||||
ParseSax.HandlerWithResult<Set<AvailabilityZoneInfo>> {
|
||||
public class DescribeAvailabilityZonesResponseHandler extends ParseSax.HandlerWithResult<Set<AvailabilityZoneInfo>> {
|
||||
private StringBuilder currentText = new StringBuilder();
|
||||
private final String defaultRegion;
|
||||
|
||||
private Set<AvailabilityZoneInfo> availablilityZones = Sets.newLinkedHashSet();
|
||||
private String zone;
|
||||
|
@ -46,6 +48,15 @@ public class DescribeAvailabilityZonesResponseHandler extends
|
|||
private boolean inMessageSet;
|
||||
private Set<String> messages = Sets.newHashSet();
|
||||
|
||||
/**
|
||||
* Eucalyptus 1.6 doesn't return region in the XML output
|
||||
*/
|
||||
@Inject
|
||||
DescribeAvailabilityZonesResponseHandler(@Region String defaultRegion) {
|
||||
this.defaultRegion = defaultRegion;
|
||||
region = defaultRegion;
|
||||
}
|
||||
|
||||
public Set<AvailabilityZoneInfo> getResult() {
|
||||
return availablilityZones;
|
||||
}
|
||||
|
@ -75,7 +86,7 @@ public class DescribeAvailabilityZonesResponseHandler extends
|
|||
} else if (qName.equals("item") && !inMessageSet) {
|
||||
availablilityZones.add(new AvailabilityZoneInfo(zone, zoneState, region, messages));
|
||||
this.zone = null;
|
||||
this.region = null;
|
||||
this.region = defaultRegion;
|
||||
this.zoneState = null;
|
||||
this.messages = Sets.newHashSet();
|
||||
}
|
||||
|
|
|
@ -49,8 +49,7 @@ import com.google.common.collect.Sets;
|
|||
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeImages.html"
|
||||
* />
|
||||
*/
|
||||
public class DescribeImagesResponseHandler extends
|
||||
ParseSax.HandlerForGeneratedRequestWithResult<Set<Image>> {
|
||||
public class DescribeImagesResponseHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Set<Image>> {
|
||||
|
||||
@Inject
|
||||
public DescribeImagesResponseHandler(@Region String defaultRegion) {
|
||||
|
@ -79,7 +78,10 @@ public class DescribeImagesResponseHandler extends
|
|||
private String ramdiskId;
|
||||
private boolean inProductCodes;
|
||||
private boolean inBlockDeviceMapping;
|
||||
private RootDeviceType rootDeviceType;
|
||||
/**
|
||||
* Eucalyptus 1.6 doesn't set rootDeviceType
|
||||
*/
|
||||
private RootDeviceType rootDeviceType = RootDeviceType.INSTANCE_STORE;
|
||||
private Map<String, EbsBlockDevice> ebsBlockDevices = Maps.newHashMap();
|
||||
private String deviceName;
|
||||
private String snapshotId;
|
||||
|
@ -149,8 +151,7 @@ public class DescribeImagesResponseHandler extends
|
|||
virtualizationType = currentText.toString().trim();
|
||||
} else if (qName.equals("item")) {
|
||||
if (inBlockDeviceMapping) {
|
||||
ebsBlockDevices.put(deviceName, new Image.EbsBlockDevice(snapshotId, volumeSize,
|
||||
deleteOnTermination));
|
||||
ebsBlockDevices.put(deviceName, new Image.EbsBlockDevice(snapshotId, volumeSize, deleteOnTermination));
|
||||
this.deviceName = null;
|
||||
this.snapshotId = null;
|
||||
this.volumeSize = 0;
|
||||
|
@ -160,10 +161,9 @@ public class DescribeImagesResponseHandler extends
|
|||
String region = EC2Utils.findRegionInArgsOrNull((GeneratedHttpRequest<?>) request);
|
||||
if (region == null)
|
||||
region = defaultRegion;
|
||||
contents.add(new Image(region, architecture, this.name, description, imageId,
|
||||
imageLocation, imageOwnerId, imageState, imageType, isPublic, productCodes,
|
||||
kernelId, platform, ramdiskId, rootDeviceType, rootDeviceName,
|
||||
ebsBlockDevices, virtualizationType));
|
||||
contents.add(new Image(region, architecture, this.name, description, imageId, imageLocation,
|
||||
imageOwnerId, imageState, imageType, isPublic, productCodes, kernelId, platform, ramdiskId,
|
||||
rootDeviceType, rootDeviceName, ebsBlockDevices, virtualizationType));
|
||||
} catch (NullPointerException e) {
|
||||
logger.warn(e, "malformed image: %s", imageId);
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ public class DescribeImagesResponseHandler extends
|
|||
this.platform = null;
|
||||
this.productCodes = Sets.newHashSet();
|
||||
this.ramdiskId = null;
|
||||
this.rootDeviceType = null;
|
||||
this.rootDeviceType = RootDeviceType.INSTANCE_STORE;
|
||||
this.rootDeviceName = null;
|
||||
this.ebsBlockDevices = Maps.newHashMap();
|
||||
this.virtualizationType = "paravirtual";
|
||||
|
|
|
@ -66,33 +66,33 @@ public class ParseAWSErrorFromXmlContent implements HttpErrorHandler {
|
|||
try {
|
||||
AWSError error = utils.parseAWSErrorFromContent(request, response);
|
||||
exception = error != null ? new AWSResponseException(command, response, error) : exception;
|
||||
String notFoundMessage = error != null ? error.getMessage() : String.format("%s -> %s", request
|
||||
.getRequestLine(), response.getStatusLine());
|
||||
switch (response.getStatusCode()) {
|
||||
case 400:
|
||||
if (error.getCode().endsWith(".NotFound"))
|
||||
exception = new ResourceNotFoundException(error.getMessage(), exception);
|
||||
else if (error.getCode().equals("IncorrectState"))
|
||||
exception = new IllegalStateException(error.getMessage(), exception);
|
||||
else if (error.getCode().equals("AuthFailure"))
|
||||
exception = new AuthorizationException(command.getRequest(),
|
||||
error != null ? error.getMessage() : response.getStatusLine());
|
||||
break;
|
||||
case 401:
|
||||
case 403:
|
||||
exception = new AuthorizationException(command.getRequest(), error != null ? error
|
||||
.getMessage() : response.getStatusLine());
|
||||
break;
|
||||
case 404:
|
||||
if (!command.getRequest().getMethod().equals("DELETE")) {
|
||||
String message = error != null ? error.getMessage() : String.format("%s -> %s",
|
||||
request.getRequestLine(), response.getStatusLine());
|
||||
String container = request.getEndpoint().getHost();
|
||||
String key = request.getEndpoint().getPath();
|
||||
if (key == null || key.equals("/"))
|
||||
exception = new ContainerNotFoundException(container, message);
|
||||
else
|
||||
exception = new KeyNotFoundException(container, key, message);
|
||||
}
|
||||
break;
|
||||
case 400:
|
||||
if (error.getCode().endsWith(".NotFound"))
|
||||
exception = new ResourceNotFoundException(notFoundMessage, exception);
|
||||
else if (error.getCode().equals("IncorrectState"))
|
||||
exception = new IllegalStateException(error.getMessage(), exception);
|
||||
else if (error.getCode().equals("AuthFailure"))
|
||||
exception = new AuthorizationException(command.getRequest(), error != null ? error.getMessage()
|
||||
: response.getStatusLine());
|
||||
break;
|
||||
case 401:
|
||||
case 403:
|
||||
exception = new AuthorizationException(command.getRequest(), error != null ? error.getMessage() : response
|
||||
.getStatusLine());
|
||||
break;
|
||||
case 404:
|
||||
if (!command.getRequest().getMethod().equals("DELETE")) {
|
||||
String container = request.getEndpoint().getHost();
|
||||
String key = request.getEndpoint().getPath();
|
||||
if (key == null || key.equals("/"))
|
||||
exception = new ContainerNotFoundException(container, notFoundMessage);
|
||||
else
|
||||
exception = new KeyNotFoundException(container, key, notFoundMessage);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} finally {
|
||||
releasePayload(response);
|
||||
|
|
|
@ -33,8 +33,10 @@ import org.jclouds.aws.ec2.services.InstanceClient;
|
|||
import org.jclouds.aws.ec2.services.KeyPairClient;
|
||||
import org.jclouds.aws.ec2.services.SecurityGroupClient;
|
||||
import org.jclouds.compute.BaseComputeServiceLiveTest;
|
||||
import org.jclouds.compute.domain.Architecture;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.OsFamily;
|
||||
import org.jclouds.compute.domain.Size;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.jclouds.compute.options.TemplateOptions;
|
||||
|
@ -66,7 +68,32 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
|||
}
|
||||
|
||||
@Test(enabled = true, dependsOnMethods = "testCorrectAuthException")
|
||||
public void testImagesResolveCorrectly() {
|
||||
Template defaultTemplate = client.templateBuilder().build();
|
||||
assertEquals(defaultTemplate.getImage().getId(), defaultTemplate.getImage().getLocation().getId() + "/"
|
||||
+ defaultTemplate.getImage().getProviderId());
|
||||
Template byId = client.templateBuilder().imageId(defaultTemplate.getImage().getId()).build();
|
||||
assertEquals(byId.getImage(), defaultTemplate.getImage());
|
||||
}
|
||||
|
||||
@Test(enabled = true, dependsOnMethods = "testImagesResolveCorrectly")
|
||||
public void testDefaultTemplateBuilder() {
|
||||
assertDefaultWorks();
|
||||
}
|
||||
|
||||
protected void assertDefaultWorks() {
|
||||
Template defaultTemplate = client.templateBuilder().build();
|
||||
assertEquals(defaultTemplate.getImage().getArchitecture(), Architecture.X86_32);
|
||||
assertEquals(defaultTemplate.getImage().getOsFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(defaultTemplate.getSize().getCores(), 1.0d);
|
||||
}
|
||||
|
||||
@Test(enabled = true, dependsOnMethods = "testDefaultTemplateBuilder")
|
||||
public void testTemplateChoiceForInstanceByCCSizeId() throws Exception {
|
||||
assertCCsizeWorks();
|
||||
}
|
||||
|
||||
protected void assertCCsizeWorks() {
|
||||
Set<? extends Size> sizes = context.getComputeService().listSizes();
|
||||
assert Iterables.any(sizes, new Predicate<Size>() {
|
||||
|
||||
|
@ -85,24 +112,21 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
|||
}
|
||||
|
||||
}) : images;
|
||||
Template template = context.getComputeService().templateBuilder()
|
||||
.fastest().build();
|
||||
Template template = context.getComputeService().templateBuilder().fastest().build();
|
||||
assert template != null : "The returned template was null, but it should have a value.";
|
||||
assertEquals(template.getSize().getProviderId(), InstanceType.CC1_4XLARGE);
|
||||
assertEquals(template.getImage().getId(), "us-east-1/ami-7ea24a17");
|
||||
}
|
||||
|
||||
@Test(enabled = true, dependsOnMethods = "testTemplateChoiceForInstanceByCCSizeId")
|
||||
@Test(enabled = true, dependsOnMethods = "testDefaultTemplateBuilder")
|
||||
public void testExtendedOptionsAndLogin() throws Exception {
|
||||
SecurityGroupClient securityGroupClient = EC2Client.class.cast(
|
||||
context.getProviderSpecificContext().getApi())
|
||||
SecurityGroupClient securityGroupClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi())
|
||||
.getSecurityGroupServices();
|
||||
|
||||
KeyPairClient keyPairClient = EC2Client.class.cast(
|
||||
context.getProviderSpecificContext().getApi()).getKeyPairServices();
|
||||
KeyPairClient keyPairClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi())
|
||||
.getKeyPairServices();
|
||||
|
||||
InstanceClient instanceClient = EC2Client.class.cast(
|
||||
context.getProviderSpecificContext().getApi())
|
||||
InstanceClient instanceClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi())
|
||||
.getInstanceServices();
|
||||
|
||||
String tag = this.tag + "optionsandlogin";
|
||||
|
@ -119,14 +143,12 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
|||
// create a security group that allows ssh in so that our scripts later
|
||||
// will work
|
||||
securityGroupClient.createSecurityGroupInRegion(null, tag, tag);
|
||||
securityGroupClient.authorizeSecurityGroupIngressInRegion(null, tag,
|
||||
IpProtocol.TCP, 22, 22, "0.0.0.0/0");
|
||||
securityGroupClient.authorizeSecurityGroupIngressInRegion(null, tag, IpProtocol.TCP, 22, 22, "0.0.0.0/0");
|
||||
|
||||
// create a keypair to pass in as well
|
||||
KeyPair result = keyPairClient.createKeyPairInRegion(null, tag);
|
||||
|
||||
Set<? extends NodeMetadata> nodes = client.runNodesWithTag(tag, 1,
|
||||
options);
|
||||
Set<? extends NodeMetadata> nodes = client.runNodesWithTag(tag, 1, options);
|
||||
NodeMetadata first = Iterables.get(nodes, 0);
|
||||
assert first.getCredentials() != null : first;
|
||||
assert first.getCredentials().identity != null : first;
|
||||
|
@ -138,27 +160,23 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
|||
assertEquals(instance.getKeyName(), tag);
|
||||
|
||||
// make sure we made our dummy group and also let in the user's group
|
||||
assertEquals(instance.getGroupIds(), ImmutableSet.<String> of(tag,
|
||||
"jclouds#" + tag));
|
||||
assertEquals(instance.getGroupIds(), ImmutableSet.<String> of(tag, "jclouds#" + tag));
|
||||
|
||||
// make sure our dummy group has no rules
|
||||
SecurityGroup group = Iterables.getOnlyElement(securityGroupClient
|
||||
.describeSecurityGroupsInRegion(null, "jclouds#" + tag));
|
||||
SecurityGroup group = Iterables.getOnlyElement(securityGroupClient.describeSecurityGroupsInRegion(null,
|
||||
"jclouds#" + tag));
|
||||
assert group.getIpPermissions().size() == 0 : group;
|
||||
|
||||
// try to run a script with the original keyPair
|
||||
runScriptWithCreds(tag, first.getImage().getOsFamily(),
|
||||
new Credentials(first.getCredentials().identity, result
|
||||
.getKeyMaterial()));
|
||||
runScriptWithCreds(tag, first.getImage().getOsFamily(), new Credentials(first.getCredentials().identity,
|
||||
result.getKeyMaterial()));
|
||||
|
||||
} finally {
|
||||
client.destroyNodesMatching(NodePredicates.withTag(tag));
|
||||
if (startedId != null) {
|
||||
// ensure we didn't delete these resources!
|
||||
assertEquals(keyPairClient.describeKeyPairsInRegion(null, tag)
|
||||
.size(), 1);
|
||||
assertEquals(securityGroupClient.describeSecurityGroupsInRegion(
|
||||
null, tag).size(), 1);
|
||||
assertEquals(keyPairClient.describeKeyPairsInRegion(null, tag).size(), 1);
|
||||
assertEquals(securityGroupClient.describeSecurityGroupsInRegion(null, tag).size(), 1);
|
||||
}
|
||||
cleanupExtendedStuff(securityGroupClient, keyPairClient, tag);
|
||||
}
|
||||
|
@ -166,15 +184,13 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
|||
|
||||
@Test(enabled = true, dependsOnMethods = "testTemplateChoiceForInstanceByCCSizeId")
|
||||
public void testExtendedOptionsNoKeyPair() throws Exception {
|
||||
SecurityGroupClient securityGroupClient = EC2Client.class.cast(
|
||||
context.getProviderSpecificContext().getApi())
|
||||
SecurityGroupClient securityGroupClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi())
|
||||
.getSecurityGroupServices();
|
||||
|
||||
KeyPairClient keyPairClient = EC2Client.class.cast(
|
||||
context.getProviderSpecificContext().getApi()).getKeyPairServices();
|
||||
KeyPairClient keyPairClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi())
|
||||
.getKeyPairServices();
|
||||
|
||||
InstanceClient instanceClient = EC2Client.class.cast(
|
||||
context.getProviderSpecificContext().getApi())
|
||||
InstanceClient instanceClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi())
|
||||
.getInstanceServices();
|
||||
|
||||
String tag = this.tag + "optionsnokey";
|
||||
|
@ -191,8 +207,7 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
|||
// create the security group
|
||||
securityGroupClient.createSecurityGroupInRegion(null, tag, tag);
|
||||
|
||||
Set<? extends NodeMetadata> nodes = client.runNodesWithTag(tag, 1,
|
||||
options);
|
||||
Set<? extends NodeMetadata> nodes = client.runNodesWithTag(tag, 1, options);
|
||||
Credentials creds = nodes.iterator().next().getCredentials();
|
||||
assert creds == null;
|
||||
|
||||
|
@ -203,20 +218,18 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
|||
assertEquals(instance.getKeyName(), null);
|
||||
|
||||
// make sure we made our dummy group and also let in the user's group
|
||||
assertEquals(instance.getGroupIds(), ImmutableSet.<String> of(tag,
|
||||
"jclouds#" + tag));
|
||||
assertEquals(instance.getGroupIds(), ImmutableSet.<String> of(tag, "jclouds#" + tag));
|
||||
|
||||
// make sure our dummy group has no rules
|
||||
SecurityGroup group = Iterables.getOnlyElement(securityGroupClient
|
||||
.describeSecurityGroupsInRegion(null, "jclouds#" + tag));
|
||||
SecurityGroup group = Iterables.getOnlyElement(securityGroupClient.describeSecurityGroupsInRegion(null,
|
||||
"jclouds#" + tag));
|
||||
assert group.getIpPermissions().size() == 0 : group;
|
||||
|
||||
} finally {
|
||||
client.destroyNodesMatching(NodePredicates.withTag(tag));
|
||||
if (startedId != null) {
|
||||
// ensure we didn't delete these resources!
|
||||
assertEquals(securityGroupClient.describeSecurityGroupsInRegion(
|
||||
null, tag).size(), 1);
|
||||
assertEquals(securityGroupClient.describeSecurityGroupsInRegion(null, tag).size(), 1);
|
||||
}
|
||||
cleanupExtendedStuff(securityGroupClient, keyPairClient, tag);
|
||||
}
|
||||
|
@ -230,15 +243,13 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
|||
// Skip test and return
|
||||
return;
|
||||
}
|
||||
SecurityGroupClient securityGroupClient = EC2Client.class.cast(
|
||||
context.getProviderSpecificContext().getApi())
|
||||
SecurityGroupClient securityGroupClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi())
|
||||
.getSecurityGroupServices();
|
||||
|
||||
KeyPairClient keyPairClient = EC2Client.class.cast(
|
||||
context.getProviderSpecificContext().getApi()).getKeyPairServices();
|
||||
KeyPairClient keyPairClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi())
|
||||
.getKeyPairServices();
|
||||
|
||||
InstanceClient instanceClient = EC2Client.class.cast(
|
||||
context.getProviderSpecificContext().getApi())
|
||||
InstanceClient instanceClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi())
|
||||
.getInstanceServices();
|
||||
|
||||
String tag = this.tag + "optionswithsubnetid";
|
||||
|
@ -260,8 +271,7 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
|||
// create a keypair to pass in as well
|
||||
keyPairClient.createKeyPairInRegion(null, tag);
|
||||
|
||||
Set<? extends NodeMetadata> nodes = client.runNodesWithTag(tag, 1,
|
||||
options);
|
||||
Set<? extends NodeMetadata> nodes = client.runNodesWithTag(tag, 1, options);
|
||||
|
||||
NodeMetadata first = Iterables.get(nodes, 0);
|
||||
assert first.getCredentials() != null : first;
|
||||
|
@ -279,22 +289,19 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
|||
client.destroyNode(nodeId);
|
||||
if (startedId != null) {
|
||||
// ensure we didn't delete these resources!
|
||||
assertEquals(keyPairClient.describeKeyPairsInRegion(null, tag)
|
||||
.size(), 1);
|
||||
assertEquals(keyPairClient.describeKeyPairsInRegion(null, tag).size(), 1);
|
||||
}
|
||||
cleanupExtendedStuff(securityGroupClient, keyPairClient, tag);
|
||||
}
|
||||
}
|
||||
|
||||
private RunningInstance getInstance(InstanceClient instanceClient, String id) {
|
||||
RunningInstance instance = Iterables
|
||||
.getOnlyElement(Iterables.getOnlyElement(instanceClient
|
||||
.describeInstancesInRegion(null, id)));
|
||||
RunningInstance instance = Iterables.getOnlyElement(Iterables.getOnlyElement(instanceClient
|
||||
.describeInstancesInRegion(null, id)));
|
||||
return instance;
|
||||
}
|
||||
|
||||
private void cleanupExtendedStuff(SecurityGroupClient securityGroupClient,
|
||||
KeyPairClient keyPairClient, String tag) {
|
||||
private void cleanupExtendedStuff(SecurityGroupClient securityGroupClient, KeyPairClient keyPairClient, String tag) {
|
||||
try {
|
||||
securityGroupClient.deleteSecurityGroupInRegion(null, tag);
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -18,6 +18,11 @@
|
|||
*/
|
||||
package org.jclouds.aws.ec2.compute;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.jclouds.compute.domain.Architecture;
|
||||
import org.jclouds.compute.domain.OsFamily;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -35,4 +40,17 @@ public class EucalyptusComputeServiceLiveTest extends EC2ComputeServiceLiveTest
|
|||
tag = "euc";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void assertDefaultWorks() {
|
||||
Template defaultTemplate = client.templateBuilder().build();
|
||||
assertEquals(defaultTemplate.getImage().getArchitecture(), Architecture.X86_64);
|
||||
assertEquals(defaultTemplate.getImage().getOsFamily(), OsFamily.CENTOS);
|
||||
// 64 bit implied 4 ecus
|
||||
assertEquals(defaultTemplate.getSize().getCores(), 4.0d);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void assertCCsizeWorks() {
|
||||
// no CC size in eucalyptus
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,54 +49,41 @@ import com.google.common.collect.Iterables;
|
|||
public class ImageParserTest extends BaseEC2HandlerTest {
|
||||
|
||||
public void testParseAlesticCanonicalImage() {
|
||||
InputStream is = getClass().getResourceAsStream(
|
||||
"/ec2/alestic_canonical.xml");
|
||||
InputStream is = getClass().getResourceAsStream("/ec2/alestic_canonical.xml");
|
||||
|
||||
Set<Image> result = parseImages(is);
|
||||
assertEquals(result.size(), 7);
|
||||
|
||||
ImageParser parser = new ImageParser(
|
||||
new EC2PopulateDefaultLoginCredentialsForImageStrategy(),
|
||||
ImmutableSet.<Location> of(defaultLocation), defaultLocation);
|
||||
org.jclouds.compute.domain.Image ubuntuHardy = parser.apply(Iterables
|
||||
.get(result, 0));
|
||||
ImageParser parser = new ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy(), ImmutableSet
|
||||
.<Location> of(defaultLocation), defaultLocation);
|
||||
org.jclouds.compute.domain.Image ubuntuHardy = parser.apply(Iterables.get(result, 0));
|
||||
|
||||
assertEquals(ubuntuHardy.getArchitecture(),
|
||||
org.jclouds.compute.domain.Architecture.X86_32);
|
||||
assertEquals(ubuntuHardy.getDescription(),
|
||||
"ubuntu-images-us/ubuntu-hardy-8.04-i386-server-20091130.manifest.xml");
|
||||
assertEquals(ubuntuHardy.getArchitecture(), org.jclouds.compute.domain.Architecture.X86_32);
|
||||
assertEquals(ubuntuHardy.getDescription(), "ubuntu-images-us/ubuntu-hardy-8.04-i386-server-20091130.manifest.xml");
|
||||
assertEquals(ubuntuHardy.getProviderId(), "ami-7e28ca17");
|
||||
assertEquals(ubuntuHardy.getLocation(), defaultLocation);
|
||||
assertEquals(ubuntuHardy.getName(), "8.04");
|
||||
assertEquals(ubuntuHardy.getOsDescription(),
|
||||
"ubuntu-images-us/ubuntu-hardy-8.04-i386-server-20091130.manifest.xml");
|
||||
assertEquals(ubuntuHardy.getOsFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(ubuntuHardy.getUserMetadata(), ImmutableMap
|
||||
.<String, String> of("owner", "099720109477"));
|
||||
assertEquals(ubuntuHardy.getUserMetadata(), ImmutableMap.<String, String> of("owner", "099720109477"));
|
||||
assertEquals(ubuntuHardy.getVersion(), "20091130");
|
||||
|
||||
org.jclouds.compute.domain.Image alesticKarmic = parser.apply(Iterables
|
||||
.get(result, 1));
|
||||
org.jclouds.compute.domain.Image alesticKarmic = parser.apply(Iterables.get(result, 1));
|
||||
|
||||
assertEquals(alesticKarmic.getArchitecture(),
|
||||
org.jclouds.compute.domain.Architecture.X86_32);
|
||||
assertEquals(alesticKarmic.getDescription(),
|
||||
"alestic/ubuntu-9.10-karmic-base-20090623.manifest.xml");
|
||||
assertEquals(alesticKarmic.getArchitecture(), org.jclouds.compute.domain.Architecture.X86_32);
|
||||
assertEquals(alesticKarmic.getDescription(), "alestic/ubuntu-9.10-karmic-base-20090623.manifest.xml");
|
||||
assertEquals(alesticKarmic.getProviderId(), "ami-19a34270");
|
||||
assertEquals(alesticKarmic.getLocation(), defaultLocation);
|
||||
assertEquals(alesticKarmic.getName(), "9.10");
|
||||
assertEquals(alesticKarmic.getOsDescription(),
|
||||
"alestic/ubuntu-9.10-karmic-base-20090623.manifest.xml");
|
||||
assertEquals(alesticKarmic.getOsDescription(), "alestic/ubuntu-9.10-karmic-base-20090623.manifest.xml");
|
||||
assertEquals(alesticKarmic.getOsFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(alesticKarmic.getUserMetadata(), ImmutableMap
|
||||
.<String, String> of("owner", "063491364108"));
|
||||
assertEquals(alesticKarmic.getUserMetadata(), ImmutableMap.<String, String> of("owner", "063491364108"));
|
||||
assertEquals(alesticKarmic.getVersion(), "20090623");
|
||||
|
||||
org.jclouds.compute.domain.Image ubuntuKarmic = parser.apply(Iterables
|
||||
.get(result, 2));
|
||||
org.jclouds.compute.domain.Image ubuntuKarmic = parser.apply(Iterables.get(result, 2));
|
||||
|
||||
assertEquals(ubuntuKarmic.getArchitecture(),
|
||||
org.jclouds.compute.domain.Architecture.X86_32);
|
||||
assertEquals(ubuntuKarmic.getArchitecture(), org.jclouds.compute.domain.Architecture.X86_32);
|
||||
assertEquals(ubuntuKarmic.getDescription(),
|
||||
"ubuntu-images-us/ubuntu-karmic-9.10-i386-server-20100121.manifest.xml");
|
||||
assertEquals(ubuntuKarmic.getProviderId(), "ami-bb709dd2");
|
||||
|
@ -105,178 +92,128 @@ public class ImageParserTest extends BaseEC2HandlerTest {
|
|||
assertEquals(ubuntuKarmic.getOsDescription(),
|
||||
"ubuntu-images-us/ubuntu-karmic-9.10-i386-server-20100121.manifest.xml");
|
||||
assertEquals(ubuntuKarmic.getOsFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(ubuntuKarmic.getUserMetadata(), ImmutableMap
|
||||
.<String, String> of("owner", "099720109477"));
|
||||
assertEquals(ubuntuKarmic.getUserMetadata(), ImmutableMap.<String, String> of("owner", "099720109477"));
|
||||
assertEquals(ubuntuKarmic.getVersion(), "20100121");
|
||||
|
||||
// should skip testing image
|
||||
assert parser.apply(Iterables.get(result, 3)) == null;
|
||||
|
||||
org.jclouds.compute.domain.Image alesticHardy = parser.apply(Iterables
|
||||
.get(result, 4));
|
||||
org.jclouds.compute.domain.Image alesticHardy = parser.apply(Iterables.get(result, 4));
|
||||
|
||||
assertEquals(alesticHardy.getArchitecture(),
|
||||
org.jclouds.compute.domain.Architecture.X86_32);
|
||||
assertEquals(alesticHardy.getDescription(),
|
||||
"alestic/ubuntu-8.04-hardy-base-20080905.manifest.xml");
|
||||
assertEquals(alesticHardy.getArchitecture(), org.jclouds.compute.domain.Architecture.X86_32);
|
||||
assertEquals(alesticHardy.getDescription(), "alestic/ubuntu-8.04-hardy-base-20080905.manifest.xml");
|
||||
assertEquals(alesticHardy.getProviderId(), "ami-c0fa1ea9");
|
||||
assertEquals(alesticHardy.getLocation(), defaultLocation);
|
||||
assertEquals(alesticHardy.getName(), "8.04");
|
||||
assertEquals(alesticHardy.getOsDescription(),
|
||||
"alestic/ubuntu-8.04-hardy-base-20080905.manifest.xml");
|
||||
assertEquals(alesticHardy.getOsDescription(), "alestic/ubuntu-8.04-hardy-base-20080905.manifest.xml");
|
||||
assertEquals(alesticHardy.getOsFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(alesticHardy.getUserMetadata(), ImmutableMap
|
||||
.<String, String> of("owner", "063491364108"));
|
||||
assertEquals(alesticHardy.getUserMetadata(), ImmutableMap.<String, String> of("owner", "063491364108"));
|
||||
assertEquals(alesticHardy.getVersion(), "20080905");
|
||||
|
||||
org.jclouds.compute.domain.Image ubuntuLucid = parser.apply(Iterables
|
||||
.get(result, 5));
|
||||
org.jclouds.compute.domain.Image ubuntuLucid = parser.apply(Iterables.get(result, 5));
|
||||
|
||||
assertEquals(ubuntuLucid.getArchitecture(),
|
||||
org.jclouds.compute.domain.Architecture.X86_32);
|
||||
assertEquals(
|
||||
ubuntuLucid.getDescription(),
|
||||
assertEquals(ubuntuLucid.getArchitecture(), org.jclouds.compute.domain.Architecture.X86_32);
|
||||
assertEquals(ubuntuLucid.getDescription(),
|
||||
"ubuntu-images-us-west-1/ubuntu-lucid-10.04-i386-server-20100427.1.manifest.xml");
|
||||
assertEquals(ubuntuLucid.getProviderId(), "ami-c597c680");
|
||||
assertEquals(ubuntuLucid.getLocation(), defaultLocation);
|
||||
assertEquals(ubuntuLucid.getName(), "10.04");
|
||||
assertEquals(
|
||||
ubuntuLucid.getOsDescription(),
|
||||
assertEquals(ubuntuLucid.getOsDescription(),
|
||||
"ubuntu-images-us-west-1/ubuntu-lucid-10.04-i386-server-20100427.1.manifest.xml");
|
||||
assertEquals(ubuntuLucid.getOsFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(ubuntuLucid.getUserMetadata(), ImmutableMap
|
||||
.<String, String> of("owner", "099720109477"));
|
||||
assertEquals(ubuntuLucid.getUserMetadata(), ImmutableMap.<String, String> of("owner", "099720109477"));
|
||||
assertEquals(ubuntuLucid.getVersion(), "20100427.1");
|
||||
|
||||
// should skip kernel
|
||||
assert parser.apply(Iterables.get(result, 6)) == null;
|
||||
}
|
||||
|
||||
private Location defaultLocation = new LocationImpl(LocationScope.REGION,
|
||||
"us-east-1", "us-east-1", null);
|
||||
private Location defaultLocation = new LocationImpl(LocationScope.REGION, "us-east-1", "us-east-1", null);
|
||||
|
||||
public void testParseVostokImage() {
|
||||
InputStream is = getClass().getResourceAsStream("/ec2/vostok.xml");
|
||||
|
||||
Set<Image> result = parseImages(is);
|
||||
|
||||
ImageParser parser = new ImageParser(
|
||||
new EC2PopulateDefaultLoginCredentialsForImageStrategy(),
|
||||
ImmutableSet.<Location> of(defaultLocation), defaultLocation);
|
||||
ImageParser parser = new ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy(), ImmutableSet
|
||||
.<Location> of(defaultLocation), defaultLocation);
|
||||
|
||||
org.jclouds.compute.domain.Image image = parser.apply(Iterables.get(
|
||||
result, 0));
|
||||
org.jclouds.compute.domain.Image image = parser.apply(Iterables.get(result, 0));
|
||||
|
||||
assertEquals(image.getArchitecture(),
|
||||
org.jclouds.compute.domain.Architecture.X86_32);
|
||||
assertEquals(image.getDescription(),
|
||||
"vostok-builds/vostok-0.95-5622/vostok-0.95-5622.manifest.xml");
|
||||
assertEquals(image.getArchitecture(), org.jclouds.compute.domain.Architecture.X86_32);
|
||||
assertEquals(image.getDescription(), "vostok-builds/vostok-0.95-5622/vostok-0.95-5622.manifest.xml");
|
||||
assertEquals(image.getProviderId(), "ami-870de2ee");
|
||||
assertEquals(image.getLocation(), defaultLocation);
|
||||
assertEquals(image.getName(), "");
|
||||
assertEquals(image.getOsDescription(),
|
||||
"vostok-builds/vostok-0.95-5622/vostok-0.95-5622.manifest.xml");
|
||||
assertEquals(image.getOsDescription(), "vostok-builds/vostok-0.95-5622/vostok-0.95-5622.manifest.xml");
|
||||
assertEquals(image.getOsFamily(), null);
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of(
|
||||
"owner", "133804938231"));
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of("owner", "133804938231"));
|
||||
assertEquals(image.getVersion(), "");
|
||||
|
||||
}
|
||||
|
||||
public void testParseRightScaleImage() {
|
||||
InputStream is = getClass().getResourceAsStream(
|
||||
"/ec2/rightscale_images.xml");
|
||||
InputStream is = getClass().getResourceAsStream("/ec2/rightscale_images.xml");
|
||||
|
||||
Set<Image> result = parseImages(is);
|
||||
|
||||
ImageParser parser = new ImageParser(
|
||||
new EC2PopulateDefaultLoginCredentialsForImageStrategy(),
|
||||
ImmutableSet.<Location> of(defaultLocation), defaultLocation);
|
||||
ImageParser parser = new ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy(), ImmutableSet
|
||||
.<Location> of(defaultLocation), defaultLocation);
|
||||
|
||||
org.jclouds.compute.domain.Image image = parser.apply(Iterables.get(
|
||||
result, 0));
|
||||
org.jclouds.compute.domain.Image image = parser.apply(Iterables.get(result, 0));
|
||||
|
||||
assertEquals(image.getArchitecture(),
|
||||
org.jclouds.compute.domain.Architecture.X86_64);
|
||||
assertEquals(image.getDescription(),
|
||||
"rightscale-us-east/CentOS_5.4_x64_v4.4.10.manifest.xml");
|
||||
assertEquals(image.getArchitecture(), org.jclouds.compute.domain.Architecture.X86_64);
|
||||
assertEquals(image.getDescription(), "rightscale-us-east/CentOS_5.4_x64_v4.4.10.manifest.xml");
|
||||
assertEquals(image.getProviderId(), "ami-ccb35ea5");
|
||||
assertEquals(image.getLocation(), defaultLocation);
|
||||
assertEquals(image.getName(), "5.4");
|
||||
assertEquals(image.getOsDescription(),
|
||||
"rightscale-us-east/CentOS_5.4_x64_v4.4.10.manifest.xml");
|
||||
assertEquals(image.getOsDescription(), "rightscale-us-east/CentOS_5.4_x64_v4.4.10.manifest.xml");
|
||||
assertEquals(image.getOsFamily(), OsFamily.CENTOS);
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of(
|
||||
"owner", "411009282317"));
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of("owner", "411009282317"));
|
||||
assertEquals(image.getVersion(), "4.4.10");
|
||||
|
||||
image = parser.apply(Iterables.get(result, 1));
|
||||
|
||||
assertEquals(image.getArchitecture(),
|
||||
org.jclouds.compute.domain.Architecture.X86_64);
|
||||
assertEquals(image.getDescription(),
|
||||
"RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha");
|
||||
assertEquals(image.getArchitecture(), org.jclouds.compute.domain.Architecture.X86_64);
|
||||
assertEquals(image.getDescription(), "RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha");
|
||||
assertEquals(image.getProviderId(), "ami-c19db6b5");
|
||||
assertEquals(image.getLocation(), defaultLocation);
|
||||
assertEquals(image.getName(), "9.10");
|
||||
assertEquals(image.getOsDescription(),
|
||||
"411009282317/RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha");
|
||||
assertEquals(image.getOsDescription(), "411009282317/RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha");
|
||||
assertEquals(image.getOsFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of(
|
||||
"owner", "411009282317"));
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of("owner", "411009282317"));
|
||||
assertEquals(image.getVersion(), "4.5.3_EBS_Alpha");
|
||||
|
||||
}
|
||||
|
||||
public void testParseEucalyptusImage() {
|
||||
InputStream is = getClass().getResourceAsStream(
|
||||
"/ec2/eucalyptus_images.xml");
|
||||
InputStream is = getClass().getResourceAsStream("/ec2/eucalyptus_images.xml");
|
||||
|
||||
Set<Image> result = parseImages(is);
|
||||
assertEquals(result.size(), 11);
|
||||
ImageParser parser = new ImageParser(
|
||||
new EC2PopulateDefaultLoginCredentialsForImageStrategy(),
|
||||
ImmutableSet.<Location> of(defaultLocation), defaultLocation);
|
||||
assertEquals(result.size(), 4);
|
||||
ImageParser parser = new ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy(), ImmutableSet
|
||||
.<Location> of(defaultLocation), defaultLocation);
|
||||
|
||||
org.jclouds.compute.domain.Image image = parser.apply(Iterables.get(
|
||||
result, 0));
|
||||
org.jclouds.compute.domain.Image image = parser.apply(Iterables.get(result, 0));
|
||||
|
||||
assertEquals(image.getArchitecture(),
|
||||
org.jclouds.compute.domain.Architecture.X86_64);
|
||||
assertEquals(image.getDescription(),
|
||||
"centos-5.3-x86_64/centos.5-3.x86-64.img.manifest.xml");
|
||||
assertEquals(image.getArchitecture(), org.jclouds.compute.domain.Architecture.X86_64);
|
||||
assertEquals(image.getDescription(), "centos-5.3-x86_64/centos.5-3.x86-64.img.manifest.xml");
|
||||
assertEquals(image.getProviderId(), "emi-9ACB1363");
|
||||
assertEquals(image.getLocation(), defaultLocation);
|
||||
assertEquals(image.getName(), "5.3");
|
||||
assertEquals(image.getOsDescription(),
|
||||
"centos-5.3-x86_64/centos.5-3.x86-64.img.manifest.xml");
|
||||
assertEquals(image.getOsDescription(), "centos-5.3-x86_64/centos.5-3.x86-64.img.manifest.xml");
|
||||
assertEquals(image.getOsFamily(), OsFamily.CENTOS);
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of(
|
||||
"owner", "admin"));
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of("owner", "admin"));
|
||||
assertEquals(image.getVersion(), "");
|
||||
|
||||
image = parser.apply(Iterables.get(result, 6));
|
||||
assertEquals(image.getDescription(),
|
||||
"Lean/ubuntu.9-04.x86-64.img.manifest.xml");
|
||||
assertEquals(image.getArchitecture(),
|
||||
org.jclouds.compute.domain.Architecture.X86_64);
|
||||
assertEquals(image.getDescription(),
|
||||
"Lean/ubuntu.9-04.x86-64.img.manifest.xml");
|
||||
assertEquals(image.getProviderId(), "emi-CBEA100C");
|
||||
assertEquals(image.getLocation(), defaultLocation);
|
||||
assertEquals(image.getName(), "9.04");
|
||||
assertEquals(image.getOsDescription(),
|
||||
"Lean/ubuntu.9-04.x86-64.img.manifest.xml");
|
||||
assertEquals(image.getOsFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of(
|
||||
"owner", "mashaobing1"));
|
||||
assertEquals(image.getVersion(), "");
|
||||
// should skip test images
|
||||
image = parser.apply(Iterables.get(result, 3));
|
||||
assertEquals(image, null);
|
||||
|
||||
}
|
||||
|
||||
private Set<Image> parseImages(InputStream is) {
|
||||
DescribeImagesResponseHandler handler = injector
|
||||
.getInstance(DescribeImagesResponseHandler.class);
|
||||
DescribeImagesResponseHandler handler = injector.getInstance(DescribeImagesResponseHandler.class);
|
||||
addDefaultRegionToHandler(handler);
|
||||
Set<Image> result = factory.create(handler).parse(is);
|
||||
return result;
|
||||
|
|
|
@ -64,14 +64,13 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
|
|||
RegionAndName knownRegionAndName = new RegionAndName("region", "ami");
|
||||
Image knownImage = createNiceMock(Image.class);
|
||||
|
||||
ConcurrentMap<RegionAndName, Image> imageMap = new MapMaker()
|
||||
.makeComputingMap(new Function<RegionAndName, Image>() {
|
||||
@Override
|
||||
public Image apply(RegionAndName from) {
|
||||
return from.equals(knownRegionAndName) ? knownImage : null;
|
||||
}
|
||||
ConcurrentMap<RegionAndName, Image> imageMap = new MapMaker().makeComputingMap(new Function<RegionAndName, Image>() {
|
||||
@Override
|
||||
public Image apply(RegionAndName from) {
|
||||
return from.equals(knownRegionAndName) ? knownImage : null;
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@BeforeTest
|
||||
void setup() {
|
||||
|
@ -84,56 +83,89 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected EC2TemplateBuilderImpl createTemplateBuilder(
|
||||
Provider<Set<? extends Location>> locations,
|
||||
Provider<Set<? extends Image>> images,
|
||||
Provider<Set<? extends Size>> sizes, Location defaultLocation,
|
||||
Provider<TemplateOptions> optionsProvider,
|
||||
Provider<TemplateBuilder> templateBuilderProvider) {
|
||||
return new EC2TemplateBuilderImpl(locations, images, sizes,
|
||||
defaultLocation, optionsProvider, templateBuilderProvider, imageMap);
|
||||
protected EC2TemplateBuilderImpl createTemplateBuilder(Provider<Set<? extends Location>> locations,
|
||||
Provider<Set<? extends Image>> images, Provider<Set<? extends Size>> sizes, Location defaultLocation,
|
||||
Provider<TemplateOptions> optionsProvider, Provider<TemplateBuilder> templateBuilderProvider) {
|
||||
return new EC2TemplateBuilderImpl(locations, images, sizes, defaultLocation, optionsProvider,
|
||||
templateBuilderProvider, imageMap);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testParseOnDemand() {
|
||||
Location location = new LocationImpl(LocationScope.REGION, "region",
|
||||
"region", null);
|
||||
Location location = new LocationImpl(LocationScope.REGION, "region", "region", null);
|
||||
|
||||
Provider<Set<? extends Location>> locations = Providers
|
||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of(location));
|
||||
Provider<Set<? extends Image>> images = Providers
|
||||
.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers
|
||||
.<Set<? extends Size>> of(ImmutableSet
|
||||
.<Size> of(new SizeImpl("1", "1", "region/1", location, null,
|
||||
ImmutableMap.<String, String> of(), 1, 1, 1,
|
||||
ImagePredicates.any())));
|
||||
Provider<Set<? extends Location>> locations = Providers.<Set<? extends Location>> of(ImmutableSet
|
||||
.<Location> of(location));
|
||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet.<Size> of(new SizeImpl("1",
|
||||
"1", "region/1", location, null, ImmutableMap.<String, String> of(), 1, 1, 1, ImagePredicates.any())));
|
||||
|
||||
Location defaultLocation = createMock(Location.class);
|
||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||
TemplateOptions defaultOptions = createMock(TemplateOptions.class);
|
||||
knownImage = createMock(Image.class);
|
||||
|
||||
expect(defaultLocation.getId()).andReturn("region");
|
||||
expect(optionsProvider.get()).andReturn(defaultOptions);
|
||||
expect(knownImage.getArchitecture()).andReturn(Architecture.X86_32);
|
||||
|
||||
expect(knownImage.getId()).andReturn("region/ami");
|
||||
expect(knownImage.getLocation()).andReturn(location).atLeastOnce();
|
||||
expect(knownImage.getOsFamily()).andReturn(null);
|
||||
expect(knownImage.getName()).andReturn(null);
|
||||
expect(knownImage.getDescription()).andReturn(null);
|
||||
expect(knownImage.getOsDescription()).andReturn(null);
|
||||
expect(knownImage.getVersion()).andReturn(null);
|
||||
expect(knownImage.getArchitecture()).andReturn(Architecture.X86_32).atLeastOnce();
|
||||
|
||||
replay(knownImage);
|
||||
replay(defaultOptions);
|
||||
replay(defaultLocation);
|
||||
replay(optionsProvider);
|
||||
replay(templateBuilderProvider);
|
||||
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes, location, optionsProvider,
|
||||
templateBuilderProvider);
|
||||
|
||||
assertEquals(template.imageId("ami").build().getImage(), knownImage);
|
||||
assertEquals(template.imageId("region/ami").build().getImage(), knownImage);
|
||||
|
||||
verify(knownImage);
|
||||
verify(defaultOptions);
|
||||
verify(defaultLocation);
|
||||
verify(optionsProvider);
|
||||
verify(templateBuilderProvider);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testParseOnDemandWithoutRegionEncodedIntoId() {
|
||||
Location location = new LocationImpl(LocationScope.REGION, "region", "region", null);
|
||||
|
||||
Provider<Set<? extends Location>> locations = Providers.<Set<? extends Location>> of(ImmutableSet
|
||||
.<Location> of(location));
|
||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet.<Size> of(new SizeImpl("1",
|
||||
"1", "region/1", location, null, ImmutableMap.<String, String> of(), 1, 1, 1, ImagePredicates.any())));
|
||||
|
||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||
TemplateOptions defaultOptions = createMock(TemplateOptions.class);
|
||||
knownImage = createMock(Image.class);
|
||||
|
||||
expect(optionsProvider.get()).andReturn(defaultOptions);
|
||||
|
||||
replay(knownImage);
|
||||
replay(defaultOptions);
|
||||
replay(optionsProvider);
|
||||
replay(templateBuilderProvider);
|
||||
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes, location, optionsProvider,
|
||||
templateBuilderProvider);
|
||||
try {
|
||||
template.imageId("ami").build();
|
||||
assert false;
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
||||
}
|
||||
verify(knownImage);
|
||||
verify(defaultOptions);
|
||||
verify(optionsProvider);
|
||||
verify(templateBuilderProvider);
|
||||
}
|
||||
|
@ -141,18 +173,13 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
|
|||
@SuppressWarnings("unchecked")
|
||||
@Test(expectedExceptions = NoSuchElementException.class)
|
||||
public void testParseOnDemandNotFound() {
|
||||
Location location = new LocationImpl(LocationScope.REGION, "region",
|
||||
"region", null);
|
||||
Location location = new LocationImpl(LocationScope.REGION, "region", "region", null);
|
||||
|
||||
Provider<Set<? extends Location>> locations = Providers
|
||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of(location));
|
||||
Provider<Set<? extends Image>> images = Providers
|
||||
.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers
|
||||
.<Set<? extends Size>> of(ImmutableSet
|
||||
.<Size> of(new SizeImpl("1", "1", "region/1", location, null,
|
||||
ImmutableMap.<String, String> of(), 1, 1, 1,
|
||||
ImagePredicates.any())));
|
||||
Provider<Set<? extends Location>> locations = Providers.<Set<? extends Location>> of(ImmutableSet
|
||||
.<Location> of(location));
|
||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet.<Size> of(new SizeImpl("1",
|
||||
"1", "region/1", location, null, ImmutableMap.<String, String> of(), 1, 1, 1, ImagePredicates.any())));
|
||||
|
||||
Location defaultLocation = createMock(Location.class);
|
||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||
|
@ -162,8 +189,7 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
|
|||
|
||||
expect(defaultLocation.getId()).andReturn("region");
|
||||
expect(optionsProvider.get()).andReturn(defaultOptions);
|
||||
expect(knownImage.getArchitecture()).andReturn(Architecture.X86_32)
|
||||
.atLeastOnce();
|
||||
expect(knownImage.getArchitecture()).andReturn(Architecture.X86_32).atLeastOnce();
|
||||
|
||||
replay(knownImage);
|
||||
replay(defaultOptions);
|
||||
|
@ -171,10 +197,10 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
|
|||
replay(optionsProvider);
|
||||
replay(templateBuilderProvider);
|
||||
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes, defaultLocation, optionsProvider,
|
||||
templateBuilderProvider);
|
||||
|
||||
assertEquals(template.imageId("bad").build().getImage(), knownImage);
|
||||
assertEquals(template.imageId("region/bad").build().getImage(), knownImage);
|
||||
|
||||
verify(knownImage);
|
||||
verify(defaultOptions);
|
||||
|
|
|
@ -51,16 +51,14 @@ import com.google.inject.TypeLiteral;
|
|||
public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
||||
|
||||
public void testCreateImage() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AMIAsyncClient.class.getMethod("createImageInRegion", String.class,
|
||||
String.class, String.class, Array.newInstance(CreateImageOptions.class, 0)
|
||||
.getClass());
|
||||
Method method = AMIAsyncClient.class.getMethod("createImageInRegion", String.class, String.class, String.class,
|
||||
Array.newInstance(CreateImageOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, "name", "instanceId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=CreateImage&InstanceId=instanceId&Name=name",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=CreateImage&InstanceId=instanceId&Name=name",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
@ -68,20 +66,18 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testCreateImageOptions() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = AMIAsyncClient.class.getMethod("createImageInRegion", String.class,
|
||||
String.class, String.class, Array.newInstance(CreateImageOptions.class, 0)
|
||||
.getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, "name", "instanceId",
|
||||
new CreateImageOptions().withDescription("description").noReboot());
|
||||
public void testCreateImageOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AMIAsyncClient.class.getMethod("createImageInRegion", String.class, String.class, String.class,
|
||||
Array.newInstance(CreateImageOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, "name", "instanceId", new CreateImageOptions()
|
||||
.withDescription("description").noReboot());
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=CreateImage&InstanceId=instanceId&Name=name&Description=description&NoReboot=true",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
request,
|
||||
"Version=2010-06-15&Action=CreateImage&InstanceId=instanceId&Name=name&Description=description&NoReboot=true",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
|
||||
|
@ -91,19 +87,19 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
|||
}
|
||||
|
||||
public void testDescribeImages() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AMIAsyncClient.class.getMethod("describeImagesInRegion", String.class, Array
|
||||
.newInstance(DescribeImagesOptions.class, 0).getClass());
|
||||
Method method = AMIAsyncClient.class.getMethod("describeImagesInRegion", String.class, Array.newInstance(
|
||||
DescribeImagesOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, (String) null);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=DescribeImages",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=DescribeImages", "application/x-www-form-urlencoded",
|
||||
false);
|
||||
filter.filter(request);
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Action=DescribeImages&Signature=qE4vexSFJqS0UWK%2BccV3s%2BP9woL3M5HI5bTBoM7s%2FLY%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Version=2010-06-15&AWSAccessKeyId=identity",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
request,
|
||||
"Action=DescribeImages&Signature=qE4vexSFJqS0UWK%2BccV3s%2BP9woL3M5HI5bTBoM7s%2FLY%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Version=2010-06-15&AWSAccessKeyId=identity",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeImagesResponseHandler.class);
|
||||
|
@ -112,19 +108,18 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testDescribeImagesOptions() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = AMIAsyncClient.class.getMethod("describeImagesInRegion", String.class, Array
|
||||
.newInstance(DescribeImagesOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, executableBy("me").ownedBy(
|
||||
"fred", "nancy").imageIds("1", "2"));
|
||||
public void testDescribeImagesOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AMIAsyncClient.class.getMethod("describeImagesInRegion", String.class, Array.newInstance(
|
||||
DescribeImagesOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, executableBy("me").ownedBy("fred", "nancy").imageIds(
|
||||
"1", "2"));
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=DescribeImages&ExecutableBy=me&Owner.1=fred&Owner.2=nancy&ImageId.1=1&ImageId.2=2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
request,
|
||||
"Version=2010-06-15&Action=DescribeImages&ExecutableBy=me&Owner.1=fred&Owner.2=nancy&ImageId.1=1&ImageId.2=2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeImagesResponseHandler.class);
|
||||
|
@ -134,14 +129,13 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
|||
}
|
||||
|
||||
public void testDeregisterImage() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AMIAsyncClient.class.getMethod("deregisterImageInRegion", String.class,
|
||||
String.class);
|
||||
Method method = AMIAsyncClient.class.getMethod("deregisterImageInRegion", String.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "imageId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=DeregisterImage&ImageId=imageId",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -150,18 +144,15 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testRegisterImageFromManifest() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = AMIAsyncClient.class.getMethod("registerImageFromManifestInRegion",
|
||||
String.class, String.class, String.class, Array.newInstance(
|
||||
RegisterImageOptions.class, 0).getClass());
|
||||
public void testRegisterImageFromManifest() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AMIAsyncClient.class.getMethod("registerImageFromManifestInRegion", String.class, String.class,
|
||||
String.class, Array.newInstance(RegisterImageOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, "name", "pathToManifest");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=RegisterImage&ImageLocation=pathToManifest&Name=name",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=RegisterImage&ImageLocation=pathToManifest&Name=name",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
@ -169,20 +160,17 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testRegisterImageFromManifestOptions() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = AMIAsyncClient.class.getMethod("registerImageFromManifestInRegion",
|
||||
String.class, String.class, String.class, Array.newInstance(
|
||||
RegisterImageOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, "name", "pathToManifest",
|
||||
new RegisterImageOptions().withDescription("description"));
|
||||
public void testRegisterImageFromManifestOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AMIAsyncClient.class.getMethod("registerImageFromManifestInRegion", String.class, String.class,
|
||||
String.class, Array.newInstance(RegisterImageOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, "name", "pathToManifest", new RegisterImageOptions()
|
||||
.withDescription("description"));
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=RegisterImage&ImageLocation=pathToManifest&Name=name&Description=description",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=RegisterImage&ImageLocation=pathToManifest&Name=name&Description=description",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
|
||||
|
@ -191,19 +179,17 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testRegisterImageBackedByEBS() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = AMIAsyncClient.class.getMethod("registerUnixImageBackedByEbsInRegion",
|
||||
String.class, String.class, String.class, Array.newInstance(
|
||||
RegisterImageBackedByEbsOptions.class, 0).getClass());
|
||||
public void testRegisterImageBackedByEBS() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AMIAsyncClient.class.getMethod("registerUnixImageBackedByEbsInRegion", String.class,
|
||||
String.class, String.class, Array.newInstance(RegisterImageBackedByEbsOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, "imageName", "snapshotId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=RegisterImage&RootDeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.0.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.0.Ebs.SnapshotId=snapshotId&Name=imageName",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
request,
|
||||
"Version=2010-06-15&Action=RegisterImage&RootDeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.0.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.0.Ebs.SnapshotId=snapshotId&Name=imageName",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
@ -211,22 +197,19 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testRegisterImageBackedByEBSOptions() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = AMIAsyncClient.class.getMethod("registerUnixImageBackedByEbsInRegion",
|
||||
String.class, String.class, String.class, Array.newInstance(
|
||||
RegisterImageBackedByEbsOptions.class, 0).getClass());
|
||||
public void testRegisterImageBackedByEBSOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AMIAsyncClient.class.getMethod("registerUnixImageBackedByEbsInRegion", String.class,
|
||||
String.class, String.class, Array.newInstance(RegisterImageBackedByEbsOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, "imageName", "snapshotId",
|
||||
new RegisterImageBackedByEbsOptions().withDescription("description")
|
||||
.addBlockDeviceFromSnapshot("/dev/device", null, "snapshot")
|
||||
.addNewBlockDevice("/dev/newdevice", "newblock", 100));
|
||||
new RegisterImageBackedByEbsOptions().withDescription("description").addBlockDeviceFromSnapshot(
|
||||
"/dev/device", null, "snapshot").addNewBlockDevice("/dev/newdevice", "newblock", 100));
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=RegisterImage&RootDeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.0.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.0.Ebs.SnapshotId=snapshotId&Name=imageName&Description=description&BlockDeviceMapping.1.Ebs.DeleteOnTermination=false&BlockDeviceMapping.1.DeviceName=%2Fdev%2Fdevice&BlockDeviceMapping.1.Ebs.SnapshotId=snapshot&BlockDeviceMapping.2.Ebs.DeleteOnTermination=false&BlockDeviceMapping.2.DeviceName=%2Fdev%2Fnewdevice&BlockDeviceMapping.2.VirtualName=newblock&BlockDeviceMapping.2.Ebs.VolumeSize=100",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
request,
|
||||
"Version=2010-06-15&Action=RegisterImage&RootDeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.0.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.0.Ebs.SnapshotId=snapshotId&Name=imageName&Description=description&BlockDeviceMapping.1.Ebs.DeleteOnTermination=false&BlockDeviceMapping.1.DeviceName=%2Fdev%2Fdevice&BlockDeviceMapping.1.Ebs.SnapshotId=snapshot&BlockDeviceMapping.2.Ebs.DeleteOnTermination=false&BlockDeviceMapping.2.DeviceName=%2Fdev%2Fnewdevice&BlockDeviceMapping.2.VirtualName=newblock&BlockDeviceMapping.2.Ebs.VolumeSize=100",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
|
||||
|
@ -235,18 +218,15 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testGetProductCodesForImage() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = AMIAsyncClient.class.getMethod("getProductCodesForImageInRegion",
|
||||
String.class, String.class);
|
||||
public void testGetProductCodesForImage() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AMIAsyncClient.class.getMethod("getProductCodesForImageInRegion", String.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "imageId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=DescribeImageAttribute&Attribute=productCodes&ImageId=imageId",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=DescribeImageAttribute&Attribute=productCodes&ImageId=imageId",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, ProductCodesHandler.class);
|
||||
|
@ -255,18 +235,16 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testGetBlockDeviceMappingsForImage() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = AMIAsyncClient.class.getMethod("getBlockDeviceMappingsForImageInRegion",
|
||||
String.class, String.class);
|
||||
public void testGetBlockDeviceMappingsForImage() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AMIAsyncClient.class.getMethod("getBlockDeviceMappingsForImageInRegion", String.class,
|
||||
String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "imageId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=DescribeImageAttribute&Attribute=blockDeviceMapping&ImageId=imageId",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=DescribeImageAttribute&Attribute=blockDeviceMapping&ImageId=imageId",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, BlockDeviceMappingHandler.class);
|
||||
|
@ -275,18 +253,15 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testGetLaunchPermissionForImage() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = AMIAsyncClient.class.getMethod("getLaunchPermissionForImageInRegion",
|
||||
String.class, String.class);
|
||||
public void testGetLaunchPermissionForImage() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AMIAsyncClient.class.getMethod("getLaunchPermissionForImageInRegion", String.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "imageId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=DescribeImageAttribute&Attribute=launchPermission&ImageId=imageId",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=DescribeImageAttribute&Attribute=launchPermission&ImageId=imageId",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, PermissionHandler.class);
|
||||
|
@ -295,24 +270,23 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testAddLaunchPermissionsToImage() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = AMIAsyncClient.class.getMethod("addLaunchPermissionsToImageInRegion",
|
||||
String.class, Iterable.class, Iterable.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, ImmutableList.of("bob", "sue"),
|
||||
ImmutableList.of("all"), "imageId");
|
||||
public void testAddLaunchPermissionsToImage() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AMIAsyncClient.class.getMethod("addLaunchPermissionsToImageInRegion", String.class,
|
||||
Iterable.class, Iterable.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, ImmutableList.of("bob", "sue"), ImmutableList
|
||||
.of("all"), "imageId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=ModifyImageAttribute&OperationType=add&Attribute=launchPermission&ImageId=imageId&UserGroup.1=all&UserId.1=bob&UserId.2=sue",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
request,
|
||||
"Version=2010-06-15&Action=ModifyImageAttribute&OperationType=add&Attribute=launchPermission&ImageId=imageId&UserGroup.1=all&UserId.1=bob&UserId.2=sue",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
filter.filter(request);
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Action=ModifyImageAttribute&Attribute=launchPermission&ImageId=imageId&OperationType=add&Signature=WZzNWOC1KHbuySvXEuLTiBA%2BVUfKpSBN2Lud6MrhlCQ%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&UserGroup.1=all&UserId.1=bob&UserId.2=sue&Version=2010-06-15&AWSAccessKeyId=identity",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
request,
|
||||
"Action=ModifyImageAttribute&Attribute=launchPermission&ImageId=imageId&OperationType=add&Signature=WZzNWOC1KHbuySvXEuLTiBA%2BVUfKpSBN2Lud6MrhlCQ%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&UserGroup.1=all&UserId.1=bob&UserId.2=sue&Version=2010-06-15&AWSAccessKeyId=identity",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -321,19 +295,18 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testRemoveLaunchPermissionsFromImage() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = AMIAsyncClient.class.getMethod("removeLaunchPermissionsFromImageInRegion",
|
||||
String.class, Iterable.class, Iterable.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, ImmutableList.of("bob", "sue"),
|
||||
ImmutableList.of("all"), "imageId");
|
||||
public void testRemoveLaunchPermissionsFromImage() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AMIAsyncClient.class.getMethod("removeLaunchPermissionsFromImageInRegion", String.class,
|
||||
Iterable.class, Iterable.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, ImmutableList.of("bob", "sue"), ImmutableList
|
||||
.of("all"), "imageId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=ModifyImageAttribute&OperationType=remove&Attribute=launchPermission&ImageId=imageId&UserGroup.1=all&UserId.1=bob&UserId.2=sue",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
request,
|
||||
"Version=2010-06-15&Action=ModifyImageAttribute&OperationType=remove&Attribute=launchPermission&ImageId=imageId&UserGroup.1=all&UserId.1=bob&UserId.2=sue",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
@ -341,18 +314,16 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testResetLaunchPermissionsOnImage() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = AMIAsyncClient.class.getMethod("resetLaunchPermissionsOnImageInRegion",
|
||||
String.class, String.class);
|
||||
public void testResetLaunchPermissionsOnImage() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AMIAsyncClient.class.getMethod("resetLaunchPermissionsOnImageInRegion", String.class,
|
||||
String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "imageId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=ResetImageAttribute&Attribute=launchPermission&ImageId=imageId",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=ResetImageAttribute&Attribute=launchPermission&ImageId=imageId",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
@ -360,19 +331,17 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testAddProductCodesToImage() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = AMIAsyncClient.class.getMethod("addProductCodesToImageInRegion",
|
||||
String.class, Iterable.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, ImmutableList
|
||||
.of("code1", "code2"), "imageId");
|
||||
public void testAddProductCodesToImage() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AMIAsyncClient.class.getMethod("addProductCodesToImageInRegion", String.class, Iterable.class,
|
||||
String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, ImmutableList.of("code1", "code2"), "imageId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=ModifyImageAttribute&OperationType=add&Attribute=productCodes&ImageId=imageId&ProductCode.1=code1&ProductCode.2=code2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
request,
|
||||
"Version=2010-06-15&Action=ModifyImageAttribute&OperationType=add&Attribute=productCodes&ImageId=imageId&ProductCode.1=code1&ProductCode.2=code2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -381,19 +350,17 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testRemoveProductCodesFromImage() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = AMIAsyncClient.class.getMethod("removeProductCodesFromImageInRegion",
|
||||
String.class, Iterable.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, ImmutableList
|
||||
.of("code1", "code2"), "imageId");
|
||||
public void testRemoveProductCodesFromImage() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AMIAsyncClient.class.getMethod("removeProductCodesFromImageInRegion", String.class,
|
||||
Iterable.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, ImmutableList.of("code1", "code2"), "imageId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=ModifyImageAttribute&OperationType=remove&Attribute=productCodes&ImageId=imageId&ProductCode.1=code1&ProductCode.2=code2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
request,
|
||||
"Version=2010-06-15&Action=ModifyImageAttribute&OperationType=remove&Attribute=productCodes&ImageId=imageId&ProductCode.1=code1&ProductCode.2=code2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
|
|
@ -45,19 +45,17 @@ import com.google.inject.TypeLiteral;
|
|||
*/
|
||||
@Test(groups = "unit", testName = "ec2.AvailabilityZoneAndRegionAsyncClientTest")
|
||||
public class AvailabilityZoneAndRegionAsyncClientTest extends
|
||||
BaseEC2AsyncClientTest<AvailabilityZoneAndRegionAsyncClient> {
|
||||
BaseEC2AsyncClientTest<AvailabilityZoneAndRegionAsyncClient> {
|
||||
|
||||
public void testDescribeAvailabilityZones() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = AvailabilityZoneAndRegionAsyncClient.class.getMethod(
|
||||
"describeAvailabilityZonesInRegion", String.class, Array.newInstance(
|
||||
DescribeAvailabilityZonesOptions.class, 0).getClass());
|
||||
public void testDescribeAvailabilityZones() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AvailabilityZoneAndRegionAsyncClient.class.getMethod("describeAvailabilityZonesInRegion",
|
||||
String.class, Array.newInstance(DescribeAvailabilityZonesOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, Region.US_WEST_1);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-west-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-west-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=DescribeAvailabilityZones",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeAvailabilityZonesResponseHandler.class);
|
||||
|
@ -66,20 +64,17 @@ public class AvailabilityZoneAndRegionAsyncClientTest extends
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testDescribeAvailabilityZonesOptions() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = AvailabilityZoneAndRegionAsyncClient.class.getMethod(
|
||||
"describeAvailabilityZonesInRegion", String.class, Array.newInstance(
|
||||
DescribeAvailabilityZonesOptions.class, 0).getClass());
|
||||
public void testDescribeAvailabilityZonesOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AvailabilityZoneAndRegionAsyncClient.class.getMethod("describeAvailabilityZonesInRegion",
|
||||
String.class, Array.newInstance(DescribeAvailabilityZonesOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, Region.US_EAST_1, availabilityZones(
|
||||
AvailabilityZone.US_EAST_1A, AvailabilityZone.US_EAST_1B));
|
||||
AvailabilityZone.US_EAST_1A, AvailabilityZone.US_EAST_1B));
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=DescribeAvailabilityZones&ZoneName.1=us-east-1a&ZoneName.2=us-east-1b",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=DescribeAvailabilityZones&ZoneName.1=us-east-1a&ZoneName.2=us-east-1b",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeAvailabilityZonesResponseHandler.class);
|
||||
|
@ -89,14 +84,14 @@ public class AvailabilityZoneAndRegionAsyncClientTest extends
|
|||
}
|
||||
|
||||
public void testDescribeRegions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AvailabilityZoneAndRegionAsyncClient.class.getMethod("describeRegions", Array
|
||||
.newInstance(DescribeRegionsOptions.class, 0).getClass());
|
||||
Method method = AvailabilityZoneAndRegionAsyncClient.class.getMethod("describeRegions", Array.newInstance(
|
||||
DescribeRegionsOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=DescribeRegions",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=DescribeRegions", "application/x-www-form-urlencoded",
|
||||
false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeRegionsResponseHandler.class);
|
||||
|
@ -105,19 +100,16 @@ public class AvailabilityZoneAndRegionAsyncClientTest extends
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testDescribeRegionsOptions() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = AvailabilityZoneAndRegionAsyncClient.class.getMethod("describeRegions", Array
|
||||
.newInstance(DescribeRegionsOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, regions(Region.US_EAST_1,
|
||||
Region.US_WEST_1));
|
||||
public void testDescribeRegionsOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AvailabilityZoneAndRegionAsyncClient.class.getMethod("describeRegions", Array.newInstance(
|
||||
DescribeRegionsOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, regions(Region.US_EAST_1, Region.US_WEST_1));
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=DescribeRegions&RegionName.1=us-east-1&RegionName.2=us-west-1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=DescribeRegions&RegionName.1=us-east-1&RegionName.2=us-west-1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeRegionsResponseHandler.class);
|
||||
|
|
|
@ -58,21 +58,20 @@ public abstract class BaseEC2AsyncClientTest<T> extends RestClientTest<T> {
|
|||
|
||||
@Override
|
||||
protected String provideTimeStamp(final DateService dateService,
|
||||
@Named(Constants.PROPERTY_SESSION_INTERVAL) final int expiration) {
|
||||
@Named(Constants.PROPERTY_SESSION_INTERVAL) final int expiration) {
|
||||
return "2009-11-08T15:54:08.897Z";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, URI> provideRegions(Injector client) {
|
||||
return ImmutableMap.<String, URI> of(Region.EU_WEST_1, URI
|
||||
.create("https://ec2.eu-west-1.amazonaws.com"), Region.US_EAST_1, URI
|
||||
.create("https://ec2.us-east-1.amazonaws.com"), Region.US_WEST_1, URI
|
||||
.create("https://ec2.us-west-1.amazonaws.com"));
|
||||
return ImmutableMap.<String, URI> of(Region.EU_WEST_1, URI.create("https://ec2.eu-west-1.amazonaws.com"),
|
||||
Region.US_EAST_1, URI.create("https://ec2.us-east-1.amazonaws.com"), Region.US_WEST_1, URI
|
||||
.create("https://ec2.us-west-1.amazonaws.com"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, String> provideAvailabilityZoneToRegions(EC2Client client,
|
||||
@org.jclouds.aws.Region Map<String, URI> regions) {
|
||||
@org.jclouds.aws.Region Map<String, URI> regions) {
|
||||
return ImmutableMap.<String, String> of(AvailabilityZone.US_EAST_1A, Region.US_EAST_1);
|
||||
}
|
||||
}
|
||||
|
@ -103,8 +102,7 @@ public abstract class BaseEC2AsyncClientTest<T> extends RestClientTest<T> {
|
|||
|
||||
@Override
|
||||
public ContextSpec<?, ?> createContextSpec() {
|
||||
return new RestContextFactory().createContextSpec("ec2", "identity", "credential",
|
||||
new Properties());
|
||||
return new RestContextFactory().createContextSpec("ec2", "identity", "credential", new Properties());
|
||||
}
|
||||
|
||||
}
|
|
@ -51,19 +51,35 @@ import com.google.inject.TypeLiteral;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "ec2.ElasticBlockStoreAsyncClientTest")
|
||||
public class ElasticBlockStoreAsyncClientTest extends
|
||||
BaseEC2AsyncClientTest<ElasticBlockStoreAsyncClient> {
|
||||
public class ElasticBlockStoreAsyncClientTest extends BaseEC2AsyncClientTest<ElasticBlockStoreAsyncClient> {
|
||||
|
||||
public void testCreateVolume() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ElasticBlockStoreAsyncClient.class.getMethod(
|
||||
"createVolumeInAvailabilityZone", String.class, int.class);
|
||||
Method method = ElasticBlockStoreAsyncClient.class.getMethod("createVolumeInAvailabilityZone", String.class,
|
||||
int.class);
|
||||
HttpRequest request = processor.createRequest(method, AvailabilityZone.US_EAST_1A, 20);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=CreateVolume&AvailabilityZone=us-east-1a&Size=20",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, CreateVolumeResponseHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testCreateVolumeFromSnapShot() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ElasticBlockStoreAsyncClient.class.getMethod("createVolumeFromSnapshotInAvailabilityZone",
|
||||
String.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, AvailabilityZone.US_EAST_1A, "snapshotId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=CreateVolume&AvailabilityZone=us-east-1a&Size=20",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
"Version=2010-06-15&Action=CreateVolume&AvailabilityZone=us-east-1a&SnapshotId=snapshotId",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, CreateVolumeResponseHandler.class);
|
||||
|
@ -72,40 +88,16 @@ public class ElasticBlockStoreAsyncClientTest extends
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testCreateVolumeFromSnapShot() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = ElasticBlockStoreAsyncClient.class.getMethod(
|
||||
"createVolumeFromSnapshotInAvailabilityZone", String.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, AvailabilityZone.US_EAST_1A,
|
||||
"snapshotId");
|
||||
public void testCreateVolumeFromSnapShotWithSize() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ElasticBlockStoreAsyncClient.class.getMethod("createVolumeFromSnapshotInAvailabilityZone",
|
||||
String.class, int.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, AvailabilityZone.US_EAST_1A, 15, "snapshotId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=CreateVolume&AvailabilityZone=us-east-1a&SnapshotId=snapshotId",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, CreateVolumeResponseHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testCreateVolumeFromSnapShotWithSize() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = ElasticBlockStoreAsyncClient.class.getMethod(
|
||||
"createVolumeFromSnapshotInAvailabilityZone", String.class, int.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, AvailabilityZone.US_EAST_1A, 15,
|
||||
"snapshotId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=CreateVolume&AvailabilityZone=us-east-1a&SnapshotId=snapshotId&Size=15",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=CreateVolume&AvailabilityZone=us-east-1a&SnapshotId=snapshotId&Size=15",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, CreateVolumeResponseHandler.class);
|
||||
|
@ -115,14 +107,13 @@ public class ElasticBlockStoreAsyncClientTest extends
|
|||
}
|
||||
|
||||
public void testDeleteVolume() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ElasticBlockStoreAsyncClient.class.getMethod("deleteVolumeInRegion",
|
||||
String.class, String.class);
|
||||
Method method = ElasticBlockStoreAsyncClient.class.getMethod("deleteVolumeInRegion", String.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "id");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=DeleteVolume&VolumeId=id",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -132,14 +123,14 @@ public class ElasticBlockStoreAsyncClientTest extends
|
|||
}
|
||||
|
||||
public void testDescribeVolumes() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ElasticBlockStoreAsyncClient.class.getMethod("describeVolumesInRegion",
|
||||
String.class, Array.newInstance(String.class, 0).getClass());
|
||||
Method method = ElasticBlockStoreAsyncClient.class.getMethod("describeVolumesInRegion", String.class, Array
|
||||
.newInstance(String.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, (String) null);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=DescribeVolumes",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=DescribeVolumes", "application/x-www-form-urlencoded",
|
||||
false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeVolumesResponseHandler.class);
|
||||
|
@ -148,17 +139,15 @@ public class ElasticBlockStoreAsyncClientTest extends
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testDescribeVolumesArgs() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = ElasticBlockStoreAsyncClient.class.getMethod("describeVolumesInRegion",
|
||||
String.class, Array.newInstance(String.class, 0).getClass());
|
||||
public void testDescribeVolumesArgs() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ElasticBlockStoreAsyncClient.class.getMethod("describeVolumesInRegion", String.class, Array
|
||||
.newInstance(String.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, "1", "2");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=DescribeVolumes&VolumeId.1=1&VolumeId.2=2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=DescribeVolumes&VolumeId.1=1&VolumeId.2=2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeVolumesResponseHandler.class);
|
||||
|
@ -168,16 +157,15 @@ public class ElasticBlockStoreAsyncClientTest extends
|
|||
}
|
||||
|
||||
public void testAttachVolume() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ElasticBlockStoreAsyncClient.class.getMethod("attachVolumeInRegion",
|
||||
String.class, String.class, String.class, String.class);
|
||||
Method method = ElasticBlockStoreAsyncClient.class.getMethod("attachVolumeInRegion", String.class, String.class,
|
||||
String.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "id", "instanceId", "/device");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=AttachVolume&InstanceId=instanceId&VolumeId=id&Device=%2Fdevice",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=AttachVolume&InstanceId=instanceId&VolumeId=id&Device=%2Fdevice",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, AttachmentHandler.class);
|
||||
|
@ -187,16 +175,14 @@ public class ElasticBlockStoreAsyncClientTest extends
|
|||
}
|
||||
|
||||
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());
|
||||
Method method = ElasticBlockStoreAsyncClient.class.getMethod("detachVolumeInRegion", String.class, String.class,
|
||||
boolean.class, Array.newInstance(DetachVolumeOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, "id", false);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=DetachVolume&Force=false&VolumeId=id",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=DetachVolume&Force=false&VolumeId=id",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -205,20 +191,17 @@ public class ElasticBlockStoreAsyncClientTest extends
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testDetachVolumeOptions() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = ElasticBlockStoreAsyncClient.class.getMethod("detachVolumeInRegion",
|
||||
String.class, String.class, boolean.class, Array.newInstance(
|
||||
DetachVolumeOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, "id", true, fromInstance(
|
||||
"instanceId").fromDevice("/device"));
|
||||
public void testDetachVolumeOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ElasticBlockStoreAsyncClient.class.getMethod("detachVolumeInRegion", String.class, String.class,
|
||||
boolean.class, Array.newInstance(DetachVolumeOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, "id", true, fromInstance("instanceId").fromDevice(
|
||||
"/device"));
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=DetachVolume&Force=true&VolumeId=id&InstanceId=instanceId&Device=%2Fdevice",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=DetachVolume&Force=true&VolumeId=id&InstanceId=instanceId&Device=%2Fdevice",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -228,15 +211,14 @@ public class ElasticBlockStoreAsyncClientTest extends
|
|||
}
|
||||
|
||||
public void testCreateSnapshot() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ElasticBlockStoreAsyncClient.class.getMethod("createSnapshotInRegion",
|
||||
String.class, String.class, Array.newInstance(CreateSnapshotOptions.class, 0)
|
||||
.getClass());
|
||||
Method method = ElasticBlockStoreAsyncClient.class.getMethod("createSnapshotInRegion", String.class,
|
||||
String.class, Array.newInstance(CreateSnapshotOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, "volumeId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=CreateSnapshot&VolumeId=volumeId",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, SnapshotHandler.class);
|
||||
|
@ -245,20 +227,17 @@ public class ElasticBlockStoreAsyncClientTest extends
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testCreateSnapshotOptions() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = ElasticBlockStoreAsyncClient.class.getMethod("createSnapshotInRegion",
|
||||
String.class, String.class, Array.newInstance(CreateSnapshotOptions.class, 0)
|
||||
.getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, "volumeId",
|
||||
CreateSnapshotOptions.Builder.withDescription("description"));
|
||||
public void testCreateSnapshotOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ElasticBlockStoreAsyncClient.class.getMethod("createSnapshotInRegion", String.class,
|
||||
String.class, Array.newInstance(CreateSnapshotOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, "volumeId", CreateSnapshotOptions.Builder
|
||||
.withDescription("description"));
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=CreateSnapshot&VolumeId=volumeId&Description=description",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=CreateSnapshot&VolumeId=volumeId&Description=description",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, SnapshotHandler.class);
|
||||
|
@ -268,14 +247,14 @@ public class ElasticBlockStoreAsyncClientTest extends
|
|||
}
|
||||
|
||||
public void testDescribeSnapshots() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ElasticBlockStoreAsyncClient.class.getMethod("describeSnapshotsInRegion",
|
||||
String.class, Array.newInstance(DescribeSnapshotsOptions.class, 0).getClass());
|
||||
Method method = ElasticBlockStoreAsyncClient.class.getMethod("describeSnapshotsInRegion", String.class, Array
|
||||
.newInstance(DescribeSnapshotsOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, (String) null);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=DescribeSnapshots",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=DescribeSnapshots", "application/x-www-form-urlencoded",
|
||||
false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeSnapshotsResponseHandler.class);
|
||||
|
@ -284,19 +263,18 @@ public class ElasticBlockStoreAsyncClientTest extends
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testDescribeSnapshotsArgs() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = ElasticBlockStoreAsyncClient.class.getMethod("describeSnapshotsInRegion",
|
||||
String.class, Array.newInstance(DescribeSnapshotsOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, ownedBy("o1", "o2").restorableBy(
|
||||
"r1", "r2").snapshotIds("s1", "s2"));
|
||||
public void testDescribeSnapshotsArgs() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ElasticBlockStoreAsyncClient.class.getMethod("describeSnapshotsInRegion", String.class, Array
|
||||
.newInstance(DescribeSnapshotsOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, ownedBy("o1", "o2").restorableBy("r1", "r2")
|
||||
.snapshotIds("s1", "s2"));
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=DescribeSnapshots&Owner.1=o1&Owner.2=o2&RestorableBy.1=r1&RestorableBy.2=r2&SnapshotId.1=s1&SnapshotId.2=s2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
request,
|
||||
"Version=2010-06-15&Action=DescribeSnapshots&Owner.1=o1&Owner.2=o2&RestorableBy.1=r1&RestorableBy.2=r2&SnapshotId.1=s1&SnapshotId.2=s2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeSnapshotsResponseHandler.class);
|
||||
|
@ -305,18 +283,17 @@ public class ElasticBlockStoreAsyncClientTest extends
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testGetCreateVolumePermissionForSnapshot() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = ElasticBlockStoreAsyncClient.class.getMethod(
|
||||
"getCreateVolumePermissionForSnapshotInRegion", String.class, String.class);
|
||||
public void testGetCreateVolumePermissionForSnapshot() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ElasticBlockStoreAsyncClient.class.getMethod("getCreateVolumePermissionForSnapshotInRegion",
|
||||
String.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "snapshotId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=DescribeSnapshotAttribute&Attribute=createVolumePermission&SnapshotId=snapshotId",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
request,
|
||||
"Version=2010-06-15&Action=DescribeSnapshotAttribute&Attribute=createVolumePermission&SnapshotId=snapshotId",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, PermissionHandler.class);
|
||||
|
@ -325,20 +302,18 @@ public class ElasticBlockStoreAsyncClientTest extends
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testAddCreateVolumePermissionsToSnapshot() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = ElasticBlockStoreAsyncClient.class.getMethod(
|
||||
"addCreateVolumePermissionsToSnapshotInRegion", String.class, Iterable.class,
|
||||
Iterable.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, ImmutableList.of("bob", "sue"),
|
||||
ImmutableList.of("all"), "snapshotId");
|
||||
public void testAddCreateVolumePermissionsToSnapshot() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ElasticBlockStoreAsyncClient.class.getMethod("addCreateVolumePermissionsToSnapshotInRegion",
|
||||
String.class, Iterable.class, Iterable.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, ImmutableList.of("bob", "sue"), ImmutableList
|
||||
.of("all"), "snapshotId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=ModifySnapshotAttribute&OperationType=add&Attribute=createVolumePermission&SnapshotId=snapshotId&UserGroup.1=all&UserId.1=bob&UserId.2=sue",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
request,
|
||||
"Version=2010-06-15&Action=ModifySnapshotAttribute&OperationType=add&Attribute=createVolumePermission&SnapshotId=snapshotId&UserGroup.1=all&UserId.1=bob&UserId.2=sue",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -347,20 +322,19 @@ public class ElasticBlockStoreAsyncClientTest extends
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testRemoveCreateVolumePermissionsFromSnapshot() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = ElasticBlockStoreAsyncClient.class.getMethod(
|
||||
"removeCreateVolumePermissionsFromSnapshotInRegion", String.class, Iterable.class,
|
||||
Iterable.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, ImmutableList.of("bob", "sue"),
|
||||
ImmutableList.of("all"), "snapshotId");
|
||||
public void testRemoveCreateVolumePermissionsFromSnapshot() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = ElasticBlockStoreAsyncClient.class.getMethod("removeCreateVolumePermissionsFromSnapshotInRegion",
|
||||
String.class, Iterable.class, Iterable.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, ImmutableList.of("bob", "sue"), ImmutableList
|
||||
.of("all"), "snapshotId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=ModifySnapshotAttribute&OperationType=remove&Attribute=createVolumePermission&SnapshotId=snapshotId&UserGroup.1=all&UserId.1=bob&UserId.2=sue",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
request,
|
||||
"Version=2010-06-15&Action=ModifySnapshotAttribute&OperationType=remove&Attribute=createVolumePermission&SnapshotId=snapshotId&UserGroup.1=all&UserId.1=bob&UserId.2=sue",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
@ -368,18 +342,17 @@ public class ElasticBlockStoreAsyncClientTest extends
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testResetCreateVolumePermissionsOnSnapshot() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = ElasticBlockStoreAsyncClient.class.getMethod(
|
||||
"resetCreateVolumePermissionsOnSnapshotInRegion", String.class, String.class);
|
||||
public void testResetCreateVolumePermissionsOnSnapshot() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = ElasticBlockStoreAsyncClient.class.getMethod("resetCreateVolumePermissionsOnSnapshotInRegion",
|
||||
String.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "snapshotId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=ResetSnapshotAttribute&Attribute=createVolumePermission&SnapshotId=snapshotId",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=ResetSnapshotAttribute&Attribute=createVolumePermission&SnapshotId=snapshotId",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
|
|
@ -38,20 +38,17 @@ import com.google.inject.TypeLiteral;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "ec2.ElasticIPAddressAsyncClientTest")
|
||||
public class ElasticIPAddressAsyncClientTest extends
|
||||
BaseEC2AsyncClientTest<ElasticIPAddressAsyncClient> {
|
||||
public class ElasticIPAddressAsyncClientTest extends BaseEC2AsyncClientTest<ElasticIPAddressAsyncClient> {
|
||||
|
||||
public void testDisassociateAddress() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = ElasticIPAddressAsyncClient.class.getMethod("disassociateAddressInRegion",
|
||||
String.class, String.class);
|
||||
public void testDisassociateAddress() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ElasticIPAddressAsyncClient.class.getMethod("disassociateAddressInRegion", String.class,
|
||||
String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "127.0.0.1");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=DisassociateAddress&PublicIp=127.0.0.1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=DisassociateAddress&PublicIp=127.0.0.1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -61,15 +58,14 @@ public class ElasticIPAddressAsyncClientTest extends
|
|||
}
|
||||
|
||||
public void testAssociateAddress() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ElasticIPAddressAsyncClient.class.getMethod("associateAddressInRegion",
|
||||
String.class, String.class, String.class);
|
||||
Method method = ElasticIPAddressAsyncClient.class.getMethod("associateAddressInRegion", String.class,
|
||||
String.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "127.0.0.1", "me");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=AssociateAddress&InstanceId=me&PublicIp=127.0.0.1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=AssociateAddress&InstanceId=me&PublicIp=127.0.0.1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -79,14 +75,13 @@ public class ElasticIPAddressAsyncClientTest extends
|
|||
}
|
||||
|
||||
public void testReleaseAddress() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ElasticIPAddressAsyncClient.class.getMethod("releaseAddressInRegion",
|
||||
String.class, String.class);
|
||||
Method method = ElasticIPAddressAsyncClient.class.getMethod("releaseAddressInRegion", String.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "127.0.0.1");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=ReleaseAddress&PublicIp=127.0.0.1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -96,15 +91,14 @@ public class ElasticIPAddressAsyncClientTest extends
|
|||
}
|
||||
|
||||
public void testDescribeAddresses() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ElasticIPAddressAsyncClient.class.getMethod("describeAddressesInRegion",
|
||||
String.class, Array.newInstance(String.class, 0).getClass());
|
||||
Method method = ElasticIPAddressAsyncClient.class.getMethod("describeAddressesInRegion", String.class, Array
|
||||
.newInstance(String.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, "127.0.0.1");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=DescribeAddresses&PublicIp.1=127.0.0.1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=DescribeAddresses&PublicIp.1=127.0.0.1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeAddressesResponseHandler.class);
|
||||
|
@ -114,14 +108,13 @@ public class ElasticIPAddressAsyncClientTest extends
|
|||
}
|
||||
|
||||
public void testAllocateAddress() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ElasticIPAddressAsyncClient.class.getMethod("allocateAddressInRegion",
|
||||
String.class);
|
||||
Method method = ElasticIPAddressAsyncClient.class.getMethod("allocateAddressInRegion", String.class);
|
||||
HttpRequest request = processor.createRequest(method, (String) null);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=AllocateAddress",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=AllocateAddress", "application/x-www-form-urlencoded",
|
||||
false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, AllocateAddressResponseHandler.class);
|
||||
|
|
|
@ -54,14 +54,14 @@ import com.google.inject.TypeLiteral;
|
|||
@Test(groups = "unit", testName = "ec2.InstanceAsyncClientTest")
|
||||
public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyncClient> {
|
||||
public void testDescribeInstances() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod("describeInstancesInRegion",
|
||||
String.class, Array.newInstance(String.class, 0).getClass());
|
||||
Method method = InstanceAsyncClient.class.getMethod("describeInstancesInRegion", String.class, Array.newInstance(
|
||||
String.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, (String) null);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=DescribeInstances",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=DescribeInstances", "application/x-www-form-urlencoded",
|
||||
false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeInstancesResponseHandler.class);
|
||||
|
@ -70,17 +70,15 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testDescribeInstancesArgs() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod("describeInstancesInRegion",
|
||||
String.class, Array.newInstance(String.class, 0).getClass());
|
||||
public void testDescribeInstancesArgs() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod("describeInstancesInRegion", String.class, Array.newInstance(
|
||||
String.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, "1", "2");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=DescribeInstances&InstanceId.1=1&InstanceId.2=2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=DescribeInstances&InstanceId.1=1&InstanceId.2=2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeInstancesResponseHandler.class);
|
||||
|
@ -89,17 +87,15 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testTerminateInstances() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod("terminateInstancesInRegion",
|
||||
String.class, Array.newInstance(String.class, 0).getClass());
|
||||
public void testTerminateInstances() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod("terminateInstancesInRegion", String.class, Array
|
||||
.newInstance(String.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, "1", "2");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=TerminateInstances&InstanceId.1=1&InstanceId.2=2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=TerminateInstances&InstanceId.1=1&InstanceId.2=2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, InstanceStateChangeHandler.class);
|
||||
|
@ -109,16 +105,14 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
}
|
||||
|
||||
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());
|
||||
Method method = InstanceAsyncClient.class.getMethod("runInstancesInRegion", String.class, String.class,
|
||||
String.class, int.class, int.class, Array.newInstance(RunInstancesOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, null, "ami-voo", 1, 1);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=RunInstances&ImageId=ami-voo&MinCount=1&MaxCount=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=RunInstances&ImageId=ami-voo&MinCount=1&MaxCount=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, RunInstancesResponseHandler.class);
|
||||
|
@ -127,22 +121,19 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testRunInstancesOptions() 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());
|
||||
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"));
|
||||
public void testRunInstancesOptions() 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());
|
||||
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(request, "POST https://ec2.eu-west-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.eu-west-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=RunInstances&ImageId=ami-voo&MinCount=1&MaxCount=5&KernelId=kernelId&Monitoring.Enabled=true&SecurityGroup.1=group1&SecurityGroup.2=group2&Placement.AvailabilityZone=eu-west-1a",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
request,
|
||||
"Version=2010-06-15&Action=RunInstances&ImageId=ami-voo&MinCount=1&MaxCount=5&KernelId=kernelId&Monitoring.Enabled=true&SecurityGroup.1=group1&SecurityGroup.2=group2&Placement.AvailabilityZone=eu-west-1a",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, RunInstancesResponseHandler.class);
|
||||
|
@ -152,15 +143,14 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
}
|
||||
|
||||
public void testStopInstances() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod("stopInstancesInRegion", String.class,
|
||||
boolean.class, Array.newInstance(String.class, 0).getClass());
|
||||
Method method = InstanceAsyncClient.class.getMethod("stopInstancesInRegion", String.class, boolean.class, Array
|
||||
.newInstance(String.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, true, "1", "2");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=StopInstances&Force=true&InstanceId.1=1&InstanceId.2=2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=StopInstances&Force=true&InstanceId.1=1&InstanceId.2=2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, InstanceStateChangeHandler.class);
|
||||
|
@ -170,15 +160,14 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
}
|
||||
|
||||
public void testRebootInstances() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod("rebootInstancesInRegion", String.class,
|
||||
Array.newInstance(String.class, 0).getClass());
|
||||
Method method = InstanceAsyncClient.class.getMethod("rebootInstancesInRegion", String.class, Array.newInstance(
|
||||
String.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, "1", "2");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=RebootInstances&InstanceId.1=1&InstanceId.2=2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=RebootInstances&InstanceId.1=1&InstanceId.2=2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -188,15 +177,14 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
}
|
||||
|
||||
public void testStartInstances() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod("startInstancesInRegion", String.class,
|
||||
Array.newInstance(String.class, 0).getClass());
|
||||
Method method = InstanceAsyncClient.class.getMethod("startInstancesInRegion", String.class, Array.newInstance(
|
||||
String.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, "1", "2");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=StartInstances&InstanceId.1=1&InstanceId.2=2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=StartInstances&InstanceId.1=1&InstanceId.2=2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, InstanceStateChangeHandler.class);
|
||||
|
@ -205,18 +193,15 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testGetUserDataForInstanceInRegion() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod("getUserDataForInstanceInRegion",
|
||||
String.class, String.class);
|
||||
public void testGetUserDataForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod("getUserDataForInstanceInRegion", String.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "1");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=DescribeInstanceAttribute&Attribute=userData&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=DescribeInstanceAttribute&Attribute=userData&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, UnencodeStringValueHandler.class);
|
||||
|
@ -225,18 +210,16 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testGetRootDeviceNameForInstanceInRegion() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod("getRootDeviceNameForInstanceInRegion",
|
||||
String.class, String.class);
|
||||
public void testGetRootDeviceNameForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod("getRootDeviceNameForInstanceInRegion", String.class,
|
||||
String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "1");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=DescribeInstanceAttribute&Attribute=rootDeviceName&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=DescribeInstanceAttribute&Attribute=rootDeviceName&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, StringValueHandler.class);
|
||||
|
@ -245,18 +228,15 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testGetRamdiskForInstanceInRegion() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod("getRamdiskForInstanceInRegion",
|
||||
String.class, String.class);
|
||||
public void testGetRamdiskForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod("getRamdiskForInstanceInRegion", String.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "1");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=DescribeInstanceAttribute&Attribute=ramdisk&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=DescribeInstanceAttribute&Attribute=ramdisk&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, StringValueHandler.class);
|
||||
|
@ -265,18 +245,17 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testGetDisableApiTerminationForInstanceInRegion() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod(
|
||||
"isApiTerminationDisabledForInstanceInRegion", String.class, String.class);
|
||||
public void testGetDisableApiTerminationForInstanceInRegion() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod("isApiTerminationDisabledForInstanceInRegion", String.class,
|
||||
String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "1");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=DescribeInstanceAttribute&Attribute=disableApiTermination&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=DescribeInstanceAttribute&Attribute=disableApiTermination&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, BooleanValueHandler.class);
|
||||
|
@ -285,17 +264,14 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testGetKernelForInstanceInRegion() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod("getKernelForInstanceInRegion",
|
||||
String.class, String.class);
|
||||
public void testGetKernelForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod("getKernelForInstanceInRegion", String.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "1");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=DescribeInstanceAttribute&Attribute=kernel&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=DescribeInstanceAttribute&Attribute=kernel&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, StringValueHandler.class);
|
||||
|
@ -304,18 +280,16 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testGetInstanceTypeForInstanceInRegion() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod("getInstanceTypeForInstanceInRegion",
|
||||
String.class, String.class);
|
||||
public void testGetInstanceTypeForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod("getInstanceTypeForInstanceInRegion", String.class,
|
||||
String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "1");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=DescribeInstanceAttribute&Attribute=instanceType&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=DescribeInstanceAttribute&Attribute=instanceType&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, InstanceTypeHandler.class);
|
||||
|
@ -324,19 +298,18 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testGetInstanceInitiatedShutdownBehaviorForInstanceInRegion()
|
||||
throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod(
|
||||
"getInstanceInitiatedShutdownBehaviorForInstanceInRegion", String.class,
|
||||
String.class);
|
||||
public void testGetInstanceInitiatedShutdownBehaviorForInstanceInRegion() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod("getInstanceInitiatedShutdownBehaviorForInstanceInRegion",
|
||||
String.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "1");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=DescribeInstanceAttribute&Attribute=instanceInitiatedShutdownBehavior&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
request,
|
||||
"Version=2010-06-15&Action=DescribeInstanceAttribute&Attribute=instanceInitiatedShutdownBehavior&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, InstanceInitiatedShutdownBehaviorHandler.class);
|
||||
|
@ -345,18 +318,17 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testGetBlockDeviceMappingForInstanceInRegion() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod(
|
||||
"getBlockDeviceMappingForInstanceInRegion", String.class, String.class);
|
||||
public void testGetBlockDeviceMappingForInstanceInRegion() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod("getBlockDeviceMappingForInstanceInRegion", String.class,
|
||||
String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "1");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=DescribeInstanceAttribute&Attribute=blockDeviceMapping&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=DescribeInstanceAttribute&Attribute=blockDeviceMapping&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, BlockDeviceMappingHandler.class);
|
||||
|
@ -365,23 +337,21 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
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());
|
||||
public void testSetUserDataForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod("setUserDataForInstanceInRegion", String.class, String.class,
|
||||
Array.newInstance(byte.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, "1", "test".getBytes());
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=ModifyInstanceAttribute&Attribute=userData&Value=dGVzdA%3D%3D&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=ModifyInstanceAttribute&Attribute=userData&Value=dGVzdA%3D%3D&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
filter.filter(request);// ensure encoding worked properly
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Action=ModifyInstanceAttribute&Attribute=userData&InstanceId=1&Signature=LfUmzLM5DsACR5nQcEfGF5FPdznOwwhJ7tjhBWfHtGs%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Value=dGVzdA%3D%3D&Version=2010-06-15&AWSAccessKeyId=identity",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
request,
|
||||
"Action=ModifyInstanceAttribute&Attribute=userData&InstanceId=1&Signature=LfUmzLM5DsACR5nQcEfGF5FPdznOwwhJ7tjhBWfHtGs%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Value=dGVzdA%3D%3D&Version=2010-06-15&AWSAccessKeyId=identity",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
@ -389,18 +359,16 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testSetRamdiskForInstanceInRegion() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod("setRamdiskForInstanceInRegion",
|
||||
String.class, String.class, String.class);
|
||||
public void testSetRamdiskForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod("setRamdiskForInstanceInRegion", String.class, String.class,
|
||||
String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "1", "test");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=ModifyInstanceAttribute&Attribute=ramdisk&Value=test&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=ModifyInstanceAttribute&Attribute=ramdisk&Value=test&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
@ -408,18 +376,16 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testSetKernelForInstanceInRegion() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod("setKernelForInstanceInRegion",
|
||||
String.class, String.class, String.class);
|
||||
public void testSetKernelForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod("setKernelForInstanceInRegion", String.class, String.class,
|
||||
String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "1", "test");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=ModifyInstanceAttribute&Attribute=kernel&Value=test&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=ModifyInstanceAttribute&Attribute=kernel&Value=test&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
@ -427,19 +393,18 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testSetApiTerminationDisabledForInstanceInRegion() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod(
|
||||
"setApiTerminationDisabledForInstanceInRegion", String.class, String.class,
|
||||
boolean.class);
|
||||
public void testSetApiTerminationDisabledForInstanceInRegion() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod("setApiTerminationDisabledForInstanceInRegion", String.class,
|
||||
String.class, boolean.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "1", true);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=ModifyInstanceAttribute&Attribute=disableApiTermination&Value=true&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
request,
|
||||
"Version=2010-06-15&Action=ModifyInstanceAttribute&Attribute=disableApiTermination&Value=true&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -448,18 +413,16 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testSetInstanceTypeForInstanceInRegion() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod("setInstanceTypeForInstanceInRegion",
|
||||
String.class, String.class, String.class);
|
||||
public void testSetInstanceTypeForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod("setInstanceTypeForInstanceInRegion", String.class,
|
||||
String.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "1", InstanceType.C1_MEDIUM);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=ModifyInstanceAttribute&Attribute=instanceType&Value=c1.medium&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=ModifyInstanceAttribute&Attribute=instanceType&Value=c1.medium&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -468,20 +431,18 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testSetInstanceInitiatedShutdownBehaviorForInstanceInRegion()
|
||||
throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod(
|
||||
"setInstanceInitiatedShutdownBehaviorForInstanceInRegion", String.class,
|
||||
String.class, InstanceInitiatedShutdownBehavior.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "1",
|
||||
InstanceInitiatedShutdownBehavior.TERMINATE);
|
||||
public void testSetInstanceInitiatedShutdownBehaviorForInstanceInRegion() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod("setInstanceInitiatedShutdownBehaviorForInstanceInRegion",
|
||||
String.class, String.class, InstanceInitiatedShutdownBehavior.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "1", InstanceInitiatedShutdownBehavior.TERMINATE);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=ModifyInstanceAttribute&Attribute=instanceInitiatedShutdownBehavior&Value=terminate&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
request,
|
||||
"Version=2010-06-15&Action=ModifyInstanceAttribute&Attribute=instanceInitiatedShutdownBehavior&Value=terminate&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -490,28 +451,26 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testSetBlockDeviceMappingForInstanceInRegion() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod(
|
||||
"setBlockDeviceMappingForInstanceInRegion", String.class, String.class,
|
||||
BlockDeviceMapping.class);
|
||||
public void testSetBlockDeviceMappingForInstanceInRegion() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = InstanceAsyncClient.class.getMethod("setBlockDeviceMappingForInstanceInRegion", String.class,
|
||||
String.class, BlockDeviceMapping.class);
|
||||
|
||||
BlockDeviceMapping blockDeviceMapping = new BlockDeviceMapping();
|
||||
blockDeviceMapping.addEbsBlockDevice("/dev/sda1", new RunningInstance.EbsBlockDevice(
|
||||
"vol-test1", true));
|
||||
blockDeviceMapping.addEbsBlockDevice("/dev/sda1", new RunningInstance.EbsBlockDevice("vol-test1", true));
|
||||
HttpRequest request = processor.createRequest(method, null, "1", blockDeviceMapping);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=ModifyInstanceAttribute&InstanceId=1&BlockDeviceMapping.1.Ebs.VolumeId=vol-test1&BlockDeviceMapping.1.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.1.Ebs.DeleteOnTermination=true",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
request,
|
||||
"Version=2010-06-15&Action=ModifyInstanceAttribute&InstanceId=1&BlockDeviceMapping.1.Ebs.VolumeId=vol-test1&BlockDeviceMapping.1.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.1.Ebs.DeleteOnTermination=true",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
filter.filter(request);// ensure encoding worked properly
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Action=ModifyInstanceAttribute&BlockDeviceMapping.1.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.1.Ebs.DeleteOnTermination=true&BlockDeviceMapping.1.Ebs.VolumeId=vol-test1&InstanceId=1&Signature=RwY8lVPHSQxQkd5efUKccHdSTkN4OxMIMFiYAe3rrUE%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Version=2010-06-15&AWSAccessKeyId=identity",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
request,
|
||||
"Action=ModifyInstanceAttribute&BlockDeviceMapping.1.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.1.Ebs.DeleteOnTermination=true&BlockDeviceMapping.1.Ebs.VolumeId=vol-test1&InstanceId=1&Signature=RwY8lVPHSQxQkd5efUKccHdSTkN4OxMIMFiYAe3rrUE%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Version=2010-06-15&AWSAccessKeyId=identity",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
|
|
@ -40,14 +40,13 @@ import com.google.inject.TypeLiteral;
|
|||
public class KeyPairAsyncClientTest extends BaseEC2AsyncClientTest<KeyPairAsyncClient> {
|
||||
|
||||
public void testDeleteKeyPair() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = KeyPairAsyncClient.class.getMethod("deleteKeyPairInRegion", String.class,
|
||||
String.class);
|
||||
Method method = KeyPairAsyncClient.class.getMethod("deleteKeyPairInRegion", String.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "mykey");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=DeleteKeyPair&KeyName=mykey",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -57,14 +56,14 @@ public class KeyPairAsyncClientTest extends BaseEC2AsyncClientTest<KeyPairAsyncC
|
|||
}
|
||||
|
||||
public void testDescribeKeyPairs() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = KeyPairAsyncClient.class.getMethod("describeKeyPairsInRegion", String.class,
|
||||
Array.newInstance(String.class, 0).getClass());
|
||||
Method method = KeyPairAsyncClient.class.getMethod("describeKeyPairsInRegion", String.class, Array.newInstance(
|
||||
String.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, (String) null);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=DescribeKeyPairs",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=DescribeKeyPairs", "application/x-www-form-urlencoded",
|
||||
false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeKeyPairsResponseHandler.class);
|
||||
|
@ -73,17 +72,15 @@ public class KeyPairAsyncClientTest extends BaseEC2AsyncClientTest<KeyPairAsyncC
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testDescribeKeyPairsArgs() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = KeyPairAsyncClient.class.getMethod("describeKeyPairsInRegion", String.class,
|
||||
Array.newInstance(String.class, 0).getClass());
|
||||
public void testDescribeKeyPairsArgs() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = KeyPairAsyncClient.class.getMethod("describeKeyPairsInRegion", String.class, Array.newInstance(
|
||||
String.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, "1", "2");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=DescribeKeyPairs&KeyName.1=1&KeyName.2=2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=DescribeKeyPairs&KeyName.1=1&KeyName.2=2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeKeyPairsResponseHandler.class);
|
||||
|
|
|
@ -38,10 +38,9 @@ import com.google.inject.TypeLiteral;
|
|||
@Test(groups = "unit", testName = "ec2.MonitoringAsyncClientTest")
|
||||
public class MonitoringAsyncClientTest extends BaseEC2AsyncClientTest<MonitoringAsyncClient> {
|
||||
|
||||
public void testUnmonitorInstances() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = MonitoringAsyncClient.class.getMethod("unmonitorInstancesInRegion",
|
||||
String.class, String.class, Array.newInstance(String.class, 0).getClass());
|
||||
public void testUnmonitorInstances() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = MonitoringAsyncClient.class.getMethod("unmonitorInstancesInRegion", String.class, String.class,
|
||||
Array.newInstance(String.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, "instance1", "instance2");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
|
@ -57,16 +56,15 @@ public class MonitoringAsyncClientTest extends BaseEC2AsyncClientTest<Monitoring
|
|||
}
|
||||
|
||||
public void testMonitorInstances() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = MonitoringAsyncClient.class.getMethod("monitorInstancesInRegion",
|
||||
String.class, String.class, Array.newInstance(String.class, 0).getClass());
|
||||
Method method = MonitoringAsyncClient.class.getMethod("monitorInstancesInRegion", String.class, String.class,
|
||||
Array.newInstance(String.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, "instance1", "instance2");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=MonitorInstances&InstanceId.0=instance1&InstanceId.1=instance2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=MonitorInstances&InstanceId.0=instance1&InstanceId.1=instance2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, MonitoringStateHandler.class);
|
||||
|
|
|
@ -42,16 +42,15 @@ import com.google.inject.TypeLiteral;
|
|||
@Test(groups = "unit", testName = "ec2.SecurityGroupAsyncClientTest")
|
||||
public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest<SecurityGroupAsyncClient> {
|
||||
|
||||
public void testDeleteSecurityGroup() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = SecurityGroupAsyncClient.class.getMethod("deleteSecurityGroupInRegion",
|
||||
String.class, String.class);
|
||||
public void testDeleteSecurityGroup() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = SecurityGroupAsyncClient.class.getMethod("deleteSecurityGroupInRegion", String.class,
|
||||
String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "name");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=DeleteSecurityGroup&GroupName=name",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -60,18 +59,16 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest<Securit
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testCreateSecurityGroup() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = SecurityGroupAsyncClient.class.getMethod("createSecurityGroupInRegion",
|
||||
String.class, String.class, String.class);
|
||||
public void testCreateSecurityGroup() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = SecurityGroupAsyncClient.class.getMethod("createSecurityGroupInRegion", String.class,
|
||||
String.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "name", "description");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=CreateSecurityGroup&GroupDescription=description&GroupName=name",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=CreateSecurityGroup&GroupDescription=description&GroupName=name",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -80,16 +77,15 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest<Securit
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testDescribeSecurityGroups() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = SecurityGroupAsyncClient.class.getMethod("describeSecurityGroupsInRegion",
|
||||
String.class, Array.newInstance(String.class, 0).getClass());
|
||||
public void testDescribeSecurityGroups() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = SecurityGroupAsyncClient.class.getMethod("describeSecurityGroupsInRegion", String.class, Array
|
||||
.newInstance(String.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, (String) null);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=DescribeSecurityGroups",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeSecurityGroupsResponseHandler.class);
|
||||
|
@ -98,17 +94,15 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest<Securit
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testDescribeSecurityGroupsArgs() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = SecurityGroupAsyncClient.class.getMethod("describeSecurityGroupsInRegion",
|
||||
String.class, Array.newInstance(String.class, 0).getClass());
|
||||
public void testDescribeSecurityGroupsArgs() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = SecurityGroupAsyncClient.class.getMethod("describeSecurityGroupsInRegion", String.class, Array
|
||||
.newInstance(String.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, "1", "2");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2010-06-15&Action=DescribeSecurityGroups&GroupName.1=1&GroupName.2=2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request, "Version=2010-06-15&Action=DescribeSecurityGroups&GroupName.1=1&GroupName.2=2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeSecurityGroupsResponseHandler.class);
|
||||
|
@ -117,20 +111,18 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest<Securit
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testAuthorizeSecurityGroupIngressGroup() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = SecurityGroupAsyncClient.class.getMethod(
|
||||
"authorizeSecurityGroupIngressInRegion", String.class, String.class,
|
||||
UserIdGroupPair.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "group", new UserIdGroupPair(
|
||||
"sourceUser", "sourceGroup"));
|
||||
public void testAuthorizeSecurityGroupIngressGroup() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = SecurityGroupAsyncClient.class.getMethod("authorizeSecurityGroupIngressInRegion", String.class,
|
||||
String.class, UserIdGroupPair.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "group", new UserIdGroupPair("sourceUser",
|
||||
"sourceGroup"));
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=AuthorizeSecurityGroupIngress&GroupName=group&SourceSecurityGroupOwnerId=sourceUser&SourceSecurityGroupName=sourceGroup",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
request,
|
||||
"Version=2010-06-15&Action=AuthorizeSecurityGroupIngress&GroupName=group&SourceSecurityGroupOwnerId=sourceUser&SourceSecurityGroupName=sourceGroup",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -139,20 +131,17 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest<Securit
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testAuthorizeSecurityGroupIngressCidr() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = SecurityGroupAsyncClient.class.getMethod(
|
||||
"authorizeSecurityGroupIngressInRegion", String.class, String.class,
|
||||
IpProtocol.class, int.class, int.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "group", IpProtocol.TCP, 6000,
|
||||
7000, "0.0.0.0/0");
|
||||
public void testAuthorizeSecurityGroupIngressCidr() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = SecurityGroupAsyncClient.class.getMethod("authorizeSecurityGroupIngressInRegion", String.class,
|
||||
String.class, IpProtocol.class, int.class, int.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "group", IpProtocol.TCP, 6000, 7000, "0.0.0.0/0");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=AuthorizeSecurityGroupIngress&CidrIp=0.0.0.0%2F0&IpProtocol=tcp&GroupName=group&FromPort=6000&ToPort=7000",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
request,
|
||||
"Version=2010-06-15&Action=AuthorizeSecurityGroupIngress&CidrIp=0.0.0.0%2F0&IpProtocol=tcp&GroupName=group&FromPort=6000&ToPort=7000",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -161,20 +150,18 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest<Securit
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testRevokeSecurityGroupIngressGroup() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = SecurityGroupAsyncClient.class.getMethod(
|
||||
"revokeSecurityGroupIngressInRegion", String.class, String.class,
|
||||
UserIdGroupPair.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "group", new UserIdGroupPair(
|
||||
"sourceUser", "sourceGroup"));
|
||||
public void testRevokeSecurityGroupIngressGroup() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = SecurityGroupAsyncClient.class.getMethod("revokeSecurityGroupIngressInRegion", String.class,
|
||||
String.class, UserIdGroupPair.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "group", new UserIdGroupPair("sourceUser",
|
||||
"sourceGroup"));
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=RevokeSecurityGroupIngress&GroupName=group&SourceSecurityGroupOwnerId=sourceUser&SourceSecurityGroupName=sourceGroup",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
request,
|
||||
"Version=2010-06-15&Action=RevokeSecurityGroupIngress&GroupName=group&SourceSecurityGroupOwnerId=sourceUser&SourceSecurityGroupName=sourceGroup",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -183,20 +170,17 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest<Securit
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testRevokeSecurityGroupIngressCidr() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = SecurityGroupAsyncClient.class.getMethod(
|
||||
"revokeSecurityGroupIngressInRegion", String.class, String.class, IpProtocol.class,
|
||||
int.class, int.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "group", IpProtocol.TCP, 6000,
|
||||
7000, "0.0.0.0/0");
|
||||
public void testRevokeSecurityGroupIngressCidr() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = SecurityGroupAsyncClient.class.getMethod("revokeSecurityGroupIngressInRegion", String.class,
|
||||
String.class, IpProtocol.class, int.class, int.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "group", IpProtocol.TCP, 6000, 7000, "0.0.0.0/0");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-06-15&Action=RevokeSecurityGroupIngress&CidrIp=0.0.0.0%2F0&IpProtocol=tcp&GroupName=group&FromPort=6000&ToPort=7000",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
request,
|
||||
"Version=2010-06-15&Action=RevokeSecurityGroupIngress&CidrIp=0.0.0.0%2F0&IpProtocol=tcp&GroupName=group&FromPort=6000&ToPort=7000",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
|
|
@ -27,9 +27,13 @@ import org.jclouds.aws.domain.Region;
|
|||
import org.jclouds.aws.ec2.domain.AvailabilityZone;
|
||||
import org.jclouds.aws.ec2.domain.AvailabilityZoneInfo;
|
||||
import org.jclouds.http.functions.BaseHandlerTest;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Guice;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code DescribeAvailabilityZonesResponseHandler}
|
||||
|
@ -39,23 +43,38 @@ import com.google.common.collect.ImmutableSet;
|
|||
@Test(groups = "unit", testName = "ec2.DescribeAvailabilityZonesResponseHandlerTest")
|
||||
public class DescribeAvailabilityZonesResponseHandlerTest extends BaseHandlerTest {
|
||||
|
||||
@BeforeTest
|
||||
protected void setUpInjector() {
|
||||
injector = Guice.createInjector(new ParserModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bindConstant().annotatedWith(org.jclouds.aws.Region.class).to("SHOULDNTSEETHISASXMLHASREGIONDATA");
|
||||
super.configure();
|
||||
}
|
||||
|
||||
});
|
||||
factory = injector.getInstance(ParseSax.Factory.class);
|
||||
assert factory != null;
|
||||
}
|
||||
|
||||
public void testApplyInputStream() {
|
||||
|
||||
InputStream is = getClass().getResourceAsStream("/ec2/availabilityZones.xml");
|
||||
|
||||
Set<AvailabilityZoneInfo> expected = ImmutableSet.<AvailabilityZoneInfo> of(
|
||||
|
||||
new AvailabilityZoneInfo(AvailabilityZone.US_EAST_1A, "available", Region.US_EAST_1,
|
||||
ImmutableSet.<String> of()), new AvailabilityZoneInfo(AvailabilityZone.US_EAST_1B,
|
||||
"available", Region.US_EAST_1, ImmutableSet.<String> of()),
|
||||
new AvailabilityZoneInfo(AvailabilityZone.US_EAST_1A, "available", Region.US_EAST_1, ImmutableSet.<String> of()),
|
||||
new AvailabilityZoneInfo(AvailabilityZone.US_EAST_1B, "available", Region.US_EAST_1, ImmutableSet
|
||||
.<String> of()),
|
||||
|
||||
new AvailabilityZoneInfo(AvailabilityZone.US_EAST_1C, "available", Region.US_EAST_1,
|
||||
ImmutableSet.<String> of("our service is awesome")),
|
||||
new AvailabilityZoneInfo(AvailabilityZone.US_EAST_1C, "available", Region.US_EAST_1, ImmutableSet
|
||||
.<String> of("our service is awesome")),
|
||||
|
||||
new AvailabilityZoneInfo(AvailabilityZone.US_EAST_1D, "downlikeaclown", Region.US_EAST_1,
|
||||
ImmutableSet.<String> of()));
|
||||
new AvailabilityZoneInfo(AvailabilityZone.US_EAST_1D, "downlikeaclown", Region.US_EAST_1, ImmutableSet
|
||||
.<String> of()));
|
||||
Set<AvailabilityZoneInfo> result = factory.create(
|
||||
injector.getInstance(DescribeAvailabilityZonesResponseHandler.class)).parse(is);
|
||||
injector.getInstance(DescribeAvailabilityZonesResponseHandler.class)).parse(is);
|
||||
|
||||
assertEquals(result, expected);
|
||||
}
|
||||
|
|
|
@ -39,7 +39,6 @@ public abstract class BaseS3AsyncClientTest extends RestClientTest<S3AsyncClient
|
|||
protected BlobToObject blobToS3Object;
|
||||
protected RequestAuthorizeSignature filter;
|
||||
|
||||
|
||||
@Override
|
||||
protected void checkFilters(HttpRequest request) {
|
||||
assertEquals(request.getFilters().size(), 1);
|
||||
|
@ -66,9 +65,7 @@ public abstract class BaseS3AsyncClientTest extends RestClientTest<S3AsyncClient
|
|||
|
||||
@Override
|
||||
public ContextSpec<?, ?> createContextSpec() {
|
||||
return new RestContextFactory().createContextSpec("s3", "identity", "credential",
|
||||
new Properties());
|
||||
return new RestContextFactory().createContextSpec("s3", "identity", "credential", new Properties());
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -81,8 +81,8 @@ import com.google.inject.Module;
|
|||
public class S3AsyncClientTest extends BaseS3AsyncClientTest {
|
||||
|
||||
public void testAllRegions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = S3AsyncClient.class.getMethod("putBucketInRegion", String.class,
|
||||
String.class, Array.newInstance(PutBucketOptions.class, 0).getClass());
|
||||
Method method = S3AsyncClient.class.getMethod("putBucketInRegion", String.class, String.class, Array.newInstance(
|
||||
PutBucketOptions.class, 0).getClass());
|
||||
for (String region : Region.ALL_S3) {
|
||||
processor.createRequest(method, region, "bucket-name");
|
||||
}
|
||||
|
@ -100,8 +100,8 @@ public class S3AsyncClientTest extends BaseS3AsyncClientTest {
|
|||
|
||||
assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/?location HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(
|
||||
request,
|
||||
"Authorization: AWS identity:2fFTeYJTDwiJmaAkKj732RjNbOg=\nDate: 2009-11-08T15:54:08.897Z\nHost: bucket.s3.amazonaws.com\n");
|
||||
request,
|
||||
"Authorization: AWS identity:2fFTeYJTDwiJmaAkKj732RjNbOg=\nDate: 2009-11-08T15:54:08.897Z\nHost: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
|
@ -115,8 +115,7 @@ public class S3AsyncClientTest extends BaseS3AsyncClientTest {
|
|||
Method method = S3AsyncClient.class.getMethod("getBucketPayer", String.class);
|
||||
HttpRequest request = processor.createRequest(method, "bucket");
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://bucket.s3.amazonaws.com/?requestPayment HTTP/1.1");
|
||||
assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/?requestPayment HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -127,18 +126,16 @@ public class S3AsyncClientTest extends BaseS3AsyncClientTest {
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testSetBucketPayerOwner() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
public void testSetBucketPayerOwner() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = S3AsyncClient.class.getMethod("setBucketPayer", String.class, Payer.class);
|
||||
HttpRequest request = processor.createRequest(method, "bucket", Payer.BUCKET_OWNER);
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"PUT https://bucket.s3.amazonaws.com/?requestPayment HTTP/1.1");
|
||||
assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/?requestPayment HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"<RequestPaymentConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Payer>BucketOwner</Payer></RequestPaymentConfiguration>",
|
||||
"text/xml", false);
|
||||
request,
|
||||
"<RequestPaymentConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Payer>BucketOwner</Payer></RequestPaymentConfiguration>",
|
||||
"text/xml", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -147,18 +144,16 @@ public class S3AsyncClientTest extends BaseS3AsyncClientTest {
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testSetBucketPayerRequester() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
public void testSetBucketPayerRequester() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = S3AsyncClient.class.getMethod("setBucketPayer", String.class, Payer.class);
|
||||
HttpRequest request = processor.createRequest(method, "bucket", Payer.REQUESTER);
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"PUT https://bucket.s3.amazonaws.com/?requestPayment HTTP/1.1");
|
||||
assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/?requestPayment HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"<RequestPaymentConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Payer>Requester</Payer></RequestPaymentConfiguration>",
|
||||
"text/xml", false);
|
||||
request,
|
||||
"<RequestPaymentConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Payer>Requester</Payer></RequestPaymentConfiguration>",
|
||||
"text/xml", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -169,7 +164,7 @@ public class S3AsyncClientTest extends BaseS3AsyncClientTest {
|
|||
|
||||
public void testListBucket() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = S3AsyncClient.class.getMethod("listBucket", String.class, Array.newInstance(
|
||||
ListBucketOptions.class, 0).getClass());
|
||||
ListBucketOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, "bucket");
|
||||
|
||||
assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/ HTTP/1.1");
|
||||
|
@ -199,28 +194,24 @@ public class S3AsyncClientTest extends BaseS3AsyncClientTest {
|
|||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testCopyObjectInvalidName() throws ArrayIndexOutOfBoundsException,
|
||||
SecurityException, IllegalArgumentException, NoSuchMethodException, IOException {
|
||||
Method method = S3AsyncClient.class
|
||||
.getMethod("copyObject", String.class, String.class, String.class, String.class,
|
||||
Array.newInstance(CopyObjectOptions.class, 0).getClass());
|
||||
processor.createRequest(method, "sourceBucket", "sourceObject", "destinationBucket",
|
||||
"destinationObject");
|
||||
public void testCopyObjectInvalidName() throws ArrayIndexOutOfBoundsException, SecurityException,
|
||||
IllegalArgumentException, NoSuchMethodException, IOException {
|
||||
Method method = S3AsyncClient.class.getMethod("copyObject", String.class, String.class, String.class,
|
||||
String.class, Array.newInstance(CopyObjectOptions.class, 0).getClass());
|
||||
processor.createRequest(method, "sourceBucket", "sourceObject", "destinationBucket", "destinationObject");
|
||||
|
||||
}
|
||||
|
||||
public void testCopyObject() throws ArrayIndexOutOfBoundsException, SecurityException,
|
||||
IllegalArgumentException, NoSuchMethodException, IOException {
|
||||
Method method = S3AsyncClient.class
|
||||
.getMethod("copyObject", String.class, String.class, String.class, String.class,
|
||||
Array.newInstance(CopyObjectOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, "sourceBucket", "sourceObject",
|
||||
"destinationbucket", "destinationObject");
|
||||
public void testCopyObject() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = S3AsyncClient.class.getMethod("copyObject", String.class, String.class, String.class,
|
||||
String.class, Array.newInstance(CopyObjectOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, "sourceBucket", "sourceObject", "destinationbucket",
|
||||
"destinationObject");
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"PUT https://destinationbucket.s3.amazonaws.com/destinationObject HTTP/1.1");
|
||||
assertRequestLineEquals(request, "PUT https://destinationbucket.s3.amazonaws.com/destinationObject HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request,
|
||||
"Host: destinationbucket.s3.amazonaws.com\nx-amz-copy-source: /sourceBucket/sourceObject\n");
|
||||
"Host: destinationbucket.s3.amazonaws.com\nx-amz-copy-source: /sourceBucket/sourceObject\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
|
@ -230,8 +221,7 @@ public class S3AsyncClientTest extends BaseS3AsyncClientTest {
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testDeleteBucketIfEmpty() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
public void testDeleteBucketIfEmpty() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = S3AsyncClient.class.getMethod("deleteBucketIfEmpty", String.class);
|
||||
HttpRequest request = processor.createRequest(method, "bucket");
|
||||
|
||||
|
@ -277,10 +267,10 @@ public class S3AsyncClientTest extends BaseS3AsyncClientTest {
|
|||
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());
|
||||
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());
|
||||
HttpRequest request = processor.createRequest(method, "bucket", "object");
|
||||
|
||||
assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/object HTTP/1.1");
|
||||
|
@ -363,17 +353,16 @@ public class S3AsyncClientTest extends BaseS3AsyncClientTest {
|
|||
}
|
||||
|
||||
public void testPutBucketACL() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = S3AsyncClient.class.getMethod("putBucketACL", String.class,
|
||||
AccessControlList.class);
|
||||
HttpRequest request = processor.createRequest(method, "bucket", AccessControlList
|
||||
.fromCannedAccessPolicy(CannedAccessPolicy.PRIVATE, "1234"));
|
||||
Method method = S3AsyncClient.class.getMethod("putBucketACL", String.class, AccessControlList.class);
|
||||
HttpRequest request = processor.createRequest(method, "bucket", AccessControlList.fromCannedAccessPolicy(
|
||||
CannedAccessPolicy.PRIVATE, "1234"));
|
||||
|
||||
assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/?acl HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
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>",
|
||||
"text/xml", false);
|
||||
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>",
|
||||
"text/xml", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -383,9 +372,9 @@ public class S3AsyncClientTest extends BaseS3AsyncClientTest {
|
|||
}
|
||||
|
||||
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());
|
||||
IllegalArgumentException, NoSuchMethodException, IOException {
|
||||
Method method = S3AsyncClient.class.getMethod("putBucketInRegion", String.class, String.class, Array.newInstance(
|
||||
PutBucketOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, (String) null, "bucket");
|
||||
|
||||
assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/ HTTP/1.1");
|
||||
|
@ -399,18 +388,17 @@ public class S3AsyncClientTest extends BaseS3AsyncClientTest {
|
|||
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());
|
||||
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());
|
||||
HttpRequest request = processor.createRequest(method, "EU", "bucket");
|
||||
|
||||
assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"<CreateBucketConfiguration><LocationConstraint>EU</LocationConstraint></CreateBucketConfiguration>",
|
||||
"text/xml", false);
|
||||
assertPayloadEquals(request,
|
||||
"<CreateBucketConfiguration><LocationConstraint>EU</LocationConstraint></CreateBucketConfiguration>",
|
||||
"text/xml", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -419,13 +407,13 @@ public class S3AsyncClientTest extends BaseS3AsyncClientTest {
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testPutObject() throws ArrayIndexOutOfBoundsException, SecurityException,
|
||||
IllegalArgumentException, NoSuchMethodException, IOException {
|
||||
public void testPutObject() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
|
||||
NoSuchMethodException, IOException {
|
||||
|
||||
Method method = S3AsyncClient.class.getMethod("putObject", String.class, S3Object.class,
|
||||
PutObjectOptions[].class);
|
||||
Method method = S3AsyncClient.class
|
||||
.getMethod("putObject", String.class, S3Object.class, PutObjectOptions[].class);
|
||||
HttpRequest request = processor.createRequest(method, "bucket", blobToS3Object
|
||||
.apply(BindBlobToMultipartFormTest.TEST_BLOB));
|
||||
.apply(BindBlobToMultipartFormTest.TEST_BLOB));
|
||||
|
||||
assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/hello HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
|
@ -439,17 +427,17 @@ public class S3AsyncClientTest extends BaseS3AsyncClientTest {
|
|||
}
|
||||
|
||||
public void testPutObjectACL() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = S3AsyncClient.class.getMethod("putObjectACL", String.class, String.class,
|
||||
AccessControlList.class);
|
||||
HttpRequest request = processor.createRequest(method, "bucket", "key", AccessControlList
|
||||
.fromCannedAccessPolicy(CannedAccessPolicy.PRIVATE, "1234"));
|
||||
Method method = S3AsyncClient.class
|
||||
.getMethod("putObjectACL", String.class, String.class, AccessControlList.class);
|
||||
HttpRequest request = processor.createRequest(method, "bucket", "key", AccessControlList.fromCannedAccessPolicy(
|
||||
CannedAccessPolicy.PRIVATE, "1234"));
|
||||
|
||||
assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/key?acl HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
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>",
|
||||
"text/xml", false);
|
||||
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>",
|
||||
"text/xml", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -473,16 +461,14 @@ public class S3AsyncClientTest extends BaseS3AsyncClientTest {
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testDisableBucketLogging() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
public void testDisableBucketLogging() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = S3AsyncClient.class.getMethod("disableBucketLogging", String.class);
|
||||
HttpRequest request = processor.createRequest(method, "bucket");
|
||||
|
||||
assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/?logging HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"<BucketLoggingStatus xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"/>",
|
||||
"text/xml", false);
|
||||
assertPayloadEquals(request, "<BucketLoggingStatus xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"/>",
|
||||
"text/xml", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -491,18 +477,16 @@ public class S3AsyncClientTest extends BaseS3AsyncClientTest {
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testEnableBucketLoggingOwner() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = S3AsyncClient.class.getMethod("enableBucketLogging", String.class,
|
||||
BucketLogging.class);
|
||||
HttpRequest request = processor.createRequest(method, "bucket", new BucketLogging("mylogs",
|
||||
"access_log-", ImmutableSet.<Grant> of(new Grant(new EmailAddressGrantee(
|
||||
"adrian@jclouds.org"), Permission.FULL_CONTROL))));
|
||||
public void testEnableBucketLoggingOwner() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = S3AsyncClient.class.getMethod("enableBucketLogging", String.class, BucketLogging.class);
|
||||
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(request, "PUT https://bucket.s3.amazonaws.com/?logging HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/s3/bucket_logging.xml")), "text/xml", false);
|
||||
assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream("/s3/bucket_logging.xml")),
|
||||
"text/xml", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
|
|
@ -69,21 +69,19 @@ public class SQSAsyncClientTest extends RestClientTest<SQSAsyncClient> {
|
|||
|
||||
@Override
|
||||
protected String provideTimeStamp(final DateService dateService,
|
||||
@Named(Constants.PROPERTY_SESSION_INTERVAL) int expiration) {
|
||||
@Named(Constants.PROPERTY_SESSION_INTERVAL) int expiration) {
|
||||
return "2009-11-08T15:54:08.897Z";
|
||||
}
|
||||
}
|
||||
|
||||
public void testListQueuesInRegion() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = SQSAsyncClient.class.getMethod("listQueuesInRegion", String.class, Array
|
||||
.newInstance(ListQueuesOptions.class, 0).getClass());
|
||||
public void testListQueuesInRegion() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = SQSAsyncClient.class.getMethod("listQueuesInRegion", String.class, Array.newInstance(
|
||||
ListQueuesOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, (String) null);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: sqs.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-02-01&Action=ListQueues",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request, "Version=2009-02-01&Action=ListQueues", "application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, RegexListQueuesResponseHandler.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -92,17 +90,15 @@ public class SQSAsyncClientTest extends RestClientTest<SQSAsyncClient> {
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testListQueuesInRegionOptions() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = SQSAsyncClient.class.getMethod("listQueuesInRegion", String.class, Array
|
||||
.newInstance(ListQueuesOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, ListQueuesOptions.Builder
|
||||
.queuePrefix("prefix"));
|
||||
public void testListQueuesInRegionOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = SQSAsyncClient.class.getMethod("listQueuesInRegion", String.class, Array.newInstance(
|
||||
ListQueuesOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, ListQueuesOptions.Builder.queuePrefix("prefix"));
|
||||
|
||||
assertRequestLineEquals(request, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: sqs.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-02-01&Action=ListQueues&QueueNamePrefix=prefix",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, RegexListQueuesResponseHandler.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -111,16 +107,15 @@ public class SQSAsyncClientTest extends RestClientTest<SQSAsyncClient> {
|
|||
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());
|
||||
public void testCreateQueueInRegion() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = SQSAsyncClient.class.getMethod("createQueueInRegion", String.class, String.class, Array
|
||||
.newInstance(CreateQueueOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, "queueName");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: sqs.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-02-01&Action=CreateQueue&QueueName=queueName",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, RegexQueueHandler.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -129,19 +124,17 @@ public class SQSAsyncClientTest extends RestClientTest<SQSAsyncClient> {
|
|||
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());
|
||||
HttpRequest request = processor.createRequest(method, null, "queueName",
|
||||
CreateQueueOptions.Builder.defaultVisibilityTimeout(45));
|
||||
public void testCreateQueueInRegionOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = SQSAsyncClient.class.getMethod("createQueueInRegion", String.class, String.class, Array
|
||||
.newInstance(CreateQueueOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, null, "queueName", CreateQueueOptions.Builder
|
||||
.defaultVisibilityTimeout(45));
|
||||
|
||||
assertRequestLineEquals(request, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: sqs.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2009-02-01&Action=CreateQueue&QueueName=queueName&DefaultVisibilityTimeout=45",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-02-01&Action=CreateQueue&QueueName=queueName&DefaultVisibilityTimeout=45",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, RegexQueueHandler.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -151,8 +144,8 @@ public class SQSAsyncClientTest extends RestClientTest<SQSAsyncClient> {
|
|||
}
|
||||
|
||||
public void testAllRegions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = SQSAsyncClient.class.getMethod("createQueueInRegion", String.class,
|
||||
String.class, Array.newInstance(CreateQueueOptions.class, 0).getClass());
|
||||
Method method = SQSAsyncClient.class.getMethod("createQueueInRegion", String.class, String.class, Array
|
||||
.newInstance(CreateQueueOptions.class, 0).getClass());
|
||||
for (String region : Iterables.filter(Region.ALL_SQS, not(equalTo("us-standard")))) {
|
||||
processor.createRequest(method, region, "queueName");
|
||||
}
|
||||
|
@ -177,8 +170,7 @@ public class SQSAsyncClientTest extends RestClientTest<SQSAsyncClient> {
|
|||
|
||||
@Override
|
||||
public ContextSpec<?, ?> createContextSpec() {
|
||||
return new RestContextFactory().createContextSpec("sqs", "identity", "credential",
|
||||
new Properties());
|
||||
return new RestContextFactory().createContextSpec("sqs", "identity", "credential", new Properties());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,189 +1,49 @@
|
|||
<DescribeImagesResponse xmlns="http://ec2.amazonaws.com/doc/2009-11-30/">
|
||||
<requestId>7b893acf-7752-4e
|
||||
2c-8c1a-3287a011b0df</requestId>
|
||||
<DescribeImagesResponse xmlns="http://ec2.amazonaws.com/doc/2010-06-15/">
|
||||
<requestId>2564fc86-9a73-4727-9298-f0b9eb9b57c8</requestId>
|
||||
<imagesSet>
|
||||
<item>
|
||||
<imageId>emi-9ACB1363</imageId>
|
||||
<imageLocation>centos-5.3-x86_64/centos.5-3.x86-64.img.manifest.xml
|
||||
</imageLocation>
|
||||
<imageState>available
|
||||
</imageState>
|
||||
<imageLocation>centos-5.3-x86_64/centos.5-3.x86-64.img.manifest.xml</imageLocation>
|
||||
<imageState>available</imageState>
|
||||
<imageOwnerId>admin</imageOwnerId>
|
||||
<isPublic>true</isPublic>
|
||||
<productCodes />
|
||||
<architecture>x86_64</architecture>
|
||||
<imageType>
|
||||
machine
|
||||
</imageType>
|
||||
<kernelId>eki-6CBD12F2</kernelId>
|
||||
<ramdiskId>eri-A97113E4</ramdiskId>
|
||||
<rootDeviceType>instance-store</rootDeviceType>
|
||||
<rootDeviceName>/dev/sda1</rootDeviceName>
|
||||
<blockDeviceMapping />
|
||||
</item>
|
||||
<item>
|
||||
<imageId>emi-D2D610D1</imageId>
|
||||
<imageLocation>martin_try1/martin_try1.manifest.xml</imageLocation>
|
||||
<imageState>
|
||||
available
|
||||
</imageState>
|
||||
<imageOwnerId>dominic</imageOwnerId>
|
||||
<isPublic>true</isPublic>
|
||||
<productCodes />
|
||||
<architecture>x86_64</architecture>
|
||||
<imageType>machine</imageType>
|
||||
<kernelId>eki-6CBD12F2</kernelId>
|
||||
<ramdiskId>eri-A97113E4</ramdiskId>
|
||||
<rootDeviceType>instance-store</rootDeviceType>
|
||||
<rootDeviceName>/dev/sda1</rootDeviceName>
|
||||
<blockDeviceMapping />
|
||||
</item>
|
||||
<item>
|
||||
<imageId>eri-A97113E4</imageId>
|
||||
<imageLocation>initrd-64/initrd.img-2.6.28-11-generic.manifest.xml
|
||||
</imageLocation>
|
||||
<imageLocation>initrd-64/initrd.img-2.6.28-11-generic.manifest.xml</imageLocation>
|
||||
<imageState>available</imageState>
|
||||
<imageOwnerId>admin</imageOwnerId>
|
||||
<isPublic>true</isPublic>
|
||||
<productCodes />
|
||||
<architecture>x86_64</architecture>
|
||||
<imageType>ramdisk</imageType>
|
||||
<rootDeviceType>
|
||||
instance-store
|
||||
</rootDeviceType>
|
||||
<rootDeviceName>/dev/sda1</rootDeviceName>
|
||||
<blockDeviceMapping />
|
||||
</item>
|
||||
<item>
|
||||
<imageId>emi-B9A40FF6</imageId>
|
||||
<imageLocation>ulteo4/ubuntu804-32-test.manifest.xml</imageLocation>
|
||||
<imageState>available</imageState>
|
||||
<imageOwnerId>gaelduval</imageOwnerId>
|
||||
<isPublic>true</isPublic>
|
||||
<productCodes />
|
||||
<architecture>
|
||||
i386
|
||||
</architecture>
|
||||
<imageType>machine</imageType>
|
||||
<rootDeviceType>instance-store</rootDeviceType>
|
||||
<rootDeviceName>/dev/sda1</rootDeviceName>
|
||||
<blockDeviceMapping />
|
||||
</item>
|
||||
<item>
|
||||
<imageId>
|
||||
emi-D1991835
|
||||
</imageId>
|
||||
<imageLocation>jamestyj-test/Eucalyptus_Guest.x86_64-0.0.2.raw.manifest.xml
|
||||
</imageLocation>
|
||||
<imageState>available</imageState>
|
||||
<imageOwnerId>jamestyj</imageOwnerId>
|
||||
<isPublic>true</isPublic>
|
||||
<productCodes />
|
||||
<architecture>x86_64</architecture>
|
||||
<imageType>machine</imageType>
|
||||
<rootDeviceType>
|
||||
instance-store
|
||||
</rootDeviceType>
|
||||
<rootDeviceName>/dev/sda1</rootDeviceName>
|
||||
<blockDeviceMapping />
|
||||
</item>
|
||||
<item>
|
||||
<imageId>emi-D8AB1044</imageId>
|
||||
<imageLocation>test/ubuntu.9-04.x86-64.img.manifest.xml
|
||||
</imageLocation>
|
||||
<imageState>available</imageState>
|
||||
<imageOwnerId>mymq0206</imageOwnerId>
|
||||
<isPublic>true</isPublic>
|
||||
<productCodes />
|
||||
<architecture>
|
||||
x86_64
|
||||
</architecture>
|
||||
<imageType>machine</imageType>
|
||||
<rootDeviceType>instance-store</rootDeviceType>
|
||||
<rootDeviceName>/dev/sda1</rootDeviceName>
|
||||
<blockDeviceMapping />
|
||||
</item>
|
||||
<item>
|
||||
<imageId>
|
||||
emi-CBEA100C
|
||||
</imageId>
|
||||
<imageLocation>Lean/ubuntu.9-04.x86-64.img.manifest.xml
|
||||
</imageLocation>
|
||||
<imageState>available</imageState>
|
||||
<imageOwnerId>
|
||||
mashaobing1
|
||||
</imageOwnerId>
|
||||
<isPublic>true</isPublic>
|
||||
<productCodes />
|
||||
<architecture>x86_64</architecture>
|
||||
<imageType>machine</imageType>
|
||||
<kernelId>eki-6CBD12F2</kernelId>
|
||||
<ramdiskId>eri-A97113E4</ramdiskId>
|
||||
<rootDeviceType>instance-store</rootDeviceType>
|
||||
<rootDeviceName>/dev/sda1</rootDeviceName>
|
||||
<blockDeviceMapping />
|
||||
</item>
|
||||
<item>
|
||||
<imageId>emi-D176182B</imageId>
|
||||
<imageLocation>jamestyj-test/Eucalyptus_Guest.x86_64-0.0.3.raw.manifest.xml
|
||||
</imageLocation>
|
||||
<imageState>available</imageState>
|
||||
<imageOwnerId>
|
||||
jamestyj
|
||||
</imageOwnerId>
|
||||
<isPublic>true</isPublic>
|
||||
<productCodes />
|
||||
<architecture>x86_64</architecture>
|
||||
<imageType>machine</imageType>
|
||||
<rootDeviceType>instance-store</rootDeviceType>
|
||||
<rootDeviceName>/dev/sda1</rootDeviceName>
|
||||
<blockDeviceMapping />
|
||||
</item>
|
||||
<item>
|
||||
<imageId>emi-D25E10CA</imageId>
|
||||
<imageLocation>
|
||||
biolinux/biolinux.qcow2.manifest.xml
|
||||
</imageLocation>
|
||||
<imageState>available</imageState>
|
||||
<imageOwnerId>brainstorm</imageOwnerId>
|
||||
<isPublic>true</isPublic>
|
||||
<productCodes />
|
||||
<architecture>x86_64</architecture>
|
||||
<imageType>machine</imageType>
|
||||
<rootDeviceType>instance-store</rootDeviceType>
|
||||
<rootDeviceName>/dev/sda1</rootDeviceName>
|
||||
<blockDeviceMapping />
|
||||
</item>
|
||||
<item>
|
||||
<imageId>
|
||||
eki-6CBD12F2
|
||||
</imageId>
|
||||
<imageLocation>kernel-64/vmlinuz-2.6.28-11-generic.manifest.xml
|
||||
</imageLocation>
|
||||
<imageId>eki-6CBD12F2</imageId>
|
||||
<imageLocation>kernel-64/vmlinuz-2.6.28-11-generic.manifest.xml</imageLocation>
|
||||
<imageState>available</imageState>
|
||||
<imageOwnerId>admin</imageOwnerId>
|
||||
<isPublic>true</isPublic>
|
||||
<productCodes />
|
||||
<architecture>x86_64</architecture>
|
||||
<imageType>kernel</imageType>
|
||||
<rootDeviceType>instance-store</rootDeviceType>
|
||||
<rootDeviceName>/dev/sda1</rootDeviceName>
|
||||
<blockDeviceMapping />
|
||||
</item>
|
||||
<item>
|
||||
<imageId>emi-2EDC1606</imageId>
|
||||
<imageLocation>
|
||||
ulteo2/Ulteo-SM-Scalability-Test-19feb2010.manifest.xml
|
||||
</imageLocation>
|
||||
<imageId>emi-B5C5103A</imageId>
|
||||
<imageLocation>shashi-test/RTestSmall.manifest.xml</imageLocation>
|
||||
<imageState>available</imageState>
|
||||
<imageOwnerId>gaelduval</imageOwnerId>
|
||||
<imageOwnerId>admin</imageOwnerId>
|
||||
<isPublic>true</isPublic>
|
||||
<productCodes />
|
||||
<architecture>i386</architecture>
|
||||
<architecture>x86_64</architecture>
|
||||
<imageType>machine</imageType>
|
||||
<rootDeviceType>instance-store</rootDeviceType>
|
||||
<rootDeviceName>/dev/sda1</rootDeviceName>
|
||||
<blockDeviceMapping />
|
||||
<kernelId>eki-6CBD12F2</kernelId>
|
||||
<ramdiskId>eri-A97113E4</ramdiskId>
|
||||
</item>
|
||||
</imagesSet>
|
||||
</DescribeImagesResponse>
|
|
@ -64,8 +64,7 @@ public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClien
|
|||
Method method = AzureBlobAsyncClient.class.getMethod("listContainers", ListOptions[].class);
|
||||
HttpRequest request = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://identity.blob.core.windows.net/?comp=list HTTP/1.1");
|
||||
assertRequestLineEquals(request, "GET https://identity.blob.core.windows.net/?comp=list HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -75,15 +74,12 @@ public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClien
|
|||
|
||||
}
|
||||
|
||||
public void testListContainersOptions() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
public void testListContainersOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("listContainers", ListOptions[].class);
|
||||
HttpRequest request = processor.createRequest(method, maxResults(1).marker("marker").prefix(
|
||||
"prefix"));
|
||||
HttpRequest request = processor.createRequest(method, maxResults(1).marker("marker").prefix("prefix"));
|
||||
|
||||
assertRequestLineEquals(
|
||||
request,
|
||||
"GET https://identity.blob.core.windows.net/?comp=list&maxresults=1&marker=marker&prefix=prefix HTTP/1.1");
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://identity.blob.core.windows.net/?comp=list&maxresults=1&marker=marker&prefix=prefix HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -94,11 +90,11 @@ public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClien
|
|||
|
||||
public void testCreateContainer() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("createContainer", String.class,
|
||||
CreateContainerOptions[].class);
|
||||
CreateContainerOptions[].class);
|
||||
HttpRequest request = processor.createRequest(method, "container");
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"PUT https://identity.blob.core.windows.net/container?restype=container HTTP/1.1");
|
||||
"PUT https://identity.blob.core.windows.net/container?restype=container HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -112,7 +108,7 @@ public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClien
|
|||
HttpRequest request = processor.createRequest(method, "container");
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"DELETE https://identity.blob.core.windows.net/container?restype=container HTTP/1.1");
|
||||
"DELETE https://identity.blob.core.windows.net/container?restype=container HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -121,17 +117,16 @@ public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClien
|
|||
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
|
||||
}
|
||||
|
||||
public void testCreateContainerOptions() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
public void testCreateContainerOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("createContainer", String.class,
|
||||
CreateContainerOptions[].class);
|
||||
HttpRequest request = processor.createRequest(method, "container", withPublicAcl()
|
||||
.withMetadata(ImmutableMultimap.of("foo", "bar")));
|
||||
CreateContainerOptions[].class);
|
||||
HttpRequest request = processor.createRequest(method, "container", withPublicAcl().withMetadata(
|
||||
ImmutableMultimap.of("foo", "bar")));
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"PUT https://identity.blob.core.windows.net/container?restype=container HTTP/1.1");
|
||||
"PUT https://identity.blob.core.windows.net/container?restype=container HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request,
|
||||
"x-ms-meta-foo: bar\nx-ms-prop-publicaccess: true\nx-ms-version: 2009-09-19\n");
|
||||
"x-ms-meta-foo: bar\nx-ms-prop-publicaccess: true\nx-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
||||
|
@ -139,15 +134,12 @@ public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClien
|
|||
assertExceptionParserClassEquals(method, ReturnFalseIfContainerAlreadyExists.class);
|
||||
}
|
||||
|
||||
public void testCreateRootContainer() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("createRootContainer",
|
||||
CreateContainerOptions[].class);
|
||||
public void testCreateRootContainer() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("createRootContainer", CreateContainerOptions[].class);
|
||||
|
||||
HttpRequest request = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"PUT https://identity.blob.core.windows.net/%24root?restype=container HTTP/1.1");
|
||||
assertRequestLineEquals(request, "PUT https://identity.blob.core.windows.net/%24root?restype=container HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -156,13 +148,12 @@ public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClien
|
|||
assertExceptionParserClassEquals(method, ReturnFalseIfContainerAlreadyExists.class);
|
||||
}
|
||||
|
||||
public void testDeleteRootContainer() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
public void testDeleteRootContainer() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("deleteRootContainer");
|
||||
HttpRequest request = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"DELETE https://identity.blob.core.windows.net/%24root?restype=container HTTP/1.1");
|
||||
"DELETE https://identity.blob.core.windows.net/%24root?restype=container HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -171,17 +162,14 @@ public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClien
|
|||
assertExceptionParserClassEquals(method, ReturnTrueOn404.class);
|
||||
}
|
||||
|
||||
public void testCreateRootContainerOptions() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("createRootContainer",
|
||||
CreateContainerOptions[].class);
|
||||
public void testCreateRootContainerOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("createRootContainer", CreateContainerOptions[].class);
|
||||
HttpRequest request = processor.createRequest(method, withPublicAcl().withMetadata(
|
||||
ImmutableMultimap.of("foo", "bar")));
|
||||
ImmutableMultimap.of("foo", "bar")));
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"PUT https://identity.blob.core.windows.net/%24root?restype=container HTTP/1.1");
|
||||
assertRequestLineEquals(request, "PUT https://identity.blob.core.windows.net/%24root?restype=container HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request,
|
||||
"x-ms-meta-foo: bar\nx-ms-prop-publicaccess: true\nx-ms-version: 2009-09-19\n");
|
||||
"x-ms-meta-foo: bar\nx-ms-prop-publicaccess: true\nx-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
||||
|
@ -190,12 +178,11 @@ public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClien
|
|||
}
|
||||
|
||||
public void testListBlobs() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("listBlobs", String.class,
|
||||
ListBlobsOptions[].class);
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("listBlobs", String.class, ListBlobsOptions[].class);
|
||||
HttpRequest request = processor.createRequest(method, "container");
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://identity.blob.core.windows.net/container?restype=container&comp=list HTTP/1.1");
|
||||
"GET https://identity.blob.core.windows.net/container?restype=container&comp=list HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -209,7 +196,7 @@ public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClien
|
|||
HttpRequest request = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://identity.blob.core.windows.net/%24root?restype=container&comp=list HTTP/1.1");
|
||||
"GET https://identity.blob.core.windows.net/%24root?restype=container&comp=list HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -218,13 +205,12 @@ public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClien
|
|||
assertExceptionParserClassEquals(method, null);
|
||||
}
|
||||
|
||||
public void testContainerProperties() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
public void testContainerProperties() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("getContainerProperties", String.class);
|
||||
HttpRequest request = processor.createRequest(method, "container");
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"HEAD https://identity.blob.core.windows.net/container?restype=container HTTP/1.1");
|
||||
"HEAD https://identity.blob.core.windows.net/container?restype=container HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -233,15 +219,13 @@ public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClien
|
|||
assertExceptionParserClassEquals(method, ReturnNullOnContainerNotFound.class);
|
||||
}
|
||||
|
||||
public void testSetResourceMetadata() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("setResourceMetadata", String.class,
|
||||
Map.class);
|
||||
HttpRequest request = processor.createRequest(method, new Object[] { "container",
|
||||
ImmutableMap.of("key", "value") });
|
||||
public void testSetResourceMetadata() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("setResourceMetadata", String.class, Map.class);
|
||||
HttpRequest request = processor.createRequest(method,
|
||||
new Object[] { "container", ImmutableMap.of("key", "value") });
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"PUT https://identity.blob.core.windows.net/container?restype=container&comp=metadata HTTP/1.1");
|
||||
"PUT https://identity.blob.core.windows.net/container?restype=container&comp=metadata HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-meta-key: value\nx-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -251,13 +235,11 @@ public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClien
|
|||
}
|
||||
|
||||
public void testSetBlobMetadata() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("setBlobMetadata", String.class,
|
||||
String.class, Map.class);
|
||||
HttpRequest request = processor.createRequest(method, "container", "blob", ImmutableMap.of(
|
||||
"key", "value"));
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("setBlobMetadata", String.class, String.class, Map.class);
|
||||
HttpRequest request = processor.createRequest(method, "container", "blob", ImmutableMap.of("key", "value"));
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"PUT https://identity.blob.core.windows.net/container/blob?comp=metadata HTTP/1.1");
|
||||
"PUT https://identity.blob.core.windows.net/container/blob?comp=metadata HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-meta-key: value\nx-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -280,7 +262,6 @@ public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClien
|
|||
|
||||
@Override
|
||||
public ContextSpec<?, ?> createContextSpec() {
|
||||
return new RestContextFactory().createContextSpec("azureblob", "identity", "credential",
|
||||
new Properties());
|
||||
return new RestContextFactory().createContextSpec("azureblob", "identity", "credential", new Properties());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,12 +57,10 @@ import com.google.inject.TypeLiteral;
|
|||
public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncClient> {
|
||||
|
||||
public void testGetMessages() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AzureQueueAsyncClient.class.getMethod("getMessages", String.class,
|
||||
GetOptions[].class);
|
||||
Method method = AzureQueueAsyncClient.class.getMethod("getMessages", String.class, GetOptions[].class);
|
||||
HttpRequest request = processor.createRequest(method, "myqueue");
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://identity.queue.core.windows.net/myqueue/messages HTTP/1.1");
|
||||
assertRequestLineEquals(request, "GET https://identity.queue.core.windows.net/myqueue/messages HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -73,16 +71,12 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testGetMessagesOptions() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = AzureQueueAsyncClient.class.getMethod("getMessages", String.class,
|
||||
GetOptions[].class);
|
||||
HttpRequest request = processor.createRequest(method, "myqueue", maxMessages(1)
|
||||
.visibilityTimeout(30));
|
||||
public void testGetMessagesOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AzureQueueAsyncClient.class.getMethod("getMessages", String.class, GetOptions[].class);
|
||||
HttpRequest request = processor.createRequest(method, "myqueue", maxMessages(1).visibilityTimeout(30));
|
||||
|
||||
assertRequestLineEquals(
|
||||
request,
|
||||
"GET https://identity.queue.core.windows.net/myqueue/messages?numofmessages=1&visibilitytimeout=30 HTTP/1.1");
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://identity.queue.core.windows.net/myqueue/messages?numofmessages=1&visibilitytimeout=30 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -97,8 +91,7 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
|
|||
Method method = AzureQueueAsyncClient.class.getMethod("listQueues", ListOptions[].class);
|
||||
HttpRequest request = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://identity.queue.core.windows.net/?comp=list HTTP/1.1");
|
||||
assertRequestLineEquals(request, "GET https://identity.queue.core.windows.net/?comp=list HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -111,12 +104,10 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
|
|||
|
||||
public void testListQueuesOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AzureQueueAsyncClient.class.getMethod("listQueues", ListOptions[].class);
|
||||
HttpRequest request = processor.createRequest(method, maxResults(1).marker("marker").prefix(
|
||||
"prefix"));
|
||||
HttpRequest request = processor.createRequest(method, maxResults(1).marker("marker").prefix("prefix"));
|
||||
|
||||
assertRequestLineEquals(
|
||||
request,
|
||||
"GET https://identity.queue.core.windows.net/?comp=list&maxresults=1&marker=marker&prefix=prefix HTTP/1.1");
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://identity.queue.core.windows.net/?comp=list&maxresults=1&marker=marker&prefix=prefix HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -128,8 +119,7 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
|
|||
}
|
||||
|
||||
public void testCreateQueue() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AzureQueueAsyncClient.class.getMethod("createQueue", String.class,
|
||||
CreateOptions[].class);
|
||||
Method method = AzureQueueAsyncClient.class.getMethod("createQueue", String.class, CreateOptions[].class);
|
||||
HttpRequest request = processor.createRequest(method, "queue");
|
||||
|
||||
assertRequestLineEquals(request, "PUT https://identity.queue.core.windows.net/queue HTTP/1.1");
|
||||
|
@ -143,13 +133,10 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testCreateQueueOptions() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
public void testCreateQueueOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
|
||||
Method method = AzureQueueAsyncClient.class.getMethod("createQueue", String.class,
|
||||
CreateOptions[].class);
|
||||
HttpRequest request = processor.createRequest(method, "queue", withMetadata(ImmutableMultimap
|
||||
.of("foo", "bar")));
|
||||
Method method = AzureQueueAsyncClient.class.getMethod("createQueue", String.class, CreateOptions[].class);
|
||||
HttpRequest request = processor.createRequest(method, "queue", withMetadata(ImmutableMultimap.of("foo", "bar")));
|
||||
|
||||
assertRequestLineEquals(request, "PUT https://identity.queue.core.windows.net/queue HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-meta-foo: bar\nx-ms-version: 2009-09-19\n");
|
||||
|
@ -167,8 +154,7 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
|
|||
Method method = AzureQueueAsyncClient.class.getMethod("deleteQueue", String.class);
|
||||
HttpRequest request = processor.createRequest(method, "queue");
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"DELETE https://identity.queue.core.windows.net/queue HTTP/1.1");
|
||||
assertRequestLineEquals(request, "DELETE https://identity.queue.core.windows.net/queue HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -182,16 +168,14 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
|
|||
|
||||
public void testPutMessage() throws SecurityException, NoSuchMethodException, IOException {
|
||||
|
||||
Method method = AzureQueueAsyncClient.class.getMethod("putMessage", String.class,
|
||||
String.class, PutMessageOptions[].class);
|
||||
Method method = AzureQueueAsyncClient.class.getMethod("putMessage", String.class, String.class,
|
||||
PutMessageOptions[].class);
|
||||
HttpRequest request = processor.createRequest(method, "queue", "message");
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"POST https://identity.queue.core.windows.net/queue/messages HTTP/1.1");
|
||||
assertRequestLineEquals(request, "POST https://identity.queue.core.windows.net/queue/messages HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request,
|
||||
"<QueueMessage><MessageText>message</MessageText></QueueMessage>",
|
||||
"application/unknown", false);
|
||||
assertPayloadEquals(request, "<QueueMessage><MessageText>message</MessageText></QueueMessage>",
|
||||
"application/unknown", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -202,16 +186,15 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
|
|||
|
||||
public void testPutMessageOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
|
||||
Method method = AzureQueueAsyncClient.class.getMethod("putMessage", String.class,
|
||||
String.class, PutMessageOptions[].class);
|
||||
Method method = AzureQueueAsyncClient.class.getMethod("putMessage", String.class, String.class,
|
||||
PutMessageOptions[].class);
|
||||
HttpRequest request = processor.createRequest(method, "queue", "message", withTTL(3));
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"POST https://identity.queue.core.windows.net/queue/messages?messagettl=3 HTTP/1.1");
|
||||
"POST https://identity.queue.core.windows.net/queue/messages?messagettl=3 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request,
|
||||
"<QueueMessage><MessageText>message</MessageText></QueueMessage>",
|
||||
"application/unknown", false);
|
||||
assertPayloadEquals(request, "<QueueMessage><MessageText>message</MessageText></QueueMessage>",
|
||||
"application/unknown", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -225,8 +208,7 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
|
|||
Method method = AzureQueueAsyncClient.class.getMethod("clearMessages", String.class);
|
||||
HttpRequest request = processor.createRequest(method, "queue");
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"DELETE https://identity.queue.core.windows.net/queue/messages HTTP/1.1");
|
||||
assertRequestLineEquals(request, "DELETE https://identity.queue.core.windows.net/queue/messages HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -251,8 +233,7 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
|
|||
|
||||
@Override
|
||||
public ContextSpec<?, ?> createContextSpec() {
|
||||
return new RestContextFactory().createContextSpec("azurequeue", "identity", "credential",
|
||||
new Properties());
|
||||
return new RestContextFactory().createContextSpec("azurequeue", "identity", "credential", new Properties());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -45,8 +45,8 @@ import com.google.common.base.Function;
|
|||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class ParseSystemAndUserMetadataFromHeaders implements
|
||||
Function<HttpResponse, MutableBlobMetadata>, InvocationContext {
|
||||
public class ParseSystemAndUserMetadataFromHeaders implements Function<HttpResponse, MutableBlobMetadata>,
|
||||
InvocationContext {
|
||||
private final String metadataPrefix;
|
||||
private final DateService dateParser;
|
||||
private final Provider<MutableBlobMetadata> metadataFactory;
|
||||
|
@ -55,9 +55,8 @@ public class ParseSystemAndUserMetadataFromHeaders implements
|
|||
private GeneratedHttpRequest<?> request;
|
||||
|
||||
@Inject
|
||||
public ParseSystemAndUserMetadataFromHeaders(Provider<MutableBlobMetadata> metadataFactory,
|
||||
DateService dateParser, @Named(PROPERTY_USER_METADATA_PREFIX) String metadataPrefix,
|
||||
@Named(PROPERTY_API_VERSION) String apiVersion) {
|
||||
public ParseSystemAndUserMetadataFromHeaders(Provider<MutableBlobMetadata> metadataFactory, DateService dateParser,
|
||||
@Named(PROPERTY_USER_METADATA_PREFIX) String metadataPrefix, @Named(PROPERTY_API_VERSION) String apiVersion) {
|
||||
this.metadataFactory = metadataFactory;
|
||||
this.dateParser = dateParser;
|
||||
this.metadataPrefix = metadataPrefix;
|
||||
|
@ -81,9 +80,8 @@ public class ParseSystemAndUserMetadataFromHeaders implements
|
|||
void addUserMetadataTo(HttpResponse from, MutableBlobMetadata metadata) {
|
||||
for (Entry<String, String> header : from.getHeaders().entries()) {
|
||||
if (header.getKey() != null && header.getKey().startsWith(metadataPrefix))
|
||||
metadata.getUserMetadata().put(
|
||||
(header.getKey().substring(metadataPrefix.length())).toLowerCase(),
|
||||
header.getValue());
|
||||
metadata.getUserMetadata().put((header.getKey().substring(metadataPrefix.length())).toLowerCase(),
|
||||
header.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,12 +91,10 @@ public class ParseSystemAndUserMetadataFromHeaders implements
|
|||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void parseLastModifiedOrThrowException(HttpResponse from, MutableBlobMetadata metadata)
|
||||
throws HttpException {
|
||||
void parseLastModifiedOrThrowException(HttpResponse from, MutableBlobMetadata metadata) throws HttpException {
|
||||
String lastModified = from.getFirstHeaderOrNull(HttpHeaders.LAST_MODIFIED);
|
||||
if (lastModified == null)
|
||||
throw new HttpException(HttpHeaders.LAST_MODIFIED + " header not present in response: "
|
||||
+ from.getStatusLine());
|
||||
throw new HttpException(HttpHeaders.LAST_MODIFIED + " header not present in response: " + from.getStatusLine());
|
||||
// Eucalyptus 1.6 returns iso8601 dates
|
||||
if (apiVersion.indexOf("Walrus-1.6") != -1) {
|
||||
metadata.setLastModified(dateParser.iso8601DateParse(lastModified.replace("+0000", "Z")));
|
||||
|
@ -107,8 +103,7 @@ public class ParseSystemAndUserMetadataFromHeaders implements
|
|||
}
|
||||
|
||||
if (metadata.getLastModified() == null)
|
||||
throw new HttpException("could not parse: " + HttpHeaders.LAST_MODIFIED + ": "
|
||||
+ lastModified);
|
||||
throw new HttpException("could not parse: " + HttpHeaders.LAST_MODIFIED + ": " + lastModified);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
@ -126,18 +121,16 @@ public class ParseSystemAndUserMetadataFromHeaders implements
|
|||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void setContentTypeOrThrowException(HttpResponse from, MutableBlobMetadata metadata)
|
||||
throws HttpException {
|
||||
void setContentTypeOrThrowException(HttpResponse from, MutableBlobMetadata metadata) throws HttpException {
|
||||
if (from.getPayload() != null)
|
||||
metadata.setContentType(from.getPayload().getContentType());
|
||||
if (metadata.getContentType() == null
|
||||
|| "application/unknown".equals(metadata.getContentType()))
|
||||
if (from.getStatusCode() != 204 && (metadata.getContentType() == null
|
||||
|| "application/unknown".equals(metadata.getContentType())))
|
||||
throw new HttpException(HttpHeaders.CONTENT_TYPE + " not found in headers");
|
||||
}
|
||||
|
||||
public ParseSystemAndUserMetadataFromHeaders setContext(HttpRequest request) {
|
||||
checkArgument(request instanceof GeneratedHttpRequest<?>,
|
||||
"note this handler requires a GeneratedHttpRequest");
|
||||
checkArgument(request instanceof GeneratedHttpRequest<?>, "note this handler requires a GeneratedHttpRequest");
|
||||
this.request = (GeneratedHttpRequest<?>) request;
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -43,7 +43,11 @@ import org.testng.annotations.Test;
|
|||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
public class ParseBlobMetadataFromHeadersTest {
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(sequential = true)
|
||||
public class ParseSystemAndUserMetadataFromHeadersTest {
|
||||
|
||||
private ParseSystemAndUserMetadataFromHeaders parser;
|
||||
private Provider<MutableBlobMetadata> blobMetadataProvider = new Provider<MutableBlobMetadata>() {
|
||||
|
@ -57,8 +61,8 @@ public class ParseBlobMetadataFromHeadersTest {
|
|||
@BeforeTest
|
||||
void setUp() {
|
||||
|
||||
parser = new ParseSystemAndUserMetadataFromHeaders(blobMetadataProvider,
|
||||
new SimpleDateFormatDateService(), "prefix", "default");
|
||||
parser = new ParseSystemAndUserMetadataFromHeaders(blobMetadataProvider, new SimpleDateFormatDateService(),
|
||||
"prefix", "default");
|
||||
|
||||
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
|
||||
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
|
||||
|
@ -77,6 +81,13 @@ public class ParseBlobMetadataFromHeadersTest {
|
|||
assertEquals(metadata.getName(), "key");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoContentOn204IsOk() {
|
||||
HttpResponse from = new HttpResponse(204, "ok", Payloads.newStringPayload(""));
|
||||
from.getHeaders().put(HttpHeaders.LAST_MODIFIED, "Wed, 09 Sep 2009 19:50:23 GMT");
|
||||
parser.apply(from);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetContentLength() {
|
||||
HttpResponse from = new HttpResponse(200, "ok", Payloads.newStringPayload(""));
|
||||
|
@ -116,7 +127,7 @@ public class ParseBlobMetadataFromHeadersTest {
|
|||
MutableBlobMetadata metadata = blobMetadataProvider.get();
|
||||
parser.parseLastModifiedOrThrowException(from, metadata);
|
||||
assertEquals(metadata.getLastModified(), new SimpleDateFormatDateService()
|
||||
.rfc822DateParse("Wed, 09 Sep 2009 19:50:23 GMT"));
|
||||
.rfc822DateParse("Wed, 09 Sep 2009 19:50:23 GMT"));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = HttpException.class)
|
|
@ -23,12 +23,10 @@
|
|||
*/
|
||||
package org.jclouds.boxdotnet;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.http.filters.BasicAuthentication;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
|
@ -47,7 +45,6 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
@RequestFilters(BasicAuthentication.class)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public interface BoxDotNetAsyncClient {
|
||||
/*
|
||||
* TODO: define interface methods for BoxDotNet
|
||||
|
|
|
@ -57,7 +57,7 @@ public class BoxDotNetAsyncClientTest extends RestClientTest<BoxDotNetAsyncClien
|
|||
GeneratedHttpRequest<BoxDotNetAsyncClient> httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://www.box.net/api/1.0/rest/items HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
// now make sure request filters apply by replaying
|
||||
|
@ -65,9 +65,10 @@ public class BoxDotNetAsyncClientTest extends RestClientTest<BoxDotNetAsyncClien
|
|||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://www.box.net/api/1.0/rest/items HTTP/1.1");
|
||||
// for example, using basic authentication, we should get "only one" header
|
||||
// for example, using basic authentication, we should get "only one"
|
||||
// header
|
||||
assertNonPayloadHeadersEqual(httpRequest,
|
||||
"Accept: application/json\nAuthorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\n");
|
||||
"Authorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
// TODO: insert expected response class, which probably extends ParseJson
|
||||
|
@ -84,7 +85,7 @@ public class BoxDotNetAsyncClientTest extends RestClientTest<BoxDotNetAsyncClien
|
|||
GeneratedHttpRequest<BoxDotNetAsyncClient> httpRequest = processor.createRequest(method, 1);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://www.box.net/api/1.0/rest/items/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
// TODO: insert expected response class, which probably extends ParseJson
|
||||
|
@ -101,9 +102,8 @@ public class BoxDotNetAsyncClientTest extends RestClientTest<BoxDotNetAsyncClien
|
|||
Method method = BoxDotNetAsyncClient.class.getMethod("delete", long.class);
|
||||
GeneratedHttpRequest<BoxDotNetAsyncClient> httpRequest = processor.createRequest(method, 1);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"DELETE https://www.box.net/api/1.0/rest/items/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertRequestLineEquals(httpRequest, "DELETE https://www.box.net/api/1.0/rest/items/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
||||
|
@ -128,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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,21 +40,22 @@ import org.jclouds.chef.binders.BindChecksumsToJsonPayload;
|
|||
import org.jclouds.chef.binders.BindClientnameToJsonPayload;
|
||||
import org.jclouds.chef.binders.BindGenerateKeyForClientToJsonPayload;
|
||||
import org.jclouds.chef.binders.BindIsCompletedToJsonPayload;
|
||||
import org.jclouds.chef.binders.NodeName;
|
||||
import org.jclouds.chef.domain.CookbookVersion;
|
||||
import org.jclouds.chef.domain.Node;
|
||||
import org.jclouds.chef.domain.Sandbox;
|
||||
import org.jclouds.chef.domain.UploadSandbox;
|
||||
import org.jclouds.chef.filters.SignedHeaderAuth;
|
||||
import org.jclouds.chef.functions.ParseCookbookVersionFromJson;
|
||||
import org.jclouds.chef.functions.ParseKeyFromJson;
|
||||
import org.jclouds.chef.functions.ParseKeySetFromJson;
|
||||
import org.jclouds.chef.functions.ParseSandboxFromJson;
|
||||
import org.jclouds.chef.functions.ParseUploadSiteFromJson;
|
||||
import org.jclouds.chef.functions.ParseValueSetFromJson;
|
||||
import org.jclouds.http.functions.ReturnStringIf2xx;
|
||||
import org.jclouds.rest.annotations.BinderParam;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.Headers;
|
||||
import org.jclouds.rest.annotations.ParamParser;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.ResponseParser;
|
||||
import org.jclouds.rest.annotations.Unwrap;
|
||||
import org.jclouds.rest.binders.BindToJsonPayload;
|
||||
import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
|
@ -71,8 +72,8 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
@RequestFilters(SignedHeaderAuth.class)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Headers(keys = "X-Chef-Version", values = ChefAsyncClient.VERSION)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public interface ChefAsyncClient {
|
||||
public static final String VERSION = "0.9.6";
|
||||
|
||||
|
@ -81,22 +82,19 @@ public interface ChefAsyncClient {
|
|||
*/
|
||||
@POST
|
||||
@Path("sandboxes")
|
||||
@ResponseParser(ParseUploadSiteFromJson.class)
|
||||
ListenableFuture<UploadSandbox> getUploadSandboxForChecksums(
|
||||
@BinderParam(BindChecksumsToJsonPayload.class) Set<List<Byte>> md5s);
|
||||
@BinderParam(BindChecksumsToJsonPayload.class) Set<List<Byte>> md5s);
|
||||
|
||||
@PUT
|
||||
ListenableFuture<Void> uploadContent(
|
||||
@BinderParam(BindChecksumsToJsonPayload.class) Set<List<Byte>> md5s);
|
||||
ListenableFuture<Void> uploadContent(@BinderParam(BindChecksumsToJsonPayload.class) Set<List<Byte>> md5s);
|
||||
|
||||
/**
|
||||
* @see ChefClient#commitSandbox
|
||||
*/
|
||||
@PUT
|
||||
@Path("sandboxes/{id}")
|
||||
@ResponseParser(ParseSandboxFromJson.class)
|
||||
ListenableFuture<Sandbox> commitSandbox(@PathParam("id") String id,
|
||||
@BinderParam(BindIsCompletedToJsonPayload.class) boolean isCompleted);
|
||||
@BinderParam(BindIsCompletedToJsonPayload.class) boolean isCompleted);
|
||||
|
||||
/**
|
||||
* @see ChefCookbooks#listCookbooks
|
||||
|
@ -112,8 +110,7 @@ public interface ChefAsyncClient {
|
|||
@PUT
|
||||
@Path("cookbooks/{cookbookname}/{version}")
|
||||
ListenableFuture<Void> updateCookbook(@PathParam("cookbookname") String cookbookName,
|
||||
@PathParam("version") String version,
|
||||
@BinderParam(BindToJsonPayload.class) CookbookVersion cookbook);
|
||||
@PathParam("version") String version, @BinderParam(BindToJsonPayload.class) CookbookVersion cookbook);
|
||||
|
||||
/**
|
||||
* @see ChefCookbook#deleteCookbook(String)
|
||||
|
@ -122,27 +119,25 @@ public interface ChefAsyncClient {
|
|||
@Path("cookbooks/{cookbookname}/{version}")
|
||||
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
||||
ListenableFuture<Void> deleteCookbook(@PathParam("cookbookname") String cookbookName,
|
||||
@PathParam("version") String version);
|
||||
@PathParam("version") String version);
|
||||
|
||||
/**
|
||||
* @see ChefCookbook#getVersionsOfCookbook
|
||||
*/
|
||||
@GET
|
||||
@Path("cookbooks/{cookbookname}")
|
||||
@ResponseParser(ParseValueSetFromJson.class)
|
||||
@Unwrap
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<Set<String>> getVersionsOfCookbook(
|
||||
@PathParam("cookbookname") String cookbookName);
|
||||
ListenableFuture<Set<String>> getVersionsOfCookbook(@PathParam("cookbookname") String cookbookName);
|
||||
|
||||
/**
|
||||
* @see ChefCookbook#getCookbook
|
||||
*/
|
||||
@GET
|
||||
@Path("cookbooks/{cookbookname}/{version}")
|
||||
@ResponseParser(ParseCookbookVersionFromJson.class)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<CookbookVersion> getCookbook(@PathParam("cookbookname") String cookbookName,
|
||||
@PathParam("version") String version);
|
||||
@PathParam("version") String version);
|
||||
|
||||
/**
|
||||
* @see ChefClient#createClient
|
||||
|
@ -150,8 +145,7 @@ public interface ChefAsyncClient {
|
|||
@POST
|
||||
@Path("clients")
|
||||
@ResponseParser(ParseKeyFromJson.class)
|
||||
ListenableFuture<String> createClient(
|
||||
@BinderParam(BindClientnameToJsonPayload.class) String clientname);
|
||||
ListenableFuture<String> createClient(@BinderParam(BindClientnameToJsonPayload.class) String clientname);
|
||||
|
||||
/**
|
||||
* @see ChefClient#generateKeyForClient
|
||||
|
@ -160,7 +154,7 @@ public interface ChefAsyncClient {
|
|||
@Path("clients/{clientname}")
|
||||
@ResponseParser(ParseKeyFromJson.class)
|
||||
ListenableFuture<String> generateKeyForClient(
|
||||
@PathParam("clientname") @BinderParam(BindGenerateKeyForClientToJsonPayload.class) String clientname);
|
||||
@PathParam("clientname") @BinderParam(BindGenerateKeyForClientToJsonPayload.class) String clientname);
|
||||
|
||||
/**
|
||||
* @see ChefClient#clientExists
|
||||
|
@ -184,6 +178,8 @@ public interface ChefAsyncClient {
|
|||
@DELETE
|
||||
@Path("clients/{clientname}")
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@ResponseParser(ReturnStringIf2xx.class)
|
||||
// TODO: why string?
|
||||
ListenableFuture<String> deleteClient(@PathParam("clientname") String clientname);
|
||||
|
||||
/**
|
||||
|
@ -194,4 +190,51 @@ public interface ChefAsyncClient {
|
|||
@ResponseParser(ParseKeySetFromJson.class)
|
||||
ListenableFuture<Set<String>> listClients();
|
||||
|
||||
/**
|
||||
* @see ChefClient#createNode
|
||||
*/
|
||||
@POST
|
||||
@Path("nodes")
|
||||
ListenableFuture<Node> createNode(@BinderParam(BindToJsonPayload.class) Node node);
|
||||
|
||||
/**
|
||||
* @see ChefClient#updateNode
|
||||
*/
|
||||
@PUT
|
||||
@Path("nodes/{nodename}")
|
||||
ListenableFuture<Node> updateNode(
|
||||
@PathParam("nodename") @ParamParser(NodeName.class) @BinderParam(BindToJsonPayload.class) Node node);
|
||||
|
||||
/**
|
||||
* @see ChefNode#nodeExists
|
||||
*/
|
||||
@HEAD
|
||||
@Path("nodes/{nodename}")
|
||||
@ExceptionParser(ReturnFalseOnNotFoundOr404.class)
|
||||
ListenableFuture<Boolean> nodeExists(@PathParam("nodename") String nodename);
|
||||
|
||||
/**
|
||||
* @see ChefNode#getNode
|
||||
*/
|
||||
@GET
|
||||
@Path("nodes/{nodename}")
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<Node> getNode(@PathParam("nodename") String nodename);
|
||||
|
||||
/**
|
||||
* @see ChefNode#deleteNode
|
||||
*/
|
||||
@DELETE
|
||||
@Path("nodes/{nodename}")
|
||||
// TODO why string?!
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<String> deleteNode(@PathParam("nodename") String nodename);
|
||||
|
||||
/**
|
||||
* @see ChefNode#listNodes
|
||||
*/
|
||||
@GET
|
||||
@Path("nodes")
|
||||
@ResponseParser(ParseKeySetFromJson.class)
|
||||
ListenableFuture<Set<String>> listNodes();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.chef.binders;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.chef.domain.Node;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class NodeName implements Function<Object, String> {
|
||||
|
||||
public String apply(Object from) {
|
||||
return ((Node) from).getName();
|
||||
}
|
||||
|
||||
}
|
|
@ -130,7 +130,6 @@ public class BaseChefRestClientModule<S, A> extends RestClientModule<S, A> {
|
|||
|
||||
@Override
|
||||
protected void configure() {
|
||||
install(new ChefTypeAdapterModule());
|
||||
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
|
||||
super.configure();
|
||||
}
|
||||
|
|
|
@ -1,139 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* 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.
|
||||
* ====================================================================
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.chef.config;
|
||||
|
||||
import static org.jclouds.Constants.PROPERTY_GSON_ADAPTERS;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.encryption.EncryptionService;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.primitives.Bytes;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
/**
|
||||
* Configures the Chef connection.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
|
||||
public class ChefTypeAdapterModule extends AbstractModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named(PROPERTY_GSON_ADAPTERS)
|
||||
public Map<Type, Object> provideCustomAdapterBindings(HexByteListAdapter byteListAdapter,
|
||||
HexByteArrayAdapter byteArrayAdapter) {
|
||||
Map<Type, Object> bindings = Maps.newHashMap();
|
||||
bindings.put(new TypeToken<List<Byte>>() {
|
||||
}.getType(), byteListAdapter);
|
||||
bindings.put(byte[].class, byteArrayAdapter);
|
||||
return bindings;
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class HexByteListAdapter implements JsonDeserializer<List<Byte>>,
|
||||
JsonSerializer<List<Byte>> {
|
||||
private final EncryptionService encryptionService;
|
||||
|
||||
@Inject
|
||||
HexByteListAdapter(EncryptionService encryptionService) {
|
||||
this.encryptionService = encryptionService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Byte> deserialize(JsonElement json, Type typeOfT,
|
||||
JsonDeserializationContext context) throws JsonParseException {
|
||||
return Bytes.asList(encryptionService.fromHex(json.getAsString()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(List<Byte> src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
return new JsonPrimitive(encryptionService.hex(Bytes.toArray(src)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class HexByteArrayAdapter implements JsonDeserializer<byte[]>,
|
||||
JsonSerializer<byte[]> {
|
||||
private final EncryptionService encryptionService;
|
||||
|
||||
@Inject
|
||||
HexByteArrayAdapter(EncryptionService encryptionService) {
|
||||
this.encryptionService = encryptionService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
||||
throws JsonParseException {
|
||||
return encryptionService.fromHex(json.getAsString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(byte[] src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
return new JsonPrimitive(encryptionService.hex(src));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,162 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.chef.domain;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
* Sandbox object.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class Node {
|
||||
|
||||
private String name;
|
||||
private Map<String, Attribute> normal = Maps.newLinkedHashMap();
|
||||
private Map<String, Attribute> override = Maps.newLinkedHashMap();
|
||||
@SerializedName("default")
|
||||
private Map<String, Attribute> defaultA = Maps.newLinkedHashMap();
|
||||
private Map<String, Attribute> automatic = Maps.newLinkedHashMap();
|
||||
@SerializedName("run_list")
|
||||
private List<String> runList = Lists.newArrayList();
|
||||
|
||||
// internal
|
||||
@SuppressWarnings("unused")
|
||||
@SerializedName("json_class")
|
||||
private String _jsonClass = "Chef::Node";
|
||||
|
||||
public Node(String name, Map<String, Attribute> normal,
|
||||
Map<String, Attribute> override, Map<String, Attribute> defaultA,
|
||||
Map<String, Attribute> automatic, Iterable<String> runList) {
|
||||
this.name = name;
|
||||
this.normal.putAll(normal);
|
||||
this.override.putAll(override);
|
||||
this.defaultA.putAll(defaultA);
|
||||
this.automatic.putAll(automatic);
|
||||
Iterables.addAll(this.runList, runList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Node [name=" + name + ", runList=" + runList + ", normal="
|
||||
+ normal + ", default=" + defaultA + ", override=" + override
|
||||
+ ", automatic=" + automatic + "]";
|
||||
}
|
||||
|
||||
public Node(String name, Iterable<String> runList) {
|
||||
this.name = name;
|
||||
Iterables.addAll(this.runList, runList);
|
||||
}
|
||||
|
||||
// hidden but needs to be here for json deserialization to work
|
||||
Node() {
|
||||
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Map<String, Attribute> getNormal() {
|
||||
return normal;
|
||||
}
|
||||
|
||||
public Map<String, Attribute> getOverride() {
|
||||
return override;
|
||||
}
|
||||
|
||||
public Map<String, Attribute> getDefault() {
|
||||
return defaultA;
|
||||
}
|
||||
|
||||
public Map<String, Attribute> getAutomatic() {
|
||||
return automatic;
|
||||
}
|
||||
|
||||
public List<String> getRunList() {
|
||||
return runList;
|
||||
}
|
||||
|
||||
@SerializedName("chef_type")
|
||||
@SuppressWarnings("unused")
|
||||
private String _chefType = "node";
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result
|
||||
+ ((automatic == null) ? 0 : automatic.hashCode());
|
||||
result = prime * result + ((defaultA == null) ? 0 : defaultA.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((normal == null) ? 0 : normal.hashCode());
|
||||
result = prime * result + ((override == null) ? 0 : override.hashCode());
|
||||
result = prime * result + ((runList == null) ? 0 : runList.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Node other = (Node) obj;
|
||||
if (automatic == null) {
|
||||
if (other.automatic != null)
|
||||
return false;
|
||||
} else if (!automatic.equals(other.automatic))
|
||||
return false;
|
||||
if (defaultA == null) {
|
||||
if (other.defaultA != null)
|
||||
return false;
|
||||
} else if (!defaultA.equals(other.defaultA))
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
if (normal == null) {
|
||||
if (other.normal != null)
|
||||
return false;
|
||||
} else if (!normal.equals(other.normal))
|
||||
return false;
|
||||
if (override == null) {
|
||||
if (other.override != null)
|
||||
return false;
|
||||
} else if (!override.equals(other.override))
|
||||
return false;
|
||||
if (runList == null) {
|
||||
if (other.runList != null)
|
||||
return false;
|
||||
} else if (!runList.equals(other.runList))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.chef.functions;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.chef.domain.CookbookVersion;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseCookbookVersionFromJson extends ParseJson<CookbookVersion> {
|
||||
@Inject
|
||||
public ParseCookbookVersionFromJson(Gson gson) {
|
||||
super(gson);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CookbookVersion apply(InputStream stream) {
|
||||
try {
|
||||
return gson.fromJson(new InputStreamReader(stream, "UTF-8"), CookbookVersion.class);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -41,41 +41,33 @@
|
|||
*/
|
||||
package org.jclouds.chef.functions;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseKeySetFromJson extends ParseJson<Set<String>> {
|
||||
public class ParseKeySetFromJson implements Function<HttpResponse, Set<String>> {
|
||||
|
||||
private final ParseJson<Map<String, String>> json;
|
||||
|
||||
@Inject
|
||||
public ParseKeySetFromJson(Gson gson) {
|
||||
super(gson);
|
||||
ParseKeySetFromJson(ParseJson<Map<String, String>> json) {
|
||||
this.json = json;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected Set<String> apply(InputStream stream) {
|
||||
try {
|
||||
Type map = new TypeToken<Map<String, String>>() {
|
||||
}.getType();
|
||||
return ((Map<String, String>) gson.fromJson(new InputStreamReader(stream, "UTF-8"), map))
|
||||
.keySet();
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
public Set<String> apply(HttpResponse arg0) {
|
||||
return json.apply(arg0).keySet();
|
||||
|
||||
}
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* 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.
|
||||
* ====================================================================
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.chef.functions;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.chef.domain.Organization;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseOrganizationFromJson extends ParseJson<Organization> {
|
||||
@Inject
|
||||
public ParseOrganizationFromJson(Gson gson) {
|
||||
super(gson);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Organization apply(InputStream stream) {
|
||||
try {
|
||||
return gson.fromJson(new InputStreamReader(stream, "UTF-8"), Organization.class);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.chef.functions;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.chef.domain.Sandbox;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseSandboxFromJson extends ParseJson<Sandbox> {
|
||||
@Inject
|
||||
public ParseSandboxFromJson(Gson gson) {
|
||||
super(gson);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sandbox apply(InputStream stream) {
|
||||
try {
|
||||
return gson.fromJson(new InputStreamReader(stream, "UTF-8"), Sandbox.class);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.chef.functions;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.chef.domain.UploadSandbox;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseUploadSiteFromJson extends ParseJson<UploadSandbox> {
|
||||
@Inject
|
||||
public ParseUploadSiteFromJson(Gson gson) {
|
||||
super(gson);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UploadSandbox apply(InputStream stream) {
|
||||
try {
|
||||
return gson.fromJson(new InputStreamReader(stream, "UTF-8"), UploadSandbox.class);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* 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.
|
||||
* ====================================================================
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.chef.functions;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.chef.domain.User;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseUserFromJson extends ParseJson<User> {
|
||||
@Inject
|
||||
public ParseUserFromJson(Gson gson) {
|
||||
super(gson);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected User apply(InputStream stream) {
|
||||
|
||||
try {
|
||||
return gson.fromJson(new InputStreamReader(stream, "UTF-8"), User.class);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,83 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* 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.
|
||||
* ====================================================================
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.chef.functions;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseValueSetFromJson extends ParseJson<Set<String>> {
|
||||
@Inject
|
||||
public ParseValueSetFromJson(Gson gson) {
|
||||
super(gson);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected Set<String> apply(InputStream stream) {
|
||||
try {
|
||||
Type map = new TypeToken<Map<String, Set<String>>>() {
|
||||
}.getType();
|
||||
return Iterables.get(
|
||||
((Map<String, Set<String>>) gson.fromJson(new InputStreamReader(stream, "UTF-8"),
|
||||
map)).entrySet(), 0).getValue();
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -34,15 +34,13 @@ import org.jclouds.chef.config.ChefRestClientModule;
|
|||
import org.jclouds.chef.domain.CookbookVersion;
|
||||
import org.jclouds.chef.filters.SignedHeaderAuth;
|
||||
import org.jclouds.chef.filters.SignedHeaderAuthTest;
|
||||
import org.jclouds.chef.functions.ParseCookbookVersionFromJson;
|
||||
import org.jclouds.chef.functions.ParseKeyFromJson;
|
||||
import org.jclouds.chef.functions.ParseKeySetFromJson;
|
||||
import org.jclouds.chef.functions.ParseSandboxFromJson;
|
||||
import org.jclouds.chef.functions.ParseUploadSiteFromJson;
|
||||
import org.jclouds.date.TimeStamp;
|
||||
import org.jclouds.encryption.EncryptionService;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.RequiresHttp;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.http.functions.ReturnStringIf2xx;
|
||||
import org.jclouds.http.functions.ReturnTrueIf2xx;
|
||||
|
@ -75,13 +73,13 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
|
||||
Method method = ChefAsyncClient.class.getMethod("commitSandbox", String.class, boolean.class);
|
||||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method,
|
||||
"0189e76ccc476701d6b374e5a1a27347", true);
|
||||
"0189e76ccc476701d6b374e5a1a27347", true);
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"PUT http://localhost:4000/sandboxes/0189e76ccc476701d6b374e5a1a27347 HTTP/1.1");
|
||||
"PUT http://localhost:4000/sandboxes/0189e76ccc476701d6b374e5a1a27347 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertPayloadEquals(httpRequest, "{\"is_completed\":\"true\"}", "application/json", false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseSandboxFromJson.class);
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -89,26 +87,21 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
|
||||
}
|
||||
|
||||
public void testGetUploadSandboxForChecksums() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
public void testGetUploadSandboxForChecksums() throws SecurityException, NoSuchMethodException, IOException {
|
||||
EncryptionService encryptionService = injector.getInstance(EncryptionService.class);
|
||||
Method method = ChefAsyncClient.class.getMethod("getUploadSandboxForChecksums", Set.class);
|
||||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method,
|
||||
ImmutableSet
|
||||
.of(Bytes.asList(encryptionService
|
||||
.fromHex("0189e76ccc476701d6b374e5a1a27347")), Bytes
|
||||
.asList(encryptionService
|
||||
.fromHex("0c5ecd7788cf4f6c7de2a57193897a6c")), Bytes
|
||||
.asList(encryptionService
|
||||
.fromHex("1dda05ed139664f1f89b9dec482b77c0"))));
|
||||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, ImmutableSet.of(Bytes
|
||||
.asList(encryptionService.fromHex("0189e76ccc476701d6b374e5a1a27347")), Bytes.asList(encryptionService
|
||||
.fromHex("0c5ecd7788cf4f6c7de2a57193897a6c")), Bytes.asList(encryptionService
|
||||
.fromHex("1dda05ed139664f1f89b9dec482b77c0"))));
|
||||
assertRequestLineEquals(httpRequest, "POST http://localhost:4000/sandboxes HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertPayloadEquals(
|
||||
httpRequest,
|
||||
"{\"checksums\":{\"0189e76ccc476701d6b374e5a1a27347\":null,\"0c5ecd7788cf4f6c7de2a57193897a6c\":null,\"1dda05ed139664f1f89b9dec482b77c0\":null}}",
|
||||
"application/json", false);
|
||||
httpRequest,
|
||||
"{\"checksums\":{\"0189e76ccc476701d6b374e5a1a27347\":null,\"0c5ecd7788cf4f6c7de2a57193897a6c\":null,\"1dda05ed139664f1f89b9dec482b77c0\":null}}",
|
||||
"application/json", false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseUploadSiteFromJson.class);
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -118,14 +111,12 @@ 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");
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:4000/cookbooks/cookbook/1.0.0 HTTP/1.1");
|
||||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, "cookbook", "1.0.0");
|
||||
assertRequestLineEquals(httpRequest, "GET http://localhost:4000/cookbooks/cookbook/1.0.0 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseCookbookVersionFromJson.class);
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
|
||||
|
@ -135,10 +126,8 @@ 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");
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"DELETE http://localhost:4000/cookbooks/cookbook/1.0.0 HTTP/1.1");
|
||||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, "cookbook", "1.0.0");
|
||||
assertRequestLineEquals(httpRequest, "DELETE http://localhost:4000/cookbooks/cookbook/1.0.0 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
|
@ -152,17 +141,16 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
|
||||
public void testUpdateCookbook() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ChefAsyncClient.class.getMethod("updateCookbook", String.class, String.class,
|
||||
CookbookVersion.class);
|
||||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method,
|
||||
"cookbook", "1.0.1", new CookbookVersion("cookbook", "1.0.1"));
|
||||
CookbookVersion.class);
|
||||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, "cookbook", "1.0.1",
|
||||
new CookbookVersion("cookbook", "1.0.1"));
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"PUT http://localhost:4000/cookbooks/cookbook/1.0.1 HTTP/1.1");
|
||||
assertRequestLineEquals(httpRequest, "PUT http://localhost:4000/cookbooks/cookbook/1.0.1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertPayloadEquals(
|
||||
httpRequest,
|
||||
"{\"name\":\"cookbook-1.0.1\",\"definitions\":[],\"attributes\":[],\"files\":[],\"metadata\":{\"suggestions\":{},\"dependencies\":{},\"conflicting\":{},\"providing\":{},\"platforms\":{},\"recipes\":{},\"replacing\":{},\"groupings\":{},\"attributes\":{},\"recommendations\":{}},\"providers\":[],\"cookbook_name\":\"cookbook\",\"resources\":[],\"templates\":[],\"libraries\":[],\"version\":\"1.0.1\",\"recipes\":[],\"root_files\":[],\"json_class\":\"Chef::CookbookVersion\",\"chef_type\":\"cookbook_version\"}",
|
||||
"application/json", false);
|
||||
httpRequest,
|
||||
"{\"name\":\"cookbook-1.0.1\",\"definitions\":[],\"attributes\":[],\"files\":[],\"metadata\":{\"suggestions\":{},\"dependencies\":{},\"conflicting\":{},\"providing\":{},\"platforms\":{},\"recipes\":{},\"replacing\":{},\"groupings\":{},\"attributes\":{},\"recommendations\":{}},\"providers\":[],\"cookbook_name\":\"cookbook\",\"resources\":[],\"templates\":[],\"libraries\":[],\"version\":\"1.0.1\",\"recipes\":[],\"root_files\":[],\"json_class\":\"Chef::CookbookVersion\",\"chef_type\":\"cookbook_version\"}",
|
||||
"application/json", false);
|
||||
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
@ -217,14 +205,12 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
|
||||
}
|
||||
|
||||
public void testGenerateKeyForClient() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
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");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertPayloadEquals(httpRequest, "{\"clientname\":\"client\", \"private_key\": true}",
|
||||
"application/json", false);
|
||||
assertPayloadEquals(httpRequest, "{\"clientname\":\"client\", \"private_key\": true}", "application/json", false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseKeyFromJson.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -295,7 +281,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
|
||||
@Override
|
||||
public ContextSpec<ChefClient, ChefAsyncClient> createContextSpec() {
|
||||
return new RestContextFactory().createContextSpec("chef", "user",
|
||||
SignedHeaderAuthTest.PRIVATE_KEY, new Properties());
|
||||
return new RestContextFactory().createContextSpec("chef", "user", SignedHeaderAuthTest.PRIVATE_KEY,
|
||||
new Properties());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import java.io.IOException;
|
|||
import java.net.URI;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.chef.config.ChefTypeAdapterModule;
|
||||
import org.jclouds.chef.domain.Attribute;
|
||||
import org.jclouds.chef.domain.CookbookVersion;
|
||||
import org.jclouds.chef.domain.Metadata;
|
||||
|
@ -14,6 +13,7 @@ import org.jclouds.chef.domain.Resource;
|
|||
import org.jclouds.encryption.EncryptionService;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.Payloads;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
|
@ -24,6 +24,8 @@ import com.google.common.collect.ImmutableSet;
|
|||
import com.google.gson.Gson;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ParseCookbookVersionFromJson}
|
||||
|
@ -33,92 +35,100 @@ import com.google.inject.Injector;
|
|||
@Test(groups = "unit", sequential = true, testName = "chef.ParseCookbookVersionFromJsonTest")
|
||||
public class ParseCookbookVersionFromJsonTest {
|
||||
|
||||
private ParseCookbookVersionFromJson handler;
|
||||
private ParseJson<CookbookVersion> handler;
|
||||
private Injector injector;
|
||||
|
||||
@BeforeTest
|
||||
protected void setUpInjector() throws IOException {
|
||||
injector = Guice.createInjector(new ParserModule(), new ChefTypeAdapterModule());
|
||||
handler = injector.getInstance(ParseCookbookVersionFromJson.class);
|
||||
injector = Guice.createInjector(new ParserModule());
|
||||
handler = injector.getInstance(Key
|
||||
.get(new TypeLiteral<ParseJson<CookbookVersion>>() {
|
||||
}));
|
||||
}
|
||||
|
||||
@Test(enabled = false)
|
||||
public void testBrew() throws IOException {
|
||||
CookbookVersion cookbook = handler.apply(new HttpResponse(200, "ok", Payloads
|
||||
.newPayload(ParseCookbookVersionFromJsonTest.class
|
||||
.getResourceAsStream("/brew-cookbook.json"))));
|
||||
CookbookVersion cookbook = handler.apply(new HttpResponse(200, "ok",
|
||||
Payloads.newPayload(ParseCookbookVersionFromJsonTest.class
|
||||
.getResourceAsStream("/brew-cookbook.json"))));
|
||||
|
||||
assertEquals(cookbook, handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(Utils
|
||||
.toInputStream(new Gson().toJson(cookbook))))));
|
||||
assertEquals(cookbook, handler.apply(new HttpResponse(200, "ok", Payloads
|
||||
.newPayload(Utils.toInputStream(new Gson().toJson(cookbook))))));
|
||||
}
|
||||
|
||||
@Test(enabled = false)
|
||||
public void testTomcat() {
|
||||
CookbookVersion cookbook = handler.apply(new HttpResponse(200, "ok", Payloads
|
||||
.newPayload(ParseCookbookVersionFromJsonTest.class
|
||||
.getResourceAsStream("/tomcat-cookbook.json"))));
|
||||
CookbookVersion cookbook = handler.apply(new HttpResponse(200, "ok",
|
||||
Payloads.newPayload(ParseCookbookVersionFromJsonTest.class
|
||||
.getResourceAsStream("/tomcat-cookbook.json"))));
|
||||
|
||||
assertEquals(cookbook, handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(Utils
|
||||
.toInputStream(new Gson().toJson(cookbook))))));
|
||||
assertEquals(cookbook, handler.apply(new HttpResponse(200, "ok", Payloads
|
||||
.newPayload(Utils.toInputStream(new Gson().toJson(cookbook))))));
|
||||
}
|
||||
|
||||
@Test(enabled = false)
|
||||
public void testMysql() throws IOException {
|
||||
CookbookVersion cookbook = handler.apply(new HttpResponse(200, "ok", Payloads
|
||||
.newPayload(ParseCookbookVersionFromJsonTest.class
|
||||
.getResourceAsStream("/mysql-cookbook.json"))));
|
||||
CookbookVersion cookbook = handler.apply(new HttpResponse(200, "ok",
|
||||
Payloads.newPayload(ParseCookbookVersionFromJsonTest.class
|
||||
.getResourceAsStream("/mysql-cookbook.json"))));
|
||||
|
||||
assertEquals(cookbook, handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(Utils
|
||||
.toInputStream(new Gson().toJson(cookbook))))));
|
||||
assertEquals(cookbook, handler.apply(new HttpResponse(200, "ok", Payloads
|
||||
.newPayload(Utils.toInputStream(new Gson().toJson(cookbook))))));
|
||||
}
|
||||
|
||||
@Test(enabled = false)
|
||||
public void testApache() {
|
||||
EncryptionService encryptionService = injector.getInstance(EncryptionService.class);
|
||||
EncryptionService encryptionService = injector
|
||||
.getInstance(EncryptionService.class);
|
||||
|
||||
assertEquals(
|
||||
handler.apply(new HttpResponse(200, "ok", Payloads
|
||||
.newPayload(ParseCookbookVersionFromJsonTest.class
|
||||
.getResourceAsStream("/apache-chef-demo-cookbook.json")))),
|
||||
new CookbookVersion(
|
||||
"apache-chef-demo-0.0.0",
|
||||
ImmutableSet.<Resource> of(),
|
||||
ImmutableSet.<Resource> of(),
|
||||
ImmutableSet.<Resource> of(),
|
||||
new Metadata("Apache v2.0", "Your Name",
|
||||
ImmutableMap.<String, String> of(), ImmutableMap
|
||||
.<String, Set<String>> of(), "youremail@example.com",
|
||||
ImmutableMap.<String, Set<String>> of(),
|
||||
"A fabulous new cookbook",
|
||||
ImmutableMap.<String, Set<String>> of(), ImmutableMap
|
||||
.<String, Set<String>> of(), "0.0.0", ImmutableMap
|
||||
.<String, String> of(), ImmutableMap
|
||||
.<String, Set<String>> of(), "apache-chef-demo",
|
||||
ImmutableMap.<String, String> of(), "", ImmutableMap
|
||||
.<String, Attribute> of(), ImmutableMap
|
||||
.<String, String> of()),
|
||||
ImmutableSet.<Resource> of(),
|
||||
"apache-chef-demo",
|
||||
ImmutableSet.<Resource> of(),
|
||||
ImmutableSet.<Resource> of(),
|
||||
ImmutableSet.<Resource> of(),
|
||||
"0.0.0",
|
||||
ImmutableSet.<Resource> of(),
|
||||
ImmutableSet
|
||||
.<Resource> of(
|
||||
new Resource(
|
||||
"README",
|
||||
URI
|
||||
.create("https://s3.amazonaws.com/opscode-platform-production-data/organization-486ca3ac66264fea926aa0b4ff74341c/checksum-11637f98942eafbf49c71b7f2f048b78?AWSAccessKeyId=AKIAJOZTD2N26S7W6APA&Expires=1277766181&Signature=zgpNl6wSxjTNovqZu2nJq0JztU8%3D"),
|
||||
encryptionService
|
||||
.fromHex("11637f98942eafbf49c71b7f2f048b78"),
|
||||
"README", "default"),
|
||||
new Resource(
|
||||
"Rakefile",
|
||||
URI
|
||||
.create("https://s3.amazonaws.com/opscode-platform-production-data/organization-486ca3ac66264fea926aa0b4ff74341c/checksum-ebcf925a1651b4e04b9cd8aac2bc54eb?AWSAccessKeyId=AKIAJOZTD2N26S7W6APA&Expires=1277766181&Signature=EFzzDSKKytTl7b%2FxrCeNLh05zj4%3D"),
|
||||
encryptionService
|
||||
.fromHex("ebcf925a1651b4e04b9cd8aac2bc54eb"),
|
||||
"Rakefile", "default"))));
|
||||
handler
|
||||
.apply(new HttpResponse(
|
||||
200,
|
||||
"ok",
|
||||
Payloads
|
||||
.newPayload(ParseCookbookVersionFromJsonTest.class
|
||||
.getResourceAsStream("/apache-chef-demo-cookbook.json")))),
|
||||
new CookbookVersion(
|
||||
"apache-chef-demo-0.0.0",
|
||||
ImmutableSet.<Resource> of(),
|
||||
ImmutableSet.<Resource> of(),
|
||||
ImmutableSet.<Resource> of(),
|
||||
new Metadata("Apache v2.0", "Your Name", ImmutableMap
|
||||
.<String, String> of(), ImmutableMap
|
||||
.<String, Set<String>> of(), "youremail@example.com",
|
||||
ImmutableMap.<String, Set<String>> of(),
|
||||
"A fabulous new cookbook", ImmutableMap
|
||||
.<String, Set<String>> of(), ImmutableMap
|
||||
.<String, Set<String>> of(), "0.0.0",
|
||||
ImmutableMap.<String, String> of(), ImmutableMap
|
||||
.<String, Set<String>> of(), "apache-chef-demo",
|
||||
ImmutableMap.<String, String> of(), "", ImmutableMap
|
||||
.<String, Attribute> of(), ImmutableMap
|
||||
.<String, String> of()),
|
||||
ImmutableSet.<Resource> of(),
|
||||
"apache-chef-demo",
|
||||
ImmutableSet.<Resource> of(),
|
||||
ImmutableSet.<Resource> of(),
|
||||
ImmutableSet.<Resource> of(),
|
||||
"0.0.0",
|
||||
ImmutableSet.<Resource> of(),
|
||||
ImmutableSet
|
||||
.<Resource> of(
|
||||
new Resource(
|
||||
"README",
|
||||
URI
|
||||
.create("https://s3.amazonaws.com/opscode-platform-production-data/organization-486ca3ac66264fea926aa0b4ff74341c/checksum-11637f98942eafbf49c71b7f2f048b78?AWSAccessKeyId=AKIAJOZTD2N26S7W6APA&Expires=1277766181&Signature=zgpNl6wSxjTNovqZu2nJq0JztU8%3D"),
|
||||
encryptionService
|
||||
.fromHex("11637f98942eafbf49c71b7f2f048b78"),
|
||||
"README", "default"),
|
||||
new Resource(
|
||||
"Rakefile",
|
||||
URI
|
||||
.create("https://s3.amazonaws.com/opscode-platform-production-data/organization-486ca3ac66264fea926aa0b4ff74341c/checksum-ebcf925a1651b4e04b9cd8aac2bc54eb?AWSAccessKeyId=AKIAJOZTD2N26S7W6APA&Expires=1277766181&Signature=EFzzDSKKytTl7b%2FxrCeNLh05zj4%3D"),
|
||||
encryptionService
|
||||
.fromHex("ebcf925a1651b4e04b9cd8aac2bc54eb"),
|
||||
"Rakefile", "default"))));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.io.IOException;
|
|||
import org.jclouds.chef.domain.Organization;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.Payloads;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
|
@ -32,6 +33,8 @@ import org.testng.annotations.Test;
|
|||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ParseOrganizationFromJson}
|
||||
|
@ -41,12 +44,14 @@ import com.google.inject.Injector;
|
|||
@Test(groups = "unit", sequential = true, testName = "chef.ParseOrganizationFromJsonTest")
|
||||
public class ParseOrganizationFromJsonTest {
|
||||
|
||||
private ParseOrganizationFromJson handler;
|
||||
private ParseJson<Organization> handler;
|
||||
|
||||
@BeforeTest
|
||||
protected void setUpInjector() throws IOException {
|
||||
Injector injector = Guice.createInjector(new ParserModule());
|
||||
handler = injector.getInstance(ParseOrganizationFromJson.class);
|
||||
handler = injector.getInstance(Key
|
||||
.get(new TypeLiteral<ParseJson<Organization>>() {
|
||||
}));
|
||||
}
|
||||
|
||||
public void test() {
|
||||
|
@ -58,7 +63,7 @@ public class ParseOrganizationFromJsonTest {
|
|||
|
||||
String toParse = "{\"name\": \"opscode\",\"full_name\": \"Opscode, Inc.\", \"org_type\": \"Business\",\"clientname\": \"opscode-validator\" }";
|
||||
|
||||
assertEquals(handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(Utils
|
||||
.toInputStream(toParse)))), org);
|
||||
assertEquals(handler.apply(new HttpResponse(200, "ok", Payloads
|
||||
.newPayload(Utils.toInputStream(toParse)))), org);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.jclouds.chef.domain.Sandbox;
|
|||
import org.jclouds.date.DateService;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.Payloads;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
|
||||
import org.jclouds.http.functions.config.ParserModule.Iso8601DateAdapter;
|
||||
|
@ -18,6 +19,8 @@ import com.google.common.collect.ImmutableSet;
|
|||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ParseSandboxFromJson}
|
||||
|
@ -27,29 +30,33 @@ import com.google.inject.Injector;
|
|||
@Test(groups = "unit", sequential = true, testName = "chef.ParseSandboxFromJsonTest")
|
||||
public class ParseSandboxFromJsonTest {
|
||||
|
||||
private ParseSandboxFromJson handler;
|
||||
private ParseJson<Sandbox> handler;
|
||||
private DateService dateService;
|
||||
|
||||
@BeforeTest
|
||||
protected void setUpInjector() throws IOException {
|
||||
Injector injector = Guice.createInjector(new ParserModule(), new AbstractModule() {
|
||||
Injector injector = Guice.createInjector(new ParserModule(),
|
||||
new AbstractModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
|
||||
}
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
|
||||
}
|
||||
|
||||
});
|
||||
handler = injector.getInstance(ParseSandboxFromJson.class);
|
||||
});
|
||||
handler = injector.getInstance(Key
|
||||
.get(new TypeLiteral<ParseJson<Sandbox>>() {
|
||||
}));
|
||||
dateService = injector.getInstance(DateService.class);
|
||||
}
|
||||
|
||||
public void test() {
|
||||
assertEquals(handler.apply(new HttpResponse(200, "ok", Payloads
|
||||
.newPayload(ParseSandboxFromJsonTest.class.getResourceAsStream("/sandbox.json")))),
|
||||
new Sandbox("1-8c27b0ea4c2b7aaedbb44cfbdfcc11b2", false, dateService
|
||||
.iso8601SecondsDateParse("2010-07-07T03:36:00+00:00"), ImmutableSet
|
||||
.<String> of(), "f9d6d9b72bae465890aae87969f98a9c",
|
||||
"f9d6d9b72bae465890aae87969f98a9c"));
|
||||
.newPayload(ParseSandboxFromJsonTest.class
|
||||
.getResourceAsStream("/sandbox.json")))), new Sandbox(
|
||||
"1-8c27b0ea4c2b7aaedbb44cfbdfcc11b2", false, dateService
|
||||
.iso8601SecondsDateParse("2010-07-07T03:36:00+00:00"),
|
||||
ImmutableSet.<String> of(), "f9d6d9b72bae465890aae87969f98a9c",
|
||||
"f9d6d9b72bae465890aae87969f98a9c"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
package org.jclouds.chef.functions;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.chef.domain.ChecksumStatus;
|
||||
import org.jclouds.chef.domain.UploadSandbox;
|
||||
import org.jclouds.encryption.EncryptionService;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.Payloads;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.primitives.Bytes;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ParseUploadSiteFromJson}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", sequential = true, testName = "chef.ParseUploadSiteFromJsonTest")
|
||||
public class ParseUploadSandboxFromJsonTest {
|
||||
|
||||
private ParseJson<UploadSandbox> handler;
|
||||
private Injector injector;
|
||||
|
||||
@BeforeTest
|
||||
protected void setUpInjector() throws IOException {
|
||||
injector = Guice.createInjector(new ParserModule());
|
||||
handler = injector.getInstance(Key
|
||||
.get(new TypeLiteral<ParseJson<UploadSandbox>>() {
|
||||
}));
|
||||
}
|
||||
|
||||
public void test() {
|
||||
EncryptionService encryptionService = injector
|
||||
.getInstance(EncryptionService.class);
|
||||
assertEquals(
|
||||
handler.apply(new HttpResponse(200, "ok", Payloads
|
||||
.newPayload(ParseUploadSandboxFromJsonTest.class
|
||||
.getResourceAsStream("/upload-site.json")))),
|
||||
new UploadSandbox(
|
||||
URI
|
||||
.create("https://api.opscode.com/organizations/jclouds/sandboxes/d454f71e2a5f400c808d0c5d04c2c88c"),
|
||||
ImmutableMap
|
||||
.<List<Byte>, ChecksumStatus> of(
|
||||
Bytes
|
||||
.asList(encryptionService
|
||||
.fromHex("0c5ecd7788cf4f6c7de2a57193897a6c")),
|
||||
new ChecksumStatus(
|
||||
URI
|
||||
.create("https://s3.amazonaws.com/opscode-platform-production-data/organization-486ca3ac66264fea926aa0b4ff74341c/sandbox-d454f71e2a5f400c808d0c5d04c2c88c/checksum-0c5ecd7788cf4f6c7de2a57193897a6c?AWSAccessKeyId=AKIAJOZTD2N26S7W6APA&Expires=1277344702&Signature=FtKyqvYEjhhEKmRY%2B0M8aGPMM7g%3D"),
|
||||
true),
|
||||
Bytes
|
||||
.asList(encryptionService
|
||||
.fromHex("0189e76ccc476701d6b374e5a1a27347")),
|
||||
new ChecksumStatus(),
|
||||
Bytes
|
||||
.asList(encryptionService
|
||||
.fromHex("1dda05ed139664f1f89b9dec482b77c0")),
|
||||
new ChecksumStatus()),
|
||||
"d454f71e2a5f400c808d0c5d04c2c88c"));
|
||||
}
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
package org.jclouds.chef.functions;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.chef.config.ChefTypeAdapterModule;
|
||||
import org.jclouds.chef.domain.ChecksumStatus;
|
||||
import org.jclouds.chef.domain.UploadSandbox;
|
||||
import org.jclouds.encryption.EncryptionService;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.Payloads;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.primitives.Bytes;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ParseUploadSiteFromJson}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", sequential = true, testName = "chef.ParseUploadSiteFromJsonTest")
|
||||
public class ParseUploadSiteFromJsonTest {
|
||||
|
||||
private ParseUploadSiteFromJson handler;
|
||||
private Injector injector;
|
||||
|
||||
@BeforeTest
|
||||
protected void setUpInjector() throws IOException {
|
||||
injector = Guice.createInjector(new ParserModule(), new ChefTypeAdapterModule());
|
||||
handler = injector.getInstance(ParseUploadSiteFromJson.class);
|
||||
}
|
||||
|
||||
public void test() {
|
||||
EncryptionService encryptionService = injector.getInstance(EncryptionService.class);
|
||||
assertEquals(
|
||||
handler.apply(new HttpResponse(200, "ok", Payloads
|
||||
.newPayload(ParseUploadSiteFromJsonTest.class
|
||||
.getResourceAsStream("/upload-site.json")))),
|
||||
new UploadSandbox(
|
||||
URI
|
||||
.create("https://api.opscode.com/organizations/jclouds/sandboxes/d454f71e2a5f400c808d0c5d04c2c88c"),
|
||||
ImmutableMap
|
||||
.<List<Byte>, ChecksumStatus> of(
|
||||
Bytes.asList(encryptionService
|
||||
.fromHex("0c5ecd7788cf4f6c7de2a57193897a6c")),
|
||||
new ChecksumStatus(
|
||||
URI
|
||||
.create("https://s3.amazonaws.com/opscode-platform-production-data/organization-486ca3ac66264fea926aa0b4ff74341c/sandbox-d454f71e2a5f400c808d0c5d04c2c88c/checksum-0c5ecd7788cf4f6c7de2a57193897a6c?AWSAccessKeyId=AKIAJOZTD2N26S7W6APA&Expires=1277344702&Signature=FtKyqvYEjhhEKmRY%2B0M8aGPMM7g%3D"),
|
||||
true), Bytes.asList(encryptionService
|
||||
.fromHex("0189e76ccc476701d6b374e5a1a27347")),
|
||||
new ChecksumStatus(), Bytes.asList(encryptionService
|
||||
.fromHex("1dda05ed139664f1f89b9dec482b77c0")),
|
||||
new ChecksumStatus()), "d454f71e2a5f400c808d0c5d04c2c88c"));
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ import java.io.IOException;
|
|||
import org.jclouds.chef.domain.User;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.Payloads;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
|
@ -14,6 +15,8 @@ import org.testng.annotations.Test;
|
|||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ParseUserFromJson}
|
||||
|
@ -23,12 +26,14 @@ import com.google.inject.Injector;
|
|||
@Test(groups = "unit", sequential = true, testName = "chef.ParseUserFromJsonTest")
|
||||
public class ParseUserFromJsonTest {
|
||||
|
||||
private ParseUserFromJson handler;
|
||||
private ParseJson<User> handler;
|
||||
|
||||
@BeforeTest
|
||||
protected void setUpInjector() throws IOException {
|
||||
Injector injector = Guice.createInjector(new ParserModule());
|
||||
handler = injector.getInstance(ParseUserFromJson.class);
|
||||
handler = injector.getInstance(Key
|
||||
.get(new TypeLiteral<ParseJson<User>>() {
|
||||
}));
|
||||
}
|
||||
|
||||
public void test() {
|
||||
|
@ -42,7 +47,7 @@ public class ParseUserFromJsonTest {
|
|||
|
||||
String toParse = "{\n\"username\": \"bobo\",\n\"first_name\": \"Bobo\",\n\"middle_name\": \"Tiberion\",\n\"last_name\": \"Clown\",\n\"display_name\": \"Bobo T. Clown\",\n\"email\": \"bobo@clownco.com\" \n}";
|
||||
|
||||
assertEquals(handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(Utils
|
||||
.toInputStream(toParse)))), user);
|
||||
assertEquals(handler.apply(new HttpResponse(200, "ok", Payloads
|
||||
.newPayload(Utils.toInputStream(toParse)))), user);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
package org.jclouds.chef.functions;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.Payloads;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ParseValueSetFromJson}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", sequential = true, testName = "chef.ParseValueSetFromJsonTest")
|
||||
public class ParseValueSetFromJsonTest {
|
||||
|
||||
private ParseValueSetFromJson handler;
|
||||
|
||||
@BeforeTest
|
||||
protected void setUpInjector() throws IOException {
|
||||
Injector injector = Guice.createInjector(new ParserModule());
|
||||
handler = injector.getInstance(ParseValueSetFromJson.class);
|
||||
}
|
||||
|
||||
public void testRegex() {
|
||||
assertEquals(handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(Utils
|
||||
.toInputStream("{\"runit\":[\"0.7.0\",\"0.7.1\"]}")))), ImmutableSet.of("0.7.0",
|
||||
"0.7.1"));
|
||||
}
|
||||
}
|
|
@ -19,6 +19,11 @@
|
|||
package org.jclouds.compute.internal;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Predicates.and;
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
import static com.google.common.collect.Iterables.find;
|
||||
import static com.google.common.collect.Lists.newArrayList;
|
||||
import static org.jclouds.util.Utils.multiMax;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
@ -42,15 +47,12 @@ import org.jclouds.compute.options.TemplateOptions;
|
|||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.util.Utils;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.ComparisonChain;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Ordering;
|
||||
import com.google.common.primitives.Doubles;
|
||||
|
||||
|
@ -65,12 +67,12 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
|||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
private final Provider<Set<? extends Image>> images;
|
||||
private final Provider<Set<? extends Size>> sizes;
|
||||
private final Provider<Set<? extends Location>> locations;
|
||||
protected final Provider<Set<? extends Image>> images;
|
||||
protected final Provider<Set<? extends Size>> sizes;
|
||||
protected final Provider<Set<? extends Location>> locations;
|
||||
protected final Provider<TemplateOptions> optionsProvider;
|
||||
private final Provider<TemplateBuilder> defaultTemplateProvider;
|
||||
private final Location defaultLocation;
|
||||
protected final Provider<TemplateBuilder> defaultTemplateProvider;
|
||||
protected final Location defaultLocation;
|
||||
|
||||
@VisibleForTesting
|
||||
protected OsFamily os;
|
||||
|
@ -102,10 +104,8 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
|||
protected TemplateOptions options;
|
||||
|
||||
@Inject
|
||||
protected TemplateBuilderImpl(Provider<Set<? extends Location>> locations,
|
||||
Provider<Set<? extends Image>> images,
|
||||
Provider<Set<? extends Size>> sizes, Location defaultLocation,
|
||||
Provider<TemplateOptions> optionsProvider,
|
||||
protected TemplateBuilderImpl(Provider<Set<? extends Location>> locations, Provider<Set<? extends Image>> images,
|
||||
Provider<Set<? extends Size>> sizes, Location defaultLocation, Provider<TemplateOptions> optionsProvider,
|
||||
@Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider) {
|
||||
this.locations = locations;
|
||||
this.images = images;
|
||||
|
@ -172,15 +172,7 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
|||
returnVal = false;
|
||||
else
|
||||
returnVal = input.getOsDescription().contains(osDescription)
|
||||
|| input.getOsDescription().matches(osDescription); /*
|
||||
* note:
|
||||
* matches
|
||||
* ()
|
||||
* expects
|
||||
* a
|
||||
* regex
|
||||
* !
|
||||
*/
|
||||
|| input.getOsDescription().matches(osDescription);
|
||||
}
|
||||
return returnVal;
|
||||
}
|
||||
|
@ -193,13 +185,7 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
|||
if (input.getVersion() == null)
|
||||
returnVal = false;
|
||||
else
|
||||
returnVal = input.getVersion().contains(imageVersion)
|
||||
|| input.getVersion().matches(imageVersion); /*
|
||||
* note:
|
||||
* matches()
|
||||
* expects a
|
||||
* regex!
|
||||
*/
|
||||
returnVal = input.getVersion().contains(imageVersion) || input.getVersion().matches(imageVersion);
|
||||
}
|
||||
return returnVal;
|
||||
}
|
||||
|
@ -212,11 +198,7 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
|||
if (input.getName() == null)
|
||||
returnVal = false;
|
||||
else
|
||||
returnVal = input.getName().contains(imageName)
|
||||
|| input.getName().matches(imageName); /*
|
||||
* note: matches()
|
||||
* expects a regex!
|
||||
*/
|
||||
returnVal = input.getName().contains(imageName) || input.getName().matches(imageName);
|
||||
}
|
||||
return returnVal;
|
||||
}
|
||||
|
@ -231,15 +213,7 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
|||
else
|
||||
returnVal = input.getDescription().equals(imageDescription)
|
||||
|| input.getDescription().contains(imageDescription)
|
||||
|| input.getDescription().matches(imageDescription); /*
|
||||
* note:
|
||||
* matches
|
||||
* ()
|
||||
* expects
|
||||
* a
|
||||
* regex
|
||||
* !
|
||||
*/
|
||||
|| input.getDescription().matches(imageDescription);
|
||||
}
|
||||
return returnVal;
|
||||
}
|
||||
|
@ -272,15 +246,13 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
|||
return input.getRam() >= TemplateBuilderImpl.this.minRam;
|
||||
}
|
||||
};
|
||||
private final Predicate<Size> sizePredicate = Predicates.and(
|
||||
sizeIdPredicate, locationPredicate, sizeCoresPredicate,
|
||||
private final Predicate<Size> sizePredicate = and(sizeIdPredicate, locationPredicate, sizeCoresPredicate,
|
||||
sizeRamPredicate);
|
||||
|
||||
static final Ordering<Size> DEFAULT_SIZE_ORDERING = new Ordering<Size>() {
|
||||
public int compare(Size left, Size right) {
|
||||
return ComparisonChain.start().compare(left.getCores(),
|
||||
right.getCores()).compare(left.getRam(), right.getRam())
|
||||
.compare(left.getDisk(), right.getDisk()).result();
|
||||
return ComparisonChain.start().compare(left.getCores(), right.getCores()).compare(left.getRam(),
|
||||
right.getRam()).compare(left.getDisk(), right.getDisk()).result();
|
||||
}
|
||||
};
|
||||
static final Ordering<Size> BY_CORES_ORDERING = new Ordering<Size>() {
|
||||
|
@ -290,13 +262,11 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
|||
};
|
||||
static final Ordering<Image> DEFAULT_IMAGE_ORDERING = new Ordering<Image>() {
|
||||
public int compare(Image left, Image right) {
|
||||
return ComparisonChain.start().compare(left.getName(),
|
||||
right.getName(), Ordering.<String> natural().nullsLast())
|
||||
.compare(left.getVersion(), right.getVersion(),
|
||||
Ordering.<String> natural().nullsLast()).compare(
|
||||
left.getOsDescription(), right.getOsDescription(),
|
||||
Ordering.<String> natural().nullsLast()).compare(
|
||||
left.getArchitecture(), right.getArchitecture()).result();
|
||||
return ComparisonChain.start().compare(left.getName(), right.getName(),
|
||||
Ordering.<String> natural().nullsLast()).compare(left.getVersion(), right.getVersion(),
|
||||
Ordering.<String> natural().nullsLast()).compare(left.getOsDescription(), right.getOsDescription(),
|
||||
Ordering.<String> natural().nullsLast()).compare(left.getArchitecture(), right.getArchitecture())
|
||||
.result();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -415,17 +385,8 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
|||
options = optionsProvider.get();
|
||||
logger.debug(">> searching params(%s)", this);
|
||||
Location location = resolveLocation();
|
||||
List<? extends Image> images = resolveImages();
|
||||
final Size size = resolveSize(sizeSorter(), images);
|
||||
|
||||
Image image = Iterables.find(images, new Predicate<Image>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(Image input) {
|
||||
return size.supportsImage(input);
|
||||
}
|
||||
|
||||
});
|
||||
Size size = resolveSize(sizeSorter(), getImages());
|
||||
Image image = resolveImage(size);
|
||||
logger.debug("<< matched image(%s)", image);
|
||||
|
||||
// ensure we have an architecture matching
|
||||
|
@ -434,52 +395,41 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
|||
}
|
||||
|
||||
protected Location resolveLocation() {
|
||||
Location location = Iterables.find(locations.get(),
|
||||
new Predicate<Location>() {
|
||||
Location location = find(locations.get(), new Predicate<Location>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(Location input) {
|
||||
return input.getId().equals(locationId);
|
||||
}
|
||||
@Override
|
||||
public boolean apply(Location input) {
|
||||
return input.getId().equals(locationId);
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
logger.debug("<< matched location(%s)", location);
|
||||
return location;
|
||||
}
|
||||
|
||||
protected Size resolveSize(Ordering<Size> sizeOrdering,
|
||||
final List<? extends Image> images) {
|
||||
protected Size resolveSize(Ordering<Size> sizeOrdering, final Iterable<? extends Image> images) {
|
||||
Size size;
|
||||
try {
|
||||
Iterable<? extends Size> sizesThatAreCompatibleWithOurImages = Iterables
|
||||
.filter(sizes.get(), new Predicate<Size>() {
|
||||
@Override
|
||||
public boolean apply(final Size size) {
|
||||
boolean returnVal = false;
|
||||
if (size != null)
|
||||
returnVal = Iterables.any(images,
|
||||
new Predicate<Image>() {
|
||||
Iterable<? extends Size> sizesThatAreCompatibleWithOurImages = filter(sizes.get(), new Predicate<Size>() {
|
||||
@Override
|
||||
public boolean apply(final Size size) {
|
||||
boolean returnVal = false;
|
||||
if (size != null) {
|
||||
returnVal = Iterables.any(images, new Predicate<Image>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(Image input) {
|
||||
boolean returnVal = size
|
||||
.supportsImage(input);
|
||||
if (!returnVal && input.getId().equals("us-east-1/ami-7ea24a17")) {
|
||||
System.err.println("goo");
|
||||
}
|
||||
return returnVal;
|
||||
@Override
|
||||
public boolean apply(Image input) {
|
||||
return size.supportsImage(input);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
return returnVal;
|
||||
}
|
||||
});
|
||||
size = sizeOrdering.max(Iterables.filter(
|
||||
sizesThatAreCompatibleWithOurImages, sizePredicate));
|
||||
});
|
||||
}
|
||||
return returnVal;
|
||||
}
|
||||
});
|
||||
size = sizeOrdering.max(filter(sizesThatAreCompatibleWithOurImages, sizePredicate));
|
||||
} catch (NoSuchElementException exception) {
|
||||
throw new NoSuchElementException("size didn't match: " + toString()
|
||||
+ "\n" + sizes.get());
|
||||
throw new NoSuchElementException("size didn't match: " + toString() + "\n" + sizes.get());
|
||||
}
|
||||
logger.debug("<< matched size(%s)", size);
|
||||
return size;
|
||||
|
@ -490,36 +440,44 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
|||
if (!biggest)
|
||||
sizeOrdering = sizeOrdering.reverse();
|
||||
if (fastest)
|
||||
sizeOrdering = Ordering.compound(ImmutableList.of(BY_CORES_ORDERING,
|
||||
sizeOrdering));
|
||||
sizeOrdering = Ordering.compound(ImmutableList.of(BY_CORES_ORDERING, sizeOrdering));
|
||||
return sizeOrdering;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param size
|
||||
* @throws NoSuchElementException
|
||||
* if there's no image that matches the predicate
|
||||
*/
|
||||
protected List<? extends Image> resolveImages() {
|
||||
Predicate<Image> imagePredicate = buildImagePredicate();
|
||||
protected Image resolveImage(final Size size) {
|
||||
Predicate<Image> imagePredicate = and(buildImagePredicate(), new Predicate<Image>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(Image arg0) {
|
||||
return size.supportsImage(arg0);
|
||||
}
|
||||
|
||||
});
|
||||
try {
|
||||
Iterable<? extends Image> matchingImages = Iterables.filter(images
|
||||
.get(), imagePredicate);
|
||||
Iterable<? extends Image> matchingImages = filter(getImages(), imagePredicate);
|
||||
if (logger.isTraceEnabled())
|
||||
logger.trace("<< matched images(%s)", matchingImages);
|
||||
List<? extends Image> maxImages = Utils.multiMax(
|
||||
DEFAULT_IMAGE_ORDERING, matchingImages);
|
||||
List<? extends Image> maxImages = multiMax(DEFAULT_IMAGE_ORDERING, matchingImages);
|
||||
if (logger.isTraceEnabled())
|
||||
logger.trace("<< best images(%s)", maxImages);
|
||||
return maxImages;
|
||||
return maxImages.get(maxImages.size() - 1);
|
||||
} catch (NoSuchElementException exception) {
|
||||
throw new NoSuchElementException("image didn't match: " + toString()
|
||||
+ "\n" + images.get());
|
||||
throw new NoSuchElementException("image didn't match: " + toString() + "\n" + getImages());
|
||||
}
|
||||
}
|
||||
|
||||
protected Set<? extends Image> getImages() {
|
||||
return images.get();
|
||||
}
|
||||
|
||||
private Predicate<Image> buildImagePredicate() {
|
||||
List<Predicate<Image>> predicates = Lists.newArrayList();
|
||||
List<Predicate<Image>> predicates = newArrayList();
|
||||
if (imageId != null) {
|
||||
predicates.add(idPredicate);
|
||||
} else {
|
||||
|
@ -539,7 +497,7 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
|||
predicates.add(imageDescriptionPredicate);
|
||||
}
|
||||
|
||||
Predicate<Image> imagePredicate = Predicates.and(predicates);
|
||||
Predicate<Image> imagePredicate = and(predicates);
|
||||
return imagePredicate;
|
||||
}
|
||||
|
||||
|
@ -650,11 +608,9 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
|||
|
||||
@VisibleForTesting
|
||||
boolean nothingChangedExceptOptions() {
|
||||
return os == null && arch == null && locationId == null
|
||||
&& imageId == null && sizeId == null && osDescription == null
|
||||
&& imageVersion == null && imageName == null
|
||||
&& imageDescription == null && minCores == 0 && minRam == 0
|
||||
&& !biggest && !fastest;
|
||||
return os == null && arch == null && locationId == null && imageId == null && sizeId == null
|
||||
&& osDescription == null && imageVersion == null && imageName == null && imageDescription == null
|
||||
&& minCores == 0 && minRam == 0 && !biggest && !fastest;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -667,11 +623,9 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[arch=" + arch + ", biggest=" + biggest + ", fastest=" + fastest
|
||||
+ ", imageName=" + imageName + ", imageDescription="
|
||||
+ imageDescription + ", imageId=" + imageId + ", imageVersion="
|
||||
+ imageVersion + ", location=" + locationId + ", minCores="
|
||||
+ minCores + ", minRam=" + minRam + ", os=" + os
|
||||
return "[arch=" + arch + ", biggest=" + biggest + ", fastest=" + fastest + ", imageName=" + imageName
|
||||
+ ", imageDescription=" + imageDescription + ", imageId=" + imageId + ", imageVersion=" + imageVersion
|
||||
+ ", location=" + locationId + ", minCores=" + minCores + ", minRam=" + minRam + ", os=" + os
|
||||
+ ", osDescription=" + osDescription + ", sizeId=" + sizeId + "]";
|
||||
}
|
||||
|
||||
|
|
|
@ -58,17 +58,14 @@ public class TemplateBuilderImplTest {
|
|||
Image image = createMock(Image.class);
|
||||
Image image2 = createMock(Image.class);
|
||||
|
||||
Size size = new SizeImpl("sizeId", null, "sizeId", defaultLocation, null,
|
||||
ImmutableMap.<String, String> of(), 1.0, 0, 0, ImagePredicates
|
||||
.any());
|
||||
Size size = new SizeImpl("sizeId", null, "sizeId", defaultLocation, null, ImmutableMap.<String, String> of(),
|
||||
1.0, 0, 0, ImagePredicates.any());
|
||||
|
||||
Provider<Set<? extends Location>> locations = Providers
|
||||
.<Set<? extends Location>> of(ImmutableSet
|
||||
.<Location> of(defaultLocation));
|
||||
Provider<Set<? extends Image>> images = Providers
|
||||
.<Set<? extends Image>> of(ImmutableSet.<Image> of(image, image2));
|
||||
Provider<Set<? extends Size>> sizes = Providers
|
||||
.<Set<? extends Size>> of(ImmutableSet.<Size> of(size));
|
||||
Provider<Set<? extends Location>> locations = Providers.<Set<? extends Location>> of(ImmutableSet
|
||||
.<Location> of(defaultLocation));
|
||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet
|
||||
.<Image> of(image, image2));
|
||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet.<Size> of(size));
|
||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||
TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class);
|
||||
|
@ -79,10 +76,8 @@ public class TemplateBuilderImplTest {
|
|||
expect(image2.getVersion()).andReturn("version");
|
||||
expect(image.getOsDescription()).andReturn("osDescription");
|
||||
expect(image2.getOsDescription()).andReturn("osDescription");
|
||||
expect(image.getArchitecture()).andReturn(Architecture.X86_64)
|
||||
.atLeastOnce();
|
||||
expect(image2.getArchitecture()).andReturn(Architecture.X86_64)
|
||||
.atLeastOnce();
|
||||
expect(image.getArchitecture()).andReturn(Architecture.X86_64).atLeastOnce();
|
||||
expect(image2.getArchitecture()).andReturn(Architecture.X86_64).atLeastOnce();
|
||||
|
||||
replay(image);
|
||||
replay(image2);
|
||||
|
@ -91,10 +86,10 @@ public class TemplateBuilderImplTest {
|
|||
replay(optionsProvider);
|
||||
replay(templateBuilderProvider);
|
||||
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes, defaultLocation, optionsProvider,
|
||||
templateBuilderProvider);
|
||||
|
||||
assertEquals(template.resolveImages(), images.get());
|
||||
assertEquals(template.resolveImage(size), image2);
|
||||
|
||||
verify(image);
|
||||
verify(image2);
|
||||
|
@ -111,17 +106,14 @@ public class TemplateBuilderImplTest {
|
|||
Image image = createMock(Image.class);
|
||||
Image image2 = createMock(Image.class);
|
||||
|
||||
Size size = new SizeImpl("sizeId", null, "sizeId", defaultLocation, null,
|
||||
ImmutableMap.<String, String> of(), 1.0, 0, 0, ImagePredicates
|
||||
.any());
|
||||
Size size = new SizeImpl("sizeId", null, "sizeId", defaultLocation, null, ImmutableMap.<String, String> of(),
|
||||
1.0, 0, 0, ImagePredicates.any());
|
||||
|
||||
Provider<Set<? extends Location>> locations = Providers
|
||||
.<Set<? extends Location>> of(ImmutableSet
|
||||
.<Location> of(defaultLocation));
|
||||
Provider<Set<? extends Image>> images = Providers
|
||||
.<Set<? extends Image>> of(ImmutableSet.<Image> of(image, image2));
|
||||
Provider<Set<? extends Size>> sizes = Providers
|
||||
.<Set<? extends Size>> of(ImmutableSet.<Size> of(size));
|
||||
Provider<Set<? extends Location>> locations = Providers.<Set<? extends Location>> of(ImmutableSet
|
||||
.<Location> of(defaultLocation));
|
||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet
|
||||
.<Image> of(image, image2));
|
||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet.<Size> of(size));
|
||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||
TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class);
|
||||
|
@ -130,12 +122,10 @@ public class TemplateBuilderImplTest {
|
|||
expect(optionsProvider.get()).andReturn(new TemplateOptions());
|
||||
|
||||
expect(image.getLocation()).andReturn(defaultLocation).atLeastOnce();
|
||||
expect(image.getArchitecture()).andReturn(Architecture.X86_32)
|
||||
.atLeastOnce();
|
||||
expect(image.getArchitecture()).andReturn(Architecture.X86_32).atLeastOnce();
|
||||
|
||||
expect(image2.getLocation()).andReturn(defaultLocation).atLeastOnce();
|
||||
expect(image2.getArchitecture()).andReturn(Architecture.X86_64)
|
||||
.atLeastOnce();
|
||||
expect(image2.getArchitecture()).andReturn(Architecture.X86_64).atLeastOnce();
|
||||
|
||||
replay(image);
|
||||
replay(image2);
|
||||
|
@ -144,11 +134,10 @@ public class TemplateBuilderImplTest {
|
|||
replay(optionsProvider);
|
||||
replay(templateBuilderProvider);
|
||||
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes, defaultLocation, optionsProvider,
|
||||
templateBuilderProvider);
|
||||
|
||||
assertEquals(template.smallest().architecture(Architecture.X86_32)
|
||||
.build().getImage(), image);
|
||||
assertEquals(template.smallest().architecture(Architecture.X86_32).build().getImage(), image);
|
||||
|
||||
verify(image);
|
||||
verify(image2);
|
||||
|
@ -163,17 +152,13 @@ public class TemplateBuilderImplTest {
|
|||
public void testSizeWithImageIdPredicateOnlyAcceptsImage() {
|
||||
Location defaultLocation = createMock(Location.class);
|
||||
Image image = createMock(Image.class);
|
||||
Size size = new SizeImpl("sizeId", null, "sizeId", defaultLocation, null,
|
||||
ImmutableMap.<String, String> of(), 0, 0, 0, ImagePredicates
|
||||
.idEquals("imageId"));
|
||||
Size size = new SizeImpl("sizeId", null, "sizeId", defaultLocation, null, ImmutableMap.<String, String> of(), 0,
|
||||
0, 0, ImagePredicates.idEquals("imageId"));
|
||||
|
||||
Provider<Set<? extends Location>> locations = Providers
|
||||
.<Set<? extends Location>> of(ImmutableSet
|
||||
.<Location> of(defaultLocation));
|
||||
Provider<Set<? extends Image>> images = Providers
|
||||
.<Set<? extends Image>> of(ImmutableSet.<Image> of(image));
|
||||
Provider<Set<? extends Size>> sizes = Providers
|
||||
.<Set<? extends Size>> of(ImmutableSet.<Size> of(size));
|
||||
Provider<Set<? extends Location>> locations = Providers.<Set<? extends Location>> of(ImmutableSet
|
||||
.<Location> of(defaultLocation));
|
||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet.<Image> of(image));
|
||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet.<Size> of(size));
|
||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||
TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class);
|
||||
|
@ -195,8 +180,8 @@ public class TemplateBuilderImplTest {
|
|||
replay(optionsProvider);
|
||||
replay(templateBuilderProvider);
|
||||
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes, defaultLocation, optionsProvider,
|
||||
templateBuilderProvider);
|
||||
|
||||
template.imageId("imageId").build();
|
||||
|
||||
|
@ -212,17 +197,13 @@ public class TemplateBuilderImplTest {
|
|||
public void testSizeWithImageIdPredicateOnlyDoesntImage() {
|
||||
Location defaultLocation = createMock(Location.class);
|
||||
Image image = createMock(Image.class);
|
||||
Size size = new SizeImpl("sizeId", null, "sizeId", defaultLocation, null,
|
||||
ImmutableMap.<String, String> of(), 0, 0, 0, ImagePredicates
|
||||
.idEquals("imageId"));
|
||||
Size size = new SizeImpl("sizeId", null, "sizeId", defaultLocation, null, ImmutableMap.<String, String> of(), 0,
|
||||
0, 0, ImagePredicates.idEquals("imageId"));
|
||||
|
||||
Provider<Set<? extends Location>> locations = Providers
|
||||
.<Set<? extends Location>> of(ImmutableSet
|
||||
.<Location> of(defaultLocation));
|
||||
Provider<Set<? extends Image>> images = Providers
|
||||
.<Set<? extends Image>> of(ImmutableSet.<Image> of(image));
|
||||
Provider<Set<? extends Size>> sizes = Providers
|
||||
.<Set<? extends Size>> of(ImmutableSet.<Size> of(size));
|
||||
Provider<Set<? extends Location>> locations = Providers.<Set<? extends Location>> of(ImmutableSet
|
||||
.<Location> of(defaultLocation));
|
||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet.<Image> of(image));
|
||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet.<Size> of(size));
|
||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||
TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class);
|
||||
|
@ -230,13 +211,6 @@ public class TemplateBuilderImplTest {
|
|||
expect(defaultLocation.getId()).andReturn("locationId").atLeastOnce();
|
||||
expect(optionsProvider.get()).andReturn(new TemplateOptions());
|
||||
expect(image.getId()).andReturn("notImageId").atLeastOnce();
|
||||
expect(image.getLocation()).andReturn(defaultLocation).atLeastOnce();
|
||||
expect(image.getOsFamily()).andReturn(null);
|
||||
expect(image.getName()).andReturn(null);
|
||||
expect(image.getDescription()).andReturn(null);
|
||||
expect(image.getOsDescription()).andReturn(null);
|
||||
expect(image.getVersion()).andReturn(null);
|
||||
expect(image.getArchitecture()).andReturn(null).atLeastOnce();
|
||||
|
||||
replay(image);
|
||||
replay(defaultTemplate);
|
||||
|
@ -244,8 +218,8 @@ public class TemplateBuilderImplTest {
|
|||
replay(optionsProvider);
|
||||
replay(templateBuilderProvider);
|
||||
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes, defaultLocation, optionsProvider,
|
||||
templateBuilderProvider);
|
||||
try {
|
||||
template.imageId("notImageId").build();
|
||||
assert false;
|
||||
|
@ -266,10 +240,8 @@ public class TemplateBuilderImplTest {
|
|||
|
||||
Provider<Set<? extends Location>> locations = Providers
|
||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
||||
Provider<Set<? extends Image>> images = Providers
|
||||
.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers
|
||||
.<Set<? extends Size>> of(ImmutableSet.<Size> of());
|
||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet.<Size> of());
|
||||
Location defaultLocation = createMock(Location.class);
|
||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||
|
@ -285,8 +257,8 @@ public class TemplateBuilderImplTest {
|
|||
replay(optionsProvider);
|
||||
replay(templateBuilderProvider);
|
||||
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes, defaultLocation, optionsProvider,
|
||||
templateBuilderProvider);
|
||||
|
||||
template.options(options).build();
|
||||
|
||||
|
@ -302,10 +274,8 @@ public class TemplateBuilderImplTest {
|
|||
|
||||
Provider<Set<? extends Location>> locations = Providers
|
||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
||||
Provider<Set<? extends Image>> images = Providers
|
||||
.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers
|
||||
.<Set<? extends Size>> of(ImmutableSet.<Size> of());
|
||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet.<Size> of());
|
||||
|
||||
Location defaultLocation = createMock(Location.class);
|
||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||
|
@ -320,8 +290,8 @@ public class TemplateBuilderImplTest {
|
|||
replay(optionsProvider);
|
||||
replay(templateBuilderProvider);
|
||||
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes, defaultLocation, optionsProvider,
|
||||
templateBuilderProvider);
|
||||
|
||||
template.build();
|
||||
|
||||
|
@ -331,14 +301,11 @@ public class TemplateBuilderImplTest {
|
|||
verify(templateBuilderProvider);
|
||||
}
|
||||
|
||||
protected TemplateBuilderImpl createTemplateBuilder(
|
||||
Provider<Set<? extends Location>> locations,
|
||||
Provider<Set<? extends Image>> images,
|
||||
Provider<Set<? extends Size>> sizes, Location defaultLocation,
|
||||
Provider<TemplateOptions> optionsProvider,
|
||||
Provider<TemplateBuilder> templateBuilderProvider) {
|
||||
TemplateBuilderImpl template = new TemplateBuilderImpl(locations, images,
|
||||
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
protected TemplateBuilderImpl createTemplateBuilder(Provider<Set<? extends Location>> locations,
|
||||
Provider<Set<? extends Image>> images, Provider<Set<? extends Size>> sizes, Location defaultLocation,
|
||||
Provider<TemplateOptions> optionsProvider, Provider<TemplateBuilder> templateBuilderProvider) {
|
||||
TemplateBuilderImpl template = new TemplateBuilderImpl(locations, images, sizes, defaultLocation,
|
||||
optionsProvider, templateBuilderProvider);
|
||||
return template;
|
||||
}
|
||||
|
||||
|
@ -347,10 +314,8 @@ public class TemplateBuilderImplTest {
|
|||
public void testSuppliedLocationWithNoOptions() {
|
||||
Provider<Set<? extends Location>> locations = Providers
|
||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
||||
Provider<Set<? extends Image>> images = Providers
|
||||
.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers
|
||||
.<Set<? extends Size>> of(ImmutableSet.<Size> of());
|
||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet.<Size> of());
|
||||
Location defaultLocation = createMock(Location.class);
|
||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||
|
@ -363,8 +328,8 @@ public class TemplateBuilderImplTest {
|
|||
replay(optionsProvider);
|
||||
replay(templateBuilderProvider);
|
||||
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes, defaultLocation, optionsProvider,
|
||||
templateBuilderProvider);
|
||||
|
||||
try {
|
||||
template.imageId("foo").locationId("location").build();
|
||||
|
@ -386,10 +351,8 @@ public class TemplateBuilderImplTest {
|
|||
|
||||
Provider<Set<? extends Location>> locations = Providers
|
||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
||||
Provider<Set<? extends Image>> images = Providers
|
||||
.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers
|
||||
.<Set<? extends Size>> of(ImmutableSet.<Size> of());
|
||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet.<Size> of());
|
||||
Location defaultLocation = createMock(Location.class);
|
||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||
|
@ -400,12 +363,11 @@ public class TemplateBuilderImplTest {
|
|||
replay(optionsProvider);
|
||||
replay(templateBuilderProvider);
|
||||
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes, defaultLocation, optionsProvider,
|
||||
templateBuilderProvider);
|
||||
|
||||
try {
|
||||
template.imageId("foo").options(provideTemplateOptions()).locationId(
|
||||
"location").build();
|
||||
template.imageId("foo").options(provideTemplateOptions()).locationId("location").build();
|
||||
assert false;
|
||||
} catch (NoSuchElementException e) {
|
||||
|
||||
|
@ -421,10 +383,8 @@ public class TemplateBuilderImplTest {
|
|||
public void testDefaultLocationWithNoOptionsNoSuchElement() {
|
||||
Provider<Set<? extends Location>> locations = Providers
|
||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
||||
Provider<Set<? extends Image>> images = Providers
|
||||
.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers
|
||||
.<Set<? extends Size>> of(ImmutableSet.<Size> of());
|
||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet.<Size> of());
|
||||
Location defaultLocation = createMock(Location.class);
|
||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||
|
@ -438,8 +398,8 @@ public class TemplateBuilderImplTest {
|
|||
replay(optionsProvider);
|
||||
replay(templateBuilderProvider);
|
||||
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes, defaultLocation, optionsProvider,
|
||||
templateBuilderProvider);
|
||||
|
||||
try {
|
||||
template.imageId("foo").build();
|
||||
|
@ -463,10 +423,8 @@ public class TemplateBuilderImplTest {
|
|||
public void testDefaultLocationWithOptions() {
|
||||
Provider<Set<? extends Location>> locations = Providers
|
||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
||||
Provider<Set<? extends Image>> images = Providers
|
||||
.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers
|
||||
.<Set<? extends Size>> of(ImmutableSet.<Size> of());
|
||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet.<Size> of());
|
||||
Location defaultLocation = createMock(Location.class);
|
||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||
TemplateOptions from = provideTemplateOptions();
|
||||
|
@ -489,8 +447,8 @@ public class TemplateBuilderImplTest {
|
|||
replay(optionsProvider);
|
||||
replay(templateBuilderProvider);
|
||||
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes, defaultLocation, optionsProvider,
|
||||
templateBuilderProvider);
|
||||
|
||||
try {
|
||||
template.imageId("foo").options(provideTemplateOptions()).build();
|
||||
|
@ -509,10 +467,8 @@ public class TemplateBuilderImplTest {
|
|||
public void testImageIdNullsEverythingElse() {
|
||||
Provider<Set<? extends Location>> locations = Providers
|
||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
||||
Provider<Set<? extends Image>> images = Providers
|
||||
.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers
|
||||
.<Set<? extends Size>> of(ImmutableSet.<Size> of());
|
||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet.<Size> of());
|
||||
Location defaultLocation = createMock(Location.class);
|
||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||
|
@ -521,8 +477,8 @@ public class TemplateBuilderImplTest {
|
|||
replay(optionsProvider);
|
||||
replay(templateBuilderProvider);
|
||||
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes, defaultLocation, optionsProvider,
|
||||
templateBuilderProvider);
|
||||
|
||||
template.architecture(Architecture.X86_32);
|
||||
template.imageDescriptionMatches("imageDescriptionMatches");
|
||||
|
|
|
@ -89,8 +89,7 @@ public class HttpUtils {
|
|||
@Inject(optional = true)
|
||||
@Named(Constants.PROPERTY_PROXY_SYSTEM)
|
||||
private boolean systemProxies = System.getProperty("java.net.useSystemProxies") != null ? Boolean
|
||||
.parseBoolean(System.getProperty("java.net.useSystemProxies"))
|
||||
: false;
|
||||
.parseBoolean(System.getProperty("java.net.useSystemProxies")) : false;
|
||||
|
||||
private final int globalMaxConnections;
|
||||
private final int globalMaxConnectionsPerHost;
|
||||
|
@ -112,10 +111,10 @@ public class HttpUtils {
|
|||
|
||||
@Inject
|
||||
public HttpUtils(EncryptionService encryptionService,
|
||||
@Named(Constants.PROPERTY_CONNECTION_TIMEOUT) int connectionTimeout,
|
||||
@Named(Constants.PROPERTY_SO_TIMEOUT) int soTimeout,
|
||||
@Named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT) int globalMaxConnections,
|
||||
@Named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST) int globalMaxConnectionsPerHost) {
|
||||
@Named(Constants.PROPERTY_CONNECTION_TIMEOUT) int connectionTimeout,
|
||||
@Named(Constants.PROPERTY_SO_TIMEOUT) int soTimeout,
|
||||
@Named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT) int globalMaxConnections,
|
||||
@Named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST) int globalMaxConnectionsPerHost) {
|
||||
this.encryptionService = encryptionService;
|
||||
this.soTimeout = soTimeout;
|
||||
this.connectionTimeout = connectionTimeout;
|
||||
|
@ -176,20 +175,20 @@ public class HttpUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* keys to the map are only used for socket information, not path. In this case, you should
|
||||
* remove any path or query details from the URI.
|
||||
* keys to the map are only used for socket information, not path. In this
|
||||
* case, you should remove any path or query details from the URI.
|
||||
*/
|
||||
public static URI createBaseEndpointFor(URI endpoint) {
|
||||
if (endpoint.getPort() == -1) {
|
||||
return URI.create(String.format("%s://%s", endpoint.getScheme(), endpoint.getHost()));
|
||||
} else {
|
||||
return URI.create(String.format("%s://%s:%d", endpoint.getScheme(), endpoint.getHost(),
|
||||
endpoint.getPort()));
|
||||
return URI.create(String.format("%s://%s:%d", endpoint.getScheme(), endpoint.getHost(), endpoint.getPort()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Web browsers do not always handle '+' characters well, use the well-supported '%20' instead.
|
||||
* Web browsers do not always handle '+' characters well, use the
|
||||
* well-supported '%20' instead.
|
||||
*/
|
||||
public static String urlEncode(String in, char... skipEncode) {
|
||||
if (isUrlEncoded(in))
|
||||
|
@ -235,7 +234,8 @@ public class HttpUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* Content stream may need to be read. However, we should always close the http stream.
|
||||
* Content stream may need to be read. However, we should always close the
|
||||
* http stream.
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
|
@ -255,12 +255,11 @@ public class HttpUtils {
|
|||
String scheme = redirectURI.getScheme();
|
||||
|
||||
checkState(redirectURI.getScheme().startsWith("http"), String.format(
|
||||
"header %s didn't parse an http scheme: [%s]", hostHeader, scheme));
|
||||
int port = redirectURI.getPort() > 0 ? redirectURI.getPort() : redirectURI.getScheme()
|
||||
.equals("https") ? 443 : 80;
|
||||
"header %s didn't parse an http scheme: [%s]", hostHeader, scheme));
|
||||
int port = redirectURI.getPort() > 0 ? redirectURI.getPort() : redirectURI.getScheme().equals("https") ? 443 : 80;
|
||||
String host = redirectURI.getHost();
|
||||
checkState(host.indexOf('/') == -1, String.format(
|
||||
"header %s didn't parse an http host correctly: [%s]", hostHeader, host));
|
||||
checkState(host.indexOf('/') == -1, String.format("header %s didn't parse an http host correctly: [%s]",
|
||||
hostHeader, host));
|
||||
URI endPoint = URI.create(String.format("%s://%s:%d", scheme, host, port));
|
||||
return endPoint;
|
||||
}
|
||||
|
@ -270,10 +269,11 @@ 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.
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
public static URI createUri(String uriPath) {
|
||||
|
@ -305,8 +305,7 @@ public class HttpUtils {
|
|||
String rest = matcher.group(4);
|
||||
String identity = matcher.group(2);
|
||||
String key = matcher.group(3);
|
||||
return URI.create(String.format("%s://%s:%s@%s", scheme, urlEncode(identity),
|
||||
urlEncode(key), rest));
|
||||
return URI.create(String.format("%s://%s:%s@%s", scheme, urlEncode(identity), urlEncode(key), rest));
|
||||
} else {
|
||||
throw new IllegalArgumentException("bad syntax");
|
||||
}
|
||||
|
@ -329,14 +328,12 @@ public class HttpUtils {
|
|||
}
|
||||
if (message.getPayload() != null) {
|
||||
if (message.getPayload().getContentType() != null)
|
||||
logger.debug("%s %s: %s", prefix, HttpHeaders.CONTENT_TYPE, message.getPayload()
|
||||
.getContentType());
|
||||
logger.debug("%s %s: %s", prefix, HttpHeaders.CONTENT_TYPE, message.getPayload().getContentType());
|
||||
if (message.getPayload().getContentLength() != null)
|
||||
logger.debug("%s %s: %s", prefix, HttpHeaders.CONTENT_LENGTH, message.getPayload()
|
||||
.getContentLength());
|
||||
logger.debug("%s %s: %s", prefix, HttpHeaders.CONTENT_LENGTH, message.getPayload().getContentLength());
|
||||
if (message.getPayload().getContentMD5() != null)
|
||||
logger.debug("%s %s: %s", prefix, "Content-MD5", encryptionService.base64(message
|
||||
.getPayload().getContentMD5()));
|
||||
logger.debug("%s %s: %s", prefix, "Content-MD5", encryptionService.base64(message.getPayload()
|
||||
.getContentMD5()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -359,12 +356,13 @@ public class HttpUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* change the destination of the current http command. typically used in handling redirects.
|
||||
* 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) {
|
||||
public static void changeSchemeHostAndPortTo(HttpRequest request, String scheme, String host, int port,
|
||||
UriBuilder builder) {
|
||||
builder.uri(request.getEndpoint());
|
||||
builder.scheme(scheme);
|
||||
builder.host(host);
|
||||
|
@ -389,18 +387,16 @@ public class HttpUtils {
|
|||
request.setMethod(HttpMethod.GET);
|
||||
}
|
||||
|
||||
public static void addQueryParamTo(HttpRequest request, String key, Object value,
|
||||
UriBuilder builder) {
|
||||
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) {
|
||||
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) {
|
||||
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)
|
||||
|
@ -409,13 +405,11 @@ public class HttpUtils {
|
|||
request.setEndpoint(builder.build());
|
||||
}
|
||||
|
||||
public static void replaceMatrixParam(HttpRequest request, String name, Object value,
|
||||
UriBuilder builder) {
|
||||
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) {
|
||||
public static void replaceMatrixParam(HttpRequest request, String name, Object[] values, UriBuilder builder) {
|
||||
builder.uri(request.getEndpoint());
|
||||
builder.replaceMatrixParam(name, values);
|
||||
request.setEndpoint(builder.build());
|
||||
|
@ -451,28 +445,25 @@ public class HttpUtils {
|
|||
return map;
|
||||
}
|
||||
|
||||
public static void parseKeyValueFromStringToMap(String stringToParse,
|
||||
Multimap<String, String> 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);
|
||||
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) {
|
||||
public static SortedSet<Entry<String, String>> sortEntries(Collection<Map.Entry<String, String>> in,
|
||||
Comparator<Map.Entry<String, String>> sorter) {
|
||||
SortedSet<Entry<String, String>> entries = 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();
|
||||
@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();
|
||||
|
@ -492,8 +483,7 @@ public class HttpUtils {
|
|||
boolean chunked = any(headers.entries(), new Predicate<Entry<String, String>>() {
|
||||
@Override
|
||||
public boolean apply(Entry<String, String> input) {
|
||||
return "Transfer-Encoding".equalsIgnoreCase(input.getKey())
|
||||
&& "chunked".equalsIgnoreCase(input.getValue());
|
||||
return "Transfer-Encoding".equalsIgnoreCase(input.getKey()) && "chunked".equalsIgnoreCase(input.getValue());
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -514,25 +504,20 @@ public class HttpUtils {
|
|||
|
||||
if (message instanceof HttpRequest) {
|
||||
checkArgument(
|
||||
message.getPayload() == null
|
||||
|| message.getFirstHeaderOrNull(CONTENT_TYPE) == null,
|
||||
"configuration error please use request.getPayload().setContentType(value) as opposed to adding a content type header: "
|
||||
+ message);
|
||||
message.getPayload() == null || message.getFirstHeaderOrNull(CONTENT_TYPE) == null,
|
||||
"configuration error please use request.getPayload().setContentType(value) as opposed to adding a content type header: "
|
||||
+ message);
|
||||
checkArgument(
|
||||
message.getPayload() == null
|
||||
|| message.getFirstHeaderOrNull(CONTENT_LENGTH) == null,
|
||||
"configuration error please use request.getPayload().setContentLength(value) as opposed to adding a content length header: "
|
||||
+ message);
|
||||
checkArgument(message.getPayload() == null
|
||||
|| message.getPayload().getContentLength() != null
|
||||
|| "chunked".equalsIgnoreCase(message.getFirstHeaderOrNull("Transfer-Encoding")),
|
||||
"either chunked encoding must be set on the http request or contentlength set on the payload: "
|
||||
+ message);
|
||||
checkArgument(
|
||||
message.getPayload() == null
|
||||
|| message.getFirstHeaderOrNull("Content-MD5") == null,
|
||||
"configuration error please use request.getPayload().setContentMD5(value) as opposed to adding a content md5 header: "
|
||||
+ message);
|
||||
message.getPayload() == null || message.getFirstHeaderOrNull(CONTENT_LENGTH) == null,
|
||||
"configuration error please use request.getPayload().setContentLength(value) as opposed to adding a content length header: "
|
||||
+ message);
|
||||
checkArgument(message.getPayload() == null || message.getPayload().getContentLength() != null
|
||||
|| "chunked".equalsIgnoreCase(message.getFirstHeaderOrNull("Transfer-Encoding")),
|
||||
"either chunked encoding must be set on the http request or contentlength set on the payload: "
|
||||
+ message);
|
||||
checkArgument(message.getPayload() == null || message.getFirstHeaderOrNull("Content-MD5") == null,
|
||||
"configuration error please use request.getPayload().setContentMD5(value) as opposed to adding a content md5 header: "
|
||||
+ message);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -555,7 +540,7 @@ public class HttpUtils {
|
|||
|
||||
public static Long attemptToParseSizeAndRangeFromHeaders(HttpResponse from) throws HttpException {
|
||||
String contentRange = from.getFirstHeaderOrNull("Content-Range");
|
||||
if (contentRange == null) {
|
||||
if (contentRange == null && from.getPayload() != null) {
|
||||
return from.getPayload().getContentLength();
|
||||
} else if (contentRange != null) {
|
||||
return Long.parseLong(contentRange.substring(contentRange.lastIndexOf('/') + 1));
|
||||
|
|
|
@ -21,6 +21,8 @@ package org.jclouds.http.functions;
|
|||
import static org.jclouds.http.HttpUtils.releasePayload;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
|
@ -32,23 +34,26 @@ import org.jclouds.logging.Logger;
|
|||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* This object will parse the body of an HttpResponse and return the result of type <T> back to the
|
||||
* caller.
|
||||
* This object will parse the body of an HttpResponse and return the result of
|
||||
* type <T> back to the caller.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public abstract class ParseJson<T> implements Function<HttpResponse, T> {
|
||||
public class ParseJson<T> implements Function<HttpResponse, T> {
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
protected final Gson gson;
|
||||
protected final TypeLiteral<T> type;
|
||||
|
||||
@Inject
|
||||
public ParseJson(Gson gson){
|
||||
public ParseJson(Gson gson, TypeLiteral<T> type) {
|
||||
this.gson = gson;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -62,12 +67,21 @@ public abstract class ParseJson<T> implements Function<HttpResponse, T> {
|
|||
StringBuilder message = new StringBuilder();
|
||||
message.append("Error parsing input");
|
||||
logger.error(e, message.toString());
|
||||
throw new HttpResponseException(message.toString() + "\n" + from, null, from, e);
|
||||
throw new HttpResponseException(message.toString() + "\n" + from,
|
||||
null, from, e);
|
||||
} finally {
|
||||
releasePayload(from);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected abstract T apply(InputStream stream);
|
||||
@SuppressWarnings("unchecked")
|
||||
public T apply(InputStream stream) {
|
||||
try {
|
||||
return (T) gson.fromJson(new InputStreamReader(stream, "UTF-8"), type
|
||||
.getType());
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,42 +16,34 @@
|
|||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.rackspace.cloudservers.functions;
|
||||
package org.jclouds.http.functions;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.rackspace.cloudservers.domain.Image;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpResponse;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.inject.internal.Iterables;
|
||||
|
||||
/**
|
||||
* This parses {@link Image} from a gson string.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseImageFromJsonResponse extends ParseJson<Image> {
|
||||
public class UnwrapOnlyJsonValue<T> implements Function<HttpResponse, T> {
|
||||
|
||||
private final ParseJson<Map<String, T>> json;
|
||||
|
||||
@Inject
|
||||
public ParseImageFromJsonResponse(Gson gson) {
|
||||
super(gson);
|
||||
UnwrapOnlyJsonValue(ParseJson<Map<String, T>> json) {
|
||||
this.json = json;
|
||||
}
|
||||
|
||||
private static class ImageListResponse {
|
||||
Image image;
|
||||
}
|
||||
|
||||
public Image apply(InputStream stream) {
|
||||
|
||||
try {
|
||||
return gson.fromJson(new InputStreamReader(stream, "UTF-8"), ImageListResponse.class).image;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
@Override
|
||||
public T apply(HttpResponse arg0) {
|
||||
Map<String, T> map = json.apply(arg0);
|
||||
return Iterables.getOnlyElement(map.values());
|
||||
}
|
||||
}
|
|
@ -20,6 +20,7 @@ package org.jclouds.http.functions.config;
|
|||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
@ -29,11 +30,13 @@ import javax.xml.parsers.SAXParserFactory;
|
|||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.date.DateService;
|
||||
import org.jclouds.encryption.EncryptionService;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ParseSax.HandlerWithResult;
|
||||
import org.xml.sax.XMLReader;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.primitives.Bytes;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
|
@ -43,6 +46,7 @@ import com.google.gson.JsonParseException;
|
|||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.ImplementedBy;
|
||||
import com.google.inject.Provides;
|
||||
|
@ -88,9 +92,13 @@ public class ParserModule extends AbstractModule {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
Gson provideGson(DateAdapter adapter, GsonAdapterBindings bindings) {
|
||||
Gson provideGson(DateAdapter adapter, ByteListAdapter byteListAdapter,
|
||||
ByteArrayAdapter byteArrayAdapter, GsonAdapterBindings bindings) {
|
||||
GsonBuilder gson = new GsonBuilder();
|
||||
gson.registerTypeAdapter(Date.class, adapter);
|
||||
gson.registerTypeAdapter(new TypeToken<List<Byte>>() {
|
||||
}.getType(), byteListAdapter);
|
||||
gson.registerTypeAdapter(byte[].class, byteArrayAdapter);
|
||||
for (Map.Entry<Type, Object> binding : bindings.getBindings().entrySet()) {
|
||||
gson.registerTypeAdapter(binding.getKey(), binding.getValue());
|
||||
}
|
||||
|
@ -98,10 +106,68 @@ public class ParserModule extends AbstractModule {
|
|||
}
|
||||
|
||||
@ImplementedBy(CDateAdapter.class)
|
||||
public static interface DateAdapter extends JsonSerializer<Date>, JsonDeserializer<Date> {
|
||||
public static interface DateAdapter extends JsonSerializer<Date>,
|
||||
JsonDeserializer<Date> {
|
||||
|
||||
}
|
||||
|
||||
@ImplementedBy(HexByteListAdapter.class)
|
||||
public static interface ByteListAdapter extends JsonSerializer<List<Byte>>,
|
||||
JsonDeserializer<List<Byte>> {
|
||||
|
||||
}
|
||||
|
||||
@ImplementedBy(HexByteArrayAdapter.class)
|
||||
public static interface ByteArrayAdapter extends JsonSerializer<byte[]>,
|
||||
JsonDeserializer<byte[]> {
|
||||
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class HexByteListAdapter implements ByteListAdapter {
|
||||
private final EncryptionService encryptionService;
|
||||
|
||||
@Inject
|
||||
HexByteListAdapter(EncryptionService encryptionService) {
|
||||
this.encryptionService = encryptionService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Byte> deserialize(JsonElement json, Type typeOfT,
|
||||
JsonDeserializationContext context) throws JsonParseException {
|
||||
return Bytes.asList(encryptionService.fromHex(json.getAsString()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(List<Byte> src, Type typeOfSrc,
|
||||
JsonSerializationContext context) {
|
||||
return new JsonPrimitive(encryptionService.hex(Bytes.toArray(src)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class HexByteArrayAdapter implements ByteArrayAdapter {
|
||||
private final EncryptionService encryptionService;
|
||||
|
||||
@Inject
|
||||
HexByteArrayAdapter(EncryptionService encryptionService) {
|
||||
this.encryptionService = encryptionService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] deserialize(JsonElement json, Type typeOfT,
|
||||
JsonDeserializationContext context) throws JsonParseException {
|
||||
return encryptionService.fromHex(json.getAsString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(byte[] src, Type typeOfSrc,
|
||||
JsonSerializationContext context) {
|
||||
return new JsonPrimitive(encryptionService.hex(src));
|
||||
}
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class Iso8601DateAdapter implements DateAdapter {
|
||||
private final DateService dateService;
|
||||
|
@ -111,12 +177,13 @@ public class ParserModule extends AbstractModule {
|
|||
this.dateService = dateService;
|
||||
}
|
||||
|
||||
public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
public JsonElement serialize(Date src, Type typeOfSrc,
|
||||
JsonSerializationContext context) {
|
||||
return new JsonPrimitive(dateService.iso8601DateFormat(src));
|
||||
}
|
||||
|
||||
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
||||
throws JsonParseException {
|
||||
public Date deserialize(JsonElement json, Type typeOfT,
|
||||
JsonDeserializationContext context) throws JsonParseException {
|
||||
String toParse = json.getAsJsonPrimitive().getAsString();
|
||||
try {
|
||||
return dateService.iso8601DateParse(toParse);
|
||||
|
@ -136,12 +203,13 @@ public class ParserModule extends AbstractModule {
|
|||
this.dateService = dateService;
|
||||
}
|
||||
|
||||
public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
public JsonElement serialize(Date src, Type typeOfSrc,
|
||||
JsonSerializationContext context) {
|
||||
return new JsonPrimitive(dateService.cDateFormat(src));
|
||||
}
|
||||
|
||||
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
||||
throws JsonParseException {
|
||||
public Date deserialize(JsonElement json, Type typeOfT,
|
||||
JsonDeserializationContext context) throws JsonParseException {
|
||||
String toParse = json.getAsJsonPrimitive().getAsString();
|
||||
Date toReturn = dateService.cDateParse(toParse);
|
||||
return toReturn;
|
||||
|
@ -152,12 +220,13 @@ public class ParserModule extends AbstractModule {
|
|||
@Singleton
|
||||
public static class LongDateAdapter implements DateAdapter {
|
||||
|
||||
public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
public JsonElement serialize(Date src, Type typeOfSrc,
|
||||
JsonSerializationContext context) {
|
||||
return new JsonPrimitive(src.getTime());
|
||||
}
|
||||
|
||||
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
||||
throws JsonParseException {
|
||||
public Date deserialize(JsonElement json, Type typeOfT,
|
||||
JsonDeserializationContext context) throws JsonParseException {
|
||||
long toParse = json.getAsJsonPrimitive().getAsLong();
|
||||
Date toReturn = new Date(toParse);
|
||||
return toReturn;
|
||||
|
@ -170,7 +239,8 @@ public class ParserModule extends AbstractModule {
|
|||
private final Map<Type, Object> bindings = Maps.newHashMap();
|
||||
|
||||
@com.google.inject.Inject(optional = true)
|
||||
public void setBindings(@Named(Constants.PROPERTY_GSON_ADAPTERS) Map<Type, Object> bindings) {
|
||||
public void setBindings(
|
||||
@Named(Constants.PROPERTY_GSON_ADAPTERS) Map<Type, Object> bindings) {
|
||||
this.bindings.putAll(bindings);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/**
|
||||
*
|
||||
* 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.rest.annotations;
|
||||
|
||||
import static java.lang.annotation.ElementType.METHOD;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Unwraps the only value in the json reponse
|
||||
*
|
||||
* ex. { "foo" :"bar" } becomes "bar"
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Target(METHOD)
|
||||
@Retention(RUNTIME)
|
||||
public @interface Unwrap {
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -51,7 +51,8 @@ public class JschSshClientModule extends AbstractModule {
|
|||
|
||||
protected void configure() {
|
||||
bind(SshClient.Factory.class).to(Factory.class).in(Scopes.SINGLETON);
|
||||
bind(SocketOpen.class).to(InetSocketAddressConnect.class).in(Scopes.SINGLETON);
|
||||
bind(SocketOpen.class).to(InetSocketAddressConnect.class).in(
|
||||
Scopes.SINGLETON);
|
||||
}
|
||||
|
||||
private static class Factory implements SshClient.Factory {
|
||||
|
@ -64,27 +65,30 @@ public class JschSshClientModule extends AbstractModule {
|
|||
|
||||
@SuppressWarnings("unused")
|
||||
@Inject
|
||||
public Factory(BackoffLimitedRetryHandler backoffLimitedRetryHandler, Injector injector) {
|
||||
public Factory(BackoffLimitedRetryHandler backoffLimitedRetryHandler,
|
||||
Injector injector) {
|
||||
this.backoffLimitedRetryHandler = backoffLimitedRetryHandler;
|
||||
this.injector = injector;
|
||||
}
|
||||
|
||||
public SshClient create(IPSocket socket, String username, String password) {
|
||||
SshClient client = new JschSshClient(backoffLimitedRetryHandler, socket, timeout,
|
||||
username, password, null);
|
||||
SshClient client = new JschSshClient(backoffLimitedRetryHandler,
|
||||
socket, timeout, username, password, null);
|
||||
injector.injectMembers(client);// add logger
|
||||
return client;
|
||||
}
|
||||
|
||||
public SshClient create(IPSocket socket, String username, byte[] privateKey) {
|
||||
SshClient client = new JschSshClient(backoffLimitedRetryHandler, socket, timeout,
|
||||
username, null, privateKey);
|
||||
public SshClient create(IPSocket socket, String username,
|
||||
byte[] privateKey) {
|
||||
SshClient client = new JschSshClient(backoffLimitedRetryHandler,
|
||||
socket, timeout, username, null, privateKey);
|
||||
injector.injectMembers(client);// add logger
|
||||
return client;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> generateRSAKeyPair(String comment, String passphrase) {
|
||||
public Map<String, String> generateRSAKeyPair(String comment,
|
||||
String passphrase) {
|
||||
KeyPair pair = null;
|
||||
try {
|
||||
pair = KeyPair.genKeyPair(new JSch(), KeyPair.RSA);
|
||||
|
@ -97,9 +101,9 @@ public class JschSshClientModule extends AbstractModule {
|
|||
pair.writePrivateKey(privateKey);
|
||||
ByteArrayOutputStream publicKey = new ByteArrayOutputStream();
|
||||
pair.writePublicKey(publicKey, comment);
|
||||
return ImmutableMap.of("comment", comment, "passphrase", passphrase, "private",
|
||||
new String(privateKey.toByteArray()), "public", new String(publicKey
|
||||
.toByteArray()));
|
||||
return ImmutableMap.of("comment", comment, "passphrase", passphrase,
|
||||
"private", new String(privateKey.toByteArray()), "public",
|
||||
new String(publicKey.toByteArray()));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -23,19 +23,15 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.functions;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.gogrid.domain.internal.ErrorResponse;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
/**
|
||||
|
@ -47,24 +43,20 @@ import com.google.inject.Singleton;
|
|||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseErrorFromJsonResponse extends
|
||||
ParseJson<SortedSet<ErrorResponse>> {
|
||||
public class ParseErrorFromJsonResponse implements
|
||||
Function<HttpResponse, SortedSet<ErrorResponse>> {
|
||||
|
||||
private final ParseJson<GenericResponseContainer<ErrorResponse>> json;
|
||||
|
||||
@Inject
|
||||
ParseErrorFromJsonResponse(Gson gson) {
|
||||
super(gson);
|
||||
ParseErrorFromJsonResponse(
|
||||
ParseJson<GenericResponseContainer<ErrorResponse>> json) {
|
||||
this.json = json;
|
||||
}
|
||||
|
||||
public SortedSet<ErrorResponse> apply(InputStream stream) {
|
||||
Type setType = new TypeToken<GenericResponseContainer<ErrorResponse>>() {
|
||||
}.getType();
|
||||
GenericResponseContainer<ErrorResponse> response;
|
||||
try {
|
||||
response = gson.fromJson(new InputStreamReader(stream, "UTF-8"),
|
||||
setType);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
return response.getList();
|
||||
@Override
|
||||
public SortedSet<ErrorResponse> apply(HttpResponse arg0) {
|
||||
return json.apply(arg0).getList();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,32 +18,31 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.functions;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.gogrid.domain.ServerImage;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseImageFromJsonResponse extends ParseJson<ServerImage> {
|
||||
public class ParseImageFromJsonResponse implements
|
||||
Function<HttpResponse, ServerImage> {
|
||||
private final ParseImageListFromJsonResponse parser;
|
||||
|
||||
@Inject
|
||||
ParseImageFromJsonResponse(Gson gson) {
|
||||
super(gson);
|
||||
ParseImageFromJsonResponse(ParseImageListFromJsonResponse parser) {
|
||||
this.parser = parser;
|
||||
}
|
||||
|
||||
public ServerImage apply(InputStream stream) {
|
||||
SortedSet<ServerImage> allImages = new ParseImageListFromJsonResponse(
|
||||
gson).apply(stream);
|
||||
return Iterables.getOnlyElement(allImages);
|
||||
@Override
|
||||
public ServerImage apply(HttpResponse arg0) {
|
||||
return Iterables.getOnlyElement(parser.apply(arg0));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,43 +18,35 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.functions;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.gogrid.domain.ServerImage;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseImageListFromJsonResponse extends
|
||||
ParseJson<SortedSet<ServerImage>> {
|
||||
public class ParseImageListFromJsonResponse implements
|
||||
Function<HttpResponse, SortedSet<ServerImage>> {
|
||||
|
||||
private final ParseJson<GenericResponseContainer<ServerImage>> json;
|
||||
|
||||
@Inject
|
||||
ParseImageListFromJsonResponse(Gson gson) {
|
||||
super(gson);
|
||||
ParseImageListFromJsonResponse(
|
||||
ParseJson<GenericResponseContainer<ServerImage>> json) {
|
||||
this.json = json;
|
||||
}
|
||||
|
||||
public SortedSet<ServerImage> apply(InputStream stream) {
|
||||
Type setType = new TypeToken<GenericResponseContainer<ServerImage>>() {
|
||||
}.getType();
|
||||
GenericResponseContainer<ServerImage> response;
|
||||
try {
|
||||
response = gson.fromJson(new InputStreamReader(stream, "UTF-8"),
|
||||
setType);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
return response.getList();
|
||||
@Override
|
||||
public SortedSet<ServerImage> apply(HttpResponse arg0) {
|
||||
return json.apply(arg0).getList();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -18,19 +18,15 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.functions;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.gogrid.domain.Ip;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
/**
|
||||
|
@ -39,23 +35,19 @@ import com.google.inject.Singleton;
|
|||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseIpListFromJsonResponse extends ParseJson<SortedSet<Ip>> {
|
||||
public class ParseIpListFromJsonResponse implements
|
||||
Function<HttpResponse, SortedSet<Ip>> {
|
||||
|
||||
private final ParseJson<GenericResponseContainer<Ip>> json;
|
||||
|
||||
@Inject
|
||||
ParseIpListFromJsonResponse(Gson gson) {
|
||||
super(gson);
|
||||
ParseIpListFromJsonResponse(ParseJson<GenericResponseContainer<Ip>> json) {
|
||||
this.json = json;
|
||||
}
|
||||
|
||||
public SortedSet<Ip> apply(InputStream stream) {
|
||||
Type setType = new TypeToken<GenericResponseContainer<Ip>>() {
|
||||
}.getType();
|
||||
GenericResponseContainer<Ip> response;
|
||||
try {
|
||||
response = gson.fromJson(new InputStreamReader(stream, "UTF-8"),
|
||||
setType);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
return response.getList();
|
||||
@Override
|
||||
public SortedSet<Ip> apply(HttpResponse arg0) {
|
||||
return json.apply(arg0).getList();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,19 +18,15 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.functions;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.gogrid.domain.Job;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
/**
|
||||
|
@ -39,23 +35,19 @@ import com.google.inject.Singleton;
|
|||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseJobListFromJsonResponse extends ParseJson<SortedSet<Job>> {
|
||||
public class ParseJobListFromJsonResponse implements
|
||||
Function<HttpResponse, SortedSet<Job>> {
|
||||
|
||||
private final ParseJson<GenericResponseContainer<Job>> json;
|
||||
|
||||
@Inject
|
||||
ParseJobListFromJsonResponse(Gson gson) {
|
||||
super(gson);
|
||||
ParseJobListFromJsonResponse(ParseJson<GenericResponseContainer<Job>> json) {
|
||||
this.json = json;
|
||||
}
|
||||
|
||||
public SortedSet<Job> apply(InputStream stream) {
|
||||
Type setType = new TypeToken<GenericResponseContainer<Job>>() {
|
||||
}.getType();
|
||||
GenericResponseContainer<Job> response;
|
||||
try {
|
||||
response = gson.fromJson(new InputStreamReader(stream, "UTF-8"),
|
||||
setType);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
return response.getList();
|
||||
@Override
|
||||
public SortedSet<Job> apply(HttpResponse arg0) {
|
||||
return json.apply(arg0).getList();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,16 +18,14 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.functions;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.inject.Singleton;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.gogrid.domain.LoadBalancer;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.InputStream;
|
||||
import java.util.SortedSet;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
/**
|
||||
* Parses the single load balancer out of the response.
|
||||
|
@ -38,17 +36,19 @@ import java.util.SortedSet;
|
|||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseLoadBalancerFromJsonResponse extends ParseJson<LoadBalancer> {
|
||||
public class ParseLoadBalancerFromJsonResponse implements
|
||||
Function<HttpResponse, LoadBalancer> {
|
||||
private final ParseLoadBalancerListFromJsonResponse parser;
|
||||
|
||||
@Inject
|
||||
ParseLoadBalancerFromJsonResponse(Gson gson) {
|
||||
super(gson);
|
||||
ParseLoadBalancerFromJsonResponse(
|
||||
ParseLoadBalancerListFromJsonResponse parser) {
|
||||
this.parser = parser;
|
||||
}
|
||||
|
||||
public LoadBalancer apply(InputStream stream) {
|
||||
SortedSet<LoadBalancer> allLoadBalancers = new ParseLoadBalancerListFromJsonResponse(
|
||||
gson).apply(stream);
|
||||
return Iterables.getOnlyElement(allLoadBalancers);
|
||||
@Override
|
||||
public LoadBalancer apply(HttpResponse arg0) {
|
||||
return Iterables.getOnlyElement(parser.apply(arg0));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,19 +18,15 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.functions;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.gogrid.domain.LoadBalancer;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
/**
|
||||
|
@ -40,24 +36,20 @@ import com.google.inject.Singleton;
|
|||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseLoadBalancerListFromJsonResponse extends
|
||||
ParseJson<SortedSet<LoadBalancer>> {
|
||||
public class ParseLoadBalancerListFromJsonResponse implements
|
||||
Function<HttpResponse, SortedSet<LoadBalancer>> {
|
||||
|
||||
private final ParseJson<GenericResponseContainer<LoadBalancer>> json;
|
||||
|
||||
@Inject
|
||||
ParseLoadBalancerListFromJsonResponse(Gson gson) {
|
||||
super(gson);
|
||||
ParseLoadBalancerListFromJsonResponse(
|
||||
ParseJson<GenericResponseContainer<LoadBalancer>> json) {
|
||||
this.json = json;
|
||||
}
|
||||
|
||||
public SortedSet<LoadBalancer> apply(InputStream stream) {
|
||||
Type setType = new TypeToken<GenericResponseContainer<LoadBalancer>>() {
|
||||
}.getType();
|
||||
GenericResponseContainer<LoadBalancer> response;
|
||||
try {
|
||||
response = gson.fromJson(new InputStreamReader(stream, "UTF-8"),
|
||||
setType);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
return response.getList();
|
||||
@Override
|
||||
public SortedSet<LoadBalancer> apply(HttpResponse arg0) {
|
||||
return json.apply(arg0).getList();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -18,46 +18,38 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.functions;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.gogrid.domain.Option;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
/**
|
||||
* Parses the list of generic options.
|
||||
*
|
||||
* GoGrid uses options as containers for id/name/description objects.
|
||||
* GoGrid uses options as containers for id/name/descrOptiontion objects.
|
||||
*
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseOptionsFromJsonResponse extends ParseJson<SortedSet<Option>> {
|
||||
public class ParseOptionsFromJsonResponse implements
|
||||
Function<HttpResponse, SortedSet<Option>> {
|
||||
|
||||
private final ParseJson<GenericResponseContainer<Option>> json;
|
||||
|
||||
@Inject
|
||||
ParseOptionsFromJsonResponse(Gson gson) {
|
||||
super(gson);
|
||||
ParseOptionsFromJsonResponse(ParseJson<GenericResponseContainer<Option>> json) {
|
||||
this.json = json;
|
||||
}
|
||||
|
||||
public SortedSet<Option> apply(InputStream stream) {
|
||||
Type setType = new TypeToken<GenericResponseContainer<Option>>() {
|
||||
}.getType();
|
||||
GenericResponseContainer<Option> response;
|
||||
try {
|
||||
response = gson.fromJson(new InputStreamReader(stream, "UTF-8"),
|
||||
setType);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
return response.getList();
|
||||
@Override
|
||||
public SortedSet<Option> apply(HttpResponse arg0) {
|
||||
return json.apply(arg0).getList();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,17 +23,14 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.functions;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.gogrid.domain.Server;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
/**
|
||||
* Parses a single {@link Server} from a json string.
|
||||
|
@ -43,16 +40,18 @@ import com.google.inject.Singleton;
|
|||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseServerFromJsonResponse extends ParseJson<Server> {
|
||||
public class ParseServerFromJsonResponse implements
|
||||
Function<HttpResponse, Server> {
|
||||
private final ParseServerListFromJsonResponse parser;
|
||||
|
||||
@Inject
|
||||
ParseServerFromJsonResponse(Gson gson) {
|
||||
super(gson);
|
||||
ParseServerFromJsonResponse(ParseServerListFromJsonResponse parser) {
|
||||
this.parser = parser;
|
||||
}
|
||||
|
||||
public Server apply(InputStream stream) {
|
||||
SortedSet<Server> allServers = new ParseServerListFromJsonResponse(gson)
|
||||
.apply(stream);
|
||||
return Iterables.getOnlyElement(allServers);
|
||||
@Override
|
||||
public Server apply(HttpResponse arg0) {
|
||||
return Iterables.getOnlyElement(parser.apply(arg0));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* regarding copyright ownershServer. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
|
@ -23,20 +23,16 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.functions;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.gogrid.domain.Server;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* Parses {@link Server servers} from a json string.
|
||||
|
@ -44,24 +40,19 @@ import com.google.gson.reflect.TypeToken;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseServerListFromJsonResponse extends
|
||||
ParseJson<SortedSet<Server>> {
|
||||
public class ParseServerListFromJsonResponse implements
|
||||
Function<HttpResponse, SortedSet<Server>> {
|
||||
|
||||
private final ParseJson<GenericResponseContainer<Server>> json;
|
||||
|
||||
@Inject
|
||||
ParseServerListFromJsonResponse(Gson gson) {
|
||||
super(gson);
|
||||
ParseServerListFromJsonResponse(ParseJson<GenericResponseContainer<Server>> json) {
|
||||
this.json = json;
|
||||
}
|
||||
|
||||
public SortedSet<Server> apply(InputStream stream) {
|
||||
Type setType = new TypeToken<GenericResponseContainer<Server>>() {
|
||||
}.getType();
|
||||
GenericResponseContainer<Server> response;
|
||||
try {
|
||||
response = gson.fromJson(new InputStreamReader(stream, "UTF-8"),
|
||||
setType);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
return response.getList();
|
||||
@Override
|
||||
public SortedSet<Server> apply(HttpResponse arg0) {
|
||||
return json.apply(arg0).getList();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,10 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.functions;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
@ -29,41 +25,25 @@ import javax.inject.Singleton;
|
|||
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.gogrid.domain.Server;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseServerNameToCredentialsMapFromJsonResponse extends
|
||||
ParseJson<Map<String, Credentials>> {
|
||||
public class ParseServerNameToCredentialsMapFromJsonResponse implements
|
||||
Function<HttpResponse, Map<String, Credentials>> {
|
||||
private final ParseJson<GenericResponseContainer<Password>> json;
|
||||
|
||||
@Inject
|
||||
ParseServerNameToCredentialsMapFromJsonResponse(Gson gson) {
|
||||
super(gson);
|
||||
}
|
||||
|
||||
public Map<String, Credentials> apply(InputStream stream) {
|
||||
Type setType = new TypeToken<GenericResponseContainer<Password>>() {
|
||||
}.getType();
|
||||
GenericResponseContainer<Password> response;
|
||||
try {
|
||||
response = gson.fromJson(new InputStreamReader(stream, "UTF-8"),
|
||||
setType);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
Map<String, Credentials> serverNameToCredentials = Maps.newHashMap();
|
||||
for (Password password : response.getList()) {
|
||||
serverNameToCredentials.put(password.getServer().getName(),
|
||||
new Credentials(password.getUserName(), password.getPassword()));
|
||||
}
|
||||
return serverNameToCredentials;
|
||||
ParseServerNameToCredentialsMapFromJsonResponse(
|
||||
ParseJson<GenericResponseContainer<Password>> json) {
|
||||
this.json = json;
|
||||
}
|
||||
|
||||
// incidental wrapper class to assist in getting the correct data
|
||||
|
@ -122,4 +102,14 @@ public class ParseServerNameToCredentialsMapFromJsonResponse extends
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Credentials> apply(HttpResponse arg0) {
|
||||
Map<String, Credentials> serverNameToCredentials = Maps.newHashMap();
|
||||
for (Password password : json.apply(arg0).getList()) {
|
||||
serverNameToCredentials.put(password.getServer().getName(),
|
||||
new Credentials(password.getUserName(), password.getPassword()));
|
||||
}
|
||||
return serverNameToCredentials;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@ import org.jclouds.http.HttpCommand;
|
|||
import org.jclouds.http.HttpErrorHandler;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.HttpResponseException;
|
||||
import org.jclouds.http.Payload;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
|
||||
|
@ -57,22 +56,24 @@ public class GoGridErrorHandler implements HttpErrorHandler {
|
|||
public void handleError(HttpCommand command, HttpResponse response) {
|
||||
try {
|
||||
Exception exception = new HttpResponseException(command, response);
|
||||
Set<ErrorResponse> errors = parseErrorsFromContentOrNull(response.getPayload());
|
||||
Set<ErrorResponse> errors = parseErrorsFromContentOrNull(response);
|
||||
switch (response.getStatusCode()) {
|
||||
case 400:
|
||||
if (Iterables.get(errors, 0).getMessage().indexOf("No object found") != -1) {
|
||||
exception = new ResourceNotFoundException(Iterables.get(errors, 0).getMessage(),
|
||||
exception);
|
||||
break;
|
||||
}
|
||||
case 403:
|
||||
|
||||
exception = new AuthorizationException(command.getRequest(), errors != null ? errors
|
||||
.toString() : response.getStatusLine());
|
||||
case 400:
|
||||
if (Iterables.get(errors, 0).getMessage()
|
||||
.indexOf("No object found") != -1) {
|
||||
exception = new ResourceNotFoundException(Iterables.get(errors,
|
||||
0).getMessage(), exception);
|
||||
break;
|
||||
default:
|
||||
exception = errors != null ? new GoGridResponseException(command, response, errors)
|
||||
: new HttpResponseException(command, response);
|
||||
}
|
||||
case 403:
|
||||
|
||||
exception = new AuthorizationException(command.getRequest(),
|
||||
errors != null ? errors.toString() : response.getStatusLine());
|
||||
break;
|
||||
default:
|
||||
exception = errors != null ? new GoGridResponseException(command,
|
||||
response, errors) : new HttpResponseException(command,
|
||||
response);
|
||||
}
|
||||
command.setException(exception);
|
||||
} finally {
|
||||
|
@ -80,10 +81,10 @@ public class GoGridErrorHandler implements HttpErrorHandler {
|
|||
}
|
||||
}
|
||||
|
||||
Set<ErrorResponse> parseErrorsFromContentOrNull(Payload payload) {
|
||||
if (payload != null) {
|
||||
Set<ErrorResponse> parseErrorsFromContentOrNull(HttpResponse response) {
|
||||
if (response.getPayload() != null) {
|
||||
try {
|
||||
return errorParser.apply(payload.getInput());
|
||||
return errorParser.apply(response);
|
||||
} catch (/* Parsing */Exception e) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -23,42 +23,45 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.functions;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import java.io.InputStream;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import org.jclouds.gogrid.config.DateSecondsAdapter;
|
||||
import org.jclouds.gogrid.domain.internal.ErrorResponse;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.Payloads;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.UnknownHostException;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
public class ParseErrorFromJsonResponseTest {
|
||||
|
||||
@Test
|
||||
public void testApplyInputStreamDetails() throws UnknownHostException {
|
||||
InputStream is = getClass().getResourceAsStream("/test_error_handler.json");
|
||||
Injector i = Guice.createInjector(new ParserModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(DateSecondsAdapter.class);
|
||||
super.configure();
|
||||
}
|
||||
});
|
||||
|
||||
ParseErrorFromJsonResponse parser = new ParseErrorFromJsonResponse(i
|
||||
.getInstance(Gson.class));
|
||||
ErrorResponse response = Iterables.getOnlyElement(parser.apply(is));
|
||||
assert "No object found that matches your input criteria.".equals(response.getMessage());
|
||||
assert "IllegalArgumentException".equals(response.getErrorCode());
|
||||
}
|
||||
|
||||
|
||||
Injector i = Guice.createInjector(new ParserModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(DateSecondsAdapter.class);
|
||||
super.configure();
|
||||
}
|
||||
});
|
||||
@Test
|
||||
public void testApplyInputStreamDetails() throws UnknownHostException {
|
||||
InputStream is = getClass().getResourceAsStream(
|
||||
"/test_error_handler.json");
|
||||
|
||||
ParseErrorFromJsonResponse parser = i
|
||||
.getInstance(ParseErrorFromJsonResponse.class);
|
||||
ErrorResponse response = Iterables.getOnlyElement(parser
|
||||
.apply(new HttpResponse(200, "ok", Payloads
|
||||
.newInputStreamPayload(is))));
|
||||
assert "No object found that matches your input criteria."
|
||||
.equals(response.getMessage());
|
||||
assert "IllegalArgumentException".equals(response.getErrorCode());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,13 +37,14 @@ import org.jclouds.gogrid.domain.JobState;
|
|||
import org.jclouds.gogrid.domain.ObjectType;
|
||||
import org.jclouds.gogrid.domain.Option;
|
||||
import org.jclouds.gogrid.functions.internal.CustomDeserializers;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.Payloads;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provides;
|
||||
|
@ -56,11 +57,13 @@ public class ParseJobsFromJsonResponseTest {
|
|||
|
||||
@Test
|
||||
public void testApplyInputStreamDetails() throws UnknownHostException {
|
||||
InputStream is = getClass().getResourceAsStream("/test_get_job_list.json");
|
||||
InputStream is = getClass()
|
||||
.getResourceAsStream("/test_get_job_list.json");
|
||||
|
||||
ParseJobListFromJsonResponse parser = new ParseJobListFromJsonResponse(i
|
||||
.getInstance(Gson.class));
|
||||
SortedSet<Job> response = parser.apply(is);
|
||||
ParseJobListFromJsonResponse parser = i
|
||||
.getInstance(ParseJobListFromJsonResponse.class);
|
||||
SortedSet<Job> response = parser.apply(new HttpResponse(200, "ok",
|
||||
Payloads.newInputStreamPayload(is)));
|
||||
|
||||
Map<String, String> details = Maps.newTreeMap();
|
||||
details.put("description", null);
|
||||
|
@ -69,12 +72,14 @@ public class ParseJobsFromJsonResponseTest {
|
|||
details.put("name", "ServerCreated40562");
|
||||
details.put("type", "virtual_server");
|
||||
|
||||
Job job = new Job(250628L, new Option(7L, "DeleteVirtualServer", "Delete Virtual Server"),
|
||||
ObjectType.VIRTUAL_SERVER, new Date(1267404528895L), new Date(1267404538592L),
|
||||
JobState.SUCCEEDED, 1, "3116784158f0af2d-24076@api.gogrid.com", ImmutableSortedSet
|
||||
.of(new JobProperties(940263L, new Date(1267404528897L), JobState.CREATED,
|
||||
null), new JobProperties(940264L, new Date(1267404528967L),
|
||||
JobState.QUEUED, null)), details);
|
||||
Job job = new Job(250628L, new Option(7L, "DeleteVirtualServer",
|
||||
"Delete Virtual Server"), ObjectType.VIRTUAL_SERVER, new Date(
|
||||
1267404528895L), new Date(1267404538592L), JobState.SUCCEEDED, 1,
|
||||
"3116784158f0af2d-24076@api.gogrid.com", ImmutableSortedSet.of(
|
||||
new JobProperties(940263L, new Date(1267404528897L),
|
||||
JobState.CREATED, null), new JobProperties(940264L,
|
||||
new Date(1267404528967L), JobState.QUEUED, null)),
|
||||
details);
|
||||
assertEquals(job, Iterables.getOnlyElement(response));
|
||||
}
|
||||
|
||||
|
@ -91,8 +96,10 @@ public class ParseJobsFromJsonResponseTest {
|
|||
@com.google.inject.name.Named(Constants.PROPERTY_GSON_ADAPTERS)
|
||||
public Map<Type, Object> provideCustomAdapterBindings() {
|
||||
Map<Type, Object> bindings = Maps.newHashMap();
|
||||
bindings.put(ObjectType.class, new CustomDeserializers.ObjectTypeAdapter());
|
||||
bindings.put(JobState.class, new CustomDeserializers.JobStateAdapter());
|
||||
bindings.put(ObjectType.class,
|
||||
new CustomDeserializers.ObjectTypeAdapter());
|
||||
bindings
|
||||
.put(JobState.class, new CustomDeserializers.JobStateAdapter());
|
||||
return bindings;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -40,13 +40,14 @@ import org.jclouds.gogrid.domain.LoadBalancerState;
|
|||
import org.jclouds.gogrid.domain.LoadBalancerType;
|
||||
import org.jclouds.gogrid.domain.Option;
|
||||
import org.jclouds.gogrid.functions.internal.CustomDeserializers;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.Payloads;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provides;
|
||||
|
@ -59,21 +60,29 @@ public class ParseLoadBalancersFromJsonResponseTest {
|
|||
|
||||
@Test
|
||||
public void testApplyInputStreamDetails() throws UnknownHostException {
|
||||
InputStream is = getClass().getResourceAsStream("/test_get_load_balancer_list.json");
|
||||
InputStream is = getClass().getResourceAsStream(
|
||||
"/test_get_load_balancer_list.json");
|
||||
|
||||
ParseLoadBalancerListFromJsonResponse parser = i
|
||||
.getInstance(ParseLoadBalancerListFromJsonResponse.class);
|
||||
SortedSet<LoadBalancer> response = parser.apply(new HttpResponse(200,
|
||||
"ok", Payloads.newInputStreamPayload(is)));
|
||||
|
||||
ParseLoadBalancerListFromJsonResponse parser = new ParseLoadBalancerListFromJsonResponse(i
|
||||
.getInstance(Gson.class));
|
||||
SortedSet<LoadBalancer> response = parser.apply(is);
|
||||
Option dc = new Option(1l, "US-West-1", "US West 1 Datacenter");
|
||||
|
||||
LoadBalancer loadBalancer = new LoadBalancer(6372L, "Balancer", null, new IpPortPair(new Ip(
|
||||
1313082L, "204.51.240.181", "204.51.240.176/255.255.255.240", true,
|
||||
IpState.ASSIGNED, dc), 80), ImmutableSortedSet.of(
|
||||
new IpPortPair(new Ip(1313086L, "204.51.240.185", "204.51.240.176/255.255.255.240",
|
||||
true, IpState.ASSIGNED, dc), 80), new IpPortPair(new Ip(1313089L,
|
||||
"204.51.240.188", "204.51.240.176/255.255.255.240", true, IpState.ASSIGNED,
|
||||
dc), 80)), LoadBalancerType.ROUND_ROBIN, LoadBalancerPersistenceType.NONE,
|
||||
LoadBalancerOs.F5, LoadBalancerState.ON, dc);
|
||||
LoadBalancer loadBalancer = new LoadBalancer(6372L, "Balancer", null,
|
||||
new IpPortPair(
|
||||
new Ip(1313082L, "204.51.240.181",
|
||||
"204.51.240.176/255.255.255.240", true,
|
||||
IpState.ASSIGNED, dc), 80), ImmutableSortedSet.of(
|
||||
new IpPortPair(new Ip(1313086L, "204.51.240.185",
|
||||
"204.51.240.176/255.255.255.240", true,
|
||||
IpState.ASSIGNED, dc), 80), new IpPortPair(new Ip(
|
||||
1313089L, "204.51.240.188",
|
||||
"204.51.240.176/255.255.255.240", true,
|
||||
IpState.ASSIGNED, dc), 80)),
|
||||
LoadBalancerType.ROUND_ROBIN, LoadBalancerPersistenceType.NONE,
|
||||
LoadBalancerOs.F5, LoadBalancerState.ON, dc);
|
||||
assertEquals(Iterables.getOnlyElement(response), loadBalancer);
|
||||
}
|
||||
|
||||
|
@ -90,11 +99,14 @@ public class ParseLoadBalancersFromJsonResponseTest {
|
|||
@com.google.inject.name.Named(Constants.PROPERTY_GSON_ADAPTERS)
|
||||
public Map<Type, Object> provideCustomAdapterBindings() {
|
||||
Map<Type, Object> bindings = Maps.newHashMap();
|
||||
bindings.put(LoadBalancerOs.class, new CustomDeserializers.LoadBalancerOsAdapter());
|
||||
bindings.put(LoadBalancerState.class, new CustomDeserializers.LoadBalancerStateAdapter());
|
||||
bindings.put(LoadBalancerOs.class,
|
||||
new CustomDeserializers.LoadBalancerOsAdapter());
|
||||
bindings.put(LoadBalancerState.class,
|
||||
new CustomDeserializers.LoadBalancerStateAdapter());
|
||||
bindings.put(LoadBalancerPersistenceType.class,
|
||||
new CustomDeserializers.LoadBalancerPersistenceTypeAdapter());
|
||||
bindings.put(LoadBalancerType.class, new CustomDeserializers.LoadBalancerTypeAdapter());
|
||||
new CustomDeserializers.LoadBalancerPersistenceTypeAdapter());
|
||||
bindings.put(LoadBalancerType.class,
|
||||
new CustomDeserializers.LoadBalancerTypeAdapter());
|
||||
bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter());
|
||||
return bindings;
|
||||
}
|
||||
|
|
|
@ -34,11 +34,12 @@ import org.jclouds.gogrid.domain.IpState;
|
|||
import org.jclouds.gogrid.domain.ServerImageState;
|
||||
import org.jclouds.gogrid.domain.ServerImageType;
|
||||
import org.jclouds.gogrid.functions.internal.CustomDeserializers;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.Payloads;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provides;
|
||||
|
@ -51,11 +52,14 @@ public class ParseServerNameToCredentialsMapFromJsonResponseTest {
|
|||
|
||||
@Test
|
||||
public void testApplyInputStreamDetails() throws UnknownHostException {
|
||||
InputStream is = getClass().getResourceAsStream("/test_credentials_list.json");
|
||||
InputStream is = getClass().getResourceAsStream(
|
||||
"/test_credentials_list.json");
|
||||
|
||||
ParseServerNameToCredentialsMapFromJsonResponse parser = i
|
||||
.getInstance(ParseServerNameToCredentialsMapFromJsonResponse.class);
|
||||
Map<String, Credentials> response = parser.apply(new HttpResponse(200,
|
||||
"ok", Payloads.newInputStreamPayload(is)));
|
||||
|
||||
ParseServerNameToCredentialsMapFromJsonResponse parser = new ParseServerNameToCredentialsMapFromJsonResponse(
|
||||
i.getInstance(Gson.class));
|
||||
Map<String, Credentials> response = parser.apply(is);
|
||||
assertEquals(response.size(), 6);
|
||||
}
|
||||
|
||||
|
@ -73,9 +77,12 @@ public class ParseServerNameToCredentialsMapFromJsonResponseTest {
|
|||
public Map<Type, Object> provideCustomAdapterBindings() {
|
||||
Map<Type, Object> bindings = Maps.newHashMap();
|
||||
bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter());
|
||||
bindings.put(ServerImageType.class, new CustomDeserializers.ServerImageTypeAdapter());
|
||||
bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter());
|
||||
bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter());
|
||||
bindings.put(ServerImageType.class,
|
||||
new CustomDeserializers.ServerImageTypeAdapter());
|
||||
bindings.put(ServerImageState.class,
|
||||
new CustomDeserializers.ServerImageStateAdapter());
|
||||
bindings.put(ServerImageState.class,
|
||||
new CustomDeserializers.ServerImageStateAdapter());
|
||||
return bindings;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -45,13 +45,14 @@ import org.jclouds.gogrid.domain.ServerImage;
|
|||
import org.jclouds.gogrid.domain.ServerImageState;
|
||||
import org.jclouds.gogrid.domain.ServerImageType;
|
||||
import org.jclouds.gogrid.functions.internal.CustomDeserializers;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.Payloads;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provides;
|
||||
|
@ -66,27 +67,36 @@ public class ParseServersFromJsonResponseTest {
|
|||
|
||||
@Test
|
||||
public void testApplyInputStreamDetails() throws UnknownHostException {
|
||||
InputStream is = getClass().getResourceAsStream("/test_get_server_list.json");
|
||||
InputStream is = getClass().getResourceAsStream(
|
||||
"/test_get_server_list.json");
|
||||
|
||||
ParseServerListFromJsonResponse parser = i
|
||||
.getInstance(ParseServerListFromJsonResponse.class);
|
||||
SortedSet<Server> response = parser.apply(new HttpResponse(200, "ok",
|
||||
Payloads.newInputStreamPayload(is)));
|
||||
|
||||
ParseServerListFromJsonResponse parser = new ParseServerListFromJsonResponse(i
|
||||
.getInstance(Gson.class));
|
||||
SortedSet<Server> response = parser.apply(is);
|
||||
Option dc = new Option(1l, "US-West-1", "US West 1 Datacenter");
|
||||
Option centOs = new Option(13L, "CentOS 5.2 (32-bit)", "CentOS 5.2 (32-bit)");
|
||||
Option webServer = new Option(1L, "Web Server", "Web or Application Server");
|
||||
Option centOs = new Option(13L, "CentOS 5.2 (32-bit)",
|
||||
"CentOS 5.2 (32-bit)");
|
||||
Option webServer = new Option(1L, "Web Server",
|
||||
"Web or Application Server");
|
||||
Server server = new Server(75245L, dc, false, "PowerServer",
|
||||
"server to test the api. created by Alex", new Option(1L, "On",
|
||||
"Server is in active state."), webServer, new Option(1L, "512MB",
|
||||
"Server with 512MB RAM"), centOs, new Ip(1313079L, "204.51.240.178",
|
||||
"204.51.240.176/255.255.255.240", true, IpState.ASSIGNED, dc), new ServerImage(
|
||||
1946L, "GSI-f8979644-e646-4711-ad58-d98a5fa3612c",
|
||||
"BitNami Gallery 2.3.1-0", "http://bitnami.org/stack/gallery", centOs,
|
||||
null, ServerImageType.WEB_APPLICATION_SERVER, ServerImageState.AVAILABLE,
|
||||
0.0, "24732/GSI-f8979644-e646-4711-ad58-d98a5fa3612c.img", true, true,
|
||||
new Date(1261504577971L), new Date(1262649582180L), ImmutableSortedSet.of(
|
||||
new BillingToken(38L, "CentOS 5.2 32bit", 0.0), new BillingToken(
|
||||
56L, "BitNami: Gallery", 0.0)), new Customer(24732L,
|
||||
"BitRock")));
|
||||
"server to test the api. created by Alex", new Option(1L, "On",
|
||||
"Server is in active state."), webServer, new Option(1L,
|
||||
"512MB", "Server with 512MB RAM"), centOs, new Ip(1313079L,
|
||||
"204.51.240.178", "204.51.240.176/255.255.255.240", true,
|
||||
IpState.ASSIGNED, dc), new ServerImage(1946L,
|
||||
"GSI-f8979644-e646-4711-ad58-d98a5fa3612c",
|
||||
"BitNami Gallery 2.3.1-0",
|
||||
"http://bitnami.org/stack/gallery", centOs, null,
|
||||
ServerImageType.WEB_APPLICATION_SERVER,
|
||||
ServerImageState.AVAILABLE, 0.0,
|
||||
"24732/GSI-f8979644-e646-4711-ad58-d98a5fa3612c.img", true,
|
||||
true, new Date(1261504577971L), new Date(1262649582180L),
|
||||
ImmutableSortedSet.of(new BillingToken(38L,
|
||||
"CentOS 5.2 32bit", 0.0), new BillingToken(56L,
|
||||
"BitNami: Gallery", 0.0)), new Customer(24732L,
|
||||
"BitRock")));
|
||||
assertEquals(Iterables.getOnlyElement(response), server);
|
||||
}
|
||||
|
||||
|
@ -104,8 +114,10 @@ public class ParseServersFromJsonResponseTest {
|
|||
public Map<Class, Object> provideCustomAdapterBindings() {
|
||||
Map<Class, Object> bindings = Maps.newHashMap();
|
||||
bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter());
|
||||
bindings.put(ServerImageType.class, new CustomDeserializers.ServerImageTypeAdapter());
|
||||
bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter());
|
||||
bindings.put(ServerImageType.class,
|
||||
new CustomDeserializers.ServerImageTypeAdapter());
|
||||
bindings.put(ServerImageState.class,
|
||||
new CustomDeserializers.ServerImageStateAdapter());
|
||||
return bindings;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -40,14 +40,13 @@ public class GridImageAsyncClientTest extends BaseGoGridAsyncClientTest<GridImag
|
|||
|
||||
@Test
|
||||
public void testGetImageListWithOptions() throws NoSuchMethodException, IOException {
|
||||
Method method = GridImageAsyncClient.class.getMethod("getImageList",
|
||||
GetImageListOptions[].class);
|
||||
Method method = GridImageAsyncClient.class.getMethod("getImageList", GetImageListOptions[].class);
|
||||
GeneratedHttpRequest<GridImageAsyncClient> httpRequest = processor.createRequest(method,
|
||||
new GetImageListOptions().onlyPublic().setState(ServerImageState.AVAILABLE).setType(
|
||||
ServerImageType.WEB_APPLICATION_SERVER));
|
||||
new GetImageListOptions().onlyPublic().setState(ServerImageState.AVAILABLE).setType(
|
||||
ServerImageType.WEB_APPLICATION_SERVER));
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/image/list?v=1.5&"
|
||||
+ "isPublic=true&image.state=Available&" + "image.type=Web%20Server HTTP/1.1");
|
||||
+ "isPublic=true&image.state=Available&" + "image.type=Web%20Server HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
|
@ -59,8 +58,8 @@ public class GridImageAsyncClientTest extends BaseGoGridAsyncClientTest<GridImag
|
|||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/image/list?"
|
||||
+ "v=1.5&isPublic=true&image.state=Available&" + "image.type=Web%20Server&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
+ "v=1.5&isPublic=true&image.state=Available&" + "image.type=Web%20Server&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
}
|
||||
|
@ -68,11 +67,10 @@ public class GridImageAsyncClientTest extends BaseGoGridAsyncClientTest<GridImag
|
|||
@Test
|
||||
public void testGetImagesByName() throws NoSuchMethodException, IOException {
|
||||
Method method = GridImageAsyncClient.class.getMethod("getImagesByName", String[].class);
|
||||
GeneratedHttpRequest<GridImageAsyncClient> httpRequest = processor.createRequest(method,
|
||||
"name1", "name2");
|
||||
GeneratedHttpRequest<GridImageAsyncClient> httpRequest = processor.createRequest(method, "name1", "name2");
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/image/get?v=1.5&"
|
||||
+ "name=name1&name=name2 HTTP/1.1");
|
||||
+ "name=name1&name=name2 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
|
@ -84,21 +82,18 @@ public class GridImageAsyncClientTest extends BaseGoGridAsyncClientTest<GridImag
|
|||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/image/get?v=1.5&"
|
||||
+ "name=name1&name=name2&" + "sig=3f446f171455fbb5574aecff4997b273&api_key=foo "
|
||||
+ "HTTP/1.1");
|
||||
+ "name=name1&name=name2&" + "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEditImageDescription() throws NoSuchMethodException, IOException {
|
||||
Method method = GridImageAsyncClient.class.getMethod("editImageDescription", String.class,
|
||||
String.class);
|
||||
GeneratedHttpRequest<GridImageAsyncClient> httpRequest = processor.createRequest(method,
|
||||
"imageName", "newDesc");
|
||||
Method method = GridImageAsyncClient.class.getMethod("editImageDescription", String.class, String.class);
|
||||
GeneratedHttpRequest<GridImageAsyncClient> httpRequest = processor.createRequest(method, "imageName", "newDesc");
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/image/edit?v=1.5&"
|
||||
+ "image=imageName&description=newDesc HTTP/1.1");
|
||||
+ "image=imageName&description=newDesc HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
|
@ -110,21 +105,19 @@ public class GridImageAsyncClientTest extends BaseGoGridAsyncClientTest<GridImag
|
|||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/image/edit?v=1.5&"
|
||||
+ "image=imageName&description=newDesc&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
+ "image=imageName&description=newDesc&" + "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEditImageFriendlyName() throws NoSuchMethodException, IOException {
|
||||
Method method = GridImageAsyncClient.class.getMethod("editImageFriendlyName", String.class,
|
||||
String.class);
|
||||
GeneratedHttpRequest<GridImageAsyncClient> httpRequest = processor.createRequest(method,
|
||||
"imageName", "newFriendlyName");
|
||||
Method method = GridImageAsyncClient.class.getMethod("editImageFriendlyName", String.class, String.class);
|
||||
GeneratedHttpRequest<GridImageAsyncClient> httpRequest = processor.createRequest(method, "imageName",
|
||||
"newFriendlyName");
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/image/edit?v=1.5&"
|
||||
+ "image=imageName&friendlyName=newFriendlyName HTTP/1.1");
|
||||
+ "image=imageName&friendlyName=newFriendlyName HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
|
@ -136,8 +129,8 @@ public class GridImageAsyncClientTest extends BaseGoGridAsyncClientTest<GridImag
|
|||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/image/edit?v=1.5&"
|
||||
+ "image=imageName&friendlyName=newFriendlyName&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
+ "image=imageName&friendlyName=newFriendlyName&" + "sig=3f446f171455fbb5574aecff4997b273&api_key=foo "
|
||||
+ "HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
}
|
||||
|
|
|
@ -39,12 +39,11 @@ public class GridIpAsyncClientTest extends BaseGoGridAsyncClientTest<GridIpAsync
|
|||
@Test
|
||||
public void testGetIpListWithOptions() throws NoSuchMethodException, IOException {
|
||||
Method method = GridIpAsyncClient.class.getMethod("getIpList", GetIpListOptions[].class);
|
||||
GeneratedHttpRequest<GridIpAsyncClient> httpRequest = processor.createRequest(method,
|
||||
new GetIpListOptions().onlyUnassigned().onlyWithType(IpType.PUBLIC));
|
||||
GeneratedHttpRequest<GridIpAsyncClient> httpRequest = processor.createRequest(method, new GetIpListOptions()
|
||||
.onlyUnassigned().onlyWithType(IpType.PUBLIC));
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/ip/list?v=1.5&ip.state=Unassigned&"
|
||||
+ "ip.type=Public HTTP/1.1");
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/ip/list?v=1.5&ip.state=Unassigned&"
|
||||
+ "ip.type=Public HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
|
@ -55,10 +54,8 @@ public class GridIpAsyncClientTest extends BaseGoGridAsyncClientTest<GridIpAsync
|
|||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/ip/list?v=1.5&ip.state=Unassigned&"
|
||||
+ "ip.type=Public&sig=3f446f171455fbb5574aecff4997b273&api_key=foo "
|
||||
+ "HTTP/1.1");
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/ip/list?v=1.5&ip.state=Unassigned&"
|
||||
+ "ip.type=Public&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
}
|
||||
|
@ -69,7 +66,7 @@ public class GridIpAsyncClientTest extends BaseGoGridAsyncClientTest<GridIpAsync
|
|||
GeneratedHttpRequest<GridIpAsyncClient> httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/ip/list?v=1.5&ip.state=Assigned HTTP/1.1");
|
||||
"GET https://api.gogrid.com/api/grid/ip/list?v=1.5&ip.state=Assigned HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
|
@ -80,9 +77,8 @@ public class GridIpAsyncClientTest extends BaseGoGridAsyncClientTest<GridIpAsync
|
|||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/ip/list?v=1.5&ip.state=Assigned&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/ip/list?v=1.5&ip.state=Assigned&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
}
|
||||
|
|
|
@ -42,14 +42,13 @@ public class GridJobAsyncClientTest extends BaseGoGridAsyncClientTest<GridJobAsy
|
|||
public void testGetJobListWithOptions() throws NoSuchMethodException, IOException {
|
||||
Method method = GridJobAsyncClient.class.getMethod("getJobList", GetJobListOptions[].class);
|
||||
GeneratedHttpRequest<GridJobAsyncClient> httpRequest = processor.createRequest(method,
|
||||
new GetJobListOptions.Builder().create().withStartDate(new Date(1267385381770L))
|
||||
.withEndDate(new Date(1267385382770L)).onlyForObjectType(
|
||||
ObjectType.VIRTUAL_SERVER).onlyForState(JobState.PROCESSING));
|
||||
new GetJobListOptions.Builder().create().withStartDate(new Date(1267385381770L)).withEndDate(
|
||||
new Date(1267385382770L)).onlyForObjectType(ObjectType.VIRTUAL_SERVER).onlyForState(
|
||||
JobState.PROCESSING));
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/job/list?v=1.5&startdate=1267385381770&"
|
||||
+ "enddate=1267385382770&job.objecttype=VirtualServer&"
|
||||
+ "job.state=Processing HTTP/1.1");
|
||||
"GET https://api.gogrid.com/api/grid/job/list?v=1.5&startdate=1267385381770&"
|
||||
+ "enddate=1267385382770&job.objecttype=VirtualServer&" + "job.state=Processing HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
|
@ -61,10 +60,9 @@ public class GridJobAsyncClientTest extends BaseGoGridAsyncClientTest<GridJobAsy
|
|||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/job/list?v=1.5&startdate=1267385381770&"
|
||||
+ "enddate=1267385382770&job.objecttype=VirtualServer&"
|
||||
+ "job.state=Processing&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo HTTP/1.1");
|
||||
"GET https://api.gogrid.com/api/grid/job/list?v=1.5&startdate=1267385381770&"
|
||||
+ "enddate=1267385382770&job.objecttype=VirtualServer&" + "job.state=Processing&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
}
|
||||
|
@ -74,8 +72,7 @@ public class GridJobAsyncClientTest extends BaseGoGridAsyncClientTest<GridJobAsy
|
|||
Method method = GridJobAsyncClient.class.getMethod("getJobList", GetJobListOptions[].class);
|
||||
GeneratedHttpRequest<GridJobAsyncClient> httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/job/list?v=1.5 HTTP/1.1");
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/job/list?v=1.5 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
}
|
||||
|
@ -83,11 +80,10 @@ public class GridJobAsyncClientTest extends BaseGoGridAsyncClientTest<GridJobAsy
|
|||
@Test
|
||||
public void testGetJobsForServerName() throws NoSuchMethodException, IOException {
|
||||
Method method = GridJobAsyncClient.class.getMethod("getJobsForObjectName", String.class);
|
||||
GeneratedHttpRequest<GridJobAsyncClient> httpRequest = processor.createRequest(method,
|
||||
"MyServer");
|
||||
GeneratedHttpRequest<GridJobAsyncClient> httpRequest = processor.createRequest(method, "MyServer");
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/job/list?v=1.5&"
|
||||
+ "object=MyServer HTTP/1.1");
|
||||
+ "object=MyServer HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
|
@ -99,7 +95,7 @@ public class GridJobAsyncClientTest extends BaseGoGridAsyncClientTest<GridJobAsy
|
|||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/job/list?v=1.5&"
|
||||
+ "object=MyServer&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
+ "object=MyServer&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
}
|
||||
|
@ -107,11 +103,10 @@ public class GridJobAsyncClientTest extends BaseGoGridAsyncClientTest<GridJobAsy
|
|||
@Test
|
||||
public void testGetJobsById() throws NoSuchMethodException, IOException {
|
||||
Method method = GridJobAsyncClient.class.getMethod("getJobsById", long[].class);
|
||||
GeneratedHttpRequest<GridJobAsyncClient> httpRequest = processor.createRequest(method, 123L,
|
||||
456L);
|
||||
GeneratedHttpRequest<GridJobAsyncClient> httpRequest = processor.createRequest(method, 123L, 456L);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/job/get?v=1.5&"
|
||||
+ "id=123&id=456 HTTP/1.1");
|
||||
+ "id=123&id=456 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
|
@ -123,7 +118,7 @@ public class GridJobAsyncClientTest extends BaseGoGridAsyncClientTest<GridJobAsy
|
|||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/job/get?v=1.5&"
|
||||
+ "id=123&id=456&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
+ "id=123&id=456&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
}
|
||||
|
|
|
@ -40,50 +40,44 @@ import com.google.inject.TypeLiteral;
|
|||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
public class GridLoadBalancerAsyncClientTest extends
|
||||
BaseGoGridAsyncClientTest<GridLoadBalancerAsyncClient> {
|
||||
public class GridLoadBalancerAsyncClientTest extends BaseGoGridAsyncClientTest<GridLoadBalancerAsyncClient> {
|
||||
|
||||
@Test
|
||||
public void testGetLoadBalancerList() throws NoSuchMethodException, IOException {
|
||||
Method method = GridLoadBalancerAsyncClient.class.getMethod("getLoadBalancerList");
|
||||
GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpRequest = processor
|
||||
.createRequest(method);
|
||||
GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/loadbalancer/list?v=1.5 HTTP/1.1");
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/loadbalancer/list?v=1.5 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest,
|
||||
ParseLoadBalancerListFromJsonResponse.class);
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseLoadBalancerListFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/loadbalancer/list?v=1.5&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/loadbalancer/list?v=1.5&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddLoadBalancer() throws NoSuchMethodException, IOException {
|
||||
Method method = GridLoadBalancerAsyncClient.class.getMethod("addLoadBalancer", String.class,
|
||||
IpPortPair.class, List.class, AddLoadBalancerOptions[].class);
|
||||
GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpRequest = processor.createRequest(
|
||||
method, "BalanceIt", new IpPortPair(new Ip("127.0.0.1"), 80), Arrays.asList(
|
||||
new IpPortPair(new Ip("127.0.0.1"), 8080), new IpPortPair(new Ip(
|
||||
"127.0.0.1"), 9090)), new AddLoadBalancerOptions.Builder().create(
|
||||
LoadBalancerType.LEAST_CONNECTED, LoadBalancerPersistenceType.SSL_STICKY));
|
||||
Method method = GridLoadBalancerAsyncClient.class.getMethod("addLoadBalancer", String.class, IpPortPair.class,
|
||||
List.class, AddLoadBalancerOptions[].class);
|
||||
GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpRequest = processor.createRequest(method, "BalanceIt",
|
||||
new IpPortPair(new Ip("127.0.0.1"), 80), Arrays.asList(new IpPortPair(new Ip("127.0.0.1"), 8080),
|
||||
new IpPortPair(new Ip("127.0.0.1"), 9090)), new AddLoadBalancerOptions.Builder().create(
|
||||
LoadBalancerType.LEAST_CONNECTED, LoadBalancerPersistenceType.SSL_STICKY));
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/loadbalancer/"
|
||||
+ "add?v=1.5&name=BalanceIt&loadbalancer.type=Least%20Connect&"
|
||||
+ "loadbalancer.persistence=SSL%20Sticky&realiplist.0.ip=127.0.0.1&"
|
||||
+ "realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090&"
|
||||
+ "virtualip.ip=127.0.0.1&virtualip.port=80 HTTP/1.1");
|
||||
+ "add?v=1.5&name=BalanceIt&loadbalancer.type=Least%20Connect&"
|
||||
+ "loadbalancer.persistence=SSL%20Sticky&realiplist.0.ip=127.0.0.1&"
|
||||
+ "realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090&"
|
||||
+ "virtualip.ip=127.0.0.1&virtualip.port=80 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
|
@ -95,26 +89,24 @@ public class GridLoadBalancerAsyncClientTest extends
|
|||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/loadbalancer/"
|
||||
+ "add?v=1.5&name=BalanceIt&loadbalancer.type=Least%20Connect&"
|
||||
+ "loadbalancer.persistence=SSL%20Sticky&realiplist.0.ip=127.0.0.1&"
|
||||
+ "realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090&"
|
||||
+ "virtualip.ip=127.0.0.1&virtualip.port=80&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
+ "add?v=1.5&name=BalanceIt&loadbalancer.type=Least%20Connect&"
|
||||
+ "loadbalancer.persistence=SSL%20Sticky&realiplist.0.ip=127.0.0.1&"
|
||||
+ "realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090&"
|
||||
+ "virtualip.ip=127.0.0.1&virtualip.port=80&" + "sig=3f446f171455fbb5574aecff4997b273&api_key=foo "
|
||||
+ "HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEditLoadBalancer() throws NoSuchMethodException, IOException {
|
||||
Method method = GridLoadBalancerAsyncClient.class.getMethod("editLoadBalancer", long.class,
|
||||
List.class);
|
||||
GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpRequest = processor.createRequest(
|
||||
method, 1l, Arrays.asList(new IpPortPair(new Ip("127.0.0.1"), 8080), new IpPortPair(
|
||||
new Ip("127.0.0.1"), 9090)));
|
||||
Method method = GridLoadBalancerAsyncClient.class.getMethod("editLoadBalancer", long.class, List.class);
|
||||
GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpRequest = processor.createRequest(method, 1l, Arrays
|
||||
.asList(new IpPortPair(new Ip("127.0.0.1"), 8080), new IpPortPair(new Ip("127.0.0.1"), 9090)));
|
||||
|
||||
assertRequestLineEquals(
|
||||
httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/loadbalancer/edit?v=1.5&id=1&realiplist.0.ip=127.0.0.1&realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090 HTTP/1.1");
|
||||
httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/loadbalancer/edit?v=1.5&id=1&realiplist.0.ip=127.0.0.1&realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
|
@ -126,23 +118,21 @@ public class GridLoadBalancerAsyncClientTest extends
|
|||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(
|
||||
httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/loadbalancer/edit?v=1.5&id=1&realiplist.0.ip=127.0.0.1&realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090&sig=3f446f171455fbb5574aecff4997b273&api_key=foo HTTP/1.1");
|
||||
httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/loadbalancer/edit?v=1.5&id=1&realiplist.0.ip=127.0.0.1&realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090&sig=3f446f171455fbb5574aecff4997b273&api_key=foo HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEditLoadBalancerNamed() throws NoSuchMethodException, IOException {
|
||||
Method method = GridLoadBalancerAsyncClient.class.getMethod("editLoadBalancerNamed",
|
||||
String.class, List.class);
|
||||
GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpRequest = processor.createRequest(
|
||||
method, "BalanceIt", Arrays.asList(new IpPortPair(new Ip("127.0.0.1"), 8080),
|
||||
new IpPortPair(new Ip("127.0.0.1"), 9090)));
|
||||
Method method = GridLoadBalancerAsyncClient.class.getMethod("editLoadBalancerNamed", String.class, List.class);
|
||||
GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpRequest = processor.createRequest(method, "BalanceIt",
|
||||
Arrays.asList(new IpPortPair(new Ip("127.0.0.1"), 8080), new IpPortPair(new Ip("127.0.0.1"), 9090)));
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/loadbalancer/"
|
||||
+ "edit?v=1.5&name=BalanceIt&realiplist.0.ip=127.0.0.1&"
|
||||
+ "realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090 HTTP/1.1");
|
||||
+ "edit?v=1.5&name=BalanceIt&realiplist.0.ip=127.0.0.1&"
|
||||
+ "realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
|
@ -154,26 +144,24 @@ public class GridLoadBalancerAsyncClientTest extends
|
|||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(
|
||||
httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/loadbalancer/edit?v=1.5&name=BalanceIt&realiplist.0.ip=127.0.0.1&realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090&sig=3f446f171455fbb5574aecff4997b273&api_key=foo HTTP/1.1");
|
||||
httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/loadbalancer/edit?v=1.5&name=BalanceIt&realiplist.0.ip=127.0.0.1&realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090&sig=3f446f171455fbb5574aecff4997b273&api_key=foo HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLoadBalancersByName() throws NoSuchMethodException, IOException {
|
||||
Method method = GridLoadBalancerAsyncClient.class.getMethod("getLoadBalancersByName",
|
||||
String[].class);
|
||||
GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpRequest = processor.createRequest(
|
||||
method, "My Load Balancer", "My Load Balancer 2");
|
||||
Method method = GridLoadBalancerAsyncClient.class.getMethod("getLoadBalancersByName", String[].class);
|
||||
GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpRequest = processor.createRequest(method,
|
||||
"My Load Balancer", "My Load Balancer 2");
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/loadbalancer/"
|
||||
+ "get?v=1.5&name=My%20Load%20Balancer&name=My%20Load%20Balancer%202 HTTP/1.1");
|
||||
+ "get?v=1.5&name=My%20Load%20Balancer&name=My%20Load%20Balancer%202 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest,
|
||||
ParseLoadBalancerListFromJsonResponse.class);
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseLoadBalancerListFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -181,8 +169,8 @@ public class GridLoadBalancerAsyncClientTest extends
|
|||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/loadbalancer/"
|
||||
+ "get?v=1.5&name=My%20Load%20Balancer&name=My%20Load%20Balancer%202&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
+ "get?v=1.5&name=My%20Load%20Balancer&name=My%20Load%20Balancer%202&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
}
|
||||
|
@ -190,11 +178,10 @@ public class GridLoadBalancerAsyncClientTest extends
|
|||
@Test
|
||||
public void testDeleteLoadBalancerById() throws NoSuchMethodException, IOException {
|
||||
Method method = GridLoadBalancerAsyncClient.class.getMethod("deleteById", Long.class);
|
||||
GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpRequest = processor.createRequest(
|
||||
method, 55L);
|
||||
GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpRequest = processor.createRequest(method, 55L);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/loadbalancer/"
|
||||
+ "delete?v=1.5&id=55 HTTP/1.1");
|
||||
+ "delete?v=1.5&id=55 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
|
@ -205,9 +192,8 @@ public class GridLoadBalancerAsyncClientTest extends
|
|||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/loadbalancer/"
|
||||
+ "delete?v=1.5&id=55&" + "sig=3f446f171455fbb5574aecff4997b273&api_key=foo "
|
||||
+ "HTTP/1.1");
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/loadbalancer/" + "delete?v=1.5&id=55&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
}
|
||||
|
|
|
@ -67,170 +67,130 @@ import com.google.inject.TypeLiteral;
|
|||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
@Test(groups = "unit", testName = "gogrid.GoGridAsyncClientTest")
|
||||
public class GridServerAsyncClientTest extends
|
||||
BaseGoGridAsyncClientTest<GridServerAsyncClient> {
|
||||
public class GridServerAsyncClientTest extends BaseGoGridAsyncClientTest<GridServerAsyncClient> {
|
||||
|
||||
@Test
|
||||
public void testGetServerListNoOptions() throws NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = GridServerAsyncClient.class.getMethod("getServerList",
|
||||
GetServerListOptions[].class);
|
||||
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor
|
||||
.createRequest(method);
|
||||
public void testGetServerListNoOptions() throws NoSuchMethodException, IOException {
|
||||
Method method = GridServerAsyncClient.class.getMethod("getServerList", GetServerListOptions[].class);
|
||||
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/server/list?v=1.5 HTTP/1.1");
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/server/list?v=1.5 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest,
|
||||
ParseServerListFromJsonResponse.class);
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseServerListFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/server/list?"
|
||||
+ "v=1.5&sig=3f446f171455fbb5574aecff4997b273&api_key=foo "
|
||||
+ "HTTP/1.1");
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/server/list?"
|
||||
+ "v=1.5&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetServerListWithOptions() throws NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = GridServerAsyncClient.class.getMethod("getServerList",
|
||||
GetServerListOptions[].class);
|
||||
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor
|
||||
.createRequest(method, new GetServerListOptions.Builder()
|
||||
.onlySandboxServers());
|
||||
public void testGetServerListWithOptions() throws NoSuchMethodException, IOException {
|
||||
Method method = GridServerAsyncClient.class.getMethod("getServerList", GetServerListOptions[].class);
|
||||
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method,
|
||||
new GetServerListOptions.Builder().onlySandboxServers());
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/server/list?v=1.5&isSandbox=true HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest,
|
||||
ParseServerListFromJsonResponse.class);
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseServerListFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(
|
||||
httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/server/list?"
|
||||
+ "v=1.5&isSandbox=true&sig=3f446f171455fbb5574aecff4997b273&api_key=foo "
|
||||
+ "HTTP/1.1");
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/server/list?"
|
||||
+ "v=1.5&isSandbox=true&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetServersByName() throws NoSuchMethodException, IOException {
|
||||
Method method = GridServerAsyncClient.class.getMethod("getServersByName",
|
||||
String[].class);
|
||||
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor
|
||||
.createRequest(method, "server1");
|
||||
Method method = GridServerAsyncClient.class.getMethod("getServersByName", String[].class);
|
||||
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method, "server1");
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/server/get?v=1.5&name=server1 HTTP/1.1");
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/server/get?v=1.5&name=server1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest,
|
||||
ParseServerListFromJsonResponse.class);
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseServerListFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFound.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/server/get?"
|
||||
+ "v=1.5&name=server1&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo "
|
||||
+ "HTTP/1.1");
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/server/get?" + "v=1.5&name=server1&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetServersById() throws NoSuchMethodException, IOException {
|
||||
Method method = GridServerAsyncClient.class.getMethod("getServersById",
|
||||
long[].class);
|
||||
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor
|
||||
.createRequest(method, 123L);
|
||||
Method method = GridServerAsyncClient.class.getMethod("getServersById", long[].class);
|
||||
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method, 123L);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/server/get?v=1.5&id=123 HTTP/1.1");
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/server/get?v=1.5&id=123 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest,
|
||||
ParseServerListFromJsonResponse.class);
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseServerListFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFound.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/server/get?" + "v=1.5&id=123&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo "
|
||||
+ "HTTP/1.1");
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/server/get?" + "v=1.5&id=123&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddServerNoOptions() throws NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = GridServerAsyncClient.class.getMethod("addServer",
|
||||
String.class, String.class, String.class, String.class,
|
||||
AddServerOptions[].class);
|
||||
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor
|
||||
.createRequest(method, "serverName", "img55", "memory", "127.0.0.1");
|
||||
public void testAddServerNoOptions() throws NoSuchMethodException, IOException {
|
||||
Method method = GridServerAsyncClient.class.getMethod("addServer", String.class, String.class, String.class,
|
||||
String.class, AddServerOptions[].class);
|
||||
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method, "serverName", "img55",
|
||||
"memory", "127.0.0.1");
|
||||
|
||||
assertRequestLineEquals(
|
||||
httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/server/add?v=1.5&"
|
||||
+ "name=serverName&server.ram=memory&image=img55&ip=127.0.0.1 "
|
||||
+ "HTTP/1.1");
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/server/add?v=1.5&"
|
||||
+ "name=serverName&server.ram=memory&image=img55&ip=127.0.0.1 " + "HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest,
|
||||
ParseServerFromJsonResponse.class);
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseServerFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/server/add?"
|
||||
+ "v=1.5&name=serverName&server.ram=memory&"
|
||||
+ "image=img55&ip=127.0.0.1&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo "
|
||||
+ "HTTP/1.1");
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/server/add?"
|
||||
+ "v=1.5&name=serverName&server.ram=memory&" + "image=img55&ip=127.0.0.1&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddServerOptions() throws NoSuchMethodException, IOException {
|
||||
Method method = GridServerAsyncClient.class.getMethod("addServer",
|
||||
String.class, String.class, String.class, String.class,
|
||||
AddServerOptions[].class);
|
||||
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor
|
||||
.createRequest(method, "serverName", "img55", "memory",
|
||||
"127.0.0.1", new AddServerOptions().asSandboxType()
|
||||
.withDescription("fooy"));
|
||||
Method method = GridServerAsyncClient.class.getMethod("addServer", String.class, String.class, String.class,
|
||||
String.class, AddServerOptions[].class);
|
||||
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method, "serverName", "img55",
|
||||
"memory", "127.0.0.1", new AddServerOptions().asSandboxType().withDescription("fooy"));
|
||||
|
||||
assertRequestLineEquals(
|
||||
httpRequest,
|
||||
|
@ -238,8 +198,7 @@ public class GridServerAsyncClientTest extends
|
|||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest,
|
||||
ParseServerFromJsonResponse.class);
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseServerFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -255,60 +214,47 @@ public class GridServerAsyncClientTest extends
|
|||
|
||||
@Test
|
||||
public void testPowerServer() throws NoSuchMethodException, IOException {
|
||||
Method method = GridServerAsyncClient.class.getMethod("power",
|
||||
String.class, PowerCommand.class);
|
||||
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor
|
||||
.createRequest(method, "PowerServer", PowerCommand.RESTART);
|
||||
Method method = GridServerAsyncClient.class.getMethod("power", String.class, PowerCommand.class);
|
||||
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method, "PowerServer",
|
||||
PowerCommand.RESTART);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/server/power?v=1.5&"
|
||||
+ "server=PowerServer&power=restart " + "HTTP/1.1");
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/server/power?v=1.5&"
|
||||
+ "server=PowerServer&power=restart " + "HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest,
|
||||
ParseServerFromJsonResponse.class);
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseServerFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/server/power?v=1.5&"
|
||||
+ "server=PowerServer&power=restart&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo "
|
||||
+ "HTTP/1.1");
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/server/power?v=1.5&"
|
||||
+ "server=PowerServer&power=restart&" + "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteByName() throws NoSuchMethodException, IOException {
|
||||
Method method = GridServerAsyncClient.class.getMethod("deleteByName",
|
||||
String.class);
|
||||
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor
|
||||
.createRequest(method, "PowerServer");
|
||||
Method method = GridServerAsyncClient.class.getMethod("deleteByName", String.class);
|
||||
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method, "PowerServer");
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/server/delete?v=1.5&"
|
||||
+ "name=PowerServer " + "HTTP/1.1");
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/server/delete?v=1.5&"
|
||||
+ "name=PowerServer " + "HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest,
|
||||
ParseServerFromJsonResponse.class);
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseServerFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/server/delete?v=1.5&"
|
||||
+ "name=PowerServer&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo "
|
||||
+ "HTTP/1.1");
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/server/delete?v=1.5&"
|
||||
+ "name=PowerServer&" + "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
}
|
||||
|
@ -316,46 +262,37 @@ public class GridServerAsyncClientTest extends
|
|||
@Test
|
||||
public void testGetRamSizes() throws NoSuchMethodException, IOException {
|
||||
Method method = GridServerAsyncClient.class.getMethod("getRamSizes");
|
||||
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor
|
||||
.createRequest(method);
|
||||
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/common/lookup/list?v=1.5&lookup=server.ram "
|
||||
+ "HTTP/1.1");
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/common/lookup/list?v=1.5&lookup=server.ram "
|
||||
+ "HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest,
|
||||
ParseOptionsFromJsonResponse.class);
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseOptionsFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/common/lookup/list?v=1.5&lookup=server.ram&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo "
|
||||
+ "HTTP/1.1");
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/common/lookup/list?v=1.5&lookup=server.ram&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServerCredentials() throws NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = GridServerAsyncClient.class.getMethod(
|
||||
"getServerCredentials", long.class);
|
||||
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor
|
||||
.createRequest(method, 1);
|
||||
public void testServerCredentials() throws NoSuchMethodException, IOException {
|
||||
Method method = GridServerAsyncClient.class.getMethod("getServerCredentials", long.class);
|
||||
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method, 1);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/support/grid/password/get?v=1.5&id=1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest,
|
||||
ParseCredentialsFromJsonResponse.class);
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseCredentialsFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
}
|
||||
|
|
|
@ -52,7 +52,6 @@ import org.jclouds.ibmdev.functions.ParseImageFromJson;
|
|||
import org.jclouds.ibmdev.functions.ParseImagesFromJson;
|
||||
import org.jclouds.ibmdev.functions.ParseInstanceFromJson;
|
||||
import org.jclouds.ibmdev.functions.ParseInstancesFromJson;
|
||||
import org.jclouds.ibmdev.functions.ParseKeyFromJson;
|
||||
import org.jclouds.ibmdev.functions.ParseKeysFromJson;
|
||||
import org.jclouds.ibmdev.functions.ParseLongFromDate;
|
||||
import org.jclouds.ibmdev.functions.ParseVolumeFromJson;
|
||||
|
@ -83,7 +82,6 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
@RequestFilters(BasicAuthentication.class)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@SkipEncoding( { '{', '}' })
|
||||
public interface IBMDeveloperCloudAsyncClient {
|
||||
public static final String VERSION = "20090403";
|
||||
|
@ -93,6 +91,7 @@ public interface IBMDeveloperCloudAsyncClient {
|
|||
*/
|
||||
@GET
|
||||
@Path(IBMDeveloperCloudAsyncClient.VERSION + "/images")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ResponseParser(ParseImagesFromJson.class)
|
||||
ListenableFuture<Set<? extends Image>> listImages();
|
||||
|
||||
|
@ -102,6 +101,7 @@ public interface IBMDeveloperCloudAsyncClient {
|
|||
@GET
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@Path(IBMDeveloperCloudAsyncClient.VERSION + "/images/{imageId}")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ResponseParser(ParseImageFromJson.class)
|
||||
ListenableFuture<Image> getImage(@PathParam("imageId") String id);
|
||||
|
||||
|
@ -119,9 +119,10 @@ public interface IBMDeveloperCloudAsyncClient {
|
|||
@PUT
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@Path(IBMDeveloperCloudAsyncClient.VERSION + "/images/{imageId}")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ResponseParser(ParseImageFromJson.class)
|
||||
ListenableFuture<Image> setImageVisibility(@PathParam("imageId") String id,
|
||||
@FormParam("visibility") Image.Visibility visibility);
|
||||
@FormParam("visibility") Image.Visibility visibility);
|
||||
|
||||
/**
|
||||
* @see IBMDeveloperCloudClient#listInstancesFromRequest(long)
|
||||
|
@ -129,15 +130,16 @@ public interface IBMDeveloperCloudAsyncClient {
|
|||
@GET
|
||||
@Path(IBMDeveloperCloudAsyncClient.VERSION + "/requests/{requestId}")
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ResponseParser(ParseInstancesFromJson.class)
|
||||
ListenableFuture<Set<? extends Instance>> listInstancesFromRequest(
|
||||
@PathParam("requestId") String requestId);
|
||||
ListenableFuture<Set<? extends Instance>> listInstancesFromRequest(@PathParam("requestId") String requestId);
|
||||
|
||||
/**
|
||||
* @see IBMDeveloperCloudClient#listInstances()
|
||||
*/
|
||||
@GET
|
||||
@Path(IBMDeveloperCloudAsyncClient.VERSION + "/instances")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ResponseParser(ParseInstancesFromJson.class)
|
||||
ListenableFuture<Set<? extends Instance>> listInstances();
|
||||
|
||||
|
@ -147,6 +149,7 @@ public interface IBMDeveloperCloudAsyncClient {
|
|||
@GET
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@Path(IBMDeveloperCloudAsyncClient.VERSION + "/instances/{instanceId}")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ResponseParser(ParseInstanceFromJson.class)
|
||||
ListenableFuture<Instance> getInstance(@PathParam("instanceId") String id);
|
||||
|
||||
|
@ -156,9 +159,10 @@ public interface IBMDeveloperCloudAsyncClient {
|
|||
*/
|
||||
@PUT
|
||||
@Path(IBMDeveloperCloudAsyncClient.VERSION + "/instances/{instanceId}")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ResponseParser(ParseExpirationTimeFromJson.class)
|
||||
ListenableFuture<Date> extendReservationForInstance(@PathParam("instanceId") String id,
|
||||
@FormParam("expirationTime") @ParamParser(ParseLongFromDate.class) Date expirationTime);
|
||||
@FormParam("expirationTime") @ParamParser(ParseLongFromDate.class) Date expirationTime);
|
||||
|
||||
/**
|
||||
* @see IBMDeveloperCloudClient#restartInstance
|
||||
|
@ -166,29 +170,29 @@ public interface IBMDeveloperCloudAsyncClient {
|
|||
@PUT
|
||||
@Path(IBMDeveloperCloudAsyncClient.VERSION + "/instances/{instanceId}")
|
||||
@FormParams(keys = "state", values = "restart")
|
||||
ListenableFuture<Void> restartInstance(@PathParam("instanceId") String id,
|
||||
RestartInstanceOptions... options);
|
||||
ListenableFuture<Void> restartInstance(@PathParam("instanceId") String id, RestartInstanceOptions... options);
|
||||
|
||||
/**
|
||||
* @see IBMDeveloperCloudClient#saveInstanceToImage
|
||||
*/
|
||||
@PUT
|
||||
@Path(IBMDeveloperCloudAsyncClient.VERSION + "/instances/{instanceId}")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@FormParams(keys = "state", values = "save")
|
||||
@ResponseParser(ParseImageFromJson.class)
|
||||
ListenableFuture<Image> saveInstanceToImage(@PathParam("instanceId") String id,
|
||||
@FormParam("name") String toImageName,
|
||||
@FormParam("description") String toImageDescription);
|
||||
@FormParam("name") String toImageName, @FormParam("description") String toImageDescription);
|
||||
|
||||
/**
|
||||
* @see IBMDeveloperCloudClient#createInstanceInLocation
|
||||
*/
|
||||
@POST
|
||||
@Path(IBMDeveloperCloudAsyncClient.VERSION + "/instances")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ResponseParser(GetFirstInstanceInList.class)
|
||||
ListenableFuture<Instance> createInstanceInLocation(@FormParam("location") String location,
|
||||
@FormParam("name") String name, @FormParam("imageID") String imageID,
|
||||
@FormParam("instanceType") String instanceType, CreateInstanceOptions... options);
|
||||
@FormParam("name") String name, @FormParam("imageID") String imageID,
|
||||
@FormParam("instanceType") String instanceType, CreateInstanceOptions... options);
|
||||
|
||||
/**
|
||||
* @see IBMDeveloperCloudClient#deleteInstance
|
||||
|
@ -203,6 +207,7 @@ public interface IBMDeveloperCloudAsyncClient {
|
|||
*/
|
||||
@GET
|
||||
@Path(IBMDeveloperCloudAsyncClient.VERSION + "/keys")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ResponseParser(ParseKeysFromJson.class)
|
||||
ListenableFuture<Set<? extends Key>> listKeys();
|
||||
|
||||
|
@ -211,7 +216,7 @@ public interface IBMDeveloperCloudAsyncClient {
|
|||
*/
|
||||
@POST
|
||||
@Path(IBMDeveloperCloudAsyncClient.VERSION + "/keys")
|
||||
@ResponseParser(ParseKeyFromJson.class)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
ListenableFuture<Key> generateKeyPair(@FormParam("name") String name);
|
||||
|
||||
/**
|
||||
|
@ -219,16 +224,14 @@ public interface IBMDeveloperCloudAsyncClient {
|
|||
*/
|
||||
@POST
|
||||
@Path(IBMDeveloperCloudAsyncClient.VERSION + "/keys")
|
||||
ListenableFuture<Void> addPublicKey(@FormParam("name") String name,
|
||||
@FormParam("publicKey") String publicKey);
|
||||
ListenableFuture<Void> addPublicKey(@FormParam("name") String name, @FormParam("publicKey") String publicKey);
|
||||
|
||||
/**
|
||||
* @see IBMDeveloperCloudClient#updatePublicKey(String, String)
|
||||
*/
|
||||
@PUT
|
||||
@Path(IBMDeveloperCloudAsyncClient.VERSION + "/keys/{keyName}")
|
||||
ListenableFuture<Void> updatePublicKey(@PathParam("keyName") String name,
|
||||
@FormParam("publicKey") String publicKey);
|
||||
ListenableFuture<Void> updatePublicKey(@PathParam("keyName") String name, @FormParam("publicKey") String publicKey);
|
||||
|
||||
/**
|
||||
* @see IBMDeveloperCloudClient#setDefaultStatusOfKey(String, boolean)
|
||||
|
@ -236,7 +239,7 @@ public interface IBMDeveloperCloudAsyncClient {
|
|||
@PUT
|
||||
@Path(IBMDeveloperCloudAsyncClient.VERSION + "/keys/{keyName}")
|
||||
ListenableFuture<Void> setDefaultStatusOfKey(@PathParam("keyName") String name,
|
||||
@FormParam("default") boolean isDefault);
|
||||
@FormParam("default") boolean isDefault);
|
||||
|
||||
/**
|
||||
* @see IBMDeveloperCloudClient#getKey(String)
|
||||
|
@ -244,7 +247,7 @@ public interface IBMDeveloperCloudAsyncClient {
|
|||
@GET
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@Path(IBMDeveloperCloudAsyncClient.VERSION + "/keys/{keyName}")
|
||||
@ResponseParser(ParseKeyFromJson.class)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
ListenableFuture<Key> getKey(@PathParam("keyName") String name);
|
||||
|
||||
/**
|
||||
|
@ -261,6 +264,7 @@ public interface IBMDeveloperCloudAsyncClient {
|
|||
@GET
|
||||
@Path(IBMDeveloperCloudAsyncClient.VERSION + "/storage")
|
||||
@ResponseParser(ParseVolumesFromJson.class)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
ListenableFuture<Set<? extends Volume>> listVolumes();
|
||||
|
||||
/**
|
||||
|
@ -268,10 +272,10 @@ public interface IBMDeveloperCloudAsyncClient {
|
|||
*/
|
||||
@POST
|
||||
@Path(IBMDeveloperCloudAsyncClient.VERSION + "/storage")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ResponseParser(ParseVolumeFromJson.class)
|
||||
ListenableFuture<Volume> createVolumeInLocation(@FormParam("location") String location,
|
||||
@FormParam("name") String name, @FormParam("format") String format,
|
||||
@FormParam("size") String size);
|
||||
@FormParam("name") String name, @FormParam("format") String format, @FormParam("size") String size);
|
||||
|
||||
/**
|
||||
* @see IBMDeveloperCloudClient#getVolume(long)
|
||||
|
@ -279,6 +283,7 @@ public interface IBMDeveloperCloudAsyncClient {
|
|||
@GET
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@Path(IBMDeveloperCloudAsyncClient.VERSION + "/storage/{volumeId}")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ResponseParser(ParseVolumeFromJson.class)
|
||||
ListenableFuture<Volume> getVolume(@PathParam("volumeId") String id);
|
||||
|
||||
|
@ -314,6 +319,7 @@ public interface IBMDeveloperCloudAsyncClient {
|
|||
*/
|
||||
@GET
|
||||
@Path(IBMDeveloperCloudAsyncClient.VERSION + "/addresses")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ResponseParser(ParseAddressesFromJson.class)
|
||||
ListenableFuture<Set<? extends Address>> listAddresses();
|
||||
|
||||
|
@ -322,6 +328,7 @@ public interface IBMDeveloperCloudAsyncClient {
|
|||
*/
|
||||
@POST
|
||||
@Path(IBMDeveloperCloudAsyncClient.VERSION + "/addresses")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ResponseParser(ParseAddressFromJson.class)
|
||||
ListenableFuture<Address> allocateAddressInLocation(@FormParam("location") String locationId);
|
||||
|
||||
|
|
|
@ -41,36 +41,32 @@
|
|||
*/
|
||||
package org.jclouds.ibmdev.functions;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.ibmdev.domain.Address;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseAddressFromJson extends ParseJson<Address> {
|
||||
public class ParseAddressFromJson implements Function<HttpResponse, Address> {
|
||||
|
||||
private final ParseJson<Address> json;
|
||||
|
||||
@Inject
|
||||
public ParseAddressFromJson(Gson gson) {
|
||||
super(gson);
|
||||
ParseAddressFromJson(ParseJson<Address> json) {
|
||||
this.json = json;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Address apply(InputStream stream) {
|
||||
try {
|
||||
Address returnVal = gson.fromJson(new InputStreamReader(stream, "UTF-8"), Address.class);
|
||||
ParseUtils.CLEAN_ADDRESS.apply(returnVal);
|
||||
return returnVal;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
public Address apply(HttpResponse arg0) {
|
||||
Address input = json.apply(arg0);
|
||||
ParseUtils.CLEAN_ADDRESS.apply(input);
|
||||
return input;
|
||||
}
|
||||
}
|
|
@ -41,28 +41,30 @@
|
|||
*/
|
||||
package org.jclouds.ibmdev.functions;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.ibmdev.domain.Address;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseAddressesFromJson extends ParseJson<Set<? extends Address>> {
|
||||
public class ParseAddressesFromJson implements
|
||||
Function<HttpResponse, Set<? extends Address>> {
|
||||
|
||||
private final ParseJson<AddressListResponse> json;
|
||||
|
||||
@Inject
|
||||
public ParseAddressesFromJson(Gson gson) {
|
||||
super(gson);
|
||||
ParseAddressesFromJson(ParseJson<AddressListResponse> json) {
|
||||
this.json = json;
|
||||
}
|
||||
|
||||
private static class AddressListResponse {
|
||||
|
@ -70,12 +72,8 @@ public class ParseAddressesFromJson extends ParseJson<Set<? extends Address>> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Set<? extends Address> apply(InputStream stream) {
|
||||
try {
|
||||
return ParseUtils.clean(gson.fromJson(new InputStreamReader(stream, "UTF-8"),
|
||||
AddressListResponse.class).addresses, ParseUtils.CLEAN_ADDRESS);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
public Set<? extends Address> apply(HttpResponse arg0) {
|
||||
return ParseUtils.clean(json.apply(arg0).addresses,
|
||||
ParseUtils.CLEAN_ADDRESS);
|
||||
}
|
||||
}
|
|
@ -18,26 +18,28 @@
|
|||
*/
|
||||
package org.jclouds.ibmdev.functions;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseExpirationTimeFromJson extends ParseJson<Date> {
|
||||
public class ParseExpirationTimeFromJson implements
|
||||
Function<HttpResponse, Date> {
|
||||
|
||||
private final ParseJson<ExpirationTimeResponse> json;
|
||||
|
||||
@Inject
|
||||
public ParseExpirationTimeFromJson(Gson gson) {
|
||||
super(gson);
|
||||
ParseExpirationTimeFromJson(ParseJson<ExpirationTimeResponse> json) {
|
||||
this.json = json;
|
||||
}
|
||||
|
||||
private static class ExpirationTimeResponse {
|
||||
|
@ -45,11 +47,7 @@ public class ParseExpirationTimeFromJson extends ParseJson<Date> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Date apply(InputStream stream) {
|
||||
try {
|
||||
return gson.fromJson(new InputStreamReader(stream, "UTF-8"), ExpirationTimeResponse.class).expirationTime;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
public Date apply(HttpResponse arg0) {
|
||||
return json.apply(arg0).expirationTime;
|
||||
}
|
||||
}
|
|
@ -41,36 +41,32 @@
|
|||
*/
|
||||
package org.jclouds.ibmdev.functions;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.ibmdev.domain.Image;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseImageFromJson extends ParseJson<Image> {
|
||||
public class ParseImageFromJson implements Function<HttpResponse, Image> {
|
||||
|
||||
private final ParseJson<Image> json;
|
||||
|
||||
@Inject
|
||||
public ParseImageFromJson(Gson gson) {
|
||||
super(gson);
|
||||
ParseImageFromJson(ParseJson<Image> json) {
|
||||
this.json = json;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Image apply(InputStream stream) {
|
||||
try {
|
||||
Image returnVal = gson.fromJson(new InputStreamReader(stream, "UTF-8"), Image.class);
|
||||
ParseUtils.CLEAN_IMAGE.apply(returnVal);
|
||||
return returnVal;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
public Image apply(HttpResponse arg0) {
|
||||
Image input = json.apply(arg0);
|
||||
ParseUtils.CLEAN_IMAGE.apply(input);
|
||||
return input;
|
||||
}
|
||||
}
|
|
@ -41,28 +41,30 @@
|
|||
*/
|
||||
package org.jclouds.ibmdev.functions;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.ibmdev.domain.Image;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseImagesFromJson extends ParseJson<Set<? extends Image>> {
|
||||
public class ParseImagesFromJson implements
|
||||
Function<HttpResponse, Set<? extends Image>> {
|
||||
|
||||
private final ParseJson<ImageListResponse> json;
|
||||
|
||||
@Inject
|
||||
public ParseImagesFromJson(Gson gson) {
|
||||
super(gson);
|
||||
ParseImagesFromJson(ParseJson<ImageListResponse> json) {
|
||||
this.json = json;
|
||||
}
|
||||
|
||||
private static class ImageListResponse {
|
||||
|
@ -70,12 +72,7 @@ public class ParseImagesFromJson extends ParseJson<Set<? extends Image>> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Set<? extends Image> apply(InputStream stream) {
|
||||
try {
|
||||
return ParseUtils.clean(gson.fromJson(new InputStreamReader(stream, "UTF-8"),
|
||||
ImageListResponse.class).images, ParseUtils.CLEAN_IMAGE);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
public Set<? extends Image> apply(HttpResponse arg0) {
|
||||
return ParseUtils.clean(json.apply(arg0).images, ParseUtils.CLEAN_IMAGE);
|
||||
}
|
||||
}
|
|
@ -41,36 +41,32 @@
|
|||
*/
|
||||
package org.jclouds.ibmdev.functions;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.ibmdev.domain.Instance;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseInstanceFromJson extends ParseJson<Instance> {
|
||||
public class ParseInstanceFromJson implements Function<HttpResponse, Instance> {
|
||||
|
||||
private final ParseJson<Instance> json;
|
||||
|
||||
@Inject
|
||||
public ParseInstanceFromJson(Gson gson) {
|
||||
super(gson);
|
||||
ParseInstanceFromJson(ParseJson<Instance> json) {
|
||||
this.json = json;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Instance apply(InputStream stream) {
|
||||
try {
|
||||
Instance returnVal = gson.fromJson(new InputStreamReader(stream, "UTF-8"), Instance.class);
|
||||
ParseUtils.CLEAN_INSTANCE.apply(returnVal);
|
||||
return returnVal;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
public Instance apply(HttpResponse arg0) {
|
||||
Instance input = json.apply(arg0);
|
||||
ParseUtils.CLEAN_INSTANCE.apply(input);
|
||||
return input;
|
||||
}
|
||||
}
|
|
@ -41,28 +41,30 @@
|
|||
*/
|
||||
package org.jclouds.ibmdev.functions;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.ibmdev.domain.Instance;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseInstancesFromJson extends ParseJson<Set<? extends Instance>> {
|
||||
public class ParseInstancesFromJson implements
|
||||
Function<HttpResponse, Set<? extends Instance>> {
|
||||
|
||||
private final ParseJson<InstanceListResponse> json;
|
||||
|
||||
@Inject
|
||||
public ParseInstancesFromJson(Gson gson) {
|
||||
super(gson);
|
||||
ParseInstancesFromJson(ParseJson<InstanceListResponse> json) {
|
||||
this.json = json;
|
||||
}
|
||||
|
||||
private static class InstanceListResponse {
|
||||
|
@ -70,12 +72,8 @@ public class ParseInstancesFromJson extends ParseJson<Set<? extends Instance>> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Set<? extends Instance> apply(InputStream stream) {
|
||||
try {
|
||||
return ParseUtils.clean(gson.fromJson(new InputStreamReader(stream, "UTF-8"),
|
||||
InstanceListResponse.class).instances, ParseUtils.CLEAN_INSTANCE);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
public Set<? extends Instance> apply(HttpResponse arg0) {
|
||||
return ParseUtils.clean(json.apply(arg0).instances,
|
||||
ParseUtils.CLEAN_INSTANCE);
|
||||
}
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* 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.
|
||||
* ====================================================================
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.ibmdev.functions;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.ibmdev.domain.Key;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseKeyFromJson extends ParseJson<Key> {
|
||||
@Inject
|
||||
public ParseKeyFromJson(Gson gson) {
|
||||
super(gson);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Key apply(InputStream stream) {
|
||||
try {
|
||||
return gson.fromJson(new InputStreamReader(stream, "UTF-8"), Key.class);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -41,40 +41,38 @@
|
|||
*/
|
||||
package org.jclouds.ibmdev.functions;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.ibmdev.domain.Key;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseKeysFromJson extends ParseJson<Set<? extends Key>> {
|
||||
public class ParseKeysFromJson implements
|
||||
Function<HttpResponse, Set<? extends Key>> {
|
||||
|
||||
private final ParseJson<KeyListResponse> json;
|
||||
|
||||
@Inject
|
||||
public ParseKeysFromJson(Gson gson) {
|
||||
super(gson);
|
||||
ParseKeysFromJson(ParseJson<KeyListResponse> json) {
|
||||
this.json = json;
|
||||
}
|
||||
|
||||
private static class KeyListResponse {
|
||||
Set<Key> keys = Sets.newLinkedHashSet();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Set<? extends Key> apply(InputStream stream) {
|
||||
try {
|
||||
return gson.fromJson(new InputStreamReader(stream, "UTF-8"), KeyListResponse.class).keys;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
public Set<? extends Key> apply(HttpResponse arg0) {
|
||||
return json.apply(arg0).keys;
|
||||
}
|
||||
}
|
|
@ -18,36 +18,32 @@
|
|||
*/
|
||||
package org.jclouds.ibmdev.functions;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.ibmdev.domain.Volume;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseVolumeFromJson extends ParseJson<Volume> {
|
||||
public class ParseVolumeFromJson implements Function<HttpResponse, Volume> {
|
||||
|
||||
private final ParseJson<Volume> json;
|
||||
|
||||
@Inject
|
||||
public ParseVolumeFromJson(Gson gson) {
|
||||
super(gson);
|
||||
ParseVolumeFromJson(ParseJson<Volume> json) {
|
||||
this.json = json;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Volume apply(InputStream stream) {
|
||||
try {
|
||||
Volume returnVal = gson.fromJson(new InputStreamReader(stream, "UTF-8"), Volume.class);
|
||||
ParseUtils.CLEAN_VOLUME.apply(returnVal);
|
||||
return returnVal;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
public Volume apply(HttpResponse arg0) {
|
||||
Volume input = json.apply(arg0);
|
||||
ParseUtils.CLEAN_VOLUME.apply(input);
|
||||
return input;
|
||||
}
|
||||
}
|
|
@ -18,28 +18,30 @@
|
|||
*/
|
||||
package org.jclouds.ibmdev.functions;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.ibmdev.domain.Volume;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseVolumesFromJson extends ParseJson<Set<? extends Volume>> {
|
||||
public class ParseVolumesFromJson implements
|
||||
Function<HttpResponse, Set<? extends Volume>> {
|
||||
|
||||
private final ParseJson<VolumeListResponse> json;
|
||||
|
||||
@Inject
|
||||
public ParseVolumesFromJson(Gson gson) {
|
||||
super(gson);
|
||||
ParseVolumesFromJson(ParseJson<VolumeListResponse> json) {
|
||||
this.json = json;
|
||||
}
|
||||
|
||||
private static class VolumeListResponse {
|
||||
|
@ -47,12 +49,8 @@ public class ParseVolumesFromJson extends ParseJson<Set<? extends Volume>> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Set<? extends Volume> apply(InputStream stream) {
|
||||
try {
|
||||
return ParseUtils.clean(gson.fromJson(new InputStreamReader(stream, "UTF-8"),
|
||||
VolumeListResponse.class).volumes, ParseUtils.CLEAN_VOLUME);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
public Set<? extends Volume> apply(HttpResponse arg0) {
|
||||
return ParseUtils
|
||||
.clean(json.apply(arg0).volumes, ParseUtils.CLEAN_VOLUME);
|
||||
}
|
||||
}
|
|
@ -32,6 +32,7 @@ import java.util.Properties;
|
|||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.filters.BasicAuthentication;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.ibmdev.domain.Image;
|
||||
|
@ -43,7 +44,6 @@ import org.jclouds.ibmdev.functions.ParseImageFromJson;
|
|||
import org.jclouds.ibmdev.functions.ParseImagesFromJson;
|
||||
import org.jclouds.ibmdev.functions.ParseInstanceFromJson;
|
||||
import org.jclouds.ibmdev.functions.ParseInstancesFromJson;
|
||||
import org.jclouds.ibmdev.functions.ParseKeyFromJson;
|
||||
import org.jclouds.ibmdev.functions.ParseKeysFromJson;
|
||||
import org.jclouds.ibmdev.functions.ParseVolumeFromJson;
|
||||
import org.jclouds.ibmdev.functions.ParseVolumesFromJson;
|
||||
|
@ -74,11 +74,10 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
|
|||
|
||||
public void testListImages() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("listImages");
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor
|
||||
.createRequest(method);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/images HTTP/1.1");
|
||||
"GET https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/images HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
|
@ -87,10 +86,11 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
|
|||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/images HTTP/1.1");
|
||||
// for example, using basic authentication, we should get "only one" header
|
||||
"GET https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/images HTTP/1.1");
|
||||
// for example, using basic authentication, we should get "only one"
|
||||
// header
|
||||
assertNonPayloadHeadersEqual(httpRequest,
|
||||
"Accept: application/json\nAuthorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\n");
|
||||
"Accept: application/json\nAuthorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseImagesFromJson.class);
|
||||
|
@ -103,11 +103,10 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
|
|||
|
||||
public void testGetImage() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("getImage", String.class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
|
||||
method, "1");
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(method, "1");
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/images/1 HTTP/1.1");
|
||||
"GET https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/images/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
|
@ -121,12 +120,11 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
|
|||
|
||||
public void testDeleteImage() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("deleteImage", String.class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
|
||||
method, "1");
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(method, "1");
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"DELETE https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/images/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
"DELETE https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/images/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
||||
|
@ -137,18 +135,16 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
|
|||
|
||||
}
|
||||
|
||||
public void testSetImageVisibility() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("setImageVisibility",
|
||||
String.class, Image.Visibility.class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
|
||||
method, "1", Image.Visibility.PUBLIC);
|
||||
public void testSetImageVisibility() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("setImageVisibility", String.class,
|
||||
Image.Visibility.class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(method, "1",
|
||||
Image.Visibility.PUBLIC);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"PUT https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/images/1 HTTP/1.1");
|
||||
"PUT https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/images/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, "visibility=PUBLIC", "application/x-www-form-urlencoded",
|
||||
false);
|
||||
assertPayloadEquals(httpRequest, "visibility=PUBLIC", "application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseImageFromJson.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -160,11 +156,10 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
|
|||
|
||||
public void testListInstances() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("listInstances");
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor
|
||||
.createRequest(method);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/instances HTTP/1.1");
|
||||
"GET https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/instances HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
|
@ -176,15 +171,12 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
|
|||
|
||||
}
|
||||
|
||||
public void testListInstancesFromRequest() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("listInstancesFromRequest",
|
||||
String.class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
|
||||
method, "1");
|
||||
public void testListInstancesFromRequest() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("listInstancesFromRequest", String.class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(method, "1");
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/requests/1 HTTP/1.1");
|
||||
"GET https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/requests/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
|
@ -198,11 +190,10 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
|
|||
|
||||
public void testGetInstance() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("getInstance", String.class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
|
||||
method, "1");
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(method, "1");
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/instances/1 HTTP/1.1");
|
||||
"GET https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/instances/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
|
@ -214,17 +205,15 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
|
|||
|
||||
}
|
||||
|
||||
public void testExtendReservationForInstance() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("extendReservationForInstance",
|
||||
String.class, Date.class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
|
||||
method, "1", new Date(123215235l));
|
||||
public void testExtendReservationForInstance() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("extendReservationForInstance", String.class,
|
||||
Date.class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(method, "1", new Date(
|
||||
123215235l));
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"PUT https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/instances/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest,
|
||||
"Accept: application/json\n");
|
||||
"PUT https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/instances/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, "expirationTime=123215235", "application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseExpirationTimeFromJson.class);
|
||||
|
@ -236,14 +225,12 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
|
|||
|
||||
public void testRestartInstance() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("restartInstance", String.class,
|
||||
RestartInstanceOptions[].class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
|
||||
method, "1");
|
||||
RestartInstanceOptions[].class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(method, "1");
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"PUT https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/instances/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest,
|
||||
"Accept: application/json\n");
|
||||
"PUT https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/instances/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, "state=restart", "application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
||||
|
@ -253,17 +240,15 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
|
|||
checkFilters(httpRequest);
|
||||
}
|
||||
|
||||
public void testRestartInstanceNewKey() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
public void testRestartInstanceNewKey() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("restartInstance", String.class,
|
||||
RestartInstanceOptions[].class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
|
||||
method, "1", new RestartInstanceOptions().authorizePublicKey("keyName"));
|
||||
RestartInstanceOptions[].class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(method, "1",
|
||||
new RestartInstanceOptions().authorizePublicKey("keyName"));
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"PUT https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/instances/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest,
|
||||
"Accept: application/json\n");
|
||||
"PUT https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/instances/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, "state=restart&keyName=keyName", "application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
||||
|
@ -273,18 +258,17 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
|
|||
checkFilters(httpRequest);
|
||||
}
|
||||
|
||||
public void testSaveInstanceToImage() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("saveInstanceToImage",
|
||||
String.class, String.class, String.class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
|
||||
method, "1", "imageName", "imageDescription");
|
||||
public void testSaveInstanceToImage() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("saveInstanceToImage", String.class, String.class,
|
||||
String.class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(method, "1",
|
||||
"imageName", "imageDescription");
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"PUT https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/instances/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest,
|
||||
"Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, "state=save&description=imageDescription&name=imageName", "application/x-www-form-urlencoded", false);
|
||||
"PUT https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/instances/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, "state=save&description=imageDescription&name=imageName",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseImageFromJson.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -295,12 +279,11 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
|
|||
|
||||
public void testDeleteInstance() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("deleteInstance", String.class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
|
||||
method, "1");
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(method, "1");
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"DELETE https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/instances/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
"DELETE https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/instances/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
||||
|
@ -313,11 +296,10 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
|
|||
|
||||
public void testListKeys() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("listKeys");
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor
|
||||
.createRequest(method);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/keys HTTP/1.1");
|
||||
"GET https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/keys HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
|
@ -331,15 +313,14 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
|
|||
|
||||
public void testGetKey() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("getKey", String.class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
|
||||
method, "1");
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(method, "1");
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/keys/1 HTTP/1.1");
|
||||
"GET https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/keys/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseKeyFromJson.class);
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
|
||||
|
@ -349,16 +330,14 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
|
|||
|
||||
public void testGenerateKeyPair() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("generateKeyPair", String.class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
|
||||
method, "key");
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(method, "key");
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"POST https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/keys HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest,
|
||||
"Accept: application/json\n");
|
||||
"POST https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/keys HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, "name=key", "application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseKeyFromJson.class);
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -367,15 +346,13 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
|
|||
}
|
||||
|
||||
public void testAddPublicKey() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("addPublicKey", String.class,
|
||||
String.class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
|
||||
method, "key", "publicbits");
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("addPublicKey", String.class, String.class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(method, "key",
|
||||
"publicbits");
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"POST https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/keys HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest,
|
||||
"Accept: application/json\n");
|
||||
"POST https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/keys HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, "name=key&publicKey=publicbits", "application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
||||
|
@ -387,15 +364,13 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
|
|||
}
|
||||
|
||||
public void testUpdatePublicKey() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("updatePublicKey", String.class,
|
||||
String.class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
|
||||
method, "key", "publicbits");
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("updatePublicKey", String.class, String.class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(method, "key",
|
||||
"publicbits");
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"PUT https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/keys/key HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest,
|
||||
"Accept: application/json\n");
|
||||
"PUT https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/keys/key HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, "publicKey=publicbits", "application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
||||
|
@ -406,17 +381,14 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
|
|||
|
||||
}
|
||||
|
||||
public void testSetDefaultStatusOfKey() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("setDefaultStatusOfKey",
|
||||
String.class, boolean.class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
|
||||
method, "key", true);
|
||||
public void testSetDefaultStatusOfKey() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class
|
||||
.getMethod("setDefaultStatusOfKey", String.class, boolean.class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(method, "key", true);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"PUT https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/keys/key HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest,
|
||||
"Accept: application/json\n");
|
||||
"PUT https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/keys/key HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, "default=true", "application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
||||
|
@ -429,12 +401,11 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
|
|||
|
||||
public void testDeleteKey() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("deleteKey", String.class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
|
||||
method, "1");
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(method, "1");
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"DELETE https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/keys/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
"DELETE https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/keys/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
||||
|
@ -447,11 +418,10 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
|
|||
|
||||
public void testListVolumes() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("listVolumes");
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor
|
||||
.createRequest(method);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/storage HTTP/1.1");
|
||||
"GET https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/storage HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
|
@ -465,11 +435,10 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
|
|||
|
||||
public void testGetVolume() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("getVolume", String.class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
|
||||
method, "1");
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(method, "1");
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/storage/1 HTTP/1.1");
|
||||
"GET https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/storage/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
|
@ -481,18 +450,17 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
|
|||
|
||||
}
|
||||
|
||||
public void testCreateVolumeInLocation() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("createVolumeInLocation",
|
||||
String.class, String.class, String.class, String.class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
|
||||
method, "location", "name", "format", "size");
|
||||
public void testCreateVolumeInLocation() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("createVolumeInLocation", String.class,
|
||||
String.class, String.class, String.class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(method, "location",
|
||||
"name", "format", "size");
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"POST https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/storage HTTP/1.1");
|
||||
"POST https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/storage HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, "location=location&format=format&name=name&size=size",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseVolumeFromJson.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -502,19 +470,17 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
|
|||
|
||||
}
|
||||
|
||||
public void testCreateInstanceInLocation() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("createInstanceInLocation",
|
||||
String.class, String.class, String.class, String.class,
|
||||
CreateInstanceOptions[].class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
|
||||
method, "1", "name", "22", "instanceType");
|
||||
public void testCreateInstanceInLocation() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("createInstanceInLocation", String.class,
|
||||
String.class, String.class, String.class, CreateInstanceOptions[].class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(method, "1", "name",
|
||||
"22", "instanceType");
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"POST https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/instances HTTP/1.1");
|
||||
"POST https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/instances HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, "location=1&imageID=22&name=name&instanceType=instanceType",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertResponseParserClassEquals(method, httpRequest, GetFirstInstanceInList.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
@ -523,26 +489,22 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
|
|||
|
||||
}
|
||||
|
||||
public void testCreateInstanceInLocationWithOptions() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("createInstanceInLocation",
|
||||
String.class, String.class, String.class, String.class,
|
||||
CreateInstanceOptions[].class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
|
||||
method, "location", "name", "22", "instanceType", new CreateInstanceOptions()
|
||||
.attachIp("1").authorizePublicKey("MOO").mountVolume("2", "/mnt")
|
||||
.configurationData(
|
||||
ImmutableMap.of("insight_admin_password", "myPassword1",
|
||||
"db2_admin_password", "myPassword2",
|
||||
"report_user_password", "myPassword3")));
|
||||
public void testCreateInstanceInLocationWithOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("createInstanceInLocation", String.class,
|
||||
String.class, String.class, String.class, CreateInstanceOptions[].class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(method, "location",
|
||||
"name", "22", "instanceType", new CreateInstanceOptions().attachIp("1").authorizePublicKey("MOO")
|
||||
.mountVolume("2", "/mnt").configurationData(
|
||||
ImmutableMap.of("insight_admin_password", "myPassword1", "db2_admin_password", "myPassword2",
|
||||
"report_user_password", "myPassword3")));
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"POST https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/instances HTTP/1.1");
|
||||
"POST https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/instances HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(
|
||||
httpRequest,
|
||||
"location=location&imageID=22&name=name&instanceType=instanceType&ip=1&publicKey=MOO&volumeID=2&oss.storage.id.0.mnt=%2Fmnt&insight_admin_password=myPassword1&db2_admin_password=myPassword2&report_user_password=myPassword3",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
httpRequest,
|
||||
"location=location&imageID=22&name=name&instanceType=instanceType&ip=1&publicKey=MOO&volumeID=2&oss.storage.id.0.mnt=%2Fmnt&insight_admin_password=myPassword1&db2_admin_password=myPassword2&report_user_password=myPassword3",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, GetFirstInstanceInList.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -554,12 +516,11 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
|
|||
|
||||
public void testDeleteVolume() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("deleteVolume", String.class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
|
||||
method, "1");
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(method, "1");
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"DELETE https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/storage/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
"DELETE https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/storage/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
||||
|
@ -572,11 +533,10 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
|
|||
|
||||
public void testListLocations() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("listLocations");
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor
|
||||
.createRequest(method);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/locations HTTP/1.1");
|
||||
"GET https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/locations HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/xml\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
|
@ -590,11 +550,10 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
|
|||
|
||||
public void testGetLocation() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("getLocation", String.class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
|
||||
method, "1");
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(method, "1");
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/locations/1 HTTP/1.1");
|
||||
"GET https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/locations/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/xml\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
|
@ -608,11 +567,10 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
|
|||
|
||||
public void testListAddresses() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("listAddresses");
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor
|
||||
.createRequest(method);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/addresses HTTP/1.1");
|
||||
"GET https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/addresses HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
|
@ -624,15 +582,12 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
|
|||
|
||||
}
|
||||
|
||||
public void testAllocateAddressInLocation() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("allocateAddressInLocation",
|
||||
String.class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
|
||||
method, "1");
|
||||
public void testAllocateAddressInLocation() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("allocateAddressInLocation", String.class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(method, "1");
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"POST https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/addresses HTTP/1.1");
|
||||
"POST https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/addresses HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, "location=1", "application/x-www-form-urlencoded", false);
|
||||
|
||||
|
@ -646,12 +601,11 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
|
|||
|
||||
public void testReleaseAddress() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("releaseAddress", String.class);
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
|
||||
method, "1");
|
||||
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(method, "1");
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"DELETE https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/addresses/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
"DELETE https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/addresses/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
||||
|
@ -676,7 +630,6 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
|
|||
|
||||
@Override
|
||||
public ContextSpec<IBMDeveloperCloudClient, IBMDeveloperCloudAsyncClient> createContextSpec() {
|
||||
return new RestContextFactory().createContextSpec("ibmdev", "identity", "credential",
|
||||
new Properties());
|
||||
return new RestContextFactory().createContextSpec("ibmdev", "identity", "credential", new Properties());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ import static org.testng.Assert.assertEquals;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.Payloads;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.ibmdev.domain.Address;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
|
@ -55,8 +57,9 @@ public class ParseAddressFromJsonTest {
|
|||
|
||||
public void test() {
|
||||
Address address = new Address(2, "1", "129.33.196.243", "1217", "1");
|
||||
Address compare = handler.apply(ParseAddressFromJsonTest.class
|
||||
.getResourceAsStream("/address.json"));
|
||||
Address compare = handler.apply(new HttpResponse(200, "ok", Payloads
|
||||
.newInputStreamPayload(ParseAddressFromJsonTest.class
|
||||
.getResourceAsStream("/address.json"))));
|
||||
assertEquals(compare, address);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,8 +24,9 @@ import static org.testng.Assert.assertEquals;
|
|||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.Payloads;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -55,7 +56,8 @@ public class ParseExpirationTimeFromJsonTest {
|
|||
}
|
||||
|
||||
public void test() {
|
||||
Date compare = handler.apply(Utils.toInputStream("{ \"expirationTime\":1249876800000 }"));
|
||||
Date compare = handler.apply(new HttpResponse(200, "ok", Payloads
|
||||
.newStringPayload("{ \"expirationTime\":1249876800000 }")));
|
||||
assertEquals(compare, new Date(1249876800000l));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,9 @@ import static org.testng.Assert.assertEquals;
|
|||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.HttpUtils;
|
||||
import org.jclouds.http.Payloads;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.ibmdev.config.IBMDeveloperCloudParserModule;
|
||||
import org.jclouds.ibmdev.domain.Image;
|
||||
|
@ -49,7 +51,7 @@ public class ParseImageFromJsonTest {
|
|||
@BeforeTest
|
||||
protected void setUpInjector() throws IOException {
|
||||
Injector injector = Guice.createInjector(new ParserModule(),
|
||||
new IBMDeveloperCloudParserModule());
|
||||
new IBMDeveloperCloudParserModule());
|
||||
handler = injector.getInstance(ParseImageFromJson.class);
|
||||
}
|
||||
|
||||
|
@ -58,8 +60,8 @@ public class ParseImageFromJsonTest {
|
|||
Image image = new Image();
|
||||
image.setName("Rational Requirements Composer");
|
||||
image
|
||||
.setManifest(HttpUtils
|
||||
.createUri("https://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{28C7B870-2C0A-003F-F886-B89F5B413B77}/1.0/parameters.xml"));
|
||||
.setManifest(HttpUtils
|
||||
.createUri("https://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{28C7B870-2C0A-003F-F886-B89F5B413B77}/1.0/parameters.xml"));
|
||||
image.setState(1);
|
||||
image.setVisibility(Visibility.PUBLIC);
|
||||
image.setOwner("mutdosch@us.ibm.com");
|
||||
|
@ -70,14 +72,15 @@ public class ParseImageFromJsonTest {
|
|||
image.setSupportedInstanceTypes(ImmutableSet.of("LARGE", "MEDIUM"));
|
||||
// image.setProductCodes();
|
||||
image
|
||||
.setDocumentation(HttpUtils
|
||||
.createUri("https://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{28C7B870-2C0A-003F-F886-B89F5B413B77}/1.0/GettingStarted.html"));
|
||||
.setDocumentation(HttpUtils
|
||||
.createUri("https://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{28C7B870-2C0A-003F-F886-B89F5B413B77}/1.0/GettingStarted.html"));
|
||||
image.setId("10005598");
|
||||
image
|
||||
.setDescription("Rational Requirements Composer helps teams define and use requirements effectively across the project lifecycle.");
|
||||
.setDescription("Rational Requirements Composer helps teams define and use requirements effectively across the project lifecycle.");
|
||||
|
||||
Image compare = handler.apply(ParseImageFromJsonTest.class
|
||||
.getResourceAsStream("/image.json"));
|
||||
Image compare = handler.apply(new HttpResponse(200, "ok", Payloads
|
||||
.newInputStreamPayload(ParseImageFromJsonTest.class
|
||||
.getResourceAsStream("/image.json"))));
|
||||
assertEquals(compare, image);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,9 @@ import java.io.IOException;
|
|||
import java.util.Date;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.HttpUtils;
|
||||
import org.jclouds.http.Payloads;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.ibmdev.config.IBMDeveloperCloudParserModule;
|
||||
import org.jclouds.ibmdev.domain.Image;
|
||||
|
@ -47,7 +49,7 @@ public class ParseImagesFromJsonTest {
|
|||
@BeforeTest
|
||||
protected void setUpInjector() throws IOException {
|
||||
Injector injector = Guice.createInjector(new ParserModule(),
|
||||
new IBMDeveloperCloudParserModule());
|
||||
new IBMDeveloperCloudParserModule());
|
||||
handler = injector.getInstance(ParseImagesFromJson.class);
|
||||
}
|
||||
|
||||
|
@ -56,8 +58,8 @@ public class ParseImagesFromJsonTest {
|
|||
|
||||
image1.setName("Rational Build Forge Agent");
|
||||
image1
|
||||
.setManifest(HttpUtils
|
||||
.createUri("https://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{A233F5A0-05A5-F21D-3E92-3793B722DFBD}/1.0/parameters.xml"));
|
||||
.setManifest(HttpUtils
|
||||
.createUri("https://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{A233F5A0-05A5-F21D-3E92-3793B722DFBD}/1.0/parameters.xml"));
|
||||
image1.setState(1);
|
||||
image1.setVisibility(Image.Visibility.PUBLIC);
|
||||
image1.setOwner("SYSTEM");
|
||||
|
@ -65,20 +67,22 @@ public class ParseImagesFromJsonTest {
|
|||
image1.setPlatform("SUSE Linux Enterprise/10 SP2");
|
||||
image1.setCreatedTime(new Date(1240632000000l));
|
||||
image1.setLocation("1");
|
||||
image1.setSupportedInstanceTypes(ImmutableSet.of("SMALL", "MEDIUM", "LARGE"));
|
||||
image1.setProductCodes(ImmutableSet.of("fd2d0478b132490897526b9b4433a334"));
|
||||
image1.setSupportedInstanceTypes(ImmutableSet.of("SMALL", "MEDIUM",
|
||||
"LARGE"));
|
||||
image1.setProductCodes(ImmutableSet
|
||||
.of("fd2d0478b132490897526b9b4433a334"));
|
||||
image1
|
||||
.setDocumentation(HttpUtils
|
||||
.createUri("https://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{A233F5A0-05A5-F21D-3E92-3793B722DFBD}/1.0/GettingStarted.html"));
|
||||
.setDocumentation(HttpUtils
|
||||
.createUri("https://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{A233F5A0-05A5-F21D-3E92-3793B722DFBD}/1.0/GettingStarted.html"));
|
||||
image1.setId("2");
|
||||
image1
|
||||
.setDescription("Rational Build Forge provides an adaptive process execution framework that automates, orchestrates, manages, and tracks all the processes between each handoff within the assembly line of software development, creating an automated software factory.");
|
||||
.setDescription("Rational Build Forge provides an adaptive process execution framework that automates, orchestrates, manages, and tracks all the processes between each handoff within the assembly line of software development, creating an automated software factory.");
|
||||
|
||||
Image image2 = new Image();
|
||||
image2.setName("Rational Requirements Composer");
|
||||
image2
|
||||
.setManifest(HttpUtils
|
||||
.createUri("https://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{28C7B870-2C0A-003F-F886-B89F5B413B77}/1.0/parameters.xml"));
|
||||
.setManifest(HttpUtils
|
||||
.createUri("https://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{28C7B870-2C0A-003F-F886-B89F5B413B77}/1.0/parameters.xml"));
|
||||
image2.setState(1);
|
||||
image2.setVisibility(Image.Visibility.PUBLIC);
|
||||
image2.setOwner("mutdosch@us.ibm.com");
|
||||
|
@ -89,14 +93,15 @@ public class ParseImagesFromJsonTest {
|
|||
image2.setSupportedInstanceTypes(ImmutableSet.of("LARGE", "MEDIUM"));
|
||||
// image.setProductCodes();
|
||||
image2
|
||||
.setDocumentation(HttpUtils
|
||||
.createUri("https://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{28C7B870-2C0A-003F-F886-B89F5B413B77}/1.0/GettingStarted.html"));
|
||||
.setDocumentation(HttpUtils
|
||||
.createUri("https://www-180.ibm.com/cloud/enterprise/beta/ram.ws/RAMSecure/artifact/{28C7B870-2C0A-003F-F886-B89F5B413B77}/1.0/GettingStarted.html"));
|
||||
image2.setId("10005598");
|
||||
image2
|
||||
.setDescription("Rational Requirements Composer helps teams define and use requirements effectively across the project lifecycle.");
|
||||
.setDescription("Rational Requirements Composer helps teams define and use requirements effectively across the project lifecycle.");
|
||||
|
||||
Set<? extends Image> compare = handler.apply(ParseImagesFromJsonTest.class
|
||||
.getResourceAsStream("/images.json"));
|
||||
Set<? extends Image> compare = handler.apply(new HttpResponse(200, "ok",
|
||||
Payloads.newInputStreamPayload(ParseImagesFromJsonTest.class
|
||||
.getResourceAsStream("/images.json"))));
|
||||
assert (compare.contains(image1));
|
||||
assert (compare.contains(image2));
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue