diff --git a/pom.xml b/pom.xml index ab1fbb0029..32b5464eb9 100644 --- a/pom.xml +++ b/pom.xml @@ -47,7 +47,7 @@ rackspace mezeo nirvanix - vcloudx + vcloud atmosonline twitter diff --git a/vcloudx/core/pom.xml b/vcloud/core/pom.xml similarity index 74% rename from vcloudx/core/pom.xml rename to vcloud/core/pom.xml index 346c3dad3a..a558f1db51 100755 --- a/vcloudx/core/pom.xml +++ b/vcloud/core/pom.xml @@ -28,26 +28,26 @@ org.jclouds - jclouds-vcloudx-project + jclouds-vcloud-project 1.0-SNAPSHOT ../pom.xml 4.0.0 org.jclouds - jclouds-vcloudx-core - jclouds vcloudx Components Core + jclouds-vcloud-core + jclouds vcloud Components Core jar - jclouds Core components to access vcloudx + jclouds Core components to access vcloud - ${jclouds.vcloudx.user} - ${jclouds.vcloudx.password} - ${jclouds.vcloudx.endpoint} + ${jclouds.vcloud.user} + ${jclouds.vcloud.password} + ${jclouds.vcloud.endpoint} - scm:svn:http://jclouds.googlecode.com/svn/trunk/vcloudx/core - scm:svn:https://jclouds.googlecode.com/svn/trunk/vcloudx/core - http://jclouds.googlecode.com/svn/trunk/vcloudx/core + scm:svn:http://jclouds.googlecode.com/svn/trunk/vcloud/core + scm:svn:https://jclouds.googlecode.com/svn/trunk/vcloud/core + http://jclouds.googlecode.com/svn/trunk/vcloud/core diff --git a/vcloudx/core/src/main/java/org/jclouds/vcloudx/BaseVCloudXContextBuilder.java b/vcloud/core/src/main/java/org/jclouds/vcloud/BaseVCloudContextBuilder.java similarity index 67% rename from vcloudx/core/src/main/java/org/jclouds/vcloudx/BaseVCloudXContextBuilder.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/BaseVCloudContextBuilder.java index 6d4dd6c36a..c860eebb18 100644 --- a/vcloudx/core/src/main/java/org/jclouds/vcloudx/BaseVCloudXContextBuilder.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/BaseVCloudContextBuilder.java @@ -21,7 +21,7 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloudx; +package org.jclouds.vcloud; import java.util.List; import java.util.Properties; @@ -30,16 +30,16 @@ import java.util.concurrent.ExecutorService; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.logging.jdk.config.JDKLoggingModule; import org.jclouds.rest.RestContextBuilder; -import org.jclouds.vcloudx.config.BaseVCloudXRestClientModule; -import org.jclouds.vcloudx.config.BaseVCloudXContextModule; -import org.jclouds.vcloudx.config.RestVCloudXAuthenticationModule; +import org.jclouds.vcloud.config.BaseVCloudContextModule; +import org.jclouds.vcloud.config.BaseVCloudRestClientModule; +import org.jclouds.vcloud.config.VCloudDiscoveryRestClientModule; import com.google.inject.Injector; import com.google.inject.Module; import com.google.inject.TypeLiteral; /** - * Creates {@link VCloudXContext} or {@link Injector} instances based on the most commonly requested + * Creates {@link VCloudContext} or {@link Injector} instances based on the most commonly requested * arguments. *

