mirror of https://github.com/apache/jclouds.git
Issue 112: stabalizing vcloud support
git-svn-id: http://jclouds.googlecode.com/svn/trunk@2365 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
638c80e58d
commit
1173689417
1
pom.xml
1
pom.xml
|
@ -48,6 +48,7 @@
|
||||||
<module>nirvanix</module>
|
<module>nirvanix</module>
|
||||||
<module>twitter</module>
|
<module>twitter</module>
|
||||||
<module>rimuhosting</module>
|
<module>rimuhosting</module>
|
||||||
|
<module>vcloud</module>
|
||||||
<module>scriptbuilder</module>
|
<module>scriptbuilder</module>
|
||||||
</modules>
|
</modules>
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.vcloud.config;
|
package org.jclouds.vcloud.config;
|
||||||
|
|
||||||
|
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTNETWORK;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
@ -55,7 +57,8 @@ import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the VCloud authentication service connection, including logging and http transport.
|
* Configures the VCloud authentication service connection, including logging
|
||||||
|
* and http transport.
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
|
@ -63,86 +66,96 @@ import com.google.inject.Provides;
|
||||||
@ConfiguresRestClient
|
@ConfiguresRestClient
|
||||||
public class VCloudRestClientModule extends AbstractModule {
|
public class VCloudRestClientModule extends AbstractModule {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
protected VCloudAsyncClient provideAsyncClient(RestClientFactory factory) {
|
protected VCloudAsyncClient provideAsyncClient(RestClientFactory factory) {
|
||||||
return factory.create(VCloudAsyncClient.class);
|
return factory.create(VCloudAsyncClient.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
public VCloudClient provideClient(VCloudAsyncClient client) throws IllegalArgumentException,
|
public VCloudClient provideClient(VCloudAsyncClient client)
|
||||||
SecurityException, NoSuchMethodException {
|
throws IllegalArgumentException, SecurityException,
|
||||||
return SyncProxy.create(VCloudClient.class, client);
|
NoSuchMethodException {
|
||||||
}
|
return SyncProxy.create(VCloudClient.class, client);
|
||||||
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@CatalogItemRoot
|
@CatalogItemRoot
|
||||||
@Singleton
|
@Singleton
|
||||||
String provideCatalogItemRoot(@VCloudLogin URI vcloudUri) {
|
String provideCatalogItemRoot(@VCloudLogin URI vcloudUri) {
|
||||||
return vcloudUri.toASCIIString().replace("/login", "/catalogItem");
|
return vcloudUri.toASCIIString().replace("/login", "/catalogItem");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@VAppRoot
|
@VAppRoot
|
||||||
@Singleton
|
@Singleton
|
||||||
String provideVAppRoot(@VCloudLogin URI vcloudUri) {
|
String provideVAppRoot(@VCloudLogin URI vcloudUri) {
|
||||||
return vcloudUri.toASCIIString().replace("/login", "/vapp");
|
return vcloudUri.toASCIIString().replace("/login", "/vapp");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@VAppTemplateRoot
|
@VAppTemplateRoot
|
||||||
@Singleton
|
@Singleton
|
||||||
String provideVAppTemplateRoot(@VCloudLogin URI vcloudUri) {
|
String provideVAppTemplateRoot(@VCloudLogin URI vcloudUri) {
|
||||||
return vcloudUri.toASCIIString().replace("/login", "/vAppTemplate");
|
return vcloudUri.toASCIIString().replace("/login", "/vAppTemplate");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
protected Organization provideOrganization(VCloudDiscovery discovery) throws ExecutionException,
|
protected Organization provideOrganization(VCloudDiscovery discovery)
|
||||||
TimeoutException, InterruptedException {
|
throws ExecutionException, TimeoutException, InterruptedException {
|
||||||
return discovery.getOrganization().get(90, TimeUnit.SECONDS);
|
return discovery.getOrganization().get(90, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@VDC
|
@VDC
|
||||||
@Singleton
|
@Singleton
|
||||||
protected URI provideDefaultVDC(Organization org) {
|
protected URI provideDefaultVDC(Organization org) {
|
||||||
return org.getVDCs().values().iterator().next().getLocation();
|
return org.getVDCs().values().iterator().next().getLocation();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Catalog
|
@Catalog
|
||||||
@Singleton
|
@Singleton
|
||||||
protected URI provideCatalog(Organization org) {
|
protected URI provideCatalog(Organization org) {
|
||||||
return org.getCatalog().getLocation();
|
return org.getCatalog().getLocation();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@Provides
|
@Provides
|
||||||
@Named("InstantiateVAppTemplateParams")
|
@Named("InstantiateVAppTemplateParams")
|
||||||
protected String provideInstantiateVAppTemplateParams() throws IOException {
|
protected String provideInstantiateVAppTemplateParams() throws IOException {
|
||||||
InputStream is = getClass().getResourceAsStream("/InstantiateVAppTemplateParams.xml");
|
InputStream is = getClass().getResourceAsStream(
|
||||||
return Utils.toStringAndClose(is);
|
"/InstantiateVAppTemplateParams.xml");
|
||||||
}
|
return Utils.toStringAndClose(is);
|
||||||
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Network
|
@Network
|
||||||
@Singleton
|
@Singleton
|
||||||
protected URI provideDefaultNetwork(VCloudAsyncClient client) throws InterruptedException,
|
protected URI provideDefaultNetwork(VCloudAsyncClient client)
|
||||||
ExecutionException, TimeoutException {
|
throws InterruptedException, ExecutionException, TimeoutException {
|
||||||
return client.getDefaultVDC().get(60, TimeUnit.SECONDS).getAvailableNetworks().values()
|
return client.getDefaultVDC().get(60, TimeUnit.SECONDS)
|
||||||
.iterator().next().getLocation();
|
.getAvailableNetworks().values().iterator().next()
|
||||||
}
|
.getLocation();
|
||||||
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@TasksList
|
@Named(PROPERTY_VCLOUD_DEFAULTNETWORK)
|
||||||
@Singleton
|
@Singleton
|
||||||
protected URI provideDefaultTasksList(Organization org) {
|
String provideDefaultNetworkString(@Network URI network) {
|
||||||
return org.getTasksLists().values().iterator().next().getLocation();
|
return network.toASCIIString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@TasksList
|
||||||
|
@Singleton
|
||||||
|
protected URI provideDefaultTasksList(Organization org) {
|
||||||
|
return org.getTasksLists().values().iterator().next().getLocation();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,53 +41,93 @@ import com.google.inject.util.Providers;
|
||||||
*/
|
*/
|
||||||
@Test(groups = "unit", testName = "vcloud.BindInstantiateVAppTemplateParamsToXmlEntityTest")
|
@Test(groups = "unit", testName = "vcloud.BindInstantiateVAppTemplateParamsToXmlEntityTest")
|
||||||
public class BindInstantiateVAppTemplateParamsToXmlEntityTest {
|
public class BindInstantiateVAppTemplateParamsToXmlEntityTest {
|
||||||
Injector injector = Guice.createInjector(new AbstractModule() {
|
Injector injector = Guice.createInjector(new AbstractModule() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(String.class).annotatedWith(Jsr330.named(PROPERTY_VCLOUD_DEFAULTCPUCOUNT))
|
bind(String.class).annotatedWith(
|
||||||
.toProvider(Providers.<String> of(null));
|
Jsr330.named(PROPERTY_VCLOUD_DEFAULTCPUCOUNT)).toProvider(
|
||||||
bind(String.class).annotatedWith(Jsr330.named(PROPERTY_VCLOUD_DEFAULTMEMORY)).toProvider(
|
Providers.<String> of("1"));
|
||||||
Providers.<String> of(null));
|
bind(String.class).annotatedWith(
|
||||||
bind(String.class).annotatedWith(Jsr330.named(PROPERTY_VCLOUD_DEFAULTNETWORK)).toProvider(
|
Jsr330.named(PROPERTY_VCLOUD_DEFAULTMEMORY)).toProvider(
|
||||||
Providers.<String> of(null));
|
Providers.<String> of("512"));
|
||||||
}
|
bind(String.class)
|
||||||
|
.annotatedWith(Jsr330.named(PROPERTY_VCLOUD_DEFAULTNETWORK))
|
||||||
|
.toProvider(
|
||||||
|
Providers
|
||||||
|
.<String> of("https://vcloud.safesecureweb.com/network/1990"));
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@Singleton
|
@Singleton
|
||||||
@Provides
|
@Provides
|
||||||
@Named("InstantiateVAppTemplateParams")
|
@Named("InstantiateVAppTemplateParams")
|
||||||
String provideInstantiateVAppTemplateParams() throws IOException {
|
String provideInstantiateVAppTemplateParams() throws IOException {
|
||||||
InputStream is = getClass().getResourceAsStream("/InstantiateVAppTemplateParams.xml");
|
InputStream is = getClass().getResourceAsStream(
|
||||||
return Utils.toStringAndClose(is);
|
"/InstantiateVAppTemplateParams.xml");
|
||||||
}
|
return Utils.toStringAndClose(is);
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
public void testApplyInputStream() throws IOException {
|
public void testApplyInputStream1() throws IOException {
|
||||||
String expected = IOUtils.toString(getClass().getResourceAsStream("/newvapp-hosting.xml"));
|
String expected = IOUtils.toString(getClass().getResourceAsStream(
|
||||||
Multimap<String, String> headers = Multimaps.synchronizedMultimap(HashMultimap
|
"/newvapp-hosting.xml"));
|
||||||
.<String, String> create());
|
Multimap<String, String> headers = Multimaps
|
||||||
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
|
.synchronizedMultimap(HashMultimap.<String, String> create());
|
||||||
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
|
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
|
||||||
expect(request.getArgs()).andReturn(new Object[] {}).atLeastOnce();
|
expect(request.getEndpoint()).andReturn(
|
||||||
expect(request.getFirstHeaderOrNull("Content-Type")).andReturn(null).atLeastOnce();
|
URI.create("http://localhost/key")).anyTimes();
|
||||||
expect(request.getHeaders()).andReturn(headers).atLeastOnce();
|
expect(request.getArgs()).andReturn(new Object[] {}).atLeastOnce();
|
||||||
request.setEntity(expected);
|
expect(request.getFirstHeaderOrNull("Content-Type")).andReturn(null)
|
||||||
replay(request);
|
.atLeastOnce();
|
||||||
|
expect(request.getHeaders()).andReturn(headers).atLeastOnce();
|
||||||
|
request.setEntity(expected);
|
||||||
|
replay(request);
|
||||||
|
|
||||||
BindInstantiateVAppTemplateParamsToXmlEntity binder = injector
|
BindInstantiateVAppTemplateParamsToXmlEntity binder = injector
|
||||||
.getInstance(BindInstantiateVAppTemplateParamsToXmlEntity.class);
|
.getInstance(BindInstantiateVAppTemplateParamsToXmlEntity.class);
|
||||||
|
|
||||||
Map<String, String> map = Maps.newHashMap();
|
Map<String, String> map = Maps.newHashMap();
|
||||||
map.put("name", "CentOS 01");
|
map.put("name", "CentOS 01");
|
||||||
map.put("template", "https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3");
|
map.put("template",
|
||||||
map.put("count", "1");
|
"https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3");
|
||||||
map.put("megabytes", "512");
|
map.put("count", "1");
|
||||||
map.put("network", "https://vcloud.safesecureweb.com/network/1990");
|
map.put("megabytes", "512");
|
||||||
binder.bindToRequest(request, map);
|
map.put("network", "https://vcloud.safesecureweb.com/network/1990");
|
||||||
assertEquals(headers.get(HttpHeaders.CONTENT_TYPE), Collections
|
binder.bindToRequest(request, map);
|
||||||
.singletonList("application/unknown"));
|
assertEquals(headers.get(HttpHeaders.CONTENT_TYPE), Collections
|
||||||
assertEquals(headers.get(HttpHeaders.CONTENT_LENGTH), Collections.singletonList("901"));
|
.singletonList("application/unknown"));
|
||||||
|
assertEquals(headers.get(HttpHeaders.CONTENT_LENGTH), Collections
|
||||||
|
.singletonList("901"));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
public void testApplyInputStream2() throws IOException {
|
||||||
|
String expected = IOUtils.toString(getClass().getResourceAsStream(
|
||||||
|
"/newvapp-hosting.xml"));
|
||||||
|
Multimap<String, String> headers = Multimaps
|
||||||
|
.synchronizedMultimap(HashMultimap.<String, String> create());
|
||||||
|
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
|
||||||
|
expect(request.getEndpoint()).andReturn(
|
||||||
|
URI.create("http://localhost/key")).anyTimes();
|
||||||
|
expect(request.getArgs()).andReturn(new Object[] {}).atLeastOnce();
|
||||||
|
expect(request.getFirstHeaderOrNull("Content-Type")).andReturn(null)
|
||||||
|
.atLeastOnce();
|
||||||
|
expect(request.getHeaders()).andReturn(headers).atLeastOnce();
|
||||||
|
request.setEntity(expected);
|
||||||
|
replay(request);
|
||||||
|
|
||||||
|
BindInstantiateVAppTemplateParamsToXmlEntity binder = injector
|
||||||
|
.getInstance(BindInstantiateVAppTemplateParamsToXmlEntity.class);
|
||||||
|
|
||||||
|
Map<String, String> map = Maps.newHashMap();
|
||||||
|
map.put("name", "CentOS 01");
|
||||||
|
map.put("template",
|
||||||
|
"https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3");
|
||||||
|
binder.bindToRequest(request, map);
|
||||||
|
assertEquals(headers.get(HttpHeaders.CONTENT_TYPE), Collections
|
||||||
|
.singletonList("application/unknown"));
|
||||||
|
assertEquals(headers.get(HttpHeaders.CONTENT_LENGTH), Collections
|
||||||
|
.singletonList("901"));
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.vcloud.hostingdotcom;
|
package org.jclouds.vcloud.hostingdotcom;
|
||||||
|
|
||||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTNETWORK;
|
|
||||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPOINT;
|
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPOINT;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
@ -41,8 +40,6 @@ public class HostingDotComVCloudPropertiesBuilder extends VCloudPropertiesBuilde
|
||||||
protected Properties defaultProperties() {
|
protected Properties defaultProperties() {
|
||||||
Properties properties = super.defaultProperties();
|
Properties properties = super.defaultProperties();
|
||||||
properties.setProperty(PROPERTY_VCLOUD_ENDPOINT, "https://vcloud.safesecureweb.com/api");
|
properties.setProperty(PROPERTY_VCLOUD_ENDPOINT, "https://vcloud.safesecureweb.com/api");
|
||||||
properties.setProperty(PROPERTY_VCLOUD_DEFAULTNETWORK,
|
|
||||||
"https://vcloud.safesecureweb.com/network/1990");
|
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,7 @@ public class HostingDotComVCloudRestClientModule extends VCloudRestClientModule
|
||||||
SecurityException, NoSuchMethodException {
|
SecurityException, NoSuchMethodException {
|
||||||
return SyncProxy.create(HostingDotComVCloudClient.class, client);
|
return SyncProxy.create(HostingDotComVCloudClient.class, client);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected URI provideDefaultNetwork(VCloudAsyncClient client) {
|
protected URI provideDefaultNetwork(VCloudAsyncClient client) {
|
||||||
return URI.create("https://vcloud.safesecureweb.com/network/1990");
|
return URI.create("https://vcloud.safesecureweb.com/network/1990");
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
package org.jclouds.vcloud.terremark;
|
package org.jclouds.vcloud.terremark;
|
||||||
|
|
||||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPOINT;
|
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPOINT;
|
||||||
|
import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTGROUP;
|
||||||
|
import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTPASSWORD;
|
||||||
|
import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTROW;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
@ -36,19 +39,23 @@ import org.jclouds.vcloud.VCloudPropertiesBuilder;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class TerremarkVCloudPropertiesBuilder extends VCloudPropertiesBuilder {
|
public class TerremarkVCloudPropertiesBuilder extends VCloudPropertiesBuilder {
|
||||||
@Override
|
@Override
|
||||||
protected Properties defaultProperties() {
|
protected Properties defaultProperties() {
|
||||||
Properties properties = super.defaultProperties();
|
Properties properties = super.defaultProperties();
|
||||||
|
properties.setProperty(PROPERTY_TERREMARK_DEFAULTGROUP, "group");
|
||||||
|
properties.setProperty(PROPERTY_TERREMARK_DEFAULTROW, "row");
|
||||||
|
properties.setProperty((PROPERTY_TERREMARK_DEFAULTPASSWORD), "password");
|
||||||
properties.setProperty(PROPERTY_VCLOUD_ENDPOINT,
|
properties.setProperty(PROPERTY_VCLOUD_ENDPOINT,
|
||||||
"https://services.vcloudexpress.terremark.com/api");
|
"https://services.vcloudexpress.terremark.com/api");
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TerremarkVCloudPropertiesBuilder(Properties properties) {
|
public TerremarkVCloudPropertiesBuilder(Properties properties) {
|
||||||
super(properties);
|
super(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TerremarkVCloudPropertiesBuilder(String id, String secret) {
|
public TerremarkVCloudPropertiesBuilder(String id, String secret) {
|
||||||
super(URI.create("https://services.vcloudexpress.terremark.com/api"), id, secret);
|
super(URI.create("https://services.vcloudexpress.terremark.com/api"),
|
||||||
}
|
id, secret);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class BindAddInternetServiceToXmlEntity implements MapBinder {
|
||||||
entity = entity.replaceAll("\\{port\\}", port);
|
entity = entity.replaceAll("\\{port\\}", port);
|
||||||
entity = entity.replaceAll("\\{enabled\\}", enabled);
|
entity = entity.replaceAll("\\{enabled\\}", enabled);
|
||||||
entity = entity.replaceAll("\\{description\\}", description == null ? "" : String.format(
|
entity = entity.replaceAll("\\{description\\}", description == null ? "" : String.format(
|
||||||
"%n <Description>%s</Description>", description));
|
"\n <Description>%s</Description>", description));
|
||||||
|
|
||||||
stringBinder.bindToRequest(request, entity);
|
stringBinder.bindToRequest(request, entity);
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class BindAddNodeServiceToXmlEntity implements MapBinder {
|
||||||
entity = entity.replaceAll("\\{port\\}", port);
|
entity = entity.replaceAll("\\{port\\}", port);
|
||||||
entity = entity.replaceAll("\\{enabled\\}", enabled);
|
entity = entity.replaceAll("\\{enabled\\}", enabled);
|
||||||
entity = entity.replaceAll("\\{description\\}", description == null ? "" : String.format(
|
entity = entity.replaceAll("\\{description\\}", description == null ? "" : String.format(
|
||||||
"%n <Description>%s</Description>", description));
|
"\n <Description>%s</Description>", description));
|
||||||
|
|
||||||
stringBinder.bindToRequest(request, entity);
|
stringBinder.bindToRequest(request, entity);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,14 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.vcloud.terremark;
|
package org.jclouds.vcloud.terremark;
|
||||||
|
|
||||||
|
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTCPUCOUNT;
|
||||||
|
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTMEMORY;
|
||||||
|
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTNETWORK;
|
||||||
import static org.jclouds.vcloud.terremark.options.AddInternetServiceOptions.Builder.disabled;
|
import static org.jclouds.vcloud.terremark.options.AddInternetServiceOptions.Builder.disabled;
|
||||||
import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.cpuCount;
|
import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.cpuCount;
|
||||||
|
import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTGROUP;
|
||||||
|
import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTPASSWORD;
|
||||||
|
import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTROW;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -45,6 +51,7 @@ import org.jclouds.logging.Logger.LoggerFactory;
|
||||||
import org.jclouds.rest.RestClientTest;
|
import org.jclouds.rest.RestClientTest;
|
||||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||||
|
import org.jclouds.util.Jsr330;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.util.Utils;
|
||||||
import org.jclouds.vcloud.endpoints.Catalog;
|
import org.jclouds.vcloud.endpoints.Catalog;
|
||||||
import org.jclouds.vcloud.endpoints.Network;
|
import org.jclouds.vcloud.endpoints.Network;
|
||||||
|
@ -53,9 +60,9 @@ import org.jclouds.vcloud.endpoints.VDC;
|
||||||
import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot;
|
import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot;
|
||||||
import org.jclouds.vcloud.endpoints.internal.VAppRoot;
|
import org.jclouds.vcloud.endpoints.internal.VAppRoot;
|
||||||
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
||||||
|
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
|
||||||
import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions;
|
import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions;
|
||||||
import org.jclouds.vcloud.terremark.options.AddNodeOptions;
|
import org.jclouds.vcloud.terremark.options.AddNodeOptions;
|
||||||
import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions;
|
|
||||||
import org.jclouds.vcloud.terremark.xml.InternetServiceHandler;
|
import org.jclouds.vcloud.terremark.xml.InternetServiceHandler;
|
||||||
import org.jclouds.vcloud.terremark.xml.NodeHandler;
|
import org.jclouds.vcloud.terremark.xml.NodeHandler;
|
||||||
import org.jclouds.vcloud.terremark.xml.TerremarkVAppHandler;
|
import org.jclouds.vcloud.terremark.xml.TerremarkVAppHandler;
|
||||||
|
@ -66,6 +73,7 @@ import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
|
import com.google.inject.util.Providers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests behavior of {@code TerremarkVCloudAsyncClient}
|
* Tests behavior of {@code TerremarkVCloudAsyncClient}
|
||||||
|
@ -73,320 +81,400 @@ import com.google.inject.TypeLiteral;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = "unit", sequential = true, testName = "vcloud.TerremarkVCloudAsyncClientTest")
|
@Test(groups = "unit", sequential = true, testName = "vcloud.TerremarkVCloudAsyncClientTest")
|
||||||
public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVCloudAsyncClient> {
|
public class TerremarkVCloudAsyncClientTest extends
|
||||||
|
RestClientTest<TerremarkVCloudAsyncClient> {
|
||||||
|
|
||||||
public void testGetDefaultVDC() throws SecurityException, NoSuchMethodException, IOException {
|
public void testGetDefaultVDC() throws SecurityException,
|
||||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("getDefaultVDC");
|
NoSuchMethodException, IOException {
|
||||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method);
|
Method method = TerremarkVCloudAsyncClient.class
|
||||||
|
.getMethod("getDefaultVDC");
|
||||||
|
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor
|
||||||
|
.createRequest(method);
|
||||||
|
|
||||||
assertRequestLineEquals(httpMethod, "GET http://vdc HTTP/1.1");
|
assertRequestLineEquals(httpMethod, "GET http://vdc HTTP/1.1");
|
||||||
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.vdc+xml\n");
|
assertHeadersEqual(httpMethod,
|
||||||
assertEntityEquals(httpMethod, null);
|
"Accept: application/vnd.vmware.vcloud.vdc+xml\n");
|
||||||
|
assertEntityEquals(httpMethod, null);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, TerremarkVDCHandler.class);
|
assertSaxResponseParserClassEquals(method, TerremarkVDCHandler.class);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
checkFilters(httpMethod);
|
checkFilters(httpMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInstantiateVAppTemplate() throws SecurityException, NoSuchMethodException,
|
public void testInstantiateVAppTemplate() throws SecurityException,
|
||||||
IOException {
|
NoSuchMethodException, IOException {
|
||||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("instantiateVAppTemplate",
|
Method method = TerremarkVCloudAsyncClient.class.getMethod(
|
||||||
String.class, String.class, Array.newInstance(TerremarkInstantiateVAppTemplateOptions.class,
|
"instantiateVAppTemplate", String.class, String.class, Array
|
||||||
0).getClass());
|
.newInstance(InstantiateVAppTemplateOptions.class, 0)
|
||||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
.getClass());
|
||||||
"name", 3 + "");
|
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor
|
||||||
|
.createRequest(method, "name", 3 + "");
|
||||||
|
|
||||||
assertRequestLineEquals(httpMethod, "POST http://vdc/action/instantiatevAppTemplate HTTP/1.1");
|
assertRequestLineEquals(httpMethod,
|
||||||
assertHeadersEqual(
|
"POST http://vdc/action/instantiatevAppTemplate HTTP/1.1");
|
||||||
httpMethod,
|
assertHeadersEqual(
|
||||||
"Content-Length: 2245\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n");
|
httpMethod,
|
||||||
assertEntityEquals(httpMethod, IOUtils.toString(getClass().getResourceAsStream(
|
"Content-Length: 2270\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n");
|
||||||
"/terremark/InstantiateVAppTemplateParams-test.xml")));
|
assertEntityEquals(httpMethod, IOUtils.toString(getClass()
|
||||||
|
.getResourceAsStream(
|
||||||
|
"/terremark/InstantiateVAppTemplateParams-test.xml")));
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, TerremarkVAppHandler.class);
|
assertSaxResponseParserClassEquals(method, TerremarkVAppHandler.class);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
checkFilters(httpMethod);
|
checkFilters(httpMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInstantiateVAppTemplateOptions() throws SecurityException,
|
public void testInstantiateVAppTemplateOptions() throws SecurityException,
|
||||||
NoSuchMethodException, IOException {
|
NoSuchMethodException, IOException {
|
||||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("instantiateVAppTemplate",
|
Method method = TerremarkVCloudAsyncClient.class.getMethod(
|
||||||
String.class, String.class, Array.newInstance(TerremarkInstantiateVAppTemplateOptions.class,
|
"instantiateVAppTemplate", String.class, String.class, Array
|
||||||
0).getClass());
|
.newInstance(
|
||||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
InstantiateVAppTemplateOptions.class,
|
||||||
"name", 3 + "", cpuCount(4).megabytes(1024).inNetwork(URI.create("http://newnet")));
|
0).getClass());
|
||||||
|
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor
|
||||||
|
.createRequest(method, "name", 3 + "", cpuCount(4).megabytes(
|
||||||
|
1024).inNetwork(URI.create("http://newnet")));
|
||||||
|
|
||||||
assertRequestLineEquals(httpMethod, "POST http://vdc/action/instantiatevAppTemplate HTTP/1.1");
|
assertRequestLineEquals(httpMethod,
|
||||||
assertHeadersEqual(
|
"POST http://vdc/action/instantiatevAppTemplate HTTP/1.1");
|
||||||
httpMethod,
|
assertHeadersEqual(
|
||||||
"Content-Length: 2245\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n");
|
httpMethod,
|
||||||
assertEntityEquals(httpMethod, IOUtils.toString(getClass().getResourceAsStream(
|
"Content-Length: 2239\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n");
|
||||||
"/terremark/InstantiateVAppTemplateParams-options-test.xml")));
|
assertEntityEquals(
|
||||||
|
httpMethod,
|
||||||
|
IOUtils
|
||||||
|
.toString(getClass()
|
||||||
|
.getResourceAsStream(
|
||||||
|
"/terremark/InstantiateVAppTemplateParams-options-test.xml")));
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, TerremarkVAppHandler.class);
|
assertSaxResponseParserClassEquals(method, TerremarkVAppHandler.class);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
checkFilters(httpMethod);
|
checkFilters(httpMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAddInternetService() throws SecurityException, NoSuchMethodException,
|
public void testAddInternetService() throws SecurityException,
|
||||||
IOException {
|
NoSuchMethodException, IOException {
|
||||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetService",
|
Method method = TerremarkVCloudAsyncClient.class.getMethod(
|
||||||
String.class, String.class, int.class, Array.newInstance(
|
"addInternetService", String.class, String.class, int.class,
|
||||||
AddInternetServiceOptions.class, 0).getClass());
|
Array.newInstance(AddInternetServiceOptions.class, 0)
|
||||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
.getClass());
|
||||||
"name", "tcp", 22);
|
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor
|
||||||
|
.createRequest(method, "name", "tcp", 22);
|
||||||
|
|
||||||
assertRequestLineEquals(httpMethod, "POST http://vdc/internetServices HTTP/1.1");
|
assertRequestLineEquals(httpMethod,
|
||||||
assertHeadersEqual(httpMethod, "Content-Length: 303\nContent-Type: application/xml\n");
|
"POST http://vdc/internetServices HTTP/1.1");
|
||||||
assertEntityEquals(httpMethod, IOUtils.toString(getClass().getResourceAsStream(
|
assertHeadersEqual(httpMethod,
|
||||||
"/terremark/CreateInternetService-test2.xml")));
|
"Content-Length: 303\nContent-Type: application/xml\n");
|
||||||
|
assertEntityEquals(httpMethod, IOUtils.toString(getClass()
|
||||||
|
.getResourceAsStream(
|
||||||
|
"/terremark/CreateInternetService-test2.xml")));
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
|
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
checkFilters(httpMethod);
|
checkFilters(httpMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAddInternetServiceOptions() throws SecurityException, NoSuchMethodException,
|
public void testAddInternetServiceOptions() throws SecurityException,
|
||||||
IOException {
|
NoSuchMethodException, IOException {
|
||||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetService",
|
Method method = TerremarkVCloudAsyncClient.class.getMethod(
|
||||||
String.class, String.class, int.class, Array.newInstance(
|
"addInternetService", String.class, String.class, int.class,
|
||||||
AddInternetServiceOptions.class, 0).getClass());
|
Array.newInstance(AddInternetServiceOptions.class, 0)
|
||||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
.getClass());
|
||||||
"name", "tcp", 22, disabled().withDescription("yahoo"));
|
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor
|
||||||
|
.createRequest(method, "name", "tcp", 22, disabled()
|
||||||
|
.withDescription("yahoo"));
|
||||||
|
|
||||||
assertRequestLineEquals(httpMethod, "POST http://vdc/internetServices HTTP/1.1");
|
assertRequestLineEquals(httpMethod,
|
||||||
assertHeadersEqual(httpMethod, "Content-Length: 341\nContent-Type: application/xml\n");
|
"POST http://vdc/internetServices HTTP/1.1");
|
||||||
assertEntityEquals(httpMethod, IOUtils.toString(getClass().getResourceAsStream(
|
assertHeadersEqual(httpMethod,
|
||||||
"/terremark/CreateInternetService-options-test.xml")));
|
"Content-Length: 341\nContent-Type: application/xml\n");
|
||||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
assertEntityEquals(httpMethod, IOUtils.toString(getClass()
|
||||||
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
|
.getResourceAsStream(
|
||||||
assertExceptionParserClassEquals(method, null);
|
"/terremark/CreateInternetService-options-test.xml")));
|
||||||
|
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||||
|
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
|
||||||
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
checkFilters(httpMethod);
|
checkFilters(httpMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetInternetService() throws SecurityException, NoSuchMethodException,
|
public void testGetInternetService() throws SecurityException,
|
||||||
IOException {
|
NoSuchMethodException, IOException {
|
||||||
Method method = TerremarkVCloudAsyncClient.class
|
Method method = TerremarkVCloudAsyncClient.class.getMethod(
|
||||||
.getMethod("getInternetService", String.class);
|
"getInternetService", String.class);
|
||||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor
|
||||||
12);
|
.createRequest(method, 12);
|
||||||
|
|
||||||
assertRequestLineEquals(httpMethod, "GET http://vcloud/internetServices/12 HTTP/1.1");
|
assertRequestLineEquals(httpMethod,
|
||||||
assertHeadersEqual(httpMethod, "");
|
"GET http://vcloud/internetServices/12 HTTP/1.1");
|
||||||
assertEntityEquals(httpMethod, null);
|
assertHeadersEqual(httpMethod, "");
|
||||||
|
assertEntityEquals(httpMethod, null);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
|
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
checkFilters(httpMethod);
|
checkFilters(httpMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDeleteInternetService() throws SecurityException, NoSuchMethodException,
|
public void testDeleteInternetService() throws SecurityException,
|
||||||
IOException {
|
NoSuchMethodException, IOException {
|
||||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("deleteInternetService",
|
Method method = TerremarkVCloudAsyncClient.class.getMethod(
|
||||||
String.class);
|
"deleteInternetService", String.class);
|
||||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor
|
||||||
12);
|
.createRequest(method, 12);
|
||||||
|
|
||||||
assertRequestLineEquals(httpMethod, "DELETE http://vcloud/internetServices/12 HTTP/1.1");
|
assertRequestLineEquals(httpMethod,
|
||||||
assertHeadersEqual(httpMethod, "");
|
"DELETE http://vcloud/internetServices/12 HTTP/1.1");
|
||||||
assertEntityEquals(httpMethod, null);
|
assertHeadersEqual(httpMethod, "");
|
||||||
|
assertEntityEquals(httpMethod, null);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class);
|
assertResponseParserClassEquals(method, httpMethod,
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
ReturnVoidIf2xx.class);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
checkFilters(httpMethod);
|
checkFilters(httpMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAddInternetServiceToExistingIp() throws SecurityException,
|
public void testAddInternetServiceToExistingIp() throws SecurityException,
|
||||||
NoSuchMethodException, IOException {
|
NoSuchMethodException, IOException {
|
||||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetServiceToExistingIp",
|
Method method = TerremarkVCloudAsyncClient.class.getMethod(
|
||||||
String.class, String.class, String.class, int.class, Array.newInstance(
|
"addInternetServiceToExistingIp", String.class, String.class,
|
||||||
AddInternetServiceOptions.class, 0).getClass());
|
String.class, int.class, Array.newInstance(
|
||||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
AddInternetServiceOptions.class, 0).getClass());
|
||||||
12, "name", "tcp", 22);
|
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor
|
||||||
|
.createRequest(method, 12, "name", "tcp", 22);
|
||||||
|
|
||||||
assertRequestLineEquals(httpMethod,
|
assertRequestLineEquals(httpMethod,
|
||||||
"POST http://vcloud/publicIps/12/InternetServices HTTP/1.1");
|
"POST http://vcloud/publicIps/12/InternetServices HTTP/1.1");
|
||||||
assertHeadersEqual(httpMethod, "Content-Length: 303\nContent-Type: application/xml\n");
|
assertHeadersEqual(httpMethod,
|
||||||
assertEntityEquals(httpMethod, IOUtils.toString(getClass().getResourceAsStream(
|
"Content-Length: 303\nContent-Type: application/xml\n");
|
||||||
"/terremark/CreateInternetService-test2.xml")));
|
assertEntityEquals(httpMethod, IOUtils.toString(getClass()
|
||||||
|
.getResourceAsStream(
|
||||||
|
"/terremark/CreateInternetService-test2.xml")));
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
|
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
checkFilters(httpMethod);
|
checkFilters(httpMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAddInternetServiceToExistingIpOptions() throws SecurityException,
|
public void testAddInternetServiceToExistingIpOptions()
|
||||||
NoSuchMethodException, IOException {
|
throws SecurityException, NoSuchMethodException, IOException {
|
||||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetServiceToExistingIp",
|
Method method = TerremarkVCloudAsyncClient.class.getMethod(
|
||||||
String.class, String.class, String.class, int.class, Array.newInstance(
|
"addInternetServiceToExistingIp", String.class, String.class,
|
||||||
AddInternetServiceOptions.class, 0).getClass());
|
String.class, int.class, Array.newInstance(
|
||||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
AddInternetServiceOptions.class, 0).getClass());
|
||||||
12, "name", "tcp", 22, disabled().withDescription("yahoo"));
|
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor
|
||||||
|
.createRequest(method, 12, "name", "tcp", 22, disabled()
|
||||||
|
.withDescription("yahoo"));
|
||||||
|
|
||||||
assertRequestLineEquals(httpMethod,
|
assertRequestLineEquals(httpMethod,
|
||||||
"POST http://vcloud/publicIps/12/InternetServices HTTP/1.1");
|
"POST http://vcloud/publicIps/12/InternetServices HTTP/1.1");
|
||||||
assertHeadersEqual(httpMethod, "Content-Length: 341\nContent-Type: application/xml\n");
|
assertHeadersEqual(httpMethod,
|
||||||
assertEntityEquals(httpMethod, IOUtils.toString(getClass().getResourceAsStream(
|
"Content-Length: 341\nContent-Type: application/xml\n");
|
||||||
"/terremark/CreateInternetService-options-test.xml")));
|
assertEntityEquals(httpMethod, IOUtils.toString(getClass()
|
||||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
.getResourceAsStream(
|
||||||
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
|
"/terremark/CreateInternetService-options-test.xml")));
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||||
|
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
|
||||||
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
checkFilters(httpMethod);
|
checkFilters(httpMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAddNode() throws SecurityException, NoSuchMethodException, IOException {
|
public void testAddNode() throws SecurityException, NoSuchMethodException,
|
||||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("addNode", String.class,
|
IOException {
|
||||||
InetAddress.class, String.class, int.class, Array.newInstance(AddNodeOptions.class,
|
Method method = TerremarkVCloudAsyncClient.class.getMethod("addNode",
|
||||||
0).getClass());
|
String.class, InetAddress.class, String.class, int.class, Array
|
||||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
.newInstance(AddNodeOptions.class, 0).getClass());
|
||||||
12, InetAddress.getByName("10.2.2.2"), "name", 22);
|
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor
|
||||||
|
.createRequest(method, 12, InetAddress.getByName("10.2.2.2"),
|
||||||
|
"name", 22);
|
||||||
|
|
||||||
assertRequestLineEquals(httpMethod, "POST http://vcloud/internetServices/12/nodes HTTP/1.1");
|
assertRequestLineEquals(httpMethod,
|
||||||
assertHeadersEqual(httpMethod, "Content-Length: 298\nContent-Type: application/xml\n");
|
"POST http://vcloud/internetServices/12/nodes HTTP/1.1");
|
||||||
assertEntityEquals(httpMethod, IOUtils.toString(getClass().getResourceAsStream(
|
assertHeadersEqual(httpMethod,
|
||||||
"/terremark/CreateNodeService-test2.xml")));
|
"Content-Length: 298\nContent-Type: application/xml\n");
|
||||||
|
assertEntityEquals(httpMethod, IOUtils.toString(getClass()
|
||||||
|
.getResourceAsStream("/terremark/CreateNodeService-test2.xml")));
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, NodeHandler.class);
|
assertSaxResponseParserClassEquals(method, NodeHandler.class);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
checkFilters(httpMethod);
|
checkFilters(httpMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAddNodeOptions() throws SecurityException, NoSuchMethodException, IOException {
|
public void testAddNodeOptions() throws SecurityException,
|
||||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("addNode", String.class,
|
NoSuchMethodException, IOException {
|
||||||
InetAddress.class, String.class, int.class, Array.newInstance(AddNodeOptions.class,
|
Method method = TerremarkVCloudAsyncClient.class.getMethod("addNode",
|
||||||
0).getClass());
|
String.class, InetAddress.class, String.class, int.class, Array
|
||||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
.newInstance(AddNodeOptions.class, 0).getClass());
|
||||||
12, InetAddress.getByName("10.2.2.2"), "name", 22, AddNodeOptions.Builder.disabled()
|
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor
|
||||||
.withDescription("yahoo"));
|
.createRequest(method, 12, InetAddress.getByName("10.2.2.2"),
|
||||||
|
"name", 22, AddNodeOptions.Builder.disabled()
|
||||||
|
.withDescription("yahoo"));
|
||||||
|
|
||||||
assertRequestLineEquals(httpMethod, "POST http://vcloud/internetServices/12/nodes HTTP/1.1");
|
assertRequestLineEquals(httpMethod,
|
||||||
assertHeadersEqual(httpMethod, "Content-Length: 336\nContent-Type: application/xml\n");
|
"POST http://vcloud/internetServices/12/nodes HTTP/1.1");
|
||||||
assertEntityEquals(httpMethod, IOUtils.toString(getClass().getResourceAsStream(
|
assertHeadersEqual(httpMethod,
|
||||||
"/terremark/CreateNodeService-options-test.xml")));
|
"Content-Length: 336\nContent-Type: application/xml\n");
|
||||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
assertEntityEquals(httpMethod, IOUtils.toString(getClass()
|
||||||
assertSaxResponseParserClassEquals(method, NodeHandler.class);
|
.getResourceAsStream(
|
||||||
assertExceptionParserClassEquals(method, null);
|
"/terremark/CreateNodeService-options-test.xml")));
|
||||||
|
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||||
|
assertSaxResponseParserClassEquals(method, NodeHandler.class);
|
||||||
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
checkFilters(httpMethod);
|
checkFilters(httpMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetNode() throws SecurityException, NoSuchMethodException, IOException {
|
public void testGetNode() throws SecurityException, NoSuchMethodException,
|
||||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("getNode", String.class);
|
IOException {
|
||||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
Method method = TerremarkVCloudAsyncClient.class.getMethod("getNode",
|
||||||
12);
|
String.class);
|
||||||
|
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor
|
||||||
|
.createRequest(method, 12);
|
||||||
|
|
||||||
assertRequestLineEquals(httpMethod, "GET http://vcloud/nodeServices/12 HTTP/1.1");
|
assertRequestLineEquals(httpMethod,
|
||||||
assertHeadersEqual(httpMethod, "");
|
"GET http://vcloud/nodeServices/12 HTTP/1.1");
|
||||||
assertEntityEquals(httpMethod, null);
|
assertHeadersEqual(httpMethod, "");
|
||||||
|
assertEntityEquals(httpMethod, null);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, NodeHandler.class);
|
assertSaxResponseParserClassEquals(method, NodeHandler.class);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
checkFilters(httpMethod);
|
checkFilters(httpMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDeleteNode() throws SecurityException, NoSuchMethodException, IOException {
|
public void testDeleteNode() throws SecurityException,
|
||||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("deleteNode", String.class);
|
NoSuchMethodException, IOException {
|
||||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
Method method = TerremarkVCloudAsyncClient.class.getMethod(
|
||||||
12);
|
"deleteNode", String.class);
|
||||||
|
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor
|
||||||
|
.createRequest(method, 12);
|
||||||
|
|
||||||
assertRequestLineEquals(httpMethod, "DELETE http://vcloud/nodeServices/12 HTTP/1.1");
|
assertRequestLineEquals(httpMethod,
|
||||||
assertHeadersEqual(httpMethod, "");
|
"DELETE http://vcloud/nodeServices/12 HTTP/1.1");
|
||||||
assertEntityEquals(httpMethod, null);
|
assertHeadersEqual(httpMethod, "");
|
||||||
|
assertEntityEquals(httpMethod, null);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class);
|
assertResponseParserClassEquals(method, httpMethod,
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
ReturnVoidIf2xx.class);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
checkFilters(httpMethod);
|
checkFilters(httpMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void checkFilters(GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod) {
|
protected void checkFilters(
|
||||||
assertEquals(httpMethod.getFilters().size(), 1);
|
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod) {
|
||||||
assertEquals(httpMethod.getFilters().get(0).getClass(), SetVCloudTokenCookie.class);
|
assertEquals(httpMethod.getFilters().size(), 1);
|
||||||
}
|
assertEquals(httpMethod.getFilters().get(0).getClass(),
|
||||||
|
SetVCloudTokenCookie.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected TypeLiteral<RestAnnotationProcessor<TerremarkVCloudAsyncClient>> createTypeLiteral() {
|
protected TypeLiteral<RestAnnotationProcessor<TerremarkVCloudAsyncClient>> createTypeLiteral() {
|
||||||
return new TypeLiteral<RestAnnotationProcessor<TerremarkVCloudAsyncClient>>() {
|
return new TypeLiteral<RestAnnotationProcessor<TerremarkVCloudAsyncClient>>() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Module createModule() {
|
protected Module createModule() {
|
||||||
return new AbstractModule() {
|
return new AbstractModule() {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(URI.class).annotatedWith(Catalog.class).toInstance(URI.create("http://catalog"));
|
bind(String.class).annotatedWith(
|
||||||
bind(String.class).annotatedWith(CatalogItemRoot.class)
|
Jsr330.named(PROPERTY_TERREMARK_DEFAULTGROUP))
|
||||||
.toInstance("http://catalogItem");
|
.toProvider(Providers.<String> of("group"));
|
||||||
bind(URI.class).annotatedWith(VCloudApi.class).toInstance(URI.create("http://vcloud"));
|
bind(String.class).annotatedWith(
|
||||||
bind(String.class).annotatedWith(VAppRoot.class).toInstance("http://vapp");
|
Jsr330.named(PROPERTY_TERREMARK_DEFAULTROW))
|
||||||
bind(URI.class).annotatedWith(VDC.class).toInstance(URI.create("http://vdc"));
|
.toProvider(Providers.<String> of("row"));
|
||||||
bind(URI.class).annotatedWith(Network.class).toInstance(URI.create("http://network"));
|
bind(String.class).annotatedWith(
|
||||||
bind(SetVCloudTokenCookie.class).toInstance(
|
Jsr330.named(PROPERTY_TERREMARK_DEFAULTPASSWORD))
|
||||||
new SetVCloudTokenCookie(new Provider<String>() {
|
.toProvider(Providers.<String> of("password"));
|
||||||
|
bind(String.class).annotatedWith(
|
||||||
|
Jsr330.named(PROPERTY_VCLOUD_DEFAULTCPUCOUNT))
|
||||||
|
.toProvider(Providers.<String> of("1"));
|
||||||
|
bind(String.class).annotatedWith(
|
||||||
|
Jsr330.named(PROPERTY_VCLOUD_DEFAULTMEMORY))
|
||||||
|
.toProvider(Providers.<String> of("512"));
|
||||||
|
bind(String.class)
|
||||||
|
.annotatedWith(
|
||||||
|
Jsr330.named(PROPERTY_VCLOUD_DEFAULTNETWORK))
|
||||||
|
.toProvider(
|
||||||
|
Providers
|
||||||
|
.<String> of("https://vcloud.safesecureweb.com/network/1990"));
|
||||||
|
bind(URI.class).annotatedWith(Catalog.class).toInstance(
|
||||||
|
URI.create("http://catalog"));
|
||||||
|
bind(String.class).annotatedWith(CatalogItemRoot.class)
|
||||||
|
.toInstance("http://catalogItem");
|
||||||
|
bind(URI.class).annotatedWith(VCloudApi.class).toInstance(
|
||||||
|
URI.create("http://vcloud"));
|
||||||
|
bind(String.class).annotatedWith(VAppRoot.class).toInstance(
|
||||||
|
"http://vapp");
|
||||||
|
bind(URI.class).annotatedWith(VDC.class).toInstance(
|
||||||
|
URI.create("http://vdc"));
|
||||||
|
bind(URI.class).annotatedWith(Network.class).toInstance(
|
||||||
|
URI.create("http://network"));
|
||||||
|
bind(SetVCloudTokenCookie.class).toInstance(
|
||||||
|
new SetVCloudTokenCookie(new Provider<String>() {
|
||||||
|
|
||||||
public String get() {
|
public String get() {
|
||||||
return "token";
|
return "token";
|
||||||
}
|
}
|
||||||
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
|
bind(Logger.LoggerFactory.class).toInstance(
|
||||||
public Logger getLogger(String category) {
|
new LoggerFactory() {
|
||||||
return Logger.NULL;
|
public Logger getLogger(String category) {
|
||||||
}
|
return Logger.NULL;
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@Singleton
|
@Singleton
|
||||||
@Provides
|
@Provides
|
||||||
@Named("InstantiateVAppTemplateParams")
|
@Named("InstantiateVAppTemplateParams")
|
||||||
String provideInstantiateVAppTemplateParams() throws IOException {
|
String provideInstantiateVAppTemplateParams() throws IOException {
|
||||||
return Utils.toStringAndClose(getClass().getResourceAsStream(
|
return Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||||
"/terremark/InstantiateVAppTemplateParams.xml"));
|
"/terremark/InstantiateVAppTemplateParams.xml"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@Singleton
|
@Singleton
|
||||||
@Provides
|
@Provides
|
||||||
@Named("CreateInternetService")
|
@Named("CreateInternetService")
|
||||||
String provideCreateInternetService() throws IOException {
|
String provideCreateInternetService() throws IOException {
|
||||||
return Utils.toStringAndClose(getClass().getResourceAsStream(
|
return Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||||
"/terremark/CreateInternetService.xml"));
|
"/terremark/CreateInternetService.xml"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@Singleton
|
@Singleton
|
||||||
@Provides
|
@Provides
|
||||||
@Named("CreateNodeService")
|
@Named("CreateNodeService")
|
||||||
String provideCreateNodeService() throws IOException {
|
String provideCreateNodeService() throws IOException {
|
||||||
return Utils.toStringAndClose(getClass().getResourceAsStream(
|
return Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||||
"/terremark/CreateNodeService.xml"));
|
"/terremark/CreateNodeService.xml"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,15 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.vcloud.terremark.binders;
|
package org.jclouds.vcloud.terremark.binders;
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.easymock.EasyMock.expect;
|
||||||
|
import static org.easymock.classextension.EasyMock.createMock;
|
||||||
|
import static org.easymock.classextension.EasyMock.replay;
|
||||||
|
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTCPUCOUNT;
|
||||||
|
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTMEMORY;
|
||||||
|
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTNETWORK;
|
||||||
|
import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTGROUP;
|
||||||
|
import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTPASSWORD;
|
||||||
|
import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTROW;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -32,63 +40,124 @@ import java.util.Map;
|
||||||
|
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||||
|
import org.jclouds.util.Jsr330;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.HashMultimap;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
import com.google.common.collect.Multimap;
|
||||||
|
import com.google.common.collect.Multimaps;
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
import com.google.inject.util.Providers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests behavior of {@code TerremarkBindInstantiateVAppTemplateParamsToXmlEntity}
|
* Tests behavior of {@code
|
||||||
|
* TerremarkBindInstantiateVAppTemplateParamsToXmlEntity}
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = "unit", testName = "vcloud.TerremarkBindInstantiateVAppTemplateParamsToXmlEntityTest")
|
@Test(groups = "unit", testName = "vcloud.TerremarkBindInstantiateVAppTemplateParamsToXmlEntityTest")
|
||||||
public class TerremarkBindInstantiateVAppTemplateParamsToXmlEntityTest {
|
public class TerremarkBindInstantiateVAppTemplateParamsToXmlEntityTest {
|
||||||
Injector injector = Guice.createInjector(new AbstractModule() {
|
Injector injector = Guice.createInjector(new AbstractModule() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
}
|
bind(String.class).annotatedWith(
|
||||||
|
Jsr330.named(PROPERTY_TERREMARK_DEFAULTGROUP)).toProvider(
|
||||||
|
Providers.<String> of("group"));
|
||||||
|
bind(String.class).annotatedWith(
|
||||||
|
Jsr330.named(PROPERTY_TERREMARK_DEFAULTROW)).toProvider(
|
||||||
|
Providers.<String> of("row"));
|
||||||
|
bind(String.class).annotatedWith(
|
||||||
|
Jsr330.named(PROPERTY_TERREMARK_DEFAULTPASSWORD))
|
||||||
|
.toProvider(Providers.<String> of("password"));
|
||||||
|
bind(String.class).annotatedWith(
|
||||||
|
Jsr330.named(PROPERTY_VCLOUD_DEFAULTCPUCOUNT)).toProvider(
|
||||||
|
Providers.<String> of("1"));
|
||||||
|
bind(String.class).annotatedWith(
|
||||||
|
Jsr330.named(PROPERTY_VCLOUD_DEFAULTMEMORY)).toProvider(
|
||||||
|
Providers.<String> of("512"));
|
||||||
|
bind(String.class)
|
||||||
|
.annotatedWith(Jsr330.named(PROPERTY_VCLOUD_DEFAULTNETWORK))
|
||||||
|
.toProvider(
|
||||||
|
Providers
|
||||||
|
.<String> of("https://vcloud.safesecureweb.com/network/1990"));
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@Singleton
|
@Singleton
|
||||||
@Provides
|
@Provides
|
||||||
@Named("InstantiateVAppTemplateParams")
|
@Named("InstantiateVAppTemplateParams")
|
||||||
String provideInstantiateVAppTemplateParams() throws IOException {
|
String provideInstantiateVAppTemplateParams() throws IOException {
|
||||||
InputStream is = getClass().getResourceAsStream(
|
InputStream is = getClass().getResourceAsStream(
|
||||||
"/terremark/InstantiateVAppTemplateParams.xml");
|
"/terremark/InstantiateVAppTemplateParams.xml");
|
||||||
return Utils.toStringAndClose(is);
|
return Utils.toStringAndClose(is);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
public void testApplyInputStream() throws IOException {
|
public void testApplyInputStream() throws IOException {
|
||||||
String expected = IOUtils.toString(getClass().getResourceAsStream(
|
|
||||||
"/terremark/InstantiateVAppTemplateParams-test-2.xml"));
|
|
||||||
HttpRequest request = new HttpRequest("GET", URI.create("http://test"));
|
|
||||||
TerremarkBindInstantiateVAppTemplateParamsToXmlEntity binder = injector
|
|
||||||
.getInstance(TerremarkBindInstantiateVAppTemplateParamsToXmlEntity.class);
|
|
||||||
|
|
||||||
Map<String, String> map = Maps.newHashMap();
|
String expected = IOUtils.toString(getClass().getResourceAsStream(
|
||||||
map.put("name", "name");
|
"/terremark/InstantiateVAppTemplateParams-test-2.xml"));
|
||||||
map.put("password", "password");
|
Multimap<String, String> headers = Multimaps
|
||||||
map.put("row", "row");
|
.synchronizedMultimap(HashMultimap.<String, String> create());
|
||||||
map.put("group", "group");
|
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
|
||||||
map.put("template", "http://catalogItem/3");
|
expect(request.getEndpoint()).andReturn(
|
||||||
map.put("count", "1");
|
URI.create("http://localhost/key")).anyTimes();
|
||||||
map.put("megabytes", "512");
|
expect(request.getArgs()).andReturn(new Object[] {}).atLeastOnce();
|
||||||
map.put("network", "http://network");
|
expect(request.getFirstHeaderOrNull("Content-Type")).andReturn(
|
||||||
binder.bindToRequest(request, map);
|
"application/unknown").atLeastOnce();
|
||||||
assertEquals(request.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE), "application/unknown");
|
expect(request.getHeaders()).andReturn(headers).atLeastOnce();
|
||||||
assertEquals(request.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH), "2239");
|
request.setEntity(expected);
|
||||||
assertEquals(request.getEntity(), expected);
|
replay(request);
|
||||||
|
|
||||||
}
|
TerremarkBindInstantiateVAppTemplateParamsToXmlEntity binder = injector
|
||||||
|
.getInstance(TerremarkBindInstantiateVAppTemplateParamsToXmlEntity.class);
|
||||||
|
|
||||||
|
Map<String, String> map = Maps.newHashMap();
|
||||||
|
map.put("name", "name");
|
||||||
|
map.put("password", "password");
|
||||||
|
map.put("row", "row");
|
||||||
|
map.put("group", "group");
|
||||||
|
map.put("template", "http://catalogItem/3");
|
||||||
|
map.put("count", "1");
|
||||||
|
map.put("megabytes", "512");
|
||||||
|
map.put("network", "http://network");
|
||||||
|
binder.bindToRequest(request, map);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testApplyInputStream2() throws IOException {
|
||||||
|
|
||||||
|
String expected = IOUtils.toString(getClass().getResourceAsStream(
|
||||||
|
"/terremark/InstantiateVAppTemplateParams-test-2.xml"));
|
||||||
|
Multimap<String, String> headers = Multimaps
|
||||||
|
.synchronizedMultimap(HashMultimap.<String, String> create());
|
||||||
|
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
|
||||||
|
expect(request.getEndpoint()).andReturn(
|
||||||
|
URI.create("http://localhost/key")).anyTimes();
|
||||||
|
expect(request.getArgs()).andReturn(new Object[] {}).atLeastOnce();
|
||||||
|
expect(request.getFirstHeaderOrNull("Content-Type")).andReturn(
|
||||||
|
"application/unknown").atLeastOnce();
|
||||||
|
expect(request.getHeaders()).andReturn(headers).atLeastOnce();
|
||||||
|
request.setEntity(expected);
|
||||||
|
replay(request);
|
||||||
|
|
||||||
|
TerremarkBindInstantiateVAppTemplateParamsToXmlEntity binder = injector
|
||||||
|
.getInstance(TerremarkBindInstantiateVAppTemplateParamsToXmlEntity.class);
|
||||||
|
|
||||||
|
Map<String, String> map = Maps.newHashMap();
|
||||||
|
map.put("name", "name");
|
||||||
|
map.put("template", "http://catalogItem/3");
|
||||||
|
map.put("count", "1");
|
||||||
|
map.put("megabytes", "512");
|
||||||
|
map.put("network", "http://network");
|
||||||
|
binder.bindToRequest(request, map);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,12 +26,6 @@ public class TerremarkInstantiateVAppTemplateOptionsTest {
|
||||||
|
|
||||||
Injector injector = Guice.createInjector(new ParserModule());
|
Injector injector = Guice.createInjector(new ParserModule());
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testInGroupDefault() {
|
|
||||||
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
|
|
||||||
assertEquals(options.getGroup(), "default");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInGroup() {
|
public void testInGroup() {
|
||||||
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
|
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
|
||||||
|
@ -45,12 +39,6 @@ public class TerremarkInstantiateVAppTemplateOptionsTest {
|
||||||
assertEquals(options.getGroup(), "group1");
|
assertEquals(options.getGroup(), "group1");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testInRowDefault() {
|
|
||||||
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
|
|
||||||
assertEquals(options.getRow(), "default");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInRow() {
|
public void testInRow() {
|
||||||
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
|
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
|
||||||
|
@ -64,12 +52,6 @@ public class TerremarkInstantiateVAppTemplateOptionsTest {
|
||||||
assertEquals(options.getRow(), "row1");
|
assertEquals(options.getRow(), "row1");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testWithPasswordDefault() {
|
|
||||||
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
|
|
||||||
assertEquals(options.getPassword(), "getPassword()");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWithPassword() {
|
public void testWithPassword() {
|
||||||
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
|
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
|
||||||
|
@ -98,9 +80,7 @@ public class TerremarkInstantiateVAppTemplateOptionsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCpuCount() {
|
public void testCpuCount() {
|
||||||
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
|
assertEquals(cpuCount(3).getCpuCount(), "3");
|
||||||
cpuCount(3);
|
|
||||||
assertEquals(options.getCpuCount(), "3");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -32,8 +32,9 @@ import java.net.URI;
|
||||||
import org.jclouds.http.functions.ParseSax;
|
import org.jclouds.http.functions.ParseSax;
|
||||||
import org.jclouds.http.functions.ParseSax.Factory;
|
import org.jclouds.http.functions.ParseSax.Factory;
|
||||||
import org.jclouds.http.functions.config.ParserModule;
|
import org.jclouds.http.functions.config.ParserModule;
|
||||||
import org.jclouds.rest.domain.NamedLink;
|
import org.jclouds.rest.domain.NamedResource;
|
||||||
import org.jclouds.rest.domain.internal.NamedLinkImpl;
|
import org.jclouds.rest.domain.internal.NamedLinkImpl;
|
||||||
|
import org.jclouds.rest.internal.NamedResourceImpl;
|
||||||
import org.jclouds.vcloud.endpoints.VCloudApi;
|
import org.jclouds.vcloud.endpoints.VCloudApi;
|
||||||
import org.jclouds.vcloud.terremark.domain.TerremarkVDC;
|
import org.jclouds.vcloud.terremark.domain.TerremarkVDC;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
@ -52,50 +53,66 @@ import com.google.inject.Provides;
|
||||||
@Test(groups = "unit", testName = "vcloud.TerremarkVDCHandlerTest")
|
@Test(groups = "unit", testName = "vcloud.TerremarkVDCHandlerTest")
|
||||||
public class TerremarkVDCHandlerTest {
|
public class TerremarkVDCHandlerTest {
|
||||||
|
|
||||||
public void testApplyInputStream() {
|
public void testApplyInputStream() {
|
||||||
InputStream is = getClass().getResourceAsStream("/terremark/vdc.xml");
|
InputStream is = getClass().getResourceAsStream("/terremark/vdc.xml");
|
||||||
Injector injector = Guice.createInjector(new ParserModule(), new AbstractModule() {
|
Injector injector = Guice.createInjector(new ParserModule(),
|
||||||
|
new AbstractModule() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@Provides
|
@Provides
|
||||||
@VCloudApi
|
@VCloudApi
|
||||||
URI provide() {
|
URI provide() {
|
||||||
return URI.create("https://services.vcloudexpress.terremark.com/api/v0.8");
|
return URI
|
||||||
}
|
.create("https://services.vcloudexpress.terremark.com/api/v0.8");
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
Factory factory = injector.getInstance(ParseSax.Factory.class);
|
Factory factory = injector.getInstance(ParseSax.Factory.class);
|
||||||
|
|
||||||
TerremarkVDC result = (TerremarkVDC) factory.create(
|
TerremarkVDC result = (TerremarkVDC) factory.create(
|
||||||
injector.getInstance(TerremarkVDCHandler.class)).parse(is);
|
injector.getInstance(TerremarkVDCHandler.class)).parse(is);
|
||||||
assertEquals(result.getName(), "Miami Environment 1");
|
assertEquals(result.getName(), "Miami Environment 1");
|
||||||
assertEquals(result.getLocation(), URI
|
assertEquals(
|
||||||
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32"));
|
result.getLocation(),
|
||||||
assertEquals(result.getResourceEntities(), ImmutableMap.<String, NamedLink> of());
|
URI
|
||||||
assertEquals(
|
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32"));
|
||||||
result.getAvailableNetworks(),
|
assertEquals(result.getResourceEntities(), ImmutableMap
|
||||||
ImmutableMap
|
.<String, NamedResource> of());
|
||||||
.of(
|
assertEquals(
|
||||||
"10.114.34.128/26",
|
result.getAvailableNetworks(),
|
||||||
new NamedLinkImpl(
|
ImmutableMap
|
||||||
"10.114.34.128/26",
|
.of(
|
||||||
"application/vnd.vmware.vcloud.network+xml",
|
"10.114.34.128/26",
|
||||||
URI
|
new NamedResourceImpl(
|
||||||
.create("https://services.vcloudexpress.terremark.com/api/v0.8/network/1708"))));
|
"1708",
|
||||||
assertEquals(result.getCatalog(), new NamedLinkImpl("Miami Environment 1", CATALOG_XML, URI
|
"10.114.34.128/26",
|
||||||
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog")));
|
"application/vnd.vmware.vcloud.network+xml",
|
||||||
assertEquals(result.getPublicIps(), new NamedLinkImpl("Public IPs", "application/xml", URI
|
URI
|
||||||
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/publicIps")));
|
.create("https://services.vcloudexpress.terremark.com/api/v0.8/network/1708"))));
|
||||||
assertEquals(
|
assertEquals(
|
||||||
result.getInternetServices(),
|
result.getCatalog(),
|
||||||
new NamedLinkImpl(
|
new NamedLinkImpl(
|
||||||
"Internet Services",
|
"Miami Environment 1",
|
||||||
"application/xml",
|
CATALOG_XML,
|
||||||
URI
|
URI
|
||||||
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/internetServices")));
|
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog")));
|
||||||
}
|
assertEquals(
|
||||||
|
result.getPublicIps(),
|
||||||
|
new NamedLinkImpl(
|
||||||
|
"Public IPs",
|
||||||
|
"application/xml",
|
||||||
|
URI
|
||||||
|
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/publicIps")));
|
||||||
|
assertEquals(
|
||||||
|
result.getInternetServices(),
|
||||||
|
new NamedLinkImpl(
|
||||||
|
"Internet Services",
|
||||||
|
"application/xml",
|
||||||
|
URI
|
||||||
|
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/internetServices")));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,9 @@
|
||||||
<Property xmlns="http://schemas.dmtf.org/ovf/envelope/1"
|
<Property xmlns="http://schemas.dmtf.org/ovf/envelope/1"
|
||||||
ovf:key="password" ovf:value="password" />
|
ovf:key="password" ovf:value="password" />
|
||||||
<Property xmlns="http://schemas.dmtf.org/ovf/envelope/1"
|
<Property xmlns="http://schemas.dmtf.org/ovf/envelope/1"
|
||||||
ovf:key="row" ovf:value="default" />
|
ovf:key="row" ovf:value="row" />
|
||||||
<Property xmlns="http://schemas.dmtf.org/ovf/envelope/1"
|
<Property xmlns="http://schemas.dmtf.org/ovf/envelope/1"
|
||||||
ovf:key="group" ovf:value="default" />
|
ovf:key="group" ovf:value="group" />
|
||||||
</ProductSection>
|
</ProductSection>
|
||||||
<VirtualHardwareSection xmlns:q1="http://www.vmware.com/vcloud/v1">
|
<VirtualHardwareSection xmlns:q1="http://www.vmware.com/vcloud/v1">
|
||||||
<Item xmlns="http://schemas.dmtf.org/ovf/envelope/1">
|
<Item xmlns="http://schemas.dmtf.org/ovf/envelope/1">
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
</VirtualHardwareSection>
|
</VirtualHardwareSection>
|
||||||
<NetworkConfigSection>
|
<NetworkConfigSection>
|
||||||
<NetworkConfig>
|
<NetworkConfig>
|
||||||
<NetworkAssociation href="http://network" />
|
<NetworkAssociation href="https://vcloud.safesecureweb.com/network/1990" />
|
||||||
</NetworkConfig>
|
</NetworkConfig>
|
||||||
</NetworkConfigSection>
|
</NetworkConfigSection>
|
||||||
</InstantiationParams>
|
</InstantiationParams>
|
||||||
|
|
|
@ -7,9 +7,9 @@
|
||||||
<Property xmlns="http://schemas.dmtf.org/ovf/envelope/1"
|
<Property xmlns="http://schemas.dmtf.org/ovf/envelope/1"
|
||||||
ovf:key="password" ovf:value="password" />
|
ovf:key="password" ovf:value="password" />
|
||||||
<Property xmlns="http://schemas.dmtf.org/ovf/envelope/1"
|
<Property xmlns="http://schemas.dmtf.org/ovf/envelope/1"
|
||||||
ovf:key="row" ovf:value="default" />
|
ovf:key="row" ovf:value="row" />
|
||||||
<Property xmlns="http://schemas.dmtf.org/ovf/envelope/1"
|
<Property xmlns="http://schemas.dmtf.org/ovf/envelope/1"
|
||||||
ovf:key="group" ovf:value="default" />
|
ovf:key="group" ovf:value="group" />
|
||||||
</ProductSection>
|
</ProductSection>
|
||||||
<VirtualHardwareSection xmlns:q1="http://www.vmware.com/vcloud/v1">
|
<VirtualHardwareSection xmlns:q1="http://www.vmware.com/vcloud/v1">
|
||||||
<Item xmlns="http://schemas.dmtf.org/ovf/envelope/1">
|
<Item xmlns="http://schemas.dmtf.org/ovf/envelope/1">
|
||||||
|
@ -31,7 +31,7 @@
|
||||||
</VirtualHardwareSection>
|
</VirtualHardwareSection>
|
||||||
<NetworkConfigSection>
|
<NetworkConfigSection>
|
||||||
<NetworkConfig>
|
<NetworkConfig>
|
||||||
<NetworkAssociation href="http://network" />
|
<NetworkAssociation href="https://vcloud.safesecureweb.com/network/1990" />
|
||||||
</NetworkConfig>
|
</NetworkConfig>
|
||||||
</NetworkConfigSection>
|
</NetworkConfigSection>
|
||||||
</InstantiationParams>
|
</InstantiationParams>
|
||||||
|
|
Loading…
Reference in New Issue