* Note that Threadsafe objects will be bound as singletons to the Injector or Context provided. @@ -51,32 +51,32 @@ import com.google.inject.TypeLiteral; * @author Adrian Cole * @see CloudFilesContext */ -public class BaseVCloudXContextBuilder extends RestContextBuilder { +public class BaseVCloudContextBuilder extends RestContextBuilder { - public BaseVCloudXContextBuilder(Properties props) { - super(new TypeLiteral() { + public BaseVCloudContextBuilder(Properties props) { + super(new TypeLiteral() { }, props); } @Override protected void addClientModule(List modules) { - modules.add(new RestVCloudXAuthenticationModule()); - modules.add(new BaseVCloudXRestClientModule()); + modules.add(new VCloudDiscoveryRestClientModule()); + modules.add(new BaseVCloudRestClientModule()); } @Override protected void addContextModule(List modules) { - modules.add(new BaseVCloudXContextModule()); + modules.add(new BaseVCloudContextModule()); } @Override - public BaseVCloudXContextBuilder withExecutorService(ExecutorService service) { - return (BaseVCloudXContextBuilder) super.withExecutorService(service); + public BaseVCloudContextBuilder withExecutorService(ExecutorService service) { + return (BaseVCloudContextBuilder) super.withExecutorService(service); } @Override - public BaseVCloudXContextBuilder withModules(Module... modules) { - return (BaseVCloudXContextBuilder) super.withModules(modules); + public BaseVCloudContextBuilder withModules(Module... modules) { + return (BaseVCloudContextBuilder) super.withModules(modules); } } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java new file mode 100644 index 0000000000..f6945a1a5b --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java @@ -0,0 +1,69 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.vcloud; + +import java.util.concurrent.Future; +import static org.jclouds.vcloud.VCloudMediaType.*; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; + +import org.jclouds.rest.annotations.Endpoint; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.XMLResponseParser; +import org.jclouds.vcloud.domain.Catalog; +import org.jclouds.vcloud.filters.SetVCloudTokenCookie; +import org.jclouds.vcloud.xml.CatalogHandler; + +/** + * Provides access to VCloud resources via their REST API. + *

+ * + * @see + * @author Adrian Cole + */ +@RequestFilters(SetVCloudTokenCookie.class) +public interface VCloudClient { + + @GET + @Endpoint(org.jclouds.vcloud.endpoints.Catalog.class) + @Consumes(CATALOG_XML) + @XMLResponseParser(CatalogHandler.class) + Future getCatalog(); + + + @GET + @Endpoint(org.jclouds.vcloud.endpoints.VDC.class) + @Consumes(VDC_XML) + String getDefaultVDC(); + + // + // @GET + // @Endpoint(vDC.class) + // public Set getvDCs(); + // + // @GET + // @Endpoint(TasksList.class) + // public Set getTasksLists(); + +} diff --git a/vcloudx/core/src/main/java/org/jclouds/vcloudx/VCloudXClient.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudDiscovery.java similarity index 74% rename from vcloudx/core/src/main/java/org/jclouds/vcloudx/VCloudXClient.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/VCloudDiscovery.java index 4f28f291f3..c12d76588f 100644 --- a/vcloudx/core/src/main/java/org/jclouds/vcloudx/VCloudXClient.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudDiscovery.java @@ -21,37 +21,36 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloudx; +package org.jclouds.vcloud; import javax.ws.rs.Consumes; import javax.ws.rs.GET; -import javax.ws.rs.core.MediaType; import org.jclouds.rest.annotations.Endpoint; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.XMLResponseParser; -import org.jclouds.vcloudx.domain.OrgLinks; -import org.jclouds.vcloudx.endpoints.Org; -import org.jclouds.vcloudx.filters.SetVCloudTokenCookie; -import org.jclouds.vcloudx.xml.OrgLinksHandler; +import org.jclouds.vcloud.domain.Organization; +import org.jclouds.vcloud.endpoints.Org; +import org.jclouds.vcloud.filters.SetVCloudTokenCookie; +import org.jclouds.vcloud.xml.OrgHandler; /** - * Provides access to VCloudX resources via their REST API. + * Provides access to VCloud resources via their REST API. *

* * @see * @author Adrian Cole */ @RequestFilters(SetVCloudTokenCookie.class) -public interface VCloudXClient { +public interface VCloudDiscovery { /** - * This call returns a list of all vCloud Data Centers (vDCs), catalogs, and task lists within + * This call returns a list of all vCloud Data Centers (vdcs), catalogs, and task lists within * the organization. */ @GET @Endpoint(Org.class) - @Consumes(MediaType.APPLICATION_XML) - @XMLResponseParser(OrgLinksHandler.class) - OrgLinks getOrganization(); + @Consumes(VCloudMediaType.ORG_XML) + @XMLResponseParser(OrgHandler.class) + Organization getOrganization(); } diff --git a/vcloudx/core/src/main/java/org/jclouds/vcloudx/VCloudXLogin.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudLogin.java similarity index 81% rename from vcloudx/core/src/main/java/org/jclouds/vcloudx/VCloudXLogin.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/VCloudLogin.java index e5a31f86b7..dbb862f723 100755 --- a/vcloudx/core/src/main/java/org/jclouds/vcloudx/VCloudXLogin.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudLogin.java @@ -21,9 +21,9 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloudx; +package org.jclouds.vcloud; -import java.net.URI; +import java.util.Map; import javax.ws.rs.Consumes; import javax.ws.rs.POST; @@ -34,27 +34,28 @@ import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.rest.annotations.Endpoint; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.ResponseParser; -import org.jclouds.vcloudx.endpoints.Org; -import org.jclouds.vcloudx.endpoints.VCloudX; -import org.jclouds.vcloudx.functions.ParseLoginResponseFromHeaders; +import org.jclouds.vcloud.domain.Link; +import org.jclouds.vcloud.endpoints.Org; +import org.jclouds.vcloud.endpoints.VCloud; +import org.jclouds.vcloud.functions.ParseLoginResponseFromHeaders; /** - * Establishes a context with a VCloudX endpoint. + * Establishes a context with a VCloud endpoint. *

* * @see * @author Adrian Cole */ -@Endpoint(VCloudX.class) +@Endpoint(VCloud.class) @RequestFilters(BasicAuthentication.class) -public interface VCloudXLogin { +public interface VCloudLogin { - public interface VCloudXSession { + public interface VCloudSession { @VCloudToken String getVCloudToken(); @Org - URI getOrg(); + Map getOrgs(); } /** @@ -65,5 +66,5 @@ public interface VCloudXLogin { @ResponseParser(ParseLoginResponseFromHeaders.class) @Path("/login") @Consumes(MediaType.APPLICATION_XML) - VCloudXSession login(); + VCloudSession login(); } diff --git a/vcloudx/core/src/main/java/org/jclouds/vcloudx/VCloudXMediaType.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudMediaType.java similarity index 85% rename from vcloudx/core/src/main/java/org/jclouds/vcloudx/VCloudXMediaType.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/VCloudMediaType.java index 19f7f3dd64..75eb8f7902 100644 --- a/vcloudx/core/src/main/java/org/jclouds/vcloudx/VCloudXMediaType.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudMediaType.java @@ -21,7 +21,7 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloudx; +package org.jclouds.vcloud; import javax.ws.rs.core.MediaType; @@ -30,7 +30,7 @@ import javax.ws.rs.core.MediaType; * * @see MediaType */ -public class VCloudXMediaType { +public class VCloudMediaType { /** * "application/vnd.vmware.vcloud.org+xml" @@ -72,4 +72,14 @@ public class VCloudXMediaType { public final static MediaType TASKSLIST_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.tasksList+xml"); + /** + * "application/vnd.vmware.vcloud.catalogItem+xml" + */ + public final static String CATALOGITEM_XML = "application/vnd.vmware.vcloud.catalogItem+xml"; + /** + * "application/vnd.vmware.vcloud.catalogItem+xml" + */ + public final static MediaType CATALOGITEM_XML_TYPE = new MediaType("application", + "vnd.vmware.vcloud.catalogItem+xml"); + } diff --git a/vcloudx/core/src/main/java/org/jclouds/vcloudx/VCloudXPropertiesBuilder.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudPropertiesBuilder.java similarity index 56% rename from vcloudx/core/src/main/java/org/jclouds/vcloudx/VCloudXPropertiesBuilder.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/VCloudPropertiesBuilder.java index de6c56f24d..6244866b34 100644 --- a/vcloudx/core/src/main/java/org/jclouds/vcloudx/VCloudXPropertiesBuilder.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudPropertiesBuilder.java @@ -21,13 +21,13 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloudx; +package org.jclouds.vcloud; import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.vcloudx.reference.VCloudXConstants.PROPERTY_VCLOUDX_ENDPOINT; -import static org.jclouds.vcloudx.reference.VCloudXConstants.PROPERTY_VCLOUDX_KEY; -import static org.jclouds.vcloudx.reference.VCloudXConstants.PROPERTY_VCLOUDX_SESSIONINTERVAL; -import static org.jclouds.vcloudx.reference.VCloudXConstants.PROPERTY_VCLOUDX_USER; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPOINT; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER; import java.net.URI; import java.util.Properties; @@ -35,41 +35,41 @@ import java.util.Properties; import org.jclouds.http.HttpPropertiesBuilder; /** - * Builds properties used in VCloudX Clients + * Builds properties used in VCloud Clients * * @author Adrian Cole */ -public class VCloudXPropertiesBuilder extends HttpPropertiesBuilder { +public class VCloudPropertiesBuilder extends HttpPropertiesBuilder { @Override protected Properties defaultProperties() { Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_VCLOUDX_SESSIONINTERVAL, 9 * 60 + ""); + properties.setProperty(PROPERTY_VCLOUD_SESSIONINTERVAL, 9 * 60 + ""); return properties; } - public VCloudXPropertiesBuilder(Properties properties) { + public VCloudPropertiesBuilder(Properties properties) { super(properties); } - public VCloudXPropertiesBuilder(URI endpoint, String id, String secret) { + public VCloudPropertiesBuilder(URI endpoint, String id, String secret) { super(); withCredentials(id, secret); withEndpoint(endpoint); } - public VCloudXPropertiesBuilder withTokenExpiration(long seconds) { - properties.setProperty(PROPERTY_VCLOUDX_SESSIONINTERVAL, seconds + ""); + public VCloudPropertiesBuilder withTokenExpiration(long seconds) { + properties.setProperty(PROPERTY_VCLOUD_SESSIONINTERVAL, seconds + ""); return this; } - public VCloudXPropertiesBuilder withCredentials(String id, String secret) { - properties.setProperty(PROPERTY_VCLOUDX_USER, checkNotNull(id, "user")); - properties.setProperty(PROPERTY_VCLOUDX_KEY, checkNotNull(secret, "key")); + public VCloudPropertiesBuilder withCredentials(String id, String secret) { + properties.setProperty(PROPERTY_VCLOUD_USER, checkNotNull(id, "user")); + properties.setProperty(PROPERTY_VCLOUD_KEY, checkNotNull(secret, "key")); return this; } - public VCloudXPropertiesBuilder withEndpoint(URI endpoint) { - properties.setProperty(PROPERTY_VCLOUDX_ENDPOINT, checkNotNull(endpoint, "endpoint") + public VCloudPropertiesBuilder withEndpoint(URI endpoint) { + properties.setProperty(PROPERTY_VCLOUD_ENDPOINT, checkNotNull(endpoint, "endpoint") .toString()); return this; } diff --git a/vcloudx/core/src/main/java/org/jclouds/vcloudx/VCloudToken.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudToken.java similarity index 98% rename from vcloudx/core/src/main/java/org/jclouds/vcloudx/VCloudToken.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/VCloudToken.java index 11572c051d..a2c61e71c6 100644 --- a/vcloudx/core/src/main/java/org/jclouds/vcloudx/VCloudToken.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudToken.java @@ -21,7 +21,7 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloudx; +package org.jclouds.vcloud; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/vcloudx/core/src/main/java/org/jclouds/vcloudx/config/BaseVCloudXContextModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/config/BaseVCloudContextModule.java similarity index 73% rename from vcloudx/core/src/main/java/org/jclouds/vcloudx/config/BaseVCloudXContextModule.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/config/BaseVCloudContextModule.java index 8b9eef4545..21d0f50f63 100644 --- a/vcloudx/core/src/main/java/org/jclouds/vcloudx/config/BaseVCloudXContextModule.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/config/BaseVCloudContextModule.java @@ -21,7 +21,7 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloudx.config; +package org.jclouds.vcloud.config; import java.net.URI; @@ -31,9 +31,9 @@ import javax.inject.Singleton; import org.jclouds.lifecycle.Closer; import org.jclouds.rest.RestContext; import org.jclouds.rest.internal.RestContextImpl; -import org.jclouds.vcloudx.VCloudXClient; -import org.jclouds.vcloudx.endpoints.Org; -import org.jclouds.vcloudx.reference.VCloudXConstants; +import org.jclouds.vcloud.VCloudClient; +import org.jclouds.vcloud.endpoints.Org; +import org.jclouds.vcloud.reference.VCloudConstants; import com.google.inject.AbstractModule; import com.google.inject.Provides; @@ -41,16 +41,16 @@ import com.google.inject.Provides; /** * @author Adrian Cole */ -public class BaseVCloudXContextModule extends AbstractModule { +public class BaseVCloudContextModule extends AbstractModule { @Override protected void configure() { } @Provides @Singleton - RestContext provideContext(Closer closer, VCloudXClient defaultApi, - @Org URI endPoint, @Named(VCloudXConstants.PROPERTY_VCLOUDX_USER) String account) { - return new RestContextImpl(closer, defaultApi, endPoint, account); + RestContext provideContext(Closer closer, VCloudClient defaultApi, + @Org URI endPoint, @Named(VCloudConstants.PROPERTY_VCLOUD_USER) String account) { + return new RestContextImpl(closer, defaultApi, endPoint, account); } } \ No newline at end of file diff --git a/vcloudx/core/src/main/java/org/jclouds/vcloudx/config/BaseVCloudXRestClientModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/config/BaseVCloudRestClientModule.java similarity index 61% rename from vcloudx/core/src/main/java/org/jclouds/vcloudx/config/BaseVCloudXRestClientModule.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/config/BaseVCloudRestClientModule.java index 58ab5b0ffb..dcb7613b8a 100644 --- a/vcloudx/core/src/main/java/org/jclouds/vcloudx/config/BaseVCloudXRestClientModule.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/config/BaseVCloudRestClientModule.java @@ -21,37 +21,53 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloudx.config; +package org.jclouds.vcloud.config; + +import java.net.URI; import javax.inject.Singleton; import org.jclouds.http.RequiresHttp; import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.RestClientFactory; -import org.jclouds.vcloudx.VCloudXClient; +import org.jclouds.vcloud.VCloudClient; +import org.jclouds.vcloud.VCloudDiscovery; +import org.jclouds.vcloud.endpoints.Catalog; +import org.jclouds.vcloud.endpoints.VDC; import com.google.inject.AbstractModule; import com.google.inject.Provides; /** - * Configures the VCloudX authentication service connection, including logging and http - * transport. + * Configures the VCloud authentication service connection, including logging and http transport. * * @author Adrian Cole */ @RequiresHttp @ConfiguresRestClient -public class BaseVCloudXRestClientModule extends AbstractModule { +public class BaseVCloudRestClientModule extends AbstractModule { @Override protected void configure() { } - + @Provides @Singleton - protected VCloudXClient provideVCloudXClient(RestClientFactory factory) { - return factory.create(VCloudXClient.class); + protected VCloudClient provideVCloudClient(RestClientFactory factory) { + return factory.create(VCloudClient.class); } + @Provides + @Catalog + @Singleton + protected URI provideCatalog(VCloudDiscovery discovery) { + return discovery.getOrganization().getCatalog().getLocation(); + } + @Provides + @VDC + @Singleton + protected URI provideDefaultVDC(VCloudDiscovery discovery) { + return discovery.getOrganization().getVDCs().values().iterator().next().getLocation(); + } } diff --git a/vcloudx/core/src/main/java/org/jclouds/vcloudx/config/RestVCloudXAuthenticationModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudDiscoveryRestClientModule.java similarity index 55% rename from vcloudx/core/src/main/java/org/jclouds/vcloudx/config/RestVCloudXAuthenticationModule.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudDiscoveryRestClientModule.java index 05509c9ea4..4dea1b7381 100755 --- a/vcloudx/core/src/main/java/org/jclouds/vcloudx/config/RestVCloudXAuthenticationModule.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudDiscoveryRestClientModule.java @@ -21,12 +21,12 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloudx.config; +package org.jclouds.vcloud.config; -import static org.jclouds.vcloudx.reference.VCloudXConstants.PROPERTY_VCLOUDX_ENDPOINT; -import static org.jclouds.vcloudx.reference.VCloudXConstants.PROPERTY_VCLOUDX_KEY; -import static org.jclouds.vcloudx.reference.VCloudXConstants.PROPERTY_VCLOUDX_SESSIONINTERVAL; -import static org.jclouds.vcloudx.reference.VCloudXConstants.PROPERTY_VCLOUDX_USER; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPOINT; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER; import java.io.UnsupportedEncodingException; import java.net.URI; @@ -39,23 +39,24 @@ import org.jclouds.concurrent.ExpirableSupplier; import org.jclouds.http.RequiresHttp; import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.rest.RestClientFactory; -import org.jclouds.vcloudx.VCloudToken; -import org.jclouds.vcloudx.VCloudXLogin; -import org.jclouds.vcloudx.VCloudXLogin.VCloudXSession; -import org.jclouds.vcloudx.endpoints.Org; -import org.jclouds.vcloudx.endpoints.VCloudX; +import org.jclouds.vcloud.VCloudDiscovery; +import org.jclouds.vcloud.VCloudLogin; +import org.jclouds.vcloud.VCloudToken; +import org.jclouds.vcloud.VCloudLogin.VCloudSession; +import org.jclouds.vcloud.endpoints.Org; +import org.jclouds.vcloud.endpoints.VCloud; import com.google.common.base.Supplier; import com.google.inject.AbstractModule; import com.google.inject.Provides; /** - * Configures the VCloudX authentication service connection, including logging and http transport. + * Configures the VCloud authentication service connection, including logging and http transport. * * @author Adrian Cole */ @RequiresHttp -public class RestVCloudXAuthenticationModule extends AbstractModule { +public class VCloudDiscoveryRestClientModule extends AbstractModule { @Override protected void configure() { @@ -63,14 +64,15 @@ public class RestVCloudXAuthenticationModule extends AbstractModule { @VCloudToken @Provides - String provideVCloudToken(Supplier cache) { + String provideVCloudToken(Supplier cache) { return cache.get().getVCloudToken(); } @Provides @Org - protected URI provideOrg(VCloudXLogin login) { - return login.login().getOrg(); + @Singleton + protected URI provideOrg(Supplier cache, @Named(PROPERTY_VCLOUD_USER) String user) { + return cache.get().getOrgs().get(user).getLocation(); } /** @@ -78,10 +80,10 @@ public class RestVCloudXAuthenticationModule extends AbstractModule { */ @Provides @Singleton - Supplier provideVCloudTokenCache( - @Named(PROPERTY_VCLOUDX_SESSIONINTERVAL) long seconds, final VCloudXLogin login) { - return new ExpirableSupplier(new Supplier() { - public VCloudXSession get() { + Supplier provideVCloudTokenCache( + @Named(PROPERTY_VCLOUD_SESSIONINTERVAL) long seconds, final VCloudLogin login) { + return new ExpirableSupplier(new Supplier() { + public VCloudSession get() { return login.login(); } }, seconds, TimeUnit.SECONDS); @@ -89,21 +91,27 @@ public class RestVCloudXAuthenticationModule extends AbstractModule { @Provides @Singleton - @VCloudX - protected URI provideAuthenticationURI(@Named(PROPERTY_VCLOUDX_ENDPOINT) String endpoint) { + @VCloud + protected URI provideAuthenticationURI(@Named(PROPERTY_VCLOUD_ENDPOINT) String endpoint) { return URI.create(endpoint); } @Provides @Singleton - protected VCloudXLogin provideVCloudXLogin(RestClientFactory factory) { - return factory.create(VCloudXLogin.class); + protected VCloudLogin provideVCloudLogin(RestClientFactory factory) { + return factory.create(VCloudLogin.class); } @Provides @Singleton - public BasicAuthentication provideBasicAuthentication(@Named(PROPERTY_VCLOUDX_USER) String user, - @Named(PROPERTY_VCLOUDX_KEY) String key) throws UnsupportedEncodingException { + protected VCloudDiscovery provideVCloudDiscovery(RestClientFactory factory) { + return factory.create(VCloudDiscovery.class); + } + + @Provides + @Singleton + public BasicAuthentication provideBasicAuthentication(@Named(PROPERTY_VCLOUD_USER) String user, + @Named(PROPERTY_VCLOUD_KEY) String key) throws UnsupportedEncodingException { return new BasicAuthentication(user, key); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Catalog.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Catalog.java new file mode 100644 index 0000000000..485a15cf66 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Catalog.java @@ -0,0 +1,39 @@ +/** + * + * Copyright (C) 2009 Global Cloud Specialists, Inc. + * + * ==================================================================== + * 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.vcloud.domain; + +import java.util.Map; + +import org.jclouds.vcloud.domain.internal.CatalogImpl; + +import com.google.inject.ImplementedBy; + +/** + * @author Adrian Cole + */ +@org.jclouds.vcloud.endpoints.Catalog +@ImplementedBy(CatalogImpl.class) +public interface Catalog extends Link, Map { + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Link.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Link.java new file mode 100644 index 0000000000..45feccbadb --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Link.java @@ -0,0 +1,47 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.vcloud.domain; + +import java.net.URI; + +import org.jclouds.vcloud.domain.internal.LinkImpl; + +import com.google.inject.ImplementedBy; + +/** + * Location of a vCloud resource + * + * @author Adrian Cole + * + */ +@ImplementedBy(LinkImpl.class) +public interface Link { + + String getName(); + + String getType(); + + URI getLocation(); + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Organization.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Organization.java new file mode 100644 index 0000000000..845882e68b --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Organization.java @@ -0,0 +1,52 @@ +/** + * + * Copyright (C) 2009 Global Cloud Specialists, Inc. + * + * ==================================================================== + * 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.vcloud.domain; + +import java.util.Map; + +import org.jclouds.vcloud.domain.internal.OrganizationImpl; +import org.jclouds.vcloud.endpoints.Catalog; +import org.jclouds.vcloud.endpoints.Org; +import org.jclouds.vcloud.endpoints.TasksList; +import org.jclouds.vcloud.endpoints.VDC; + +import com.google.inject.ImplementedBy; + +/** + * @author Adrian Cole + */ +@Org +@ImplementedBy(OrganizationImpl.class) +public interface Organization extends Link { + + @Catalog + Link getCatalog(); + + @VDC + Map getVDCs(); + + @TasksList + Map getTasksLists(); + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/CatalogImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/CatalogImpl.java new file mode 100644 index 0000000000..dd56897a2c --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/CatalogImpl.java @@ -0,0 +1,91 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.vcloud.domain.internal; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; +import java.util.HashMap; +import java.util.Map; + +import org.jclouds.vcloud.domain.Catalog; +import org.jclouds.vcloud.domain.Link; + +/** + * Locations of resources in vCloud + * + * @author Adrian Cole + * + */ +public class CatalogImpl extends HashMap implements Catalog { + + /** The serialVersionUID */ + private static final long serialVersionUID = 8464716396538298809L; + private final Link catalog; + + public CatalogImpl(String name, String type, URI location, Map contents) { + super(contents.size()); + this.catalog = new LinkImpl(checkNotNull(name, "name"), checkNotNull(type, "type"), + checkNotNull(location, "location")); + putAll(checkNotNull(contents, "contents")); + } + + public URI getLocation() { + return catalog.getLocation(); + } + + public String getName() { + return catalog.getName(); + } + + public String getType() { + return catalog.getType(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((catalog == null) ? 0 : catalog.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + CatalogImpl other = (CatalogImpl) obj; + if (catalog == null) { + if (other.catalog != null) + return false; + } else if (!catalog.equals(other.catalog)) + return false; + return true; + } + +} \ No newline at end of file diff --git a/vcloudx/core/src/main/java/org/jclouds/vcloudx/domain/OrgLinks.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/LinkImpl.java similarity index 54% rename from vcloudx/core/src/main/java/org/jclouds/vcloudx/domain/OrgLinks.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/LinkImpl.java index c3b40a81dc..e25deaabaa 100644 --- a/vcloudx/core/src/main/java/org/jclouds/vcloudx/domain/OrgLinks.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/LinkImpl.java @@ -21,65 +21,53 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloudx.domain; +package org.jclouds.vcloud.domain.internal; import java.net.URI; -import java.util.Set; -import javax.inject.Singleton; +import org.jclouds.vcloud.domain.Link; /** - * Locations of resources in VCloud Express + * Location of a vCloud resource * * @author Adrian Cole * */ -@Singleton -public class OrgLinks { - +public class LinkImpl implements Link { private final String name; - private final URI org; - private final URI catalog; - private final Set vDCs; - private final Set taskLists; + private final String type; + private final URI location; - public OrgLinks(String name, URI org, URI catalog, Set vDCs, Set tasksLists) { + public LinkImpl(String name, String type, URI location) { this.name = name; - this.org = org; - this.catalog = catalog; - this.vDCs = vDCs; - this.taskLists = tasksLists; + this.type = type; + this.location = location; } public String getName() { return name; } - public URI getOrg() { - return org; + public String getType() { + return type; } - public URI getCatalog() { - return catalog; + public URI getLocation() { + return location; } - public Set getVDCs() { - return vDCs; - } - - public Set getTaskLists() { - return taskLists; + @Override + public String toString() { + return "Link [name=" + name + ", type=" + type + ", location=" + location + "]"; } @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((catalog == null) ? 0 : catalog.hashCode()); + result = prime * result + ((location == null) ? 0 : location.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result + ((org == null) ? 0 : org.hashCode()); - result = prime * result + ((taskLists == null) ? 0 : taskLists.hashCode()); - result = prime * result + ((vDCs == null) ? 0 : vDCs.hashCode()); + result = prime * result + ((type == null) ? 0 : type.hashCode()); return result; } @@ -91,33 +79,22 @@ public class OrgLinks { return false; if (getClass() != obj.getClass()) return false; - OrgLinks other = (OrgLinks) obj; - if (catalog == null) { - if (other.catalog != null) + LinkImpl other = (LinkImpl) obj; + if (location == null) { + if (other.location != null) return false; - } else if (!catalog.equals(other.catalog)) + } else if (!location.equals(other.location)) return false; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; - if (org == null) { - if (other.org != null) + if (type == null) { + if (other.type != null) return false; - } else if (!org.equals(other.org)) - return false; - if (taskLists == null) { - if (other.taskLists != null) - return false; - } else if (!taskLists.equals(other.taskLists)) - return false; - if (vDCs == null) { - if (other.vDCs != null) - return false; - } else if (!vDCs.equals(other.vDCs)) + } else if (!type.equals(other.type)) return false; return true; } - } \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/OrganizationImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/OrganizationImpl.java new file mode 100644 index 0000000000..24092d0cd0 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/OrganizationImpl.java @@ -0,0 +1,107 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.vcloud.domain.internal; + +import java.net.URI; +import java.util.Map; + +import org.jclouds.vcloud.domain.Link; +import org.jclouds.vcloud.domain.Organization; +import org.jclouds.vcloud.endpoints.Catalog; +import org.jclouds.vcloud.endpoints.TasksList; +import org.jclouds.vcloud.endpoints.VDC; + +/** + * Locations of resources in vCloud + * + * @author Adrian Cole + * + */ +public class OrganizationImpl extends LinkImpl implements Organization { + + private final Link catalog; + private final Map vdcs; + private final Map tasksLists; + + public OrganizationImpl(String name, String type, URI location, Link catalog, + Map vdcs, Map tasksLists) { + super(name, type, location); + this.catalog = catalog; + this.vdcs = vdcs; + this.tasksLists = tasksLists; + } + + @Catalog + public Link getCatalog() { + return catalog; + } + + @VDC + public Map getVDCs() { + return vdcs; + } + + @TasksList + public Map getTasksLists() { + return tasksLists; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((catalog == null) ? 0 : catalog.hashCode()); + result = prime * result + ((tasksLists == null) ? 0 : tasksLists.hashCode()); + result = prime * result + ((vdcs == null) ? 0 : vdcs.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + OrganizationImpl other = (OrganizationImpl) obj; + if (catalog == null) { + if (other.catalog != null) + return false; + } else if (!catalog.equals(other.catalog)) + return false; + if (tasksLists == null) { + if (other.tasksLists != null) + return false; + } else if (!tasksLists.equals(other.tasksLists)) + return false; + if (vdcs == null) { + if (other.vdcs != null) + return false; + } else if (!vdcs.equals(other.vdcs)) + return false; + return true; + } + +} \ No newline at end of file diff --git a/vcloudx/core/src/main/java/org/jclouds/vcloudx/endpoints/Catalog.java b/vcloud/core/src/main/java/org/jclouds/vcloud/endpoints/Catalog.java similarity index 88% rename from vcloudx/core/src/main/java/org/jclouds/vcloudx/endpoints/Catalog.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/endpoints/Catalog.java index 7b342457ce..600ba76e23 100644 --- a/vcloudx/core/src/main/java/org/jclouds/vcloudx/endpoints/Catalog.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/endpoints/Catalog.java @@ -21,7 +21,7 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloudx.endpoints; +package org.jclouds.vcloud.endpoints; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -31,13 +31,13 @@ import java.lang.annotation.Target; import javax.inject.Qualifier; /** - * Related to a VCloud express vDC. + * Related to a VCloud Catalog. * * @author Adrian Cole * */ @Retention(value = RetentionPolicy.RUNTIME) -@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD }) +@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD }) @Qualifier public @interface Catalog { diff --git a/vcloudx/core/src/main/java/org/jclouds/vcloudx/endpoints/Org.java b/vcloud/core/src/main/java/org/jclouds/vcloud/endpoints/Org.java similarity index 90% rename from vcloudx/core/src/main/java/org/jclouds/vcloudx/endpoints/Org.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/endpoints/Org.java index 7472f6e833..59a47f53b2 100644 --- a/vcloudx/core/src/main/java/org/jclouds/vcloudx/endpoints/Org.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/endpoints/Org.java @@ -21,7 +21,7 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloudx.endpoints; +package org.jclouds.vcloud.endpoints; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -37,7 +37,7 @@ import javax.inject.Qualifier; * */ @Retention(value = RetentionPolicy.RUNTIME) -@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD }) +@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD }) @Qualifier public @interface Org { diff --git a/vcloudx/core/src/main/java/org/jclouds/vcloudx/endpoints/TaskList.java b/vcloud/core/src/main/java/org/jclouds/vcloud/endpoints/TasksList.java similarity index 95% rename from vcloudx/core/src/main/java/org/jclouds/vcloudx/endpoints/TaskList.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/endpoints/TasksList.java index 2b05c94330..3ac64b4398 100644 --- a/vcloudx/core/src/main/java/org/jclouds/vcloudx/endpoints/TaskList.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/endpoints/TasksList.java @@ -21,7 +21,7 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloudx.endpoints; +package org.jclouds.vcloud.endpoints; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -39,6 +39,6 @@ import javax.inject.Qualifier; @Retention(value = RetentionPolicy.RUNTIME) @Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD }) @Qualifier -public @interface TaskList { +public @interface TasksList { } \ No newline at end of file diff --git a/vcloudx/core/src/main/java/org/jclouds/vcloudx/endpoints/VCloudX.java b/vcloud/core/src/main/java/org/jclouds/vcloud/endpoints/VCloud.java similarity index 92% rename from vcloudx/core/src/main/java/org/jclouds/vcloudx/endpoints/VCloudX.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/endpoints/VCloud.java index 7735bc90bb..0f319f9e43 100644 --- a/vcloudx/core/src/main/java/org/jclouds/vcloudx/endpoints/VCloudX.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/endpoints/VCloud.java @@ -21,7 +21,7 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloudx.endpoints; +package org.jclouds.vcloud.endpoints; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -31,7 +31,7 @@ import java.lang.annotation.Target; import javax.inject.Qualifier; /** - * Represents a component related to VCloud Express. + * Represents a component related to vCloud. * * @see * @author Adrian Cole @@ -40,6 +40,6 @@ import javax.inject.Qualifier; @Retention(value = RetentionPolicy.RUNTIME) @Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD }) @Qualifier -public @interface VCloudX { +public @interface VCloud { } diff --git a/vcloudx/core/src/main/java/org/jclouds/vcloudx/endpoints/VDC.java b/vcloud/core/src/main/java/org/jclouds/vcloud/endpoints/VDC.java similarity index 97% rename from vcloudx/core/src/main/java/org/jclouds/vcloudx/endpoints/VDC.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/endpoints/VDC.java index 43779edcc2..0635a111b6 100644 --- a/vcloudx/core/src/main/java/org/jclouds/vcloudx/endpoints/VDC.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/endpoints/VDC.java @@ -21,7 +21,7 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloudx.endpoints; +package org.jclouds.vcloud.endpoints; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/vcloudx/core/src/main/java/org/jclouds/vcloudx/filters/SetVCloudTokenCookie.java b/vcloud/core/src/main/java/org/jclouds/vcloud/filters/SetVCloudTokenCookie.java similarity index 96% rename from vcloudx/core/src/main/java/org/jclouds/vcloudx/filters/SetVCloudTokenCookie.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/filters/SetVCloudTokenCookie.java index 35ec57d897..56218deb99 100644 --- a/vcloudx/core/src/main/java/org/jclouds/vcloudx/filters/SetVCloudTokenCookie.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/filters/SetVCloudTokenCookie.java @@ -21,7 +21,7 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloudx.filters; +package org.jclouds.vcloud.filters; import java.util.Collections; @@ -32,7 +32,7 @@ import javax.inject.Singleton; import org.jclouds.http.HttpException; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequestFilter; -import org.jclouds.vcloudx.VCloudToken; +import org.jclouds.vcloud.VCloudToken; /** * Adds the VCloud Token to the request as a cookie diff --git a/vcloudx/core/src/main/java/org/jclouds/vcloudx/functions/ParseLoginResponseFromHeaders.java b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/ParseLoginResponseFromHeaders.java similarity index 76% rename from vcloudx/core/src/main/java/org/jclouds/vcloudx/functions/ParseLoginResponseFromHeaders.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/functions/ParseLoginResponseFromHeaders.java index d957385a03..fba6f838c8 100755 --- a/vcloudx/core/src/main/java/org/jclouds/vcloudx/functions/ParseLoginResponseFromHeaders.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/ParseLoginResponseFromHeaders.java @@ -21,11 +21,11 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloudx.functions; +package org.jclouds.vcloud.functions; import static com.google.common.base.Preconditions.checkNotNull; -import java.net.URI; +import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -38,36 +38,37 @@ import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponseException; import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax.Factory; -import org.jclouds.vcloudx.VCloudToken; -import org.jclouds.vcloudx.VCloudXLogin.VCloudXSession; -import org.jclouds.vcloudx.endpoints.Org; -import org.jclouds.vcloudx.xml.OrgListToOrgUriHandler; +import org.jclouds.vcloud.VCloudToken; +import org.jclouds.vcloud.VCloudLogin.VCloudSession; +import org.jclouds.vcloud.domain.Link; +import org.jclouds.vcloud.endpoints.Org; +import org.jclouds.vcloud.xml.OrgListHandler; import com.google.common.base.Function; /** - * This parses {@link VCloudXSession} from HTTP headers. + * This parses {@link VCloudSession} from HTTP headers. * * @author Adrian Cole */ @Singleton -public class ParseLoginResponseFromHeaders implements Function { +public class ParseLoginResponseFromHeaders implements Function { static final Pattern pattern = Pattern.compile("vcloud-token=(.*); path=.*"); private final ParseSax.Factory factory; - private final Provider orgHandlerProvider; + private final Provider orgHandlerProvider; @Inject private ParseLoginResponseFromHeaders(Factory factory, - Provider orgHandlerProvider) { + Provider orgHandlerProvider) { this.factory = factory; this.orgHandlerProvider = orgHandlerProvider; } /** - * parses the http response headers to create a new {@link VCloudXSession} object. + * parses the http response headers to create a new {@link VCloudSession} object. */ - public VCloudXSession apply(HttpResponse from) { + public VCloudSession apply(HttpResponse from) { String cookieHeader = checkNotNull(from.getFirstHeaderOrNull(HttpHeaders.SET_COOKIE), HttpHeaders.SET_COOKIE); @@ -75,16 +76,17 @@ public class ParseLoginResponseFromHeaders implements Function org = factory.create(orgHandlerProvider.get()).parse( + from.getContent()); - return new VCloudXSession() { + return new VCloudSession() { @VCloudToken public String getVCloudToken() { return matcher.group(1); } @Org - public URI getOrg() { + public Map getOrgs() { return org; } }; diff --git a/vcloudx/core/src/main/java/org/jclouds/vcloudx/reference/VCloudXConstants.java b/vcloud/core/src/main/java/org/jclouds/vcloud/reference/VCloudConstants.java similarity index 70% rename from vcloudx/core/src/main/java/org/jclouds/vcloudx/reference/VCloudXConstants.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/reference/VCloudConstants.java index 0d10648069..fe6dcaca8f 100644 --- a/vcloudx/core/src/main/java/org/jclouds/vcloudx/reference/VCloudXConstants.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/reference/VCloudConstants.java @@ -21,19 +21,19 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloudx.reference; +package org.jclouds.vcloud.reference; /** - * Configuration properties and constants used in VCloudX connections. + * Configuration properties and constants used in VCloud connections. * * @author Adrian Cole */ -public interface VCloudXConstants { - public static final String PROPERTY_VCLOUDX_ENDPOINT = "jclouds.vcloudx.endpoint"; - public static final String PROPERTY_VCLOUDX_USER = "jclouds.vcloudx.user"; - public static final String PROPERTY_VCLOUDX_KEY = "jclouds.vcloudx.key"; +public interface VCloudConstants { + public static final String PROPERTY_VCLOUD_ENDPOINT = "jclouds.vcloud.endpoint"; + public static final String PROPERTY_VCLOUD_USER = "jclouds.vcloud.user"; + public static final String PROPERTY_VCLOUD_KEY = "jclouds.vcloud.key"; /** * automatically renew vcloud token before this interval expires. */ - public static final String PROPERTY_VCLOUDX_SESSIONINTERVAL = "jclouds.vcloudx.sessioninterval"; + public static final String PROPERTY_VCLOUD_SESSIONINTERVAL = "jclouds.vcloud.sessioninterval"; } diff --git a/vcloudx/core/src/main/java/org/jclouds/vcloudx/reference/package-info.java b/vcloud/core/src/main/java/org/jclouds/vcloud/reference/package-info.java similarity index 89% rename from vcloudx/core/src/main/java/org/jclouds/vcloudx/reference/package-info.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/reference/package-info.java index a3b68da07e..182eefbaa6 100755 --- a/vcloudx/core/src/main/java/org/jclouds/vcloudx/reference/package-info.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/reference/package-info.java @@ -22,7 +22,7 @@ * ==================================================================== */ /** - * This package contains properties and reference data used in VCloud Express. + * This package contains properties and reference data used in vCloud. * @author Adrian Cole */ -package org.jclouds.vcloudx.reference; +package org.jclouds.vcloud.reference; diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/util/Utils.java b/vcloud/core/src/main/java/org/jclouds/vcloud/util/Utils.java new file mode 100644 index 0000000000..35bca128d0 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/util/Utils.java @@ -0,0 +1,48 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.vcloud.util; + +import java.net.URI; +import java.util.Map; + +import org.jclouds.vcloud.domain.Link; +import org.jclouds.vcloud.domain.internal.LinkImpl; +import org.xml.sax.Attributes; + +/** + * + * @author Adrian Cole + */ +public class Utils { + + public static void putLink(Map map, Attributes attributes) { + map.put(attributes.getValue(attributes.getIndex("name")), newLink(attributes)); + } + + public static Link newLink(Attributes attributes) { + return new LinkImpl(attributes.getValue(attributes.getIndex("name")), attributes + .getValue(attributes.getIndex("type")), URI.create(attributes.getValue(attributes + .getIndex("href")))); + } +} diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/CatalogHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/CatalogHandler.java new file mode 100644 index 0000000000..25446190c3 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/CatalogHandler.java @@ -0,0 +1,64 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.vcloud.xml; + +import static org.jclouds.vcloud.util.Utils.putLink; + +import java.net.URI; +import java.util.Map; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.vcloud.domain.Catalog; +import org.jclouds.vcloud.domain.Link; +import org.jclouds.vcloud.domain.internal.CatalogImpl; +import org.jclouds.vcloud.domain.internal.LinkImpl; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +import com.google.common.collect.Maps; + +/** + * @author Adrian Cole + */ +public class CatalogHandler extends ParseSax.HandlerWithResult { + private Link Catalog; + private Map contents = Maps.newHashMap(); + + public Catalog getResult() { + return new CatalogImpl(Catalog.getName(), Catalog.getType(), Catalog.getLocation(), contents); + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attributes) + throws SAXException { + if (qName.equals("Catalog")) { + Catalog = new LinkImpl(attributes.getValue(attributes.getIndex("name")), attributes + .getValue(attributes.getIndex("type")), URI.create(attributes.getValue(attributes + .getIndex("href")))); + } else if (qName.equals("CatalogItem")) { + putLink(contents, attributes); + } + } + +} diff --git a/vcloudx/core/src/main/java/org/jclouds/vcloudx/xml/OrgLinksHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/OrgHandler.java similarity index 54% rename from vcloudx/core/src/main/java/org/jclouds/vcloudx/xml/OrgLinksHandler.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/xml/OrgHandler.java index 091736baff..28357d4bf3 100644 --- a/vcloudx/core/src/main/java/org/jclouds/vcloudx/xml/OrgLinksHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/OrgHandler.java @@ -21,68 +21,60 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloudx.xml; +package org.jclouds.vcloud.xml; -import static org.jclouds.vcloudx.VCloudXMediaType.CATALOG_XML; -import static org.jclouds.vcloudx.VCloudXMediaType.TASKSLIST_XML; -import static org.jclouds.vcloudx.VCloudXMediaType.VDC_XML; +import static org.jclouds.vcloud.VCloudMediaType.CATALOG_XML; +import static org.jclouds.vcloud.VCloudMediaType.ORG_XML; +import static org.jclouds.vcloud.VCloudMediaType.TASKSLIST_XML; +import static org.jclouds.vcloud.VCloudMediaType.VDC_XML; +import static org.jclouds.vcloud.util.Utils.newLink; +import static org.jclouds.vcloud.util.Utils.putLink; import java.net.URI; -import java.util.Set; +import java.util.Map; import org.jclouds.http.functions.ParseSax; -import org.jclouds.vcloudx.domain.OrgLinks; +import org.jclouds.vcloud.domain.Link; +import org.jclouds.vcloud.domain.Organization; +import org.jclouds.vcloud.domain.internal.LinkImpl; +import org.jclouds.vcloud.domain.internal.OrganizationImpl; import org.xml.sax.Attributes; import org.xml.sax.SAXException; -import com.google.common.collect.Sets; +import com.google.common.collect.Maps; /** * @author Adrian Cole */ -public class OrgLinksHandler extends ParseSax.HandlerWithResult { - private String name; - private URI org; - private Set vdcs = Sets.newHashSet(); - private Set tasksLists = Sets.newHashSet(); - private URI catalog; +public class OrgHandler extends ParseSax.HandlerWithResult { + private Link org; + private Map vdcs = Maps.newHashMap(); + private Map tasksLists = Maps.newHashMap(); + private Link catalog; - public OrgLinks getResult() { - return new OrgLinks(name, org, catalog, vdcs, tasksLists); + public Organization getResult() { + return new OrganizationImpl(org.getName(), org.getType(), org.getLocation(), catalog, vdcs, + tasksLists); } @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if (qName.equals("Org")) { - int index = attributes.getIndex("href"); - if (index != -1) { - org = URI.create(attributes.getValue(index)); - } - index = attributes.getIndex("name"); - if (index != -1) { - name = attributes.getValue(index); - } + org = new LinkImpl(attributes.getValue(attributes.getIndex("name")), ORG_XML, URI + .create(attributes.getValue(attributes.getIndex("href")))); } else if (qName.equals("Link")) { int typeIndex = attributes.getIndex("type"); if (typeIndex != -1) { if (attributes.getValue(typeIndex).equals(VDC_XML)) { - int index = attributes.getIndex("href"); - if (index != -1) { - vdcs.add(URI.create(attributes.getValue(index))); - } + putLink(vdcs, attributes); } else if (attributes.getValue(typeIndex).equals(CATALOG_XML)) { - int index = attributes.getIndex("href"); - if (index != -1) { - catalog = URI.create(attributes.getValue(index)); - } + catalog = newLink(attributes); } else if (attributes.getValue(typeIndex).equals(TASKSLIST_XML)) { - int index = attributes.getIndex("href"); - if (index != -1) { - tasksLists.add(URI.create(attributes.getValue(index))); - } + putLink(tasksLists, attributes); } } } } + } diff --git a/vcloudx/core/src/main/java/org/jclouds/vcloudx/xml/OrgListToOrgUriHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/OrgListHandler.java similarity index 76% rename from vcloudx/core/src/main/java/org/jclouds/vcloudx/xml/OrgListToOrgUriHandler.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/xml/OrgListHandler.java index d3dbabfafa..0490580202 100755 --- a/vcloudx/core/src/main/java/org/jclouds/vcloudx/xml/OrgListToOrgUriHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/OrgListHandler.java @@ -21,22 +21,28 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloudx.xml; +package org.jclouds.vcloud.xml; + +import static org.jclouds.vcloud.VCloudMediaType.ORG_XML; +import static org.jclouds.vcloud.util.Utils.putLink; + +import java.util.Map; -import java.net.URI; -import static org.jclouds.vcloudx.VCloudXMediaType.*; import org.jclouds.http.functions.ParseSax; +import org.jclouds.vcloud.domain.Link; import org.xml.sax.Attributes; import org.xml.sax.SAXException; +import com.google.common.collect.Maps; + /** * @author Adrian Cole */ -public class OrgListToOrgUriHandler extends ParseSax.HandlerWithResult { +public class OrgListHandler extends ParseSax.HandlerWithResult> { - private URI org; + private Map org = Maps.newHashMap(); - public URI getResult() { + public Map getResult() { return org; } @@ -47,10 +53,7 @@ public class OrgListToOrgUriHandler extends ParseSax.HandlerWithResult { int typeIndex = attributes.getIndex("type"); if (typeIndex != -1) { if (attributes.getValue(typeIndex).equals(ORG_XML)) { - int index = attributes.getIndex("href"); - if (index != -1) { - org = URI.create(attributes.getValue(index)); - } + putLink(org, attributes); } } } diff --git a/vcloudx/core/src/test/java/org/jclouds/vcloudx/BaseVCloudXContextBuilderTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/BaseVCloudContextBuilderTest.java similarity index 60% rename from vcloudx/core/src/test/java/org/jclouds/vcloudx/BaseVCloudXContextBuilderTest.java rename to vcloud/core/src/test/java/org/jclouds/vcloud/BaseVCloudContextBuilderTest.java index f184d66a6c..d8b86ae74b 100755 --- a/vcloudx/core/src/test/java/org/jclouds/vcloudx/BaseVCloudXContextBuilderTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/BaseVCloudContextBuilderTest.java @@ -21,9 +21,13 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloudx; +package org.jclouds.vcloud; import static org.easymock.classextension.EasyMock.createMock; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPOINT; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER; import static org.testng.Assert.assertEquals; import java.net.URI; @@ -34,10 +38,9 @@ import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContextBuilder; import org.jclouds.rest.internal.RestContextImpl; -import org.jclouds.vcloudx.config.BaseVCloudXContextModule; -import org.jclouds.vcloudx.config.BaseVCloudXRestClientModule; -import org.jclouds.vcloudx.endpoints.Org; -import org.jclouds.vcloudx.reference.VCloudXConstants; +import org.jclouds.vcloud.config.BaseVCloudContextModule; +import org.jclouds.vcloud.config.BaseVCloudRestClientModule; +import org.jclouds.vcloud.endpoints.Org; import org.testng.annotations.Test; import com.google.inject.AbstractModule; @@ -47,72 +50,70 @@ import com.google.inject.Module; import com.google.inject.TypeLiteral; /** - * Tests behavior of modules configured in BaseVCloudXContextBuilder + * Tests behavior of modules configured in BaseVCloudContextBuilder * * @author Adrian Cole */ -@Test(groups = "unit", testName = "vcloudx.BaseVCloudXContextBuilderTest") -public class BaseVCloudXContextBuilderTest { - VCloudXClient connection = createMock(VCloudXClient.class); +@Test(groups = "unit", testName = "vcloud.BaseVCloudContextBuilderTest") +public class BaseVCloudContextBuilderTest { + VCloudClient connection = createMock(VCloudClient.class); @ConfiguresRestClient private final class StubClientModule extends AbstractModule { @Override protected void configure() { bind(URI.class).annotatedWith(Org.class).toInstance(URI.create("http://org")); - bind(VCloudXClient.class).toInstance(connection); + bind(VCloudClient.class).toInstance(connection); } } public void testNewBuilder() { - RestContextBuilder builder = builder(); + RestContextBuilder builder = builder(); - assertEquals(builder.getProperties().getProperty(VCloudXConstants.PROPERTY_VCLOUDX_ENDPOINT), + assertEquals(builder.getProperties().getProperty(PROPERTY_VCLOUD_ENDPOINT), "http://localhost"); - assertEquals(builder.getProperties().getProperty(VCloudXConstants.PROPERTY_VCLOUDX_USER), - "id"); - assertEquals(builder.getProperties().getProperty(VCloudXConstants.PROPERTY_VCLOUDX_KEY), - "secret"); - assertEquals(builder.getProperties().getProperty( - VCloudXConstants.PROPERTY_VCLOUDX_SESSIONINTERVAL), "540"); + assertEquals(builder.getProperties().getProperty(PROPERTY_VCLOUD_USER), "id"); + assertEquals(builder.getProperties().getProperty(PROPERTY_VCLOUD_KEY), "secret"); + assertEquals(builder.getProperties().getProperty(PROPERTY_VCLOUD_SESSIONINTERVAL), "540"); } public void testBuildContext() { - RestContextBuilder builder = builder(); - RestContext context = builder.buildContext(); + RestContextBuilder builder = builder(); + RestContext context = builder.buildContext(); assertEquals(context.getClass(), RestContextImpl.class); assertEquals(context.getApi(), connection); assertEquals(context.getAccount(), "id"); assertEquals(context.getEndPoint(), URI.create("http://org")); } - public BaseVCloudXContextBuilder builder() { - return new BaseVCloudXContextBuilder(new VCloudXPropertiesBuilder(URI + public BaseVCloudContextBuilder builder() { + return new BaseVCloudContextBuilder(new VCloudPropertiesBuilder(URI .create("http://localhost"), "id", "secret").build()) .withModules(new StubClientModule()); } public void testBuildInjector() { - RestContextBuilder builder = builder(); + RestContextBuilder builder = builder(); Injector i = builder.buildInjector(); - assert i.getInstance(Key.get(new TypeLiteral>() { + assert i.getInstance(Key.get(URI.class, Org.class)) != null; + assert i.getInstance(Key.get(new TypeLiteral>() { })) != null; } protected void testAddContextModule() { List modules = new ArrayList(); - BaseVCloudXContextBuilder builder = builder(); + BaseVCloudContextBuilder builder = builder(); builder.addContextModule(modules); assertEquals(modules.size(), 1); - assertEquals(modules.get(0).getClass(), BaseVCloudXContextModule.class); + assertEquals(modules.get(0).getClass(), BaseVCloudContextModule.class); } protected void addClientModule() { List modules = new ArrayList(); - BaseVCloudXContextBuilder builder = builder(); + BaseVCloudContextBuilder builder = builder(); builder.addClientModule(modules); assertEquals(modules.size(), 1); - assertEquals(modules.get(0).getClass(), BaseVCloudXRestClientModule.class); + assertEquals(modules.get(0).getClass(), BaseVCloudRestClientModule.class); } } diff --git a/vcloudx/core/src/test/java/org/jclouds/vcloudx/VCloudXClientLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java similarity index 69% rename from vcloudx/core/src/test/java/org/jclouds/vcloudx/VCloudXClientLiveTest.java rename to vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java index 75b6980b93..ab4cef7379 100644 --- a/vcloudx/core/src/test/java/org/jclouds/vcloudx/VCloudXClientLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java @@ -21,39 +21,46 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloudx; +package org.jclouds.vcloud; import static com.google.common.base.Preconditions.checkNotNull; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import java.net.URI; +import java.util.concurrent.TimeUnit; import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.vcloudx.domain.OrgLinks; +import org.jclouds.vcloud.domain.Catalog; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; /** - * Tests behavior of {@code VCloudXClient} + * Tests behavior of {@code VCloudClient} * * @author Adrian Cole */ -@Test(groups = "live", sequential = true, testName = "vcloudx.VCloudXClientLiveTest") -public class VCloudXClientLiveTest { +@Test(groups = "live", sequential = true, testName = "vcloud.VCloudClientLiveTest") +public class VCloudClientLiveTest { - private VCloudXClient connection; + private VCloudClient connection; private String account; @Test public void testOrganization() throws Exception { - OrgLinks response = connection.getOrganization(); + Catalog response = connection.getCatalog().get(10, TimeUnit.SECONDS); assertNotNull(response); - assertEquals(response.getName(), account); - assertNotNull(response.getOrg()); - assertNotNull(response.getCatalog()); - assertEquals(response.getTaskLists().size(), 1); - assertEquals(response.getVDCs().size(), 1); + assertNotNull(response.getName()); + assertNotNull(response.getLocation()); + assertEquals(response.getType(), "application/vnd.vmware.vcloud.catalog+xml"); + assert response.size() > 0; + } + + @Test + public void testDefaultVDC() throws Exception { + String response = connection.getDefaultVDC(); + assertNotNull(response); +System.err.println(response); } @BeforeGroups(groups = { "live" }) @@ -62,7 +69,7 @@ public class VCloudXClientLiveTest { "jclouds.test.endpoint"); account = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user"); String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key"); - connection = new BaseVCloudXContextBuilder(new VCloudXPropertiesBuilder(URI.create(endpoint), + connection = new BaseVCloudContextBuilder(new VCloudPropertiesBuilder(URI.create(endpoint), account, key).build()).withModules(new Log4JLoggingModule()).buildContext().getApi(); } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientTest.java new file mode 100644 index 0000000000..19b220df8f --- /dev/null +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientTest.java @@ -0,0 +1,127 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.vcloud; + +import static org.testng.Assert.assertEquals; + +import java.io.IOException; +import java.lang.reflect.Method; +import java.net.URI; + +import javax.inject.Provider; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.http.functions.ReturnStringIf200; +import org.jclouds.logging.Logger; +import org.jclouds.logging.Logger.LoggerFactory; +import org.jclouds.rest.RestClientTest; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.jclouds.vcloud.endpoints.Catalog; +import org.jclouds.vcloud.endpoints.VDC; +import org.jclouds.vcloud.filters.SetVCloudTokenCookie; +import org.jclouds.vcloud.xml.CatalogHandler; +import org.testng.annotations.Test; + +import com.google.inject.AbstractModule; +import com.google.inject.Module; +import com.google.inject.TypeLiteral; + +/** + * Tests behavior of {@code VCloudClient} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "vcloud.VCloudClientTest") +public class VCloudClientTest extends RestClientTest { + + public void testCatalog() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudClient.class.getMethod("getCatalog"); + GeneratedHttpRequest httpMethod = processor.createRequest(method); + + assertRequestLineEquals(httpMethod, "GET http://catalog HTTP/1.1"); + assertHeadersEqual(httpMethod,"Accept: application/vnd.vmware.vcloud.catalog+xml\n"); + assertEntityEquals(httpMethod, null); + + assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertSaxResponseParserClassEquals(method, CatalogHandler.class); + assertExceptionParserClassEquals(method, null); + + checkFilters(httpMethod); + } + + public void testGetDefaultVDC() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudClient.class.getMethod("getDefaultVDC"); + GeneratedHttpRequest httpMethod = processor.createRequest(method); + + assertRequestLineEquals(httpMethod, "GET http://vdc HTTP/1.1"); + assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.vdc+xml\n"); + assertEntityEquals(httpMethod, null); + + assertResponseParserClassEquals(method, httpMethod, ReturnStringIf200.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(httpMethod); + } + + @Override + protected void checkFilters(GeneratedHttpRequest httpMethod) { + assertEquals(httpMethod.getFilters().size(), 1); + assertEquals(httpMethod.getFilters().get(0).getClass(), SetVCloudTokenCookie.class); + } + + @Override + protected TypeLiteral> createTypeLiteral() { + return new TypeLiteral>() { + }; + } + + @Override + protected Module createModule() { + return new AbstractModule() { + @Override + protected void configure() { + bind(URI.class).annotatedWith(Catalog.class).toInstance(URI.create("http://catalog")); + bind(URI.class).annotatedWith(VDC.class).toInstance(URI.create("http://vdc")); + bind(SetVCloudTokenCookie.class).toInstance( + new SetVCloudTokenCookie(new Provider() { + + public String get() { + return "token"; + } + + })); + + bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() { + public Logger getLogger(String category) { + return Logger.NULL; + } + }); + } + + }; + } + +} diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudDiscoveryLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudDiscoveryLiveTest.java new file mode 100644 index 0000000000..f9a4e1e2cb --- /dev/null +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudDiscoveryLiveTest.java @@ -0,0 +1,123 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.vcloud; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +import java.net.URI; +import java.util.List; +import java.util.Properties; + +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.concurrent.WithinThreadExecutorService; +import org.jclouds.concurrent.config.ExecutorServiceModule; +import org.jclouds.lifecycle.Closer; +import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.jclouds.rest.RestContext; +import org.jclouds.rest.RestContextBuilder; +import org.jclouds.rest.internal.RestContextImpl; +import org.jclouds.vcloud.config.VCloudDiscoveryRestClientModule; +import org.jclouds.vcloud.domain.Organization; +import org.jclouds.vcloud.endpoints.VCloud; +import org.jclouds.vcloud.reference.VCloudConstants; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.google.inject.AbstractModule; +import com.google.inject.Module; +import com.google.inject.Provides; +import com.google.inject.TypeLiteral; + +/** + * Tests behavior of {@code VCloudDiscovery} + * + * @author Adrian Cole + */ +@Test(groups = "live", sequential = true, testName = "vcloud.VCloudDiscoveryLiveTest") +public class VCloudDiscoveryLiveTest { + + String endpoint = checkNotNull(System.getProperty("jclouds.test.endpoint"), + "jclouds.test.endpoint"); + String account = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user"); + String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key"); + private final class VCloudDiscoveryContextModule extends AbstractModule { + + @SuppressWarnings( { "unused" }) + @Provides + @Singleton + RestContext provideContext(Closer closer, VCloudDiscovery api, + @VCloud URI endPoint, @Named(VCloudConstants.PROPERTY_VCLOUD_USER) String account) { + return new RestContextImpl(closer, api, endPoint, account); + } + + @Override + protected void configure() { + + } + } + + private RestContext context; + + @Test + public void testOrganization() throws Exception { + Organization response = context.getApi().getOrganization(); + assertNotNull(response); + assertEquals(response.getName(), account); + assertEquals(response.getType(), VCloudMediaType.ORG_XML); + assertNotNull(response.getCatalog()); + assertEquals(response.getTasksLists().size(), 1); + assertEquals(response.getVDCs().size(), 1); + } + + @BeforeClass + void setupFactory() { + context = new RestContextBuilder(new TypeLiteral() { + }, new Properties()) { + + public void addContextModule(List modules) { + + modules.add(new VCloudDiscoveryContextModule()); + } + + @Override + protected void addClientModule(List modules) { + properties.setProperty(VCloudConstants.PROPERTY_VCLOUD_ENDPOINT, checkNotNull(endpoint, + "endpoint").toString()); + properties.setProperty(PROPERTY_VCLOUD_USER, checkNotNull(account, "user")); + properties.setProperty(PROPERTY_VCLOUD_KEY, checkNotNull(key, "key")); + properties.setProperty(PROPERTY_VCLOUD_SESSIONINTERVAL, "4"); + modules.add(new VCloudDiscoveryRestClientModule()); + } + + }.withModules(new Log4JLoggingModule(), + new ExecutorServiceModule(new WithinThreadExecutorService())).buildContext(); + } +} diff --git a/vcloudx/core/src/test/java/org/jclouds/vcloudx/VCloudXClientTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudDiscoveryTest.java similarity index 55% rename from vcloudx/core/src/test/java/org/jclouds/vcloudx/VCloudXClientTest.java rename to vcloud/core/src/test/java/org/jclouds/vcloud/VCloudDiscoveryTest.java index 25aac39acb..556ab6d0d3 100644 --- a/vcloudx/core/src/test/java/org/jclouds/vcloudx/VCloudXClientTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudDiscoveryTest.java @@ -21,62 +21,69 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloudx; +package org.jclouds.vcloud; import static org.testng.Assert.assertEquals; +import java.io.IOException; import java.lang.reflect.Method; import java.net.URI; import javax.inject.Provider; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; -import org.jclouds.concurrent.WithinThreadExecutorService; -import org.jclouds.concurrent.config.ExecutorServiceModule; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; +import org.jclouds.http.functions.ParseSax; import org.jclouds.logging.Logger; import org.jclouds.logging.Logger.LoggerFactory; -import org.jclouds.rest.config.RestModule; +import org.jclouds.rest.RestClientTest; +import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; -import org.jclouds.vcloudx.endpoints.Org; -import org.jclouds.vcloudx.filters.SetVCloudTokenCookie; -import org.jclouds.vcloudx.xml.OrgLinksHandler; -import org.testng.annotations.BeforeClass; +import org.jclouds.vcloud.endpoints.Org; +import org.jclouds.vcloud.filters.SetVCloudTokenCookie; +import org.jclouds.vcloud.xml.OrgHandler; import org.testng.annotations.Test; import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.google.inject.Key; +import com.google.inject.Module; import com.google.inject.TypeLiteral; /** - * Tests behavior of {@code VCloudXClient} + * Tests behavior of {@code VCloudDiscovery} * * @author Adrian Cole */ -@Test(groups = "unit", testName = "vcloudx.VCloudXClient") -public class VCloudXClientTest { +@Test(groups = "unit", testName = "vcloud.VCloudDiscoveryTest") +public class VCloudDiscoveryTest extends RestClientTest { - private RestAnnotationProcessor processor; + public void testOrganization() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudDiscovery.class.getMethod("getOrganization"); + GeneratedHttpRequest httpMethod = processor.createRequest(method); - public void testOrganization() throws SecurityException, NoSuchMethodException { - Method method = VCloudXClient.class.getMethod("getOrganization"); - HttpRequest httpMethod = processor.createRequest(method); - assertEquals(httpMethod.getRequestLine(), "GET http://org HTTP/1.1"); - assertEquals(httpMethod.getHeaders().size(), 1); - assertEquals(httpMethod.getFirstHeaderOrNull(HttpHeaders.ACCEPT), MediaType.APPLICATION_XML); - assertEquals(RestAnnotationProcessor.getSaxResponseParserClassOrNull(method),OrgLinksHandler.class); - assertEquals(httpMethod.getFilters().size(), 1); - assertEquals(httpMethod.getFilters().get(0).getClass(), SetVCloudTokenCookie.class); - assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null); + assertRequestLineEquals(httpMethod, "GET http://org HTTP/1.1"); + assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.org+xml\n"); + assertEntityEquals(httpMethod, null); + + assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertSaxResponseParserClassEquals(method, OrgHandler.class); + assertExceptionParserClassEquals(method, null); + + checkFilters(httpMethod); } - @BeforeClass - void setupFactory() { - Injector injector = Guice.createInjector(new AbstractModule() { + @Override + protected void checkFilters(GeneratedHttpRequest httpMethod) { + assertEquals(httpMethod.getFilters().size(), 1); + assertEquals(httpMethod.getFilters().get(0).getClass(), SetVCloudTokenCookie.class); + } + + @Override + protected TypeLiteral> createTypeLiteral() { + return new TypeLiteral>() { + }; + } + + @Override + protected Module createModule() { + return new AbstractModule() { @Override protected void configure() { bind(URI.class).annotatedWith(Org.class).toInstance(URI.create("http://org")); @@ -95,11 +102,8 @@ public class VCloudXClientTest { } }); } - }, new RestModule(), new ExecutorServiceModule(new WithinThreadExecutorService()), - new JavaUrlHttpCommandExecutorServiceModule()); - processor = injector.getInstance(Key - .get(new TypeLiteral>() { - })); + + }; } } diff --git a/vcloudx/core/src/test/java/org/jclouds/vcloudx/VCloudXLoginLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudLoginLiveTest.java similarity index 62% rename from vcloudx/core/src/test/java/org/jclouds/vcloudx/VCloudXLoginLiveTest.java rename to vcloud/core/src/test/java/org/jclouds/vcloud/VCloudLoginLiveTest.java index 537d71fd98..edd7c6caf1 100755 --- a/vcloudx/core/src/test/java/org/jclouds/vcloudx/VCloudXLoginLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudLoginLiveTest.java @@ -21,12 +21,12 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloudx; +package org.jclouds.vcloud; import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.vcloudx.reference.VCloudXConstants.PROPERTY_VCLOUDX_KEY; -import static org.jclouds.vcloudx.reference.VCloudXConstants.PROPERTY_VCLOUDX_SESSIONINTERVAL; -import static org.jclouds.vcloudx.reference.VCloudXConstants.PROPERTY_VCLOUDX_USER; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER; import static org.testng.Assert.assertNotNull; import java.net.URI; @@ -43,10 +43,11 @@ import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContextBuilder; import org.jclouds.rest.internal.RestContextImpl; -import org.jclouds.vcloudx.VCloudXLogin.VCloudXSession; -import org.jclouds.vcloudx.config.RestVCloudXAuthenticationModule; -import org.jclouds.vcloudx.endpoints.VCloudX; -import org.jclouds.vcloudx.reference.VCloudXConstants; +import org.jclouds.vcloud.VCloudLogin; +import org.jclouds.vcloud.VCloudLogin.VCloudSession; +import org.jclouds.vcloud.config.VCloudDiscoveryRestClientModule; +import org.jclouds.vcloud.endpoints.VCloud; +import org.jclouds.vcloud.reference.VCloudConstants; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -56,21 +57,21 @@ import com.google.inject.Provides; import com.google.inject.TypeLiteral; /** - * Tests behavior of {@code VCloudXLogin} + * Tests behavior of {@code VCloudLogin} * * @author Adrian Cole */ -@Test(groups = "live", testName = "vcloudx.VCloudXLoginLiveTest") -public class VCloudXLoginLiveTest { +@Test(groups = "live", testName = "vcloud.VCloudLoginLiveTest") +public class VCloudLoginLiveTest { - private final class VCloudXLoginContextModule extends AbstractModule { + private final class VCloudLoginContextModule extends AbstractModule { @SuppressWarnings( { "unused" }) @Provides @Singleton - RestContext provideContext(Closer closer, VCloudXLogin api, - @VCloudX URI endPoint, @Named(VCloudXConstants.PROPERTY_VCLOUDX_USER) String account) { - return new RestContextImpl(closer, api, endPoint, account); + RestContext provideContext(Closer closer, VCloudLogin api, + @VCloud URI endPoint, @Named(VCloudConstants.PROPERTY_VCLOUD_USER) String account) { + return new RestContextImpl(closer, api, endPoint, account); } @Override @@ -84,37 +85,37 @@ public class VCloudXLoginLiveTest { String account = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user"); String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key"); - private RestContext context; + private RestContext context; @Test public void testLogin() throws Exception { - VCloudXLogin authentication = context.getApi(); + VCloudLogin authentication = context.getApi(); for (int i = 0; i < 5; i++) { - VCloudXSession response = authentication.login(); + VCloudSession response = authentication.login(); assertNotNull(response); assertNotNull(response.getVCloudToken()); - assertNotNull(response.getOrg()); + assertNotNull(response.getOrgs()); } } @BeforeClass void setupFactory() { - context = new RestContextBuilder(new TypeLiteral() { + context = new RestContextBuilder(new TypeLiteral() { }, new Properties()) { public void addContextModule(List modules) { - modules.add(new VCloudXLoginContextModule()); + modules.add(new VCloudLoginContextModule()); } @Override protected void addClientModule(List modules) { - properties.setProperty(VCloudXConstants.PROPERTY_VCLOUDX_ENDPOINT, checkNotNull( + properties.setProperty(VCloudConstants.PROPERTY_VCLOUD_ENDPOINT, checkNotNull( endpoint, "endpoint").toString()); - properties.setProperty(PROPERTY_VCLOUDX_USER, checkNotNull(account, "user")); - properties.setProperty(PROPERTY_VCLOUDX_KEY, checkNotNull(key, "key")); - properties.setProperty(PROPERTY_VCLOUDX_SESSIONINTERVAL, "4"); - modules.add(new RestVCloudXAuthenticationModule()); + properties.setProperty(PROPERTY_VCLOUD_USER, checkNotNull(account, "user")); + properties.setProperty(PROPERTY_VCLOUD_KEY, checkNotNull(key, "key")); + properties.setProperty(PROPERTY_VCLOUD_SESSIONINTERVAL, "4"); + modules.add(new VCloudDiscoveryRestClientModule()); } }.withModules(new Log4JLoggingModule(), diff --git a/vcloudx/core/src/test/java/org/jclouds/vcloudx/VCloudXLoginTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudLoginTest.java similarity index 58% rename from vcloudx/core/src/test/java/org/jclouds/vcloudx/VCloudXLoginTest.java rename to vcloud/core/src/test/java/org/jclouds/vcloud/VCloudLoginTest.java index bd863c88a5..5e13368fab 100755 --- a/vcloudx/core/src/test/java/org/jclouds/vcloudx/VCloudXLoginTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudLoginTest.java @@ -21,10 +21,11 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloudx; +package org.jclouds.vcloud; import static org.testng.Assert.assertEquals; +import java.io.IOException; import java.io.UnsupportedEncodingException; import java.lang.reflect.Method; import java.net.URI; @@ -32,54 +33,61 @@ import java.net.URI; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; -import org.jclouds.concurrent.WithinThreadExecutorService; -import org.jclouds.concurrent.config.ExecutorServiceModule; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.logging.Logger; import org.jclouds.logging.Logger.LoggerFactory; -import org.jclouds.rest.config.RestModule; +import org.jclouds.rest.RestClientTest; +import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; -import org.jclouds.vcloudx.endpoints.VCloudX; -import org.jclouds.vcloudx.functions.ParseLoginResponseFromHeaders; -import org.testng.annotations.BeforeClass; +import org.jclouds.vcloud.endpoints.VCloud; +import org.jclouds.vcloud.functions.ParseLoginResponseFromHeaders; import org.testng.annotations.Test; import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.google.inject.Key; +import com.google.inject.Module; import com.google.inject.TypeLiteral; /** - * Tests behavior of {@code VCloudXLogin} + * Tests behavior of {@code VCloudLogin} * * @author Adrian Cole */ -@Test(groups = "unit", testName = "vcloudx.VCloudXLogin") -public class VCloudXLoginTest { +@Test(groups = "unit", testName = "vcloud.VCloudLoginTest") +public class VCloudLoginTest extends RestClientTest { - private RestAnnotationProcessor processor; + public void testLogin() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudLogin.class.getMethod("login"); + GeneratedHttpRequest httpMethod = processor.createRequest(method); - public void testAuthenticate() throws SecurityException, NoSuchMethodException { - Method method = VCloudXLogin.class.getMethod("login"); - HttpRequest httpMethod = processor.createRequest(method); assertEquals(httpMethod.getRequestLine(), "POST http://localhost:8080/login HTTP/1.1"); - assertEquals(httpMethod.getHeaders().size(), 1); - assertEquals(httpMethod.getFirstHeaderOrNull(HttpHeaders.ACCEPT), MediaType.APPLICATION_XML); - assertEquals(RestAnnotationProcessor.getParserOrThrowException(method), - ParseLoginResponseFromHeaders.class); + assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + ": " + MediaType.APPLICATION_XML + "\n"); + assertEntityEquals(httpMethod, null); + + assertResponseParserClassEquals(method, httpMethod, ParseLoginResponseFromHeaders.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(httpMethod); + } + + @Override + protected void checkFilters(GeneratedHttpRequest httpMethod) { assertEquals(httpMethod.getFilters().size(), 1); assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class); } - @BeforeClass - void setupFactory() { - Injector injector = Guice.createInjector(new AbstractModule() { + @Override + protected TypeLiteral> createTypeLiteral() { + return new TypeLiteral>() { + }; + } + + @Override + protected Module createModule() { + return new AbstractModule() { @Override protected void configure() { - bind(URI.class).annotatedWith(VCloudX.class).toInstance( + bind(URI.class).annotatedWith(VCloud.class).toInstance( URI.create("http://localhost:8080")); try { bind(BasicAuthentication.class).toInstance(new BasicAuthentication("user", "pass")); @@ -92,11 +100,8 @@ public class VCloudXLoginTest { } }); } - }, new RestModule(), new ExecutorServiceModule(new WithinThreadExecutorService()), - new JavaUrlHttpCommandExecutorServiceModule()); - processor = injector.getInstance(Key - .get(new TypeLiteral>() { - })); + + }; } } diff --git a/vcloudx/core/src/test/java/org/jclouds/vcloudx/config/RestVCloudXAuthenticationModuleTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/config/RestVCloudAuthenticationModuleTest.java similarity index 76% rename from vcloudx/core/src/test/java/org/jclouds/vcloudx/config/RestVCloudXAuthenticationModuleTest.java rename to vcloud/core/src/test/java/org/jclouds/vcloud/config/RestVCloudAuthenticationModuleTest.java index 712f68ca44..1497929a50 100644 --- a/vcloudx/core/src/test/java/org/jclouds/vcloudx/config/RestVCloudXAuthenticationModuleTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/config/RestVCloudAuthenticationModuleTest.java @@ -21,15 +21,15 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloudx.config; +package org.jclouds.vcloud.config; -import static org.jclouds.vcloudx.reference.VCloudXConstants.PROPERTY_VCLOUDX_ENDPOINT; -import static org.jclouds.vcloudx.reference.VCloudXConstants.PROPERTY_VCLOUDX_KEY; -import static org.jclouds.vcloudx.reference.VCloudXConstants.PROPERTY_VCLOUDX_SESSIONINTERVAL; -import static org.jclouds.vcloudx.reference.VCloudXConstants.PROPERTY_VCLOUDX_USER; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPOINT; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER; import static org.testng.Assert.assertEquals; -import java.net.URI; +import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import org.jclouds.http.HttpRetryHandler; @@ -39,8 +39,9 @@ import org.jclouds.http.handlers.DelegatingErrorHandler; import org.jclouds.http.handlers.DelegatingRetryHandler; import org.jclouds.http.handlers.RedirectionRetryHandler; import org.jclouds.util.Jsr330; -import org.jclouds.vcloudx.VCloudXLogin; -import org.jclouds.vcloudx.VCloudXLogin.VCloudXSession; +import org.jclouds.vcloud.VCloudLogin; +import org.jclouds.vcloud.VCloudLogin.VCloudSession; +import org.jclouds.vcloud.domain.Link; import org.testng.annotations.Test; import com.google.common.base.Supplier; @@ -51,19 +52,19 @@ import com.google.inject.Injector; /** * @author Adrian Cole */ -@Test(groups = "unit", testName = "vcloudx.RestVCloudXAuthenticationModuleTest") -public class RestVCloudXAuthenticationModuleTest { +@Test(groups = "unit", testName = "vcloud.RestVCloudAuthenticationModuleTest") +public class RestVCloudAuthenticationModuleTest { Injector createInjector() { - return Guice.createInjector(new RestVCloudXAuthenticationModule(), new ParserModule(), + return Guice.createInjector(new VCloudDiscoveryRestClientModule(), new ParserModule(), new AbstractModule() { @Override protected void configure() { - bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUDX_USER)).to("user"); - bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUDX_KEY)).to("secret"); - bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUDX_ENDPOINT)).to( + bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_USER)).to("user"); + bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_KEY)).to("secret"); + bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_ENDPOINT)).to( "http://localhost"); - bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUDX_SESSIONINTERVAL)) + bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_SESSIONINTERVAL)) .to("2"); } }); @@ -71,15 +72,15 @@ public class RestVCloudXAuthenticationModuleTest { @Test void testUpdatesOnlyOncePerSecond() throws NoSuchMethodException, InterruptedException { - RestVCloudXAuthenticationModule module = new RestVCloudXAuthenticationModule(); - VCloudXLogin login = new VCloudXLogin() { + VCloudDiscoveryRestClientModule module = new VCloudDiscoveryRestClientModule(); + VCloudLogin login = new VCloudLogin() { private final AtomicInteger token = new AtomicInteger(); - public VCloudXSession login() { - return new VCloudXSession() { + public VCloudSession login() { + return new VCloudSession() { - public URI getOrg() { + public Map getOrgs() { return null; } @@ -91,7 +92,7 @@ public class RestVCloudXAuthenticationModuleTest { } }; - Supplier map = module.provideVCloudTokenCache(1, login); + Supplier map = module.provideVCloudTokenCache(1, login); for (int i = 0; i < 10; i++) map.get(); assert "1".equals(map.get().getVCloudToken()); diff --git a/vcloudx/core/src/test/java/org/jclouds/vcloudx/filters/SetVCloudTokenCookieTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/filters/SetVCloudTokenCookieTest.java similarity index 95% rename from vcloudx/core/src/test/java/org/jclouds/vcloudx/filters/SetVCloudTokenCookieTest.java rename to vcloud/core/src/test/java/org/jclouds/vcloud/filters/SetVCloudTokenCookieTest.java index 3a62550399..f3493fdc97 100644 --- a/vcloudx/core/src/test/java/org/jclouds/vcloudx/filters/SetVCloudTokenCookieTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/filters/SetVCloudTokenCookieTest.java @@ -21,7 +21,7 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloudx.filters; +package org.jclouds.vcloud.filters; import static org.testng.Assert.assertEquals; @@ -31,6 +31,7 @@ import javax.inject.Provider; import javax.ws.rs.core.HttpHeaders; import org.jclouds.http.HttpRequest; +import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; diff --git a/vcloudx/core/src/test/java/org/jclouds/vcloudx/functions/ParseLoginResponseFromHeadersTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/functions/ParseLoginResponseFromHeadersTest.java similarity index 80% rename from vcloudx/core/src/test/java/org/jclouds/vcloudx/functions/ParseLoginResponseFromHeadersTest.java rename to vcloud/core/src/test/java/org/jclouds/vcloud/functions/ParseLoginResponseFromHeadersTest.java index cebd8eeb1e..bc439295d4 100644 --- a/vcloudx/core/src/test/java/org/jclouds/vcloudx/functions/ParseLoginResponseFromHeadersTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/functions/ParseLoginResponseFromHeadersTest.java @@ -21,7 +21,7 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloudx.functions; +package org.jclouds.vcloud.functions; import static org.testng.Assert.assertEquals; @@ -31,9 +31,14 @@ import javax.ws.rs.core.HttpHeaders; import org.jclouds.http.HttpResponse; import org.jclouds.http.functions.BaseHandlerTest; -import org.jclouds.vcloudx.VCloudXLogin.VCloudXSession; +import org.jclouds.vcloud.VCloudMediaType; +import org.jclouds.vcloud.VCloudLogin.VCloudSession; +import org.jclouds.vcloud.domain.internal.LinkImpl; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMap; + /** * @author Adrian Cole */ @@ -57,10 +62,11 @@ public class ParseLoginResponseFromHeadersTest extends BaseHandlerTest { response.getHeaders().put(HttpHeaders.CONTENT_LENGTH, "307"); response.getHeaders().put(HttpHeaders.CONTENT_TYPE, "Content-Type: application/xml; charset=utf-8"); - VCloudXSession reply = parser.apply(response); + VCloudSession reply = parser.apply(response); assertEquals(reply.getVCloudToken(), "9er4d061-4bff-48fa-84b1-5da7166764d2"); - assertEquals(reply.getOrg(), URI - .create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48")); + assertEquals(reply.getOrgs(), ImmutableMap.of("adrian@jclouds.org", new LinkImpl( + "adrian@jclouds.org", VCloudMediaType.ORG_XML, URI + .create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48")))); } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/CatalogHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/CatalogHandlerTest.java new file mode 100644 index 0000000000..37b31fbc6e --- /dev/null +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/CatalogHandlerTest.java @@ -0,0 +1,137 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.vcloud.xml; + +import static org.jclouds.vcloud.VCloudMediaType.CATALOGITEM_XML; +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.net.URI; + +import org.jclouds.http.functions.BaseHandlerTest; +import org.jclouds.vcloud.domain.Catalog; +import org.jclouds.vcloud.domain.internal.LinkImpl; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +/** + * Tests behavior of {@code CatalogHandler} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "vcloud.CatalogHandlerTest") +public class CatalogHandlerTest extends BaseHandlerTest { + + @BeforeTest + @Override + protected void setUpInjector() { + super.setUpInjector(); + } + + public void testApplyInputStream() { + InputStream is = getClass().getResourceAsStream("/catalog.xml"); + + Catalog result = (Catalog) factory.create(injector.getInstance(CatalogHandler.class)).parse( + is); + assertEquals(result.getName(), "Miami Environment 1"); + assertEquals(result.getLocation(), URI + .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog")); + assertEquals(result.getType(), "application/vnd.vmware.vcloud.catalog+xml"); + + assertEquals(result.get("CentOS 5.3 (32-bit)"), new LinkImpl("CentOS 5.3 (32-bit)", + CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/5"))); + assertEquals(result.get("CentOS 5.3 (64-bit)"), new LinkImpl("CentOS 5.3 (64-bit)", + CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/6"))); + assertEquals(result.get("RHEL 5.3 (32-bit)"), new LinkImpl("RHEL 5.3 (32-bit)", + CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/7"))); + assertEquals(result.get("RHEL 5.3 (64-bit)"), new LinkImpl("RHEL 5.3 (64-bit)", + CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/8"))); + assertEquals(result.get("Ubuntu JeOS 9.04 (32-bit)"), new LinkImpl( + "Ubuntu JeOS 9.04 (32-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/11"))); + assertEquals(result.get("Ubuntu JeOS 9.04 (64-bit)"), new LinkImpl( + "Ubuntu JeOS 9.04 (64-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/12"))); + assertEquals(result.get("Ubuntu Server 9.04 (32-bit)"), new LinkImpl( + "Ubuntu Server 9.04 (32-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/9"))); + assertEquals(result.get("Ubuntu Server 9.04 (64-bit)"), new LinkImpl( + "Ubuntu Server 9.04 (64-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/10"))); + assertEquals(result.get("Windows 2003 Enterprise R2 (32-bit)"), new LinkImpl( + "Windows 2003 Enterprise R2 (32-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/1"))); + assertEquals(result.get("Windows 2003 Enterprise R2 (64-bit)"), new LinkImpl( + "Windows 2003 Enterprise R2 (64-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/2"))); + assertEquals(result.get("Windows 2003 Standard R2 (32-bit)"), new LinkImpl( + "Windows 2003 Standard R2 (32-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/3"))); + assertEquals(result.get("Windows 2003 Standard R2 (64-bit)"), new LinkImpl( + "Windows 2003 Standard R2 (64-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/4"))); + assertEquals(result.get("Windows 2003 Standard R2 w.SQL 2008 Web (64-bit)"), new LinkImpl( + "Windows 2003 Standard R2 w.SQL 2008 Web (64-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/23"))); + assertEquals(result.get("Windows Server 2008 Enterprise (32-bit)"), new LinkImpl( + "Windows Server 2008 Enterprise (32-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/13"))); + assertEquals(result.get("Windows Server 2008 Enterprise (64-bit)"), new LinkImpl( + "Windows Server 2008 Enterprise (64-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/15"))); + assertEquals(result.get("Windows Server 2008 Enterprise R2 (64-bit)"), new LinkImpl( + "Windows Server 2008 Enterprise R2 (64-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/16"))); + assertEquals(result.get("Windows Server 2008 Standard (32-bit)"), new LinkImpl( + "Windows Server 2008 Standard (32-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/17"))); + assertEquals(result.get("Windows Server 2008 Standard (64-bit)"), new LinkImpl( + "Windows Server 2008 Standard (64-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/18"))); + assertEquals(result.get("Windows Server 2008 Standard R2 (64-bit)"), new LinkImpl( + "Windows Server 2008 Standard R2 (64-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/19"))); + assertEquals( + result.get("Windows Server 2008 Standard w.SQL 2008 Web (64-bit)"), + new LinkImpl( + "Windows Server 2008 Standard w.SQL 2008 Web (64-bit)", + CATALOGITEM_XML, + URI + .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/14"))); + assertEquals(result.get("Windows Web Server 2008 (32-bit)"), new LinkImpl( + "Windows Web Server 2008 (32-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/20"))); + assertEquals(result.get("Windows Web Server 2008 (64-bit)"), new LinkImpl( + "Windows Web Server 2008 (64-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/21"))); + assertEquals(result.get("Windows Web Server 2008 R2 (64-bit)"), new LinkImpl( + "Windows Web Server 2008 R2 (64-bit)", CATALOGITEM_XML, + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/22"))); + + } +} diff --git a/vcloudx/core/src/test/java/org/jclouds/vcloudx/xml/OrgLinksHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/OrgHandlerTest.java similarity index 50% rename from vcloudx/core/src/test/java/org/jclouds/vcloudx/xml/OrgLinksHandlerTest.java rename to vcloud/core/src/test/java/org/jclouds/vcloud/xml/OrgHandlerTest.java index a4ee21a596..b23938c463 100644 --- a/vcloudx/core/src/test/java/org/jclouds/vcloudx/xml/OrgLinksHandlerTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/OrgHandlerTest.java @@ -21,27 +21,32 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloudx.xml; +package org.jclouds.vcloud.xml; +import static org.jclouds.vcloud.VCloudMediaType.CATALOG_XML; +import static org.jclouds.vcloud.VCloudMediaType.ORG_XML; +import static org.jclouds.vcloud.VCloudMediaType.TASKSLIST_XML; import static org.testng.Assert.assertEquals; import java.io.InputStream; import java.net.URI; import org.jclouds.http.functions.BaseHandlerTest; -import org.jclouds.vcloudx.domain.OrgLinks; +import org.jclouds.vcloud.VCloudMediaType; +import org.jclouds.vcloud.domain.Organization; +import org.jclouds.vcloud.domain.internal.LinkImpl; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; -import com.google.common.collect.Sets; +import com.google.common.collect.ImmutableMap; /** - * Tests behavior of {@code OrgLinksHandler} + * Tests behavior of {@code OrgHandler} * * @author Adrian Cole */ -@Test(groups = "unit", testName = "vcloudx.OrgLinksHandlerTest") -public class OrgLinksHandlerTest extends BaseHandlerTest { +@Test(groups = "unit", testName = "vcloud.OrgHandlerTest") +public class OrgHandlerTest extends BaseHandlerTest { @BeforeTest @Override @@ -52,16 +57,26 @@ public class OrgLinksHandlerTest extends BaseHandlerTest { public void testApplyInputStream() { InputStream is = getClass().getResourceAsStream("/org.xml"); - OrgLinks result = (OrgLinks) factory.create(injector.getInstance(OrgLinksHandler.class)) + Organization result = (Organization) factory.create(injector.getInstance(OrgHandler.class)) .parse(is); assertEquals(result.getName(), "adrian@jclouds.org"); - assertEquals(result.getOrg(), URI + assertEquals(result.getLocation(), URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48")); - assertEquals(result.getCatalog(), URI - .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog")); - assertEquals(result.getVDCs(), Sets.newHashSet(URI - .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32"))); - assertEquals(result.getTaskLists(), Sets.newHashSet(URI - .create("https://services.vcloudexpress.terremark.com/api/v0.8/tasksList/32"))); + assertEquals(result.getType(), ORG_XML); + assertEquals(result.getCatalog(), new LinkImpl("Miami Environment 1 Catalog", CATALOG_XML, URI + .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog"))); + assertEquals(result.getVDCs(), ImmutableMap.of("Miami Environment 1", new LinkImpl( + "Miami Environment 1", VCloudMediaType.VDC_XML, URI + .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32")))); + assertEquals( + result.getTasksLists(), + ImmutableMap + .of( + "Miami Environment 1 Tasks List", + new LinkImpl( + "Miami Environment 1 Tasks List", + TASKSLIST_XML, + URI + .create("https://services.vcloudexpress.terremark.com/api/v0.8/tasksList/32")))); } } diff --git a/vcloudx/core/src/test/java/org/jclouds/vcloudx/xml/OrgListToOrgUriHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/OrgListHandlerTest.java similarity index 67% rename from vcloudx/core/src/test/java/org/jclouds/vcloudx/xml/OrgListToOrgUriHandlerTest.java rename to vcloud/core/src/test/java/org/jclouds/vcloud/xml/OrgListHandlerTest.java index fca7972a15..8030a0b06c 100644 --- a/vcloudx/core/src/test/java/org/jclouds/vcloudx/xml/OrgListToOrgUriHandlerTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/OrgListHandlerTest.java @@ -21,24 +21,30 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloudx.xml; +package org.jclouds.vcloud.xml; import static org.testng.Assert.assertEquals; import java.io.InputStream; import java.net.URI; +import java.util.Map; import org.jclouds.http.functions.BaseHandlerTest; +import org.jclouds.vcloud.VCloudMediaType; +import org.jclouds.vcloud.domain.Link; +import org.jclouds.vcloud.domain.internal.LinkImpl; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; +import com.google.common.collect.ImmutableMap; + /** - * Tests behavior of {@code OrgListToOrgUriHandler} + * Tests behavior of {@code OrgListHandler} * * @author Adrian Cole */ -@Test(groups = "unit", testName = "vcloudx.OrgListToOrgUriHandlerTest") -public class OrgListToOrgUriHandlerTest extends BaseHandlerTest { +@Test(groups = "unit", testName = "vcloud.OrgListHandlerTest") +public class OrgListHandlerTest extends BaseHandlerTest { @BeforeTest @Override @@ -49,9 +55,10 @@ public class OrgListToOrgUriHandlerTest extends BaseHandlerTest { public void testApplyInputStream() { InputStream is = getClass().getResourceAsStream("/orglist.xml"); - URI result = (URI) factory.create(injector.getInstance(OrgListToOrgUriHandler.class)).parse( + Map result = factory.create(injector.getInstance(OrgListHandler.class)).parse( is); - assertEquals(result, URI - .create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48")); + assertEquals(result, ImmutableMap.of("adrian@jclouds.org", new LinkImpl("adrian@jclouds.org", + VCloudMediaType.ORG_XML, URI + .create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48")))); } } diff --git a/vcloud/core/src/test/resources/catalog.xml b/vcloud/core/src/test/resources/catalog.xml new file mode 100644 index 0000000000..2389e55dcc --- /dev/null +++ b/vcloud/core/src/test/resources/catalog.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/vcloudx/core/src/test/resources/log4j.xml b/vcloud/core/src/test/resources/log4j.xml similarity index 98% rename from vcloudx/core/src/test/resources/log4j.xml rename to vcloud/core/src/test/resources/log4j.xml index c996547bd7..d712a5bd47 100755 --- a/vcloudx/core/src/test/resources/log4j.xml +++ b/vcloud/core/src/test/resources/log4j.xml @@ -98,13 +98,12 @@ - + diff --git a/vcloudx/core/src/test/resources/org.xml b/vcloud/core/src/test/resources/org.xml similarity index 100% rename from vcloudx/core/src/test/resources/org.xml rename to vcloud/core/src/test/resources/org.xml diff --git a/vcloudx/core/src/test/resources/orglist.xml b/vcloud/core/src/test/resources/orglist.xml similarity index 100% rename from vcloudx/core/src/test/resources/orglist.xml rename to vcloud/core/src/test/resources/orglist.xml diff --git a/vcloud/core/src/test/resources/vdc.xml b/vcloud/core/src/test/resources/vdc.xml new file mode 100644 index 0000000000..981d296170 --- /dev/null +++ b/vcloud/core/src/test/resources/vdc.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/vcloudx/pom.xml b/vcloud/pom.xml similarity index 96% rename from vcloudx/pom.xml rename to vcloud/pom.xml index 4d4bec379c..c8ef0bbd58 100755 --- a/vcloudx/pom.xml +++ b/vcloud/pom.xml @@ -33,9 +33,9 @@ ../project/pom.xml 4.0.0 - jclouds-vcloudx-project + jclouds-vcloud-project pom - jclouds vcloudx project + jclouds vcloud project core