Issue 830: Cleaned up CatalogApi and AdminCatalogApi; added logic to use URNs as opposed to Hrefs

This commit is contained in:
Adrian Cole 2012-08-19 02:34:25 -07:00
parent 7fe724db43
commit 9e69626413
43 changed files with 1484 additions and 854 deletions

View File

@ -40,6 +40,7 @@
<test.vcloud-director.identity>FIXME_USERNAME_WHICH_MIGHT_BE_EMAIL@JClouds</test.vcloud-director.identity> <test.vcloud-director.identity>FIXME_USERNAME_WHICH_MIGHT_BE_EMAIL@JClouds</test.vcloud-director.identity>
<test.vcloud-director.credential>FIXME_PASSWORD</test.vcloud-director.credential> <test.vcloud-director.credential>FIXME_PASSWORD</test.vcloud-director.credential>
<test.vcloud-director.template></test.vcloud-director.template> <test.vcloud-director.template></test.vcloud-director.template>
<!-- URN format: ex. urn:vcloud:catalog:7212e451-76e1-4631-b2de-ba1dfd8080e4 -->
<test.vcloud-director.catalog-id></test.vcloud-director.catalog-id> <test.vcloud-director.catalog-id></test.vcloud-director.catalog-id>
<test.vcloud-director.media-id></test.vcloud-director.media-id> <test.vcloud-director.media-id></test.vcloud-director.media-id>
<test.vcloud-director.vapptemplate-id></test.vcloud-director.vapptemplate-id> <test.vcloud-director.vapptemplate-id></test.vcloud-director.vapptemplate-id>
@ -57,6 +58,11 @@
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>com.jamesmurty.utils</groupId>
<artifactId>java-xmlbuilder</artifactId>
<version>0.4</version>
</dependency>
<dependency> <dependency>
<groupId>org.jclouds</groupId> <groupId>org.jclouds</groupId>
<artifactId>jclouds-compute</artifactId> <artifactId>jclouds-compute</artifactId>

View File

@ -40,6 +40,9 @@ public class VCloudDirectorException extends RuntimeException {
private final Error error; private final Error error;
private final Task task; private final Task task;
// TODO: this type wipes out the http response, which often has the data needed to troubleshoot
// the issue
public VCloudDirectorException(Error error) { public VCloudDirectorException(Error error) {
super(message(error, "Error")); super(message(error, "Error"));
this.error = error; this.error = error;

View File

@ -41,56 +41,58 @@ import org.jclouds.rest.config.BinderUtils;
import org.jclouds.rest.config.RestClientModule; import org.jclouds.rest.config.RestClientModule;
import org.jclouds.rest.internal.RestContextImpl; import org.jclouds.rest.internal.RestContextImpl;
import org.jclouds.util.Suppliers2; import org.jclouds.util.Suppliers2;
import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminAsyncApi;
import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminApi; import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminApi;
import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminAsyncApi;
import org.jclouds.vcloud.director.v1_5.annotations.Login; import org.jclouds.vcloud.director.v1_5.annotations.Login;
import org.jclouds.vcloud.director.v1_5.domain.Entity;
import org.jclouds.vcloud.director.v1_5.domain.Session; import org.jclouds.vcloud.director.v1_5.domain.Session;
import org.jclouds.vcloud.director.v1_5.domain.SessionWithToken; import org.jclouds.vcloud.director.v1_5.domain.SessionWithToken;
import org.jclouds.vcloud.director.v1_5.features.CatalogAsyncApi;
import org.jclouds.vcloud.director.v1_5.features.CatalogApi; import org.jclouds.vcloud.director.v1_5.features.CatalogApi;
import org.jclouds.vcloud.director.v1_5.features.MediaAsyncApi; import org.jclouds.vcloud.director.v1_5.features.CatalogAsyncApi;
import org.jclouds.vcloud.director.v1_5.features.MediaApi; import org.jclouds.vcloud.director.v1_5.features.MediaApi;
import org.jclouds.vcloud.director.v1_5.features.MetadataAsyncApi; import org.jclouds.vcloud.director.v1_5.features.MediaAsyncApi;
import org.jclouds.vcloud.director.v1_5.features.MetadataApi; import org.jclouds.vcloud.director.v1_5.features.MetadataApi;
import org.jclouds.vcloud.director.v1_5.features.NetworkAsyncApi; import org.jclouds.vcloud.director.v1_5.features.MetadataAsyncApi;
import org.jclouds.vcloud.director.v1_5.features.NetworkApi; import org.jclouds.vcloud.director.v1_5.features.NetworkApi;
import org.jclouds.vcloud.director.v1_5.features.OrgAsyncApi; import org.jclouds.vcloud.director.v1_5.features.NetworkAsyncApi;
import org.jclouds.vcloud.director.v1_5.features.OrgApi; import org.jclouds.vcloud.director.v1_5.features.OrgApi;
import org.jclouds.vcloud.director.v1_5.features.QueryAsyncApi; import org.jclouds.vcloud.director.v1_5.features.OrgAsyncApi;
import org.jclouds.vcloud.director.v1_5.features.QueryApi; import org.jclouds.vcloud.director.v1_5.features.QueryApi;
import org.jclouds.vcloud.director.v1_5.features.TaskAsyncApi; import org.jclouds.vcloud.director.v1_5.features.QueryAsyncApi;
import org.jclouds.vcloud.director.v1_5.features.TaskApi; import org.jclouds.vcloud.director.v1_5.features.TaskApi;
import org.jclouds.vcloud.director.v1_5.features.UploadAsyncApi; import org.jclouds.vcloud.director.v1_5.features.TaskAsyncApi;
import org.jclouds.vcloud.director.v1_5.features.UploadApi; import org.jclouds.vcloud.director.v1_5.features.UploadApi;
import org.jclouds.vcloud.director.v1_5.features.VAppAsyncApi; import org.jclouds.vcloud.director.v1_5.features.UploadAsyncApi;
import org.jclouds.vcloud.director.v1_5.features.VAppApi; import org.jclouds.vcloud.director.v1_5.features.VAppApi;
import org.jclouds.vcloud.director.v1_5.features.VAppTemplateAsyncApi; import org.jclouds.vcloud.director.v1_5.features.VAppAsyncApi;
import org.jclouds.vcloud.director.v1_5.features.VAppTemplateApi; import org.jclouds.vcloud.director.v1_5.features.VAppTemplateApi;
import org.jclouds.vcloud.director.v1_5.features.VdcAsyncApi; import org.jclouds.vcloud.director.v1_5.features.VAppTemplateAsyncApi;
import org.jclouds.vcloud.director.v1_5.features.VdcApi; import org.jclouds.vcloud.director.v1_5.features.VdcApi;
import org.jclouds.vcloud.director.v1_5.features.VmAsyncApi; import org.jclouds.vcloud.director.v1_5.features.VdcAsyncApi;
import org.jclouds.vcloud.director.v1_5.features.VmApi; import org.jclouds.vcloud.director.v1_5.features.VmApi;
import org.jclouds.vcloud.director.v1_5.features.admin.AdminCatalogAsyncApi; import org.jclouds.vcloud.director.v1_5.features.VmAsyncApi;
import org.jclouds.vcloud.director.v1_5.features.admin.AdminCatalogApi; import org.jclouds.vcloud.director.v1_5.features.admin.AdminCatalogApi;
import org.jclouds.vcloud.director.v1_5.features.admin.AdminNetworkAsyncApi; import org.jclouds.vcloud.director.v1_5.features.admin.AdminCatalogAsyncApi;
import org.jclouds.vcloud.director.v1_5.features.admin.AdminNetworkApi; import org.jclouds.vcloud.director.v1_5.features.admin.AdminNetworkApi;
import org.jclouds.vcloud.director.v1_5.features.admin.AdminOrgAsyncApi; import org.jclouds.vcloud.director.v1_5.features.admin.AdminNetworkAsyncApi;
import org.jclouds.vcloud.director.v1_5.features.admin.AdminOrgApi; import org.jclouds.vcloud.director.v1_5.features.admin.AdminOrgApi;
import org.jclouds.vcloud.director.v1_5.features.admin.AdminQueryAsyncApi; import org.jclouds.vcloud.director.v1_5.features.admin.AdminOrgAsyncApi;
import org.jclouds.vcloud.director.v1_5.features.admin.AdminQueryApi; import org.jclouds.vcloud.director.v1_5.features.admin.AdminQueryApi;
import org.jclouds.vcloud.director.v1_5.features.admin.AdminVdcAsyncApi; import org.jclouds.vcloud.director.v1_5.features.admin.AdminQueryAsyncApi;
import org.jclouds.vcloud.director.v1_5.features.admin.AdminVdcApi; import org.jclouds.vcloud.director.v1_5.features.admin.AdminVdcApi;
import org.jclouds.vcloud.director.v1_5.features.admin.GroupAsyncApi; import org.jclouds.vcloud.director.v1_5.features.admin.AdminVdcAsyncApi;
import org.jclouds.vcloud.director.v1_5.features.admin.GroupApi; import org.jclouds.vcloud.director.v1_5.features.admin.GroupApi;
import org.jclouds.vcloud.director.v1_5.features.admin.UserAsyncApi; import org.jclouds.vcloud.director.v1_5.features.admin.GroupAsyncApi;
import org.jclouds.vcloud.director.v1_5.features.admin.UserApi; import org.jclouds.vcloud.director.v1_5.features.admin.UserApi;
import org.jclouds.vcloud.director.v1_5.features.admin.UserAsyncApi;
import org.jclouds.vcloud.director.v1_5.functions.LoginUserInOrgWithPassword; import org.jclouds.vcloud.director.v1_5.functions.LoginUserInOrgWithPassword;
import org.jclouds.vcloud.director.v1_5.functions.href.ResolveEntity;
import org.jclouds.vcloud.director.v1_5.handlers.InvalidateSessionAndRetryOn401AndLogoutOnClose; import org.jclouds.vcloud.director.v1_5.handlers.InvalidateSessionAndRetryOn401AndLogoutOnClose;
import org.jclouds.vcloud.director.v1_5.handlers.VCloudDirectorErrorHandler; import org.jclouds.vcloud.director.v1_5.handlers.VCloudDirectorErrorHandler;
import org.jclouds.vcloud.director.v1_5.login.SessionAsyncApi;
import org.jclouds.vcloud.director.v1_5.login.SessionApi; import org.jclouds.vcloud.director.v1_5.login.SessionApi;
import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorAsyncApi; import org.jclouds.vcloud.director.v1_5.login.SessionAsyncApi;
import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorApi; import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorApi;
import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorAsyncApi;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
@ -225,6 +227,20 @@ public class VCloudDirectorRestClientModule extends RestClientModule<VCloudDirec
} }
@Provides
@Singleton
protected Function<String, Entity> makeSureResolveEntityRetriesOnTimeout(ResolveEntity resolveEntity) {
// we should retry on timeout exception logging in.
return new RetryOnTimeOutExceptionFunction<String, Entity>(resolveEntity);
}
@Provides
@Singleton
public LoadingCache<String, Entity> resolveEntityCache(Function<String, Entity> getEntity,
@Named(Constants.PROPERTY_SESSION_INTERVAL) int seconds) {
return CacheBuilder.newBuilder().expireAfterWrite(seconds, TimeUnit.SECONDS).build(CacheLoader.from(getEntity));
}
@Provides @Provides
@Singleton @Singleton
protected Function<Credentials, SessionWithToken> makeSureFilterRetriesOnTimeout( protected Function<Credentials, SessionWithToken> makeSureFilterRetriesOnTimeout(

View File

@ -42,6 +42,7 @@ import com.google.common.collect.Sets;
* *
* @author danikov * @author danikov
*/ */
//TODO: this is a ridiculously complicated way of representing Map<String, String>
@XmlRootElement(name = "MetadataEntry") @XmlRootElement(name = "MetadataEntry")
public class MetadataEntry extends Resource { public class MetadataEntry extends Resource {

View File

@ -46,6 +46,7 @@ import com.google.common.base.Objects;
@XmlType(propOrder = { @XmlType(propOrder = {
"isPublished" "isPublished"
}) })
//TODO: this is ridiculous
public class PublishCatalogParams { public class PublishCatalogParams {
public static Builder builder() { public static Builder builder() {

View File

@ -25,12 +25,13 @@ import org.jclouds.concurrent.Timeout;
import org.jclouds.rest.annotations.Delegate; import org.jclouds.rest.annotations.Delegate;
import org.jclouds.vcloud.director.v1_5.domain.Catalog; import org.jclouds.vcloud.director.v1_5.domain.Catalog;
import org.jclouds.vcloud.director.v1_5.domain.CatalogItem; import org.jclouds.vcloud.director.v1_5.domain.CatalogItem;
import org.jclouds.vcloud.director.v1_5.domain.Metadata;
/** /**
* Provides synchronous access to {@link Catalog} objects. * Provides synchronous access to {@link Catalog} objects.
* *
* @see CatalogAsyncApi * @see CatalogAsyncApi
* @author grkvlt@apache.org * @author grkvlt@apache.org, Adrian Cole
*/ */
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public interface CatalogApi { public interface CatalogApi {
@ -42,10 +43,13 @@ public interface CatalogApi {
* GET /catalog/{id} * GET /catalog/{id}
* </pre> * </pre>
* *
* @param catalogUri the reference for the catalog * @param catalogUri
* the reference for the catalog
* @return a catalog * @return a catalog
*/ */
Catalog getCatalog(URI catalogUri); Catalog get(String catalogUrn);
Catalog get(URI catalogHref);
/** /**
* Creates a catalog item in a catalog. * Creates a catalog item in a catalog.
@ -54,11 +58,15 @@ public interface CatalogApi {
* POST /catalog/{id}/catalogItems * POST /catalog/{id}/catalogItems
* </pre> * </pre>
* *
* @param catalogUri the URI of the catalog * @param catalogUri
* @param item the catalog item to create * the URI of the catalog
* @param item
* the catalog item to create
* @return the created catalog item * @return the created catalog item
*/ */
CatalogItem addCatalogItem(URI catalogUri, CatalogItem item); CatalogItem addItem(String catalogUrn, CatalogItem item);
CatalogItem addItem(URI catalogHref, CatalogItem item);
/** /**
* Retrieves a catalog item. * Retrieves a catalog item.
@ -67,10 +75,13 @@ public interface CatalogApi {
* GET /catalogItem/{id} * GET /catalogItem/{id}
* </pre> * </pre>
* *
* @param catalogItemRef the reference for the catalog item * @param catalogItemRef
* the reference for the catalog item
* @return the catalog item * @return the catalog item
*/ */
CatalogItem getCatalogItem(URI catalogItemRef); CatalogItem getItem(String catalogItemUrn);
CatalogItem getItem(URI catalogItemHref);
/** /**
* Modifies a catalog item. * Modifies a catalog item.
@ -79,11 +90,15 @@ public interface CatalogApi {
* PUT /catalogItem/{id} * PUT /catalogItem/{id}
* </pre> * </pre>
* *
* @param catalogItemRef the reference for the catalog item * @param catalogItemRef
* @param catalogItem the catalog item * the reference for the catalog item
* @param catalogItem
* the catalog item
* @return the updated catalog item * @return the updated catalog item
*/ */
CatalogItem updateCatalogItem(URI catalogItemRef, CatalogItem catalogItem); CatalogItem updateItem(String catalogItemUrn, CatalogItem catalogItem);
CatalogItem updateItem(URI catalogItemHref, CatalogItem catalogItem);
/** /**
* Deletes a catalog item. * Deletes a catalog item.
@ -92,9 +107,12 @@ public interface CatalogApi {
* DELETE /catalogItem/{id} * DELETE /catalogItem/{id}
* </pre> * </pre>
* *
* @param catalogItemRef the reference for the catalog item * @param catalogItemRef
* the reference for the catalog item
*/ */
void deleteCatalogItem(URI catalogItemRef); void deleteItem(String catalogItemUrn);
void deleteItem(URI catalogItemHref);
/** /**
* @return synchronous access to {@link Metadata.Readable} features * @return synchronous access to {@link Metadata.Readable} features
@ -106,6 +124,6 @@ public interface CatalogApi {
* @return synchronous access to {@link Metadata.Writeable} features for CatalogItems * @return synchronous access to {@link Metadata.Writeable} features for CatalogItems
*/ */
@Delegate @Delegate
MetadataApi.Writeable getCatalogItemMetadataApi(); MetadataApi.Writeable getItemMetadataApi();
} }

View File

@ -39,63 +39,113 @@ import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Catalog; import org.jclouds.vcloud.director.v1_5.domain.Catalog;
import org.jclouds.vcloud.director.v1_5.domain.CatalogItem; import org.jclouds.vcloud.director.v1_5.domain.CatalogItem;
import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationAndCookieToRequest; import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationAndCookieToRequest;
import org.jclouds.vcloud.director.v1_5.functions.href.CatalogItemURNToHref;
import org.jclouds.vcloud.director.v1_5.functions.href.CatalogURNToHref;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
/** /**
* @see CatalogApi * @see CatalogApi
* @author grkvlt@apache.org * @author grkvlt@apache.org, Adrian Cole
*/ */
@RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class) @RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class)
public interface CatalogAsyncApi { public interface CatalogAsyncApi {
/** /**
* Retrieves a catalog. * @see CatalogApi#get(String)
*/ */
@GET @GET
@Consumes @Consumes
@JAXBResponseParser @JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends Catalog> getCatalog(@EndpointParam URI catalogUri); ListenableFuture<? extends Catalog> get(@EndpointParam(parser = CatalogURNToHref.class) String catalogUrn);
/** /**
* Creates a catalog item in a catalog. * @see CatalogApi#addItem(String, CatalogItem)
*/ */
@POST @POST
@Path("/catalogItems") @Path("/catalogItems")
@Consumes(VCloudDirectorMediaType.CATALOG_ITEM) @Consumes(VCloudDirectorMediaType.CATALOG_ITEM)
@Produces(VCloudDirectorMediaType.CATALOG_ITEM) @Produces(VCloudDirectorMediaType.CATALOG_ITEM)
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<CatalogItem> addCatalogItem(@EndpointParam URI catalogUri, ListenableFuture<CatalogItem> addItem(@EndpointParam(parser = CatalogURNToHref.class) String catalogUrn,
@BinderParam(BindToXMLPayload.class) CatalogItem catalogItem); @BinderParam(BindToXMLPayload.class) CatalogItem catalogItem);
/** /**
* Retrieves a catalog item. * @see CatalogApi#getItem(String)
*/ */
@GET @GET
@Consumes @Consumes
@JAXBResponseParser @JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<CatalogItem> getCatalogItem(@EndpointParam URI catalogItemUri); ListenableFuture<CatalogItem> getItem(@EndpointParam(parser = CatalogItemURNToHref.class) String catalogItemUrn);
/** /**
* Modifies a catalog item. * @see CatalogApi#updateItem(String, CatalogItem)
*/ */
@PUT @PUT
@Consumes(VCloudDirectorMediaType.CATALOG_ITEM) @Consumes(VCloudDirectorMediaType.CATALOG_ITEM)
@Produces(VCloudDirectorMediaType.CATALOG_ITEM) @Produces(VCloudDirectorMediaType.CATALOG_ITEM)
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<CatalogItem> updateCatalogItem(@EndpointParam URI catalogItemUri, ListenableFuture<CatalogItem> updateItem(@EndpointParam(parser = CatalogItemURNToHref.class) String catalogItemUrn,
@BinderParam(BindToXMLPayload.class) CatalogItem catalogItem); @BinderParam(BindToXMLPayload.class) CatalogItem catalogItem);
/** /**
* Deletes a catalog item. * @see CatalogApi#deleteItem(String)
*/ */
@DELETE @DELETE
@Consumes @Consumes
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<Void> deleteCatalogItem(@EndpointParam URI catalogItemUri); ListenableFuture<Void> deleteItem(@EndpointParam(parser = CatalogItemURNToHref.class) String catalogItemUrn);
/**
* @see CatalogApi#get(URI)
*/
@GET
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends Catalog> get(@EndpointParam URI catalogHref);
/**
* @see CatalogApi#addItem(URI, CatalogItem)
*/
@POST
@Path("/catalogItems")
@Consumes(VCloudDirectorMediaType.CATALOG_ITEM)
@Produces(VCloudDirectorMediaType.CATALOG_ITEM)
@JAXBResponseParser
ListenableFuture<CatalogItem> addItem(@EndpointParam URI catalogHref,
@BinderParam(BindToXMLPayload.class) CatalogItem catalogItem);
/**
* @see CatalogApi#getItem(URI)
*/
@GET
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<CatalogItem> getItem(@EndpointParam URI catalogItemHref);
/**
* @see CatalogApi#updateItem(URI, CatalogItem)
*/
@PUT
@Consumes(VCloudDirectorMediaType.CATALOG_ITEM)
@Produces(VCloudDirectorMediaType.CATALOG_ITEM)
@JAXBResponseParser
ListenableFuture<CatalogItem> updateItem(@EndpointParam URI catalogItemHref,
@BinderParam(BindToXMLPayload.class) CatalogItem catalogItem);
/**
* @see CatalogApi#deleteItem(URI)
*/
@DELETE
@Consumes
@JAXBResponseParser
ListenableFuture<Void> deleteItem(@EndpointParam URI catalogItemHref);
/** /**
* @return asynchronous access to {@link Metadata.Readable} features * @return asynchronous access to {@link Metadata.Readable} features
@ -104,8 +154,8 @@ public interface CatalogAsyncApi {
MetadataAsyncApi.Readable getMetadataApi(); MetadataAsyncApi.Readable getMetadataApi();
/** /**
* @return asynchronous access to {@link Metadata.Writeable} features for CatalogItems * @see CatalogApi#getItemMetadataApi
*/ */
@Delegate @Delegate
MetadataAsyncApi.Writeable getCatalogItemMetadataApi(); MetadataAsyncApi.Writeable getItemMetadataApi();
} }

View File

@ -36,20 +36,19 @@ public interface MetadataApi {
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public static interface Readable extends MetadataApi { public static interface Readable extends MetadataApi {
/** /**
* Retrieves an list of metadata * Retrieves an list of metadata
* *
* @return a list of metadata * @return a list of metadata
*/ */
Metadata getMetadata(URI uri); Metadata get(URI uri);
/** /**
* Retrieves a metadata value * Retrieves a metadata value
* *
* @return the metadata value, or null if not found * @return the metadata value, or null if not found
*/ */
MetadataValue getMetadataValue(URI uri, String key); MetadataValue getValue(URI uri, String key);
} }
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
@ -61,16 +60,16 @@ public interface MetadataApi {
* @return a task. This operation is asynchronous and the user should monitor the returned * @return a task. This operation is asynchronous and the user should monitor the returned
* task status in order to check when it is completed. * task status in order to check when it is completed.
*/ */
Task mergeMetadata(URI uri, Metadata metadata); Task merge(URI uri, Metadata metadata);
/** /**
* Sets the metadata for the particular key for the media to the value provided. * Sets the metadata for the particular key for the media to the value provided. Note: this
* Note: this will replace any existing metadata information * will replace any existing metadata information
* *
* @return a task. This operation is asynchronous and the user should monitor the returned * @return a task. This operation is asynchronous and the user should monitor the returned
* task status in order to check when it is completed. * task status in order to check when it is completed.
*/ */
Task setMetadata(URI uri, String key, MetadataValue metadataValue); Task putEntry(URI uri, String key, MetadataValue metadataValue);
/** /**
* Deletes a metadata entry. * Deletes a metadata entry.
@ -78,6 +77,7 @@ public interface MetadataApi {
* @return a task. This operation is asynchronous and the user should monitor the returned * @return a task. This operation is asynchronous and the user should monitor the returned
* task status in order to check when it is completed. * task status in order to check when it is completed.
*/ */
Task deleteMetadataEntry(URI uri, String key); Task deleteEntry(URI uri, String key);
} }
} }

View File

@ -48,64 +48,68 @@ import com.google.common.util.concurrent.ListenableFuture;
* @see MetadataApi * @see MetadataApi
* @author danikov * @author danikov
*/ */
//TODO: take out the endpoint params and supply them in the Delegate calls.
public interface MetadataAsyncApi { public interface MetadataAsyncApi {
@RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class) @RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class)
public static interface Readable extends MetadataAsyncApi { public static interface Readable extends MetadataAsyncApi {
/** /**
* @see MetadataApi.Readable#getMetadata(URISupplier) * @see MetadataApi.Readable#get(URI)
*/ */
@GET @GET
@Path("/metadata") @Path("/metadata")
@Consumes @Consumes
@JAXBResponseParser @JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Metadata> getMetadata(@EndpointParam URI metaDataUri); ListenableFuture<Metadata> get(@EndpointParam URI metaDataUri);
/** /**
* @see MetadataApi.Readable#getMetadataValue(URI, String) * @see MetadataApi.Readable#getValue(URI, String)
*/ */
@GET @GET
@Path("/metadata/{key}") @Path("/metadata/{key}")
@Consumes @Consumes
@JAXBResponseParser @JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<MetadataValue> getMetadataValue(@EndpointParam URI metaDataUri, @PathParam("key") String key); ListenableFuture<MetadataValue> getValue(@EndpointParam URI metaDataUri, @PathParam("key") String key);
} }
@RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class) @RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class)
public static interface Writeable extends Readable { public static interface Writeable extends Readable {
/** /**
* @see MetadataApi.Writable#mergeMetadata(URI, Metadata)) * @see MetadataApi.Writable#merge(URI, Metadata))
*/ */
@POST @POST
@Path("/metadata") @Path("/metadata")
@Consumes(VCloudDirectorMediaType.TASK) @Consumes(VCloudDirectorMediaType.TASK)
@Produces(VCloudDirectorMediaType.METADATA) @Produces(VCloudDirectorMediaType.METADATA)
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<Task> mergeMetadata(@EndpointParam URI metaDataUri, @BinderParam(BindToXMLPayload.class) Metadata metadata); ListenableFuture<Task> merge(@EndpointParam URI metaDataUri,
@BinderParam(BindToXMLPayload.class) Metadata metadata);
/** /**
* @see MetadataApi.Writable#setMetadata(URI, String, MetadataEntry)) * @see MetadataApi.Writeable#putEntry(URI, String, MetadataEntry))
*/ */
@PUT @PUT
@Path("/metadata/{key}") @Path("/metadata/{key}")
@Consumes(VCloudDirectorMediaType.TASK) @Consumes(VCloudDirectorMediaType.TASK)
@Produces(VCloudDirectorMediaType.METADATA_VALUE) @Produces(VCloudDirectorMediaType.METADATA_VALUE)
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<Task> setMetadata(@EndpointParam URI metaDataUri, // TODO: this is rediculous. get rid of the MetadataValue type, as it is only a string!
@PathParam("key") String key, ListenableFuture<Task> putEntry(@EndpointParam URI metaDataUri, @PathParam("key") String key,
@BinderParam(BindToXMLPayload.class) MetadataValue metadataValue); @BinderParam(BindToXMLPayload.class) MetadataValue metadataValue);
/** /**
* @see MetadataApi.Writable#deleteMetadataEntry(URISupplier, String)) * @see MetadataApi.Writable#deleteEntry(URI, String))
*/ */
@DELETE @DELETE
@Path("/metadata/{key}") @Path("/metadata/{key}")
@Consumes(VCloudDirectorMediaType.TASK) @Consumes(VCloudDirectorMediaType.TASK)
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<Task> deleteMetadataEntry(@EndpointParam URI metaDataUri, @PathParam("key") String key); ListenableFuture<Task> deleteEntry(@EndpointParam URI metaDataUri, @PathParam("key") String key);
} }
} }

View File

@ -24,6 +24,7 @@ import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
import org.jclouds.rest.annotations.Delegate; import org.jclouds.rest.annotations.Delegate;
import org.jclouds.vcloud.director.v1_5.domain.AdminCatalog; import org.jclouds.vcloud.director.v1_5.domain.AdminCatalog;
import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.Owner; import org.jclouds.vcloud.director.v1_5.domain.Owner;
import org.jclouds.vcloud.director.v1_5.domain.params.PublishCatalogParams; import org.jclouds.vcloud.director.v1_5.domain.params.PublishCatalogParams;
import org.jclouds.vcloud.director.v1_5.features.CatalogApi; import org.jclouds.vcloud.director.v1_5.features.CatalogApi;
@ -33,12 +34,11 @@ import org.jclouds.vcloud.director.v1_5.features.MetadataApi;
* Provides synchronous access to {@link AdminCatalog} objects. * Provides synchronous access to {@link AdminCatalog} objects.
* *
* @see AdminCatalogAsyncApi * @see AdminCatalogAsyncApi
* @author danikov * @author danikov, Adrian Cole
*/ */
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public interface AdminCatalogApi extends CatalogApi { public interface AdminCatalogApi extends CatalogApi {
/** /**
* Creates a catalog in an organization. The catalog will always be created in unpublished state. * Creates a catalog in an organization. The catalog will always be created in unpublished state.
* *
@ -46,10 +46,13 @@ public interface AdminCatalogApi extends CatalogApi {
* POST /admin/org/{id}/catalogs * POST /admin/org/{id}/catalogs
* </pre> * </pre>
* *
* @param orgRef the reference for the org * @param orgUrn
* the urn for the org
* @return contains a , which will point to the running asynchronous creation operation. * @return contains a , which will point to the running asynchronous creation operation.
*/ */
AdminCatalog createCatalog(URI orgRef, AdminCatalog catalog); AdminCatalog createCatalogInOrg(AdminCatalog catalog, String orgUrn);
AdminCatalog createCatalogInOrg(AdminCatalog catalog, URI adminCatalogHref);
/** /**
* Retrieves a catalog. * Retrieves a catalog.
@ -58,15 +61,20 @@ public interface AdminCatalogApi extends CatalogApi {
* GET /admin/catalog/{id} * GET /admin/catalog/{id}
* </pre> * </pre>
* *
* @param catalogRef the reference for the catalog * @param catalogUrn
* the urn for the catalog
* @return a catalog * @return a catalog
*/ */
@Override @Override
AdminCatalog getCatalog(URI catalogRef); AdminCatalog get(String catalogUrn);
@Override
AdminCatalog get(URI adminCatalogHref);
/** /**
* Modifies a catalog. A catalog could be published or unpublished. The IsPublished property is treated as a * Modifies a catalog. A catalog could be published or unpublished. The IsPublished property is
* read only value by the server. In order to control publishing settings use the 'publish' action must be used. * treated as a read only value by the server. In order to control publishing settings use the
* 'publish' action must be used.
* *
* <pre> * <pre>
* PUT /admin/catalog/{id} * PUT /admin/catalog/{id}
@ -74,7 +82,9 @@ public interface AdminCatalogApi extends CatalogApi {
* *
* @return the updated catalog * @return the updated catalog
*/ */
AdminCatalog updateCatalog(URI catalogRef, AdminCatalog catalog); AdminCatalog update(String catalogUrn, AdminCatalog catalog);
AdminCatalog update(URI adminCatalogHref, AdminCatalog catalog);
/** /**
* Deletes a catalog. The catalog could be deleted if it is either published or unpublished. * Deletes a catalog. The catalog could be deleted if it is either published or unpublished.
@ -83,7 +93,9 @@ public interface AdminCatalogApi extends CatalogApi {
* DELETE /admin/catalog/{id} * DELETE /admin/catalog/{id}
* </pre> * </pre>
*/ */
void deleteCatalog(URI catalogRef); void delete(String catalogUrn);
void delete(URI adminCatalogHref);
/** /**
* Retrieves the owner of a catalog. * Retrieves the owner of a catalog.
@ -94,7 +106,9 @@ public interface AdminCatalogApi extends CatalogApi {
* *
* @return the owner or null if not found * @return the owner or null if not found
*/ */
Owner getOwner(URI catalogRef); Owner getOwner(String catalogUrn);
Owner getOwner(URI adminCatalogHref);
/** /**
* Changes owner for catalog. * Changes owner for catalog.
@ -103,15 +117,22 @@ public interface AdminCatalogApi extends CatalogApi {
* PUT /admin/catalog/{id}/owner * PUT /admin/catalog/{id}/owner
* </pre> * </pre>
*/ */
void setOwner(URI catalogRef, Owner newOwner); void setOwner(String catalogUrn, Owner newOwner);
void setOwner(URI adminCatalogHref, Owner newOwner);
/** /**
* Publish a catalog. Publishing a catalog makes the catalog visible to all organizations in a vCloud. * Publish a catalog. Publishing a catalog makes the catalog visible to all organizations in a
* vCloud.
* @param orgUrn
*/ */
void publishCatalog(URI catalogRef, PublishCatalogParams params); void publish(String catalogUrn, PublishCatalogParams params);
//TODO: lot of work to pass in a single boolean, would like to polymorphically include something like: void publish(URI adminCatalogHref, PublishCatalogParams params);
//void publishCatalog(URI catalogRef)
// TODO: lot of work to pass in a single boolean, would like to polymorphically include something
// like:
// void publishCatalog(String catalogUrn)
/** /**
* @return synchronous access to {@link Metadata.Writeable} features * @return synchronous access to {@link Metadata.Writeable} features

View File

@ -38,90 +38,164 @@ import org.jclouds.rest.binders.BindToXMLPayload;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.AdminCatalog; import org.jclouds.vcloud.director.v1_5.domain.AdminCatalog;
import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.Owner; import org.jclouds.vcloud.director.v1_5.domain.Owner;
import org.jclouds.vcloud.director.v1_5.domain.params.PublishCatalogParams; import org.jclouds.vcloud.director.v1_5.domain.params.PublishCatalogParams;
import org.jclouds.vcloud.director.v1_5.features.CatalogAsyncApi; import org.jclouds.vcloud.director.v1_5.features.CatalogAsyncApi;
import org.jclouds.vcloud.director.v1_5.features.MetadataAsyncApi; import org.jclouds.vcloud.director.v1_5.features.MetadataAsyncApi;
import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationAndCookieToRequest; import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationAndCookieToRequest;
import org.jclouds.vcloud.director.v1_5.functions.href.CatalogURNToAdminHref;
import org.jclouds.vcloud.director.v1_5.functions.href.OrgURNToAdminHref;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
/** /**
* @see AdminCatalogApi * @see AdminCatalogApi
* @author danikov * @author danikov, Adrian Cole
*/ */
@RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class) @RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class)
public interface AdminCatalogAsyncApi extends CatalogAsyncApi { public interface AdminCatalogAsyncApi extends CatalogAsyncApi {
/** /**
* @see AdminApi#createCatalog(URI, AdminCatalog) * @see AdminCatalogApi#createCatalogInOrg(AdminCatalog, String)
*/ */
@POST @POST
@Path("/catalogs") @Path("/catalogs")
@Consumes(VCloudDirectorMediaType.ADMIN_CATALOG) @Consumes(VCloudDirectorMediaType.ADMIN_CATALOG)
@Produces(VCloudDirectorMediaType.ADMIN_CATALOG) @Produces(VCloudDirectorMediaType.ADMIN_CATALOG)
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<AdminCatalog> createCatalog(@EndpointParam URI orgRef, ListenableFuture<AdminCatalog> createCatalogInOrg(@BinderParam(BindToXMLPayload.class) AdminCatalog catalog,
@BinderParam(BindToXMLPayload.class) AdminCatalog catalog); @EndpointParam(parser = OrgURNToAdminHref.class) String orgUrn);
/** /**
* @see AdminApi#getCatalog(URI) * @see AdminCatalogApi#createCatalogInOrg(AdminCatalog, URI)
*/
@POST
@Path("/catalogs")
@Consumes(VCloudDirectorMediaType.ADMIN_CATALOG)
@Produces(VCloudDirectorMediaType.ADMIN_CATALOG)
@JAXBResponseParser
ListenableFuture<AdminCatalog> createCatalogInOrg(@BinderParam(BindToXMLPayload.class) AdminCatalog catalog,
@EndpointParam URI orgHref);
/**
* @see AdminCatalogApi#get(String)
*/ */
@Override @Override
@GET @GET
@Consumes @Consumes
@JAXBResponseParser @JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<AdminCatalog> getCatalog(@EndpointParam URI catalogRef); ListenableFuture<AdminCatalog> get(@EndpointParam(parser = CatalogURNToAdminHref.class) String catalogUrn);
/** /**
* @see AdminApi#getCatalog(URI) * @see AdminCatalogApi#get(URI)
*/
@Override
@GET
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<AdminCatalog> get(@EndpointParam URI orgHref);
/**
* @see AdminCatalogApi#update(String, AdminCatalog)
*/ */
@PUT @PUT
@Consumes(VCloudDirectorMediaType.ADMIN_CATALOG) @Consumes(VCloudDirectorMediaType.ADMIN_CATALOG)
@Produces(VCloudDirectorMediaType.ADMIN_CATALOG) @Produces(VCloudDirectorMediaType.ADMIN_CATALOG)
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<AdminCatalog> updateCatalog(@EndpointParam URI catalogRef, ListenableFuture<AdminCatalog> update(@EndpointParam(parser = CatalogURNToAdminHref.class) String catalogUrn,
@BinderParam(BindToXMLPayload.class) AdminCatalog catalog); @BinderParam(BindToXMLPayload.class) AdminCatalog catalog);
/** /**
* @see AdminApi#deleteCatalog(URI) * @see AdminCatalogApi#update(URI, AdminCatalog)
*/
@PUT
@Consumes(VCloudDirectorMediaType.ADMIN_CATALOG)
@Produces(VCloudDirectorMediaType.ADMIN_CATALOG)
@JAXBResponseParser
ListenableFuture<AdminCatalog> update(@EndpointParam URI adminCatalogHref,
@BinderParam(BindToXMLPayload.class) AdminCatalog catalog);
/**
* @see AdminCatalogApi#delete(String)
*/ */
@DELETE @DELETE
@Consumes @Consumes
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<Void> deleteCatalog(@EndpointParam URI catalogRef); ListenableFuture<Void> delete(@EndpointParam(parser = CatalogURNToAdminHref.class) String catalogUrn);
/** /**
* @see AdminApi#getOwner(URI) * @see AdminCatalogApi#delete(URI)
*/
@DELETE
@Consumes
@JAXBResponseParser
ListenableFuture<Void> delete(@EndpointParam URI adminCatalogHref);
/**
* @see AdminCatalogApi#getOwner(String)
*/ */
@GET @GET
@Path("/owner") @Path("/owner")
@Consumes @Consumes
@JAXBResponseParser @JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Owner> getOwner(@EndpointParam URI catalogRef); ListenableFuture<Owner> getOwner(@EndpointParam(parser = CatalogURNToAdminHref.class) String catalogUrn);
/** /**
* @see AdminApi#setOwner(URI, Owner) * @see AdminCatalogApi#getOwner(URI)
*/
@GET
@Path("/owner")
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Owner> getOwner(@EndpointParam URI adminCatalogHref);
/**
* @see AdminCatalogApi#setOwner(String, Owner)
*/ */
@PUT @PUT
@Path("/owner") @Path("/owner")
@Consumes @Consumes
@Produces(VCloudDirectorMediaType.OWNER) @Produces(VCloudDirectorMediaType.OWNER)
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<Void> setOwner(@EndpointParam URI catalogRef, ListenableFuture<Void> setOwner(@EndpointParam(parser = CatalogURNToAdminHref.class) String catalogUrn,
@BinderParam(BindToXMLPayload.class) Owner newOwner); @BinderParam(BindToXMLPayload.class) Owner newOwner);
/** /**
* @see AdminApi#AdminApi(URI, PublishCatalogParams) * @see AdminCatalogApi#setOwner(URI, Owner)
*/
@PUT
@Path("/owner")
@Consumes
@Produces(VCloudDirectorMediaType.OWNER)
@JAXBResponseParser
ListenableFuture<Void> setOwner(@EndpointParam URI adminCatalogHref,
@BinderParam(BindToXMLPayload.class) Owner newOwner);
/**
* @see AdminCatalogApi#publish(String, PublishCatalogParams)
*/ */
@POST @POST
@Path("/action/publish") @Path("/action/publish")
@Consumes @Consumes
@Produces(VCloudDirectorMediaType.PUBLISH_CATALOG_PARAMS) @Produces(VCloudDirectorMediaType.PUBLISH_CATALOG_PARAMS)
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<Void> publishCatalog(@EndpointParam URI catalogRef, ListenableFuture<Void> publish(@EndpointParam(parser = CatalogURNToAdminHref.class) String catalogUrn,
@BinderParam(BindToXMLPayload.class) PublishCatalogParams params);
/**
* @see AdminCatalogApi#publish(URI, PublishCatalogParams)
*/
@POST
@Path("/action/publish")
@Consumes
@Produces(VCloudDirectorMediaType.PUBLISH_CATALOG_PARAMS)
@JAXBResponseParser
ListenableFuture<Void> publish(@EndpointParam URI adminCatalogHref,
@BinderParam(BindToXMLPayload.class) PublishCatalogParams params); @BinderParam(BindToXMLPayload.class) PublishCatalogParams params);
/** /**

View File

@ -25,9 +25,9 @@ import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.director.v1_5.domain.User; import org.jclouds.vcloud.director.v1_5.domain.User;
/** /**
* Provides synchronous access to {@link Group} objects. * Provides synchronous access to {@link User} objects.
* *
* @see GroupAsyncApi * @see UserAsyncApi
* @author danikov * @author danikov
*/ */
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)

View File

@ -71,7 +71,7 @@ public class AllCatalogItemsInCatalog implements Function<Catalog, Iterable<? ex
@Override @Override
public Future<CatalogItem> apply(Reference from) { public Future<CatalogItem> apply(Reference from) {
return aapi.getCatalogApi().getCatalogItem(from.getHref()); return aapi.getCatalogApi().getItem(from.getHref());
} }
}, executor, null, logger, "catalogItems in " + from.getHref()); }, executor, null, logger, "catalogItems in " + from.getHref());

View File

@ -59,7 +59,7 @@ public class AllCatalogsInOrg implements Function<AdminOrg, Iterable<? extends C
new Function<Reference, Future<? extends Catalog>>() { new Function<Reference, Future<? extends Catalog>>() {
@Override @Override
public Future<? extends Catalog> apply(Reference from) { public Future<? extends Catalog> apply(Reference from) {
return aapi.getCatalogApi().getCatalog(from.getHref()); return aapi.getCatalogApi().get(from.getHref());
} }
}, executor, null, logger, "catalogs in " + org.getName()); }, executor, null, logger, "catalogs in " + org.getName());

View File

@ -0,0 +1,68 @@
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.director.v1_5.functions;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.vcloud.director.v1_5.domain.Entity;
import org.jclouds.vcloud.director.v1_5.domain.Link;
import org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.Iterables;
/**
* Resolves URN to its HREF via the entity Resolver
*
* @author Adrian Cole
*/
@Singleton
public abstract class URNToHref implements Function<Object, URI> {
private final LoadingCache<String, Entity> resolveEntityCache;
@Inject
public URNToHref(LoadingCache<String, Entity> resolveEntityCache) {
this.resolveEntityCache = checkNotNull(resolveEntityCache, "resolveEntityCache");
}
/**
* media type to search for.
*
* @see VCloudDirectorMediaType
*/
protected abstract String type();
@Override
public URI apply(@Nullable Object from) {
checkArgument(checkNotNull(from, "urn") instanceof String, "urn is a String argument");
Entity entity = resolveEntityCache.getUnchecked(from.toString());
Optional<Link> link = Iterables.tryFind(entity.getLinks(), LinkPredicates.typeEquals(type()));
checkArgument(link.isPresent(), "no link for type %s found for entity %s", type(), entity);
return link.get().getHref();
}
}

View File

@ -0,0 +1,43 @@
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.director.v1_5.functions.href;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Entity;
import org.jclouds.vcloud.director.v1_5.functions.URNToHref;
import com.google.common.cache.LoadingCache;
@Singleton
public class CatalogItemURNToHref extends URNToHref {
@Inject
public CatalogItemURNToHref(LoadingCache<String, Entity> resolveEntityCache) {
super(resolveEntityCache);
}
@Override
protected String type() {
return VCloudDirectorMediaType.CATALOG_ITEM;
}
}

View File

@ -0,0 +1,43 @@
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.director.v1_5.functions.href;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Entity;
import org.jclouds.vcloud.director.v1_5.functions.URNToHref;
import com.google.common.cache.LoadingCache;
@Singleton
public class CatalogURNToAdminHref extends URNToHref {
@Inject
public CatalogURNToAdminHref(LoadingCache<String, Entity> resolveEntityCache) {
super(resolveEntityCache);
}
@Override
protected String type() {
return VCloudDirectorMediaType.ADMIN_CATALOG;
}
}

View File

@ -0,0 +1,43 @@
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.director.v1_5.functions.href;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Entity;
import org.jclouds.vcloud.director.v1_5.functions.URNToHref;
import com.google.common.cache.LoadingCache;
@Singleton
public class CatalogURNToHref extends URNToHref {
@Inject
public CatalogURNToHref(LoadingCache<String, Entity> resolveEntityCache) {
super(resolveEntityCache);
}
@Override
protected String type() {
return VCloudDirectorMediaType.CATALOG;
}
}

View File

@ -0,0 +1,43 @@
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.director.v1_5.functions.href;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Entity;
import org.jclouds.vcloud.director.v1_5.functions.URNToHref;
import com.google.common.cache.LoadingCache;
@Singleton
public class OrgURNToAdminHref extends URNToHref {
@Inject
public OrgURNToAdminHref(LoadingCache<String, Entity> resolveEntityCache) {
super(resolveEntityCache);
}
@Override
protected String type() {
return VCloudDirectorMediaType.ADMIN_ORG;
}
}

View File

@ -16,24 +16,28 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.jclouds.vcloud.director.v1_5.functions; package org.jclouds.vcloud.director.v1_5.functions.href;
import java.net.URI;
import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Entity;
import org.jclouds.vcloud.director.v1_5.functions.URNToHref;
import com.google.common.base.Function; import com.google.common.cache.LoadingCache;
/**
* @author danikov
*/
@Singleton @Singleton
public class ReferenceToEndpoint implements Function<Reference, URI> { public class OrgURNToHref extends URNToHref {
@Inject
public OrgURNToHref(LoadingCache<String, Entity> resolveEntityCache) {
super(resolveEntityCache);
}
@Override @Override
public URI apply(Reference from) { protected String type() {
return from.getHref(); return VCloudDirectorMediaType.ORG;
} }
} }

View File

@ -0,0 +1,49 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.director.v1_5.functions.href;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.director.v1_5.domain.Entity;
import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorApi;
import com.google.common.base.Function;
@Singleton
public class ResolveEntity implements Function<String, Entity> {
private final VCloudDirectorApi api;
@Inject
public ResolveEntity(VCloudDirectorApi api) {
this.api = checkNotNull(api, "api");
}
@Override
public Entity apply(String input) {
return api.resolveEntity(checkNotNull(input, "urn"));
}
@Override
public String toString() {
return "resolveEntity()";
}
}

View File

@ -31,6 +31,8 @@ import org.testng.annotations.Test;
@Test(groups = "unit", testName = "VCloudDirectorApi") @Test(groups = "unit", testName = "VCloudDirectorApi")
public class VCloudDirectorApiExpectTest extends VCloudDirectorAdminApiExpectTest { public class VCloudDirectorApiExpectTest extends VCloudDirectorAdminApiExpectTest {
//TODO: this inheritance is all wrong!! the base client shouldn't inherit from the admin client tests!!
public void testRestClientModuleWorksProperly() throws Exception { public void testRestClientModuleWorksProperly() throws Exception {
VCloudDirectorApi apiWhenSessionsExist = requestSendsResponse(loginRequest, sessionResponse); VCloudDirectorApi apiWhenSessionsExist = requestSendsResponse(loginRequest, sessionResponse);

View File

@ -18,6 +18,13 @@
*/ */
package org.jclouds.vcloud.director.v1_5.features; package org.jclouds.vcloud.director.v1_5.features;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.ADMIN_CATALOG;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.CATALOG;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.CATALOG_ITEM;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.ENTITY;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.METADATA;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.METADATA_VALUE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.TASK;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.net.URI; import java.net.URI;
@ -25,7 +32,6 @@ import java.net.URI;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorApiExpectTest; import org.jclouds.vcloud.director.v1_5.VCloudDirectorApiExpectTest;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Catalog; import org.jclouds.vcloud.director.v1_5.domain.Catalog;
import org.jclouds.vcloud.director.v1_5.domain.CatalogItem; import org.jclouds.vcloud.director.v1_5.domain.CatalogItem;
import org.jclouds.vcloud.director.v1_5.domain.Link; import org.jclouds.vcloud.director.v1_5.domain.Link;
@ -43,349 +49,376 @@ import com.google.common.net.HttpHeaders;
/** /**
* Test the {@link CatalogApi} by observing its side effects. * Test the {@link CatalogApi} by observing its side effects.
* *
* @author grkvlt@apache.org * @author grkvlt@apache.org, Adrian Cole
*/ */
@Test(groups = { "unit", "user" }, singleThreaded = true, testName = "CatalogApiExpectTest") @Test(groups = { "unit", "user" }, singleThreaded = true, testName = "CatalogApiExpectTest")
public class CatalogApiExpectTest extends VCloudDirectorApiExpectTest { public class CatalogApiExpectTest extends VCloudDirectorApiExpectTest {
static String catalog = "7212e451-76e1-4631-b2de-ba1dfd8080e4";
static String catalogUrn = "urn:vcloud:catalog:" + catalog;
static URI catalogHref = URI.create(endpoint + "/catalog/" + catalog);
@Test HttpRequest get = HttpRequest.builder()
public void testGetCatalog() {
HttpRequest catalogRequest = HttpRequest.builder()
.method("GET") .method("GET")
.endpoint(endpoint + "/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4") .endpoint(catalogHref)
.addHeader("Accept", "*/*") .addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token) .addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token) .addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.build(); .build();
HttpResponse catalogResponse = HttpResponse.builder() HttpResponse getResponse = HttpResponse.builder()
.statusCode(200) .statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/catalog.xml", VCloudDirectorMediaType.CATALOG + ";version=1.5")) .payload(payloadFromResourceWithContentType("/catalog/catalog.xml", CATALOG + ";version=1.5"))
.build(); .build();
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, catalogRequest, catalogResponse); @Test
public void testGetCatalogHref() {
Catalog expected = catalog(); VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, get, getResponse);
assertEquals(api.getCatalogApi().get(catalogHref), catalog());
URI catalogURI = URI.create(endpoint + "/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4");
assertEquals(api.getCatalogApi().getCatalog(catalogURI), expected);
} }
HttpRequest resolveCatalog = HttpRequest.builder()
.method("GET")
.endpoint(endpoint + "/entity/" + catalogUrn)
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.build();
String catalogEntity = asString(createXMLBuilder("Entity").a("xmlns", "http://www.vmware.com/vcloud/v1.5")
.a("name", catalogUrn)
.a("id", catalogUrn)
.a("type", ENTITY)
.a("href", endpoint + "/entity/" + catalogUrn)
.e("Link").a("rel", "alternate").a("type", CATALOG).a("href", catalogHref.toString()).up()
// TODO: remove this when VCloudDirectorApiExpectTest no longer inherits from VCloudDirectorAdminApiExpectTest
.e("Link").a("rel", "alternate").a("type", ADMIN_CATALOG).a("href", catalogHref.toString()).up());
HttpResponse resolveCatalogResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromStringWithContentType(catalogEntity, ENTITY + ";version=1.5"))
.build();
@Test @Test
public void testAddCatalogItem() { public void testGetCatalogUrn() {
HttpRequest catalogItemRequest = HttpRequest.builder() VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, resolveCatalog, resolveCatalogResponse, get, getResponse);
assertEquals(api.getCatalogApi().get(catalogUrn), catalog());
}
HttpRequest add = HttpRequest.builder()
.method("POST") .method("POST")
.endpoint(endpoint + "/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/catalogItems") .endpoint(catalogHref + "/catalogItems")
.addHeader("Accept", "application/vnd.vmware.vcloud.catalogItem+xml") .addHeader("Accept", "application/vnd.vmware.vcloud.catalogItem+xml")
.addHeader("x-vcloud-authorization", token) .addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token) .addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.payload(payloadFromResourceWithContentType("/catalog/newCatalogItem.xml", VCloudDirectorMediaType.CATALOG_ITEM)) .payload(payloadFromResourceWithContentType("/catalog/newCatalogItem.xml", CATALOG_ITEM))
.build(); .build();
HttpResponse catalogItemResponse = HttpResponse.builder() HttpResponse addResponse = HttpResponse.builder()
.statusCode(200) .statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/createdCatalogItem.xml", VCloudDirectorMediaType.CATALOG_ITEM + ";version=1.5")) .payload(payloadFromResourceWithContentType("/catalog/createdCatalogItem.xml", CATALOG_ITEM + ";version=1.5"))
.build(); .build();
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse);
URI catalogURI = URI.create(endpoint + "/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4");
CatalogItem newItem = CatalogItem.builder() CatalogItem newItem = CatalogItem.builder()
.name("newCatalogItem") .name("newCatalogItem")
.description("New Catalog Item") .description("New Catalog Item")
.entity(ubuntuVappTemplateReference()) .entity(ubuntuVappTemplateReference())
.build(); .build();
CatalogItem expected = createdCatalogItem(); @Test
public void testAddCatalogItemHref() {
assertEquals(api.getCatalogApi().addCatalogItem(catalogURI, newItem), expected); VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, add, addResponse);
assertEquals(api.getCatalogApi().addItem(catalogHref, newItem), createdCatalogItem());
} }
@Test @Test
public void testGetCatalogMetadata() { public void testAddCatalogItemUrn() {
HttpRequest catalogRequest = HttpRequest.builder() VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, resolveCatalog, resolveCatalogResponse, add, addResponse);
assertEquals(api.getCatalogApi().addItem(catalogUrn, newItem), createdCatalogItem());
}
HttpRequest getMetadata = HttpRequest.builder()
.method("GET") .method("GET")
.endpoint(endpoint + "/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/metadata") .endpoint(catalogHref + "/metadata")
.addHeader("Accept", "*/*") .addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token) .addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build(); .addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build();
HttpResponse catalogResponse = HttpResponse.builder() HttpResponse getMetadataResponse = HttpResponse.builder()
.statusCode(200) .statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/catalogMetadata.xml", VCloudDirectorMediaType.METADATA)) .payload(payloadFromResourceWithContentType("/catalog/catalogMetadata.xml", METADATA))
.build(); .build();
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, catalogRequest, catalogResponse); @Test
public void testGetCatalogMetadataHref() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, getMetadata, getMetadataResponse);
assertEquals(api.getCatalogApi().getMetadataApi().get(catalogHref), metadata());
}
URI catalogURI = URI.create(endpoint + "/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4"); static Metadata metadata() {
return Metadata.builder()
Metadata expected = Metadata.builder()
.type("application/vnd.vmware.vcloud.metadata+xml") .type("application/vnd.vmware.vcloud.metadata+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/metadata")) .href(URI.create(endpoint + "/catalog/" + catalog + "/metadata"))
.link(Link.builder() .link(Link.builder()
.rel("up") .rel("up")
.type("application/vnd.vmware.vcloud.catalog+xml") .type("application/vnd.vmware.vcloud.catalog+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) .href(catalogHref)
.build()) .build())
.entries(ImmutableSet.of(metadataEntry())) .entries(ImmutableSet.of(metadataEntry()))
.build(); .build();
assertEquals(api.getCatalogApi().getMetadataApi().getMetadata(catalogURI), expected);
} }
@Test HttpRequest getMetadataValue = HttpRequest.builder()
public void testGetCatalogMetadataEntry() {
HttpRequest catalogRequest = HttpRequest.builder()
.method("GET") .method("GET")
.endpoint(endpoint + "/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/metadata/KEY") .endpoint(catalogHref + "/metadata/KEY")
.addHeader("Accept", "*/*") .addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token) .addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build(); .addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build();
HttpResponse catalogResponse = HttpResponse.builder() HttpResponse getMetadataValueResponse = HttpResponse.builder()
.statusCode(200) .statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/catalogMetadataValue.xml", VCloudDirectorMediaType.METADATA_VALUE)) .payload(payloadFromResourceWithContentType("/catalog/catalogMetadataValue.xml", METADATA_VALUE))
.build(); .build();
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, catalogRequest, catalogResponse); @Test
public void testGetCatalogMetadataEntryHref() {
URI catalogURI = URI.create(endpoint + "/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4"); VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, getMetadataValue, getMetadataValueResponse);
assertEquals(api.getCatalogApi().getMetadataApi().getValue(catalogHref, "KEY"), metadataValue());
MetadataValue expected = metadataValue();
assertEquals(api.getCatalogApi().getMetadataApi().getMetadataValue(catalogURI, "KEY"), expected);
} }
@Test static String item = "a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df";
public void testGetCatalogItem() { static URI itemHref = URI.create(endpoint + "/catalogItem/" + item);
HttpRequest catalogItemRequest = HttpRequest.builder() static String itemUrn = "urn:vcloud:catalogitem:" + item;
HttpRequest resolveItem = HttpRequest.builder()
.method("GET") .method("GET")
.endpoint(endpoint + "/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df") .endpoint(endpoint + "/entity/" + itemUrn)
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.build();
String itemEntity = asString(createXMLBuilder("Entity").a("xmlns", "http://www.vmware.com/vcloud/v1.5")
.a("name", itemUrn)
.a("id", itemUrn)
.a("type", ENTITY)
.a("href", endpoint + "/entity/" + itemUrn)
.e("Link").a("rel", "alternate").a("type", CATALOG_ITEM).a("href", itemHref.toString()).up());
HttpResponse resolveItemResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromStringWithContentType(itemEntity, ENTITY + ";version=1.5"))
.build();
HttpRequest getItem = HttpRequest.builder()
.method("GET")
.endpoint(endpoint + "/catalogItem/" + item)
.addHeader("Accept", "*/*") .addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token) .addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build(); .addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build();
HttpResponse catalogItemResponse = HttpResponse.builder() HttpResponse getItemResponse = HttpResponse.builder()
.statusCode(200) .statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/catalogItem.xml", VCloudDirectorMediaType.CATALOG_ITEM)) .payload(payloadFromResourceWithContentType("/catalog/catalogItem.xml", CATALOG_ITEM))
.build(); .build();
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse); @Test
public void testGetCatalogItemHref() {
URI catalogItemURI = URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df"); VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, getItem, getItemResponse);
assertEquals(api.getCatalogApi().getItem(itemHref), catalogItem());
CatalogItem expected = catalogItem();
assertEquals(api.getCatalogApi().getCatalogItem(catalogItemURI), expected);
} }
@Test @Test
public void testUpdateCatalogItem() { public void testGetCatalogItemUrn() {
HttpRequest catalogItemRequest = HttpRequest.builder() VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, resolveItem, resolveItemResponse, getItem, getItemResponse);
assertEquals(api.getCatalogApi().getItem(itemUrn), catalogItem());
}
HttpRequest updateItem = HttpRequest.builder()
.method("PUT") .method("PUT")
.endpoint(endpoint + "/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df") .endpoint(endpoint + "/catalogItem/" + item)
.addHeader("Accept", "application/vnd.vmware.vcloud.catalogItem+xml") .addHeader("Accept", "application/vnd.vmware.vcloud.catalogItem+xml")
.addHeader("x-vcloud-authorization", token) .addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token) .addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.payload(payloadFromResourceWithContentType("/catalog/updateCatalogItem.xml", VCloudDirectorMediaType.CATALOG_ITEM)) .payload(payloadFromResourceWithContentType("/catalog/updateCatalogItem.xml", CATALOG_ITEM))
.build(); .build();
HttpResponse catalogItemResponse = HttpResponse.builder() HttpResponse updateItemResponse = HttpResponse.builder()
.statusCode(200) .statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/updateCatalogItem.xml", VCloudDirectorMediaType.CATALOG_ITEM + ";version=1.5")) .payload(payloadFromResourceWithContentType("/catalog/updateCatalogItem.xml", CATALOG_ITEM + ";version=1.5"))
.build(); .build();
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse); @Test
public void testUpdateCatalogItemHref() {
URI catalogItemURI = URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df"); VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, updateItem, updateItemResponse);
CatalogItem expected = catalogItem(); assertEquals(api.getCatalogApi().updateItem(itemHref, catalogItem()), catalogItem());
assertEquals(api.getCatalogApi().updateCatalogItem(catalogItemURI, expected), expected);
} }
@Test @Test
public void testDeleteCatalogItem() { public void testUpdateCatalogItemUrn() {
HttpRequest catalogItemRequest = HttpRequest.builder() VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, resolveItem, resolveItemResponse, updateItem, updateItemResponse);
assertEquals(api.getCatalogApi().updateItem(itemUrn, catalogItem()), catalogItem());
}
HttpRequest deleteItem = HttpRequest.builder()
.method("DELETE") .method("DELETE")
.endpoint(endpoint + "/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df") .endpoint(endpoint + "/catalogItem/" + item)
.addHeader("Accept", "*/*") .addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token) .addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build(); .addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build();
HttpResponse catalogItemResponse = HttpResponse.builder() HttpResponse deleteItemResponse = HttpResponse.builder()
.statusCode(200) .statusCode(200)
.build(); .build();
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse); @Test
public void testDeleteCatalogItemHref() {
URI catalogItemURI = URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df"); VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, deleteItem, deleteItemResponse);
api.getCatalogApi().deleteItem(itemHref);
api.getCatalogApi().deleteCatalogItem(catalogItemURI);
} }
@Test @Test
public void testGetCatalogItemMetadata() { public void testDeleteCatalogItemUrn() {
HttpRequest catalogItemRequest = HttpRequest.builder() VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, resolveItem, resolveItemResponse, deleteItem, deleteItemResponse);
api.getCatalogApi().deleteItem(itemUrn);
}
HttpRequest getItemMetadata = HttpRequest.builder()
.method("GET") .method("GET")
.endpoint(endpoint + "/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df/metadata") .endpoint(endpoint + "/catalogItem/" + item + "/metadata")
.addHeader("Accept", "*/*") .addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token) .addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build(); .addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build();
HttpResponse catalogItemResponse = HttpResponse.builder() HttpResponse getItemMetadataResponse = HttpResponse.builder()
.statusCode(200) .statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/catalogItemMetadata.xml", VCloudDirectorMediaType.METADATA)) .payload(payloadFromResourceWithContentType("/catalog/catalogItemMetadata.xml", METADATA))
.build(); .build();
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse);
URI catalogItemURI = URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df");
Metadata expected = Metadata.builder() Metadata expected = Metadata.builder()
.type("application/vnd.vmware.vcloud.metadata+xml") .type("application/vnd.vmware.vcloud.metadata+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df/metadata")) .href(URI.create(endpoint + "/catalogItem/" + item + "/metadata"))
.link(Link.builder() .link(Link.builder()
.rel("up") .rel("up")
.type("application/vnd.vmware.vcloud.catalogItem+xml") .type("application/vnd.vmware.vcloud.catalogItem+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df")) .href(itemHref)
.build()) .build())
.entries(ImmutableSet.of(itemMetadataEntry())) .entries(ImmutableSet.of(itemMetadataEntry()))
.build(); .build();
assertEquals(api.getCatalogApi().getMetadataApi().getMetadata(catalogItemURI), expected); @Test
public void testGetCatalogItemMetadataHref() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, getItemMetadata, getItemMetadataResponse);
assertEquals(api.getCatalogApi().getMetadataApi().get(itemHref), expected);
} }
@Test HttpRequest mergeItemMetadata = HttpRequest.builder()
public void testMergeCatalogItemMetadata() {
HttpRequest catalogItemRequest = HttpRequest.builder()
.method("POST") .method("POST")
.endpoint(endpoint + "/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df/metadata") .endpoint(endpoint + "/catalogItem/" + item + "/metadata")
.addHeader("Accept", "application/vnd.vmware.vcloud.task+xml") .addHeader("Accept", "application/vnd.vmware.vcloud.task+xml")
.addHeader("x-vcloud-authorization", token) .addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token) .addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.payload(payloadFromResourceWithContentType("/catalog/mergeCatalogItemMetadata.xml", VCloudDirectorMediaType.METADATA)) .payload(payloadFromResourceWithContentType("/catalog/mergeCatalogItemMetadata.xml", METADATA))
.build(); .build();
HttpResponse catalogItemResponse = HttpResponse.builder() HttpResponse mergeItemMetadataResponse = HttpResponse.builder()
.statusCode(200) .statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/mergeMetadataTask.xml", VCloudDirectorMediaType.TASK + ";version=1.5")) .payload(payloadFromResourceWithContentType("/catalog/mergeMetadataTask.xml", TASK + ";version=1.5"))
.build(); .build();
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse);
URI catalogItemURI = URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df");
Metadata metadata = Metadata.builder().entry(MetadataEntry.builder().entry("KEY", "VALUE").build()).build();
Task expected = mergeMetadataTask();
assertEquals(api.getCatalogApi().getCatalogItemMetadataApi().mergeMetadata(catalogItemURI, metadata), expected);
}
@Test @Test
public void testGetCatalogItemMetadataEntry() { public void testMergeCatalogItemMetadataHref() {
HttpRequest catalogItemRequest = HttpRequest.builder() VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, mergeItemMetadata, mergeItemMetadataResponse);
// TODO: horrendous way of representing Map<String,String>
Metadata metadata = Metadata.builder().entry(MetadataEntry.builder().entry("KEY", "VALUE").build()).build();
assertEquals(api.getCatalogApi().getItemMetadataApi().merge(itemHref, metadata), mergeMetadataTask());
}
HttpRequest getItemMetadataValue = HttpRequest.builder()
.method("GET") .method("GET")
.endpoint(endpoint + "/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df/metadata/KEY") .endpoint(endpoint + "/catalogItem/" + item + "/metadata/KEY")
.addHeader("Accept", "*/*") .addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token) .addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build(); .addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build();
HttpResponse catalogItemResponse = HttpResponse.builder() HttpResponse getItemMetadataValueResponse = HttpResponse.builder()
.statusCode(200) .statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/catalogItemMetadataValue.xml", VCloudDirectorMediaType.METADATA_VALUE + ";version=1.5")) .payload(payloadFromResourceWithContentType("/catalog/catalogItemMetadataValue.xml", METADATA_VALUE + ";version=1.5"))
.build(); .build();
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse); @Test
public void testGetCatalogItemMetadataEntryHref() {
URI catalogItemURI = URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df"); VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, getItemMetadataValue, getItemMetadataValueResponse);
assertEquals(api.getCatalogApi().getMetadataApi().getValue(itemHref, "KEY"), itemMetadataValue());
MetadataValue expected = itemMetadataValue();
assertEquals(api.getCatalogApi().getMetadataApi().getMetadataValue(catalogItemURI, "KEY"), expected);
} }
@Test HttpRequest putItemMetadata = HttpRequest.builder()
public void testSetCatalogItemMetadataEntry() {
HttpRequest catalogItemRequest = HttpRequest.builder()
.method("PUT") .method("PUT")
.endpoint(endpoint + "/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df/metadata/KEY") .endpoint(endpoint + "/catalogItem/" + item + "/metadata/KEY")
.addHeader("Accept", "application/vnd.vmware.vcloud.task+xml") .addHeader("Accept", "application/vnd.vmware.vcloud.task+xml")
.addHeader("x-vcloud-authorization", token) .addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token) .addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.payload(payloadFromResourceWithContentType("/catalog/setCatalogItemMetadataValue.xml", VCloudDirectorMediaType.METADATA_VALUE)) .payload(payloadFromResourceWithContentType("/catalog/setCatalogItemMetadataValue.xml", METADATA_VALUE))
.build(); .build();
HttpResponse catalogItemResponse = HttpResponse.builder() HttpResponse putItemMetadataResponse = HttpResponse.builder()
.statusCode(200) .statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/setMetadataValueTask.xml", VCloudDirectorMediaType.TASK + ";version=1.5")) .payload(payloadFromResourceWithContentType("/catalog/setMetadataValueTask.xml", TASK + ";version=1.5"))
.build(); .build();
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse);
URI catalogItemURI = URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df");
MetadataValue value = MetadataValue.builder().value("KITTENS").build();
Task expected = setMetadataValueTask();
assertEquals(api.getCatalogApi().getCatalogItemMetadataApi().setMetadata(catalogItemURI, "KEY", value), expected);
}
@Test @Test
public void testDeleteCatalogItemMetadataEntry() { public void testSetCatalogItemMetadataEntryHref() {
HttpRequest catalogItemRequest = HttpRequest.builder() VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, putItemMetadata, putItemMetadataResponse);
assertEquals(api.getCatalogApi().getItemMetadataApi().putEntry(itemHref, "KEY", MetadataValue.builder().value("KITTENS").build()), setMetadataValueTask());
}
HttpRequest deleteItemMetadataEntry = HttpRequest.builder()
.method("DELETE") .method("DELETE")
.endpoint(endpoint + "/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df/metadata/KEY") .endpoint(endpoint + "/catalogItem/" + item + "/metadata/KEY")
.addHeader("Accept", "application/vnd.vmware.vcloud.task+xml") .addHeader("Accept", "application/vnd.vmware.vcloud.task+xml")
.addHeader("x-vcloud-authorization", token) .addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build(); .addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build();
HttpResponse catalogItemResponse = HttpResponse.builder() HttpResponse deleteItemMetadataEntryResponse = HttpResponse.builder()
.statusCode(200) .statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/deleteMetadataEntryTask.xml", VCloudDirectorMediaType.TASK)) .payload(payloadFromResourceWithContentType("/catalog/deleteMetadataEntryTask.xml", TASK))
.build(); .build();
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse); @Test
public void testDeleteCatalogItemMetadataEntryHref() {
URI catalogItemURI = URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df"); VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, deleteItemMetadataEntry, deleteItemMetadataEntryResponse);
assertEquals(api.getCatalogApi().getItemMetadataApi().deleteEntry(itemHref, "KEY"), deleteEntryTask());
Task expected = deleteMetadataEntryTask();
assertEquals(api.getCatalogApi().getCatalogItemMetadataApi().deleteMetadataEntry(catalogItemURI, "KEY"), expected);
} }
public static final Catalog catalog() { public static final Catalog catalog() {
return Catalog.builder() return Catalog.builder()
.name("QunyingTestCatalog") .name("QunyingTestCatalog")
.type("application/vnd.vmware.vcloud.catalog+xml") .type("application/vnd.vmware.vcloud.catalog+xml")
.id("urn:vcloud:catalog:7212e451-76e1-4631-b2de-ba1dfd8080e4") .id(catalogUrn)
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) .href(catalogHref)
.link(Link.builder() .link(Link.builder()
.rel("up") .rel("up")
.type("application/vnd.vmware.vcloud.org+xml") .type("application/vnd.vmware.vcloud.org+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) .href(URI.create(endpoint + "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.build()) .build())
.link(Link.builder() .link(Link.builder()
.rel("add") .rel("add")
.type("application/vnd.vmware.vcloud.catalogItem+xml") .type("application/vnd.vmware.vcloud.catalogItem+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/catalogItems")) .href(URI.create(endpoint + "/catalog/" + catalog + "/catalogItems"))
.build()) .build())
.link(Link.builder() .link(Link.builder()
.rel("down") .rel("down")
.type("application/vnd.vmware.vcloud.metadata+xml") .type("application/vnd.vmware.vcloud.metadata+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/metadata")) .href(URI.create(endpoint + "/catalog/" + catalog + "/metadata"))
.build()) .build())
.item(Reference.builder() .item(Reference.builder()
.type("application/vnd.vmware.vcloud.catalogItem+xml") .type("application/vnd.vmware.vcloud.catalogItem+xml")
.name("ubuntu10") .name("ubuntu10")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df")) .href(itemHref)
.build()) .build())
.item(Reference.builder() .item(Reference.builder()
.type("application/vnd.vmware.vcloud.catalogItem+xml") .type("application/vnd.vmware.vcloud.catalogItem+xml")
.name("imageTesting") .name("imageTesting")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a9e0afdb-a42b-4688-8409-2ac68cf22939")) .href(URI.create(endpoint + "/catalogItem/a9e0afdb-a42b-4688-8409-2ac68cf22939"))
.build()) .build())
.description("Testing") .description("Testing")
.isPublished(false) .isPublished(false)
@ -395,27 +428,27 @@ public class CatalogApiExpectTest extends VCloudDirectorApiExpectTest {
public static CatalogItem createdCatalogItem() { public static CatalogItem createdCatalogItem() {
return CatalogItem.builder() return CatalogItem.builder()
.name("newCatalogItem") .name("newCatalogItem")
.id("urn:vcloud:catalogitem:a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df") .id("urn:vcloud:catalogitem:" + item)
.type("application/vnd.vmware.vcloud.catalogItem+xml") .type("application/vnd.vmware.vcloud.catalogItem+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df")) .href(itemHref)
.link(Link.builder() .link(Link.builder()
.rel("up") .rel("up")
.type("application/vnd.vmware.vcloud.catalog+xml") .type("application/vnd.vmware.vcloud.catalog+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) .href(catalogHref)
.build()) .build())
.link(Link.builder() .link(Link.builder()
.rel("down") .rel("down")
.type("application/vnd.vmware.vcloud.metadata+xml") .type("application/vnd.vmware.vcloud.metadata+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df/metadata")) .href(URI.create(endpoint + "/catalogItem/" + item + "/metadata"))
.build()) .build())
.link(Link.builder() .link(Link.builder()
.rel("edit") .rel("edit")
.type("application/vnd.vmware.vcloud.catalogItem+xml") .type("application/vnd.vmware.vcloud.catalogItem+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df")) .href(itemHref)
.build()) .build())
.link(Link.builder() .link(Link.builder()
.rel("remove") .rel("remove")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df")) .href(itemHref)
.build()) .build())
.description("New Catalog Item") .description("New Catalog Item")
.entity(ubuntuVappTemplateReference()) .entity(ubuntuVappTemplateReference())
@ -426,17 +459,17 @@ public class CatalogApiExpectTest extends VCloudDirectorApiExpectTest {
return Reference.builder() return Reference.builder()
.type("application/vnd.vmware.vcloud.vAppTemplate+xml") .type("application/vnd.vmware.vcloud.vAppTemplate+xml")
.name("ubuntu10") .name("ubuntu10")
.href(URI.create("https://vcloudbeta.bluelock.com/api/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9")) .href(URI.create(endpoint + "/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9"))
.build(); .build();
} }
public static MetadataEntry metadataEntry() { public static MetadataEntry metadataEntry() {
return MetadataEntry.builder() return MetadataEntry.builder()
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/metadata/KEY")) .href(URI.create(endpoint + "/catalog/" + catalog + "/metadata/KEY"))
.link(Link.builder() .link(Link.builder()
.rel("up") .rel("up")
.type("application/vnd.vmware.vcloud.metadata+xml") .type("application/vnd.vmware.vcloud.metadata+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/metadata")) .href(URI.create(endpoint + "/catalog/" + catalog + "/metadata"))
.build()) .build())
.entry("KEY", "VALUE") .entry("KEY", "VALUE")
.build(); .build();
@ -444,11 +477,11 @@ public class CatalogApiExpectTest extends VCloudDirectorApiExpectTest {
public static MetadataEntry itemMetadataEntry() { public static MetadataEntry itemMetadataEntry() {
return MetadataEntry.builder() return MetadataEntry.builder()
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df/metadata/KEY")) .href(URI.create(endpoint + "/catalogItem/" + item + "/metadata/KEY"))
.link(Link.builder() .link(Link.builder()
.rel("up") .rel("up")
.type("application/vnd.vmware.vcloud.metadata+xml") .type("application/vnd.vmware.vcloud.metadata+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df/metadata")) .href(URI.create(endpoint + "/catalogItem/" + item + "/metadata"))
.build()) .build())
.entry("KEY", "VALUE") .entry("KEY", "VALUE")
.build(); .build();
@ -456,11 +489,11 @@ public class CatalogApiExpectTest extends VCloudDirectorApiExpectTest {
public static MetadataValue metadataValue() { public static MetadataValue metadataValue() {
return MetadataValue.builder() return MetadataValue.builder()
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/metadata/KEY")) .href(URI.create(endpoint + "/catalog/" + catalog + "/metadata/KEY"))
.link(Link.builder() .link(Link.builder()
.rel("up") .rel("up")
.type("application/vnd.vmware.vcloud.metadata+xml") .type("application/vnd.vmware.vcloud.metadata+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/metadata")) .href(URI.create(endpoint + "/catalog/" + catalog + "/metadata"))
.build()) .build())
.value("VALUE") .value("VALUE")
.build(); .build();
@ -468,11 +501,11 @@ public class CatalogApiExpectTest extends VCloudDirectorApiExpectTest {
public static MetadataValue itemMetadataValue() { public static MetadataValue itemMetadataValue() {
return MetadataValue.builder() return MetadataValue.builder()
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df/metadata/KEY")) .href(URI.create(endpoint + "/catalogItem/" + item + "/metadata/KEY"))
.link(Link.builder() .link(Link.builder()
.rel("up") .rel("up")
.type("application/vnd.vmware.vcloud.metadata+xml") .type("application/vnd.vmware.vcloud.metadata+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df/metadata")) .href(URI.create(endpoint + "/catalogItem/" + item + "/metadata"))
.build()) .build())
.value("VALUE") .value("VALUE")
.build(); .build();
@ -481,27 +514,27 @@ public class CatalogApiExpectTest extends VCloudDirectorApiExpectTest {
public static CatalogItem catalogItem() { public static CatalogItem catalogItem() {
return CatalogItem.builder() return CatalogItem.builder()
.name("ubuntu10") .name("ubuntu10")
.id("urn:vcloud:catalogitem:a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df") .id("urn:vcloud:catalogitem:" + item)
.type("application/vnd.vmware.vcloud.catalogItem+xml") .type("application/vnd.vmware.vcloud.catalogItem+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df")) .href(itemHref)
.link(Link.builder() .link(Link.builder()
.rel("up") .rel("up")
.type("application/vnd.vmware.vcloud.catalog+xml") .type("application/vnd.vmware.vcloud.catalog+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) .href(catalogHref)
.build()) .build())
.link(Link.builder() .link(Link.builder()
.rel("down") .rel("down")
.type("application/vnd.vmware.vcloud.metadata+xml") .type("application/vnd.vmware.vcloud.metadata+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df/metadata")) .href(URI.create(endpoint + "/catalogItem/" + item + "/metadata"))
.build()) .build())
.link(Link.builder() .link(Link.builder()
.rel("edit") .rel("edit")
.type("application/vnd.vmware.vcloud.catalogItem+xml") .type("application/vnd.vmware.vcloud.catalogItem+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df")) .href(itemHref)
.build()) .build())
.link(Link.builder() .link(Link.builder()
.rel("remove") .rel("remove")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df")) .href(itemHref)
.build()) .build())
.description("For testing") .description("For testing")
.entity(ubuntuVappTemplateReference()) .entity(ubuntuVappTemplateReference())
@ -513,30 +546,30 @@ public class CatalogApiExpectTest extends VCloudDirectorApiExpectTest {
.name("task") .name("task")
.id("urn:vcloud:task:c6dca927-eab4-41fa-ad6a-3ac58602541c") .id("urn:vcloud:task:c6dca927-eab4-41fa-ad6a-3ac58602541c")
.type("application/vnd.vmware.vcloud.task+xml") .type("application/vnd.vmware.vcloud.task+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/task/c6dca927-eab4-41fa-ad6a-3ac58602541c")) .href(URI.create(endpoint + "/task/c6dca927-eab4-41fa-ad6a-3ac58602541c"))
.status("running") .status("running")
.startTime(dateService.iso8601DateParse("2012-02-13T06:35:08.011-05:00")) .startTime(dateService.iso8601DateParse("2012-02-13T06:35:08.011-05:00"))
.expiryTime(dateService.iso8601DateParse("2012-05-13T06:35:08.011-04:00")) .expiryTime(dateService.iso8601DateParse("2012-05-13T06:35:08.011-04:00"))
.operationName("metadataUpdate") .operationName("metadataUpdate")
.operation("Updating metadata for Catalog Item (a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df)") .operation("Updating metadata for Catalog Item (" + item + ")")
.link(Link.builder() .link(Link.builder()
.rel("task:cancel") .rel("task:cancel")
.href(URI.create("https://vcloudbeta.bluelock.com/api/task/c6dca927-eab4-41fa-ad6a-3ac58602541c/action/cancel")) .href(URI.create(endpoint + "/task/c6dca927-eab4-41fa-ad6a-3ac58602541c/action/cancel"))
.build()) .build())
.owner(Reference.builder() .owner(Reference.builder()
.type("application/vnd.vmware.vcloud.catalogItem+xml") .type("application/vnd.vmware.vcloud.catalogItem+xml")
.name("") .name("")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df")) .href(itemHref)
.build()) .build())
.user(Reference.builder() .user(Reference.builder()
.type("application/vnd.vmware.admin.user+xml") .type("application/vnd.vmware.admin.user+xml")
.name("adk@cloudsoftcorp.com") .name("adk@cloudsoftcorp.com")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/e9eb1b29-0404-4c5e-8ef7-e584acc51da9")) .href(URI.create(endpoint + "/admin/user/e9eb1b29-0404-4c5e-8ef7-e584acc51da9"))
.build()) .build())
.org(Reference.builder() .org(Reference.builder()
.type("application/vnd.vmware.vcloud.org+xml") .type("application/vnd.vmware.vcloud.org+xml")
.name("JClouds") .name("JClouds")
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) .href(URI.create(endpoint + "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.build()) .build())
.build(); .build();
} }
@ -546,63 +579,63 @@ public class CatalogApiExpectTest extends VCloudDirectorApiExpectTest {
.name("task") .name("task")
.id("urn:vcloud:task:c6dca927-eab4-41fa-ad6a-3ac58602541c") .id("urn:vcloud:task:c6dca927-eab4-41fa-ad6a-3ac58602541c")
.type("application/vnd.vmware.vcloud.task+xml") .type("application/vnd.vmware.vcloud.task+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/task/c6dca927-eab4-41fa-ad6a-3ac58602541c")) .href(URI.create(endpoint + "/task/c6dca927-eab4-41fa-ad6a-3ac58602541c"))
.status("running") .status("running")
.startTime(dateService.iso8601DateParse("2012-02-13T06:35:08.011-05:00")) .startTime(dateService.iso8601DateParse("2012-02-13T06:35:08.011-05:00"))
.expiryTime(dateService.iso8601DateParse("2012-05-13T06:35:08.011-04:00")) .expiryTime(dateService.iso8601DateParse("2012-05-13T06:35:08.011-04:00"))
.operationName("metadataSet") .operationName("metadataSet")
.operation("Setting metadata for Catalog Item (a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df)") .operation("Setting metadata for Catalog Item (" + item + ")")
.link(Link.builder() .link(Link.builder()
.rel("task:cancel") .rel("task:cancel")
.href(URI.create("https://vcloudbeta.bluelock.com/api/task/c6dca927-eab4-41fa-ad6a-3ac58602541c/action/cancel")) .href(URI.create(endpoint + "/task/c6dca927-eab4-41fa-ad6a-3ac58602541c/action/cancel"))
.build()) .build())
.owner(Reference.builder() .owner(Reference.builder()
.type("application/vnd.vmware.vcloud.catalogItem+xml") .type("application/vnd.vmware.vcloud.catalogItem+xml")
.name("") .name("")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df")) .href(itemHref)
.build()) .build())
.user(Reference.builder() .user(Reference.builder()
.type("application/vnd.vmware.admin.user+xml") .type("application/vnd.vmware.admin.user+xml")
.name("adk@cloudsoftcorp.com") .name("adk@cloudsoftcorp.com")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/e9eb1b29-0404-4c5e-8ef7-e584acc51da9")) .href(URI.create(endpoint + "/admin/user/e9eb1b29-0404-4c5e-8ef7-e584acc51da9"))
.build()) .build())
.org(Reference.builder() .org(Reference.builder()
.type("application/vnd.vmware.vcloud.org+xml") .type("application/vnd.vmware.vcloud.org+xml")
.name("JClouds") .name("JClouds")
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) .href(URI.create(endpoint + "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.build()) .build())
.build(); .build();
} }
public static Task deleteMetadataEntryTask() { public static Task deleteEntryTask() {
return Task.builder() return Task.builder()
.name("task") .name("task")
.id("urn:vcloud:task:c6dca927-eab4-41fa-ad6a-3ac58602541c") .id("urn:vcloud:task:c6dca927-eab4-41fa-ad6a-3ac58602541c")
.type("application/vnd.vmware.vcloud.task+xml") .type("application/vnd.vmware.vcloud.task+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/task/c6dca927-eab4-41fa-ad6a-3ac58602541c")) .href(URI.create(endpoint + "/task/c6dca927-eab4-41fa-ad6a-3ac58602541c"))
.status("running") .status("running")
.startTime(dateService.iso8601DateParse("2012-02-13T06:35:08.011-05:00")) .startTime(dateService.iso8601DateParse("2012-02-13T06:35:08.011-05:00"))
.expiryTime(dateService.iso8601DateParse("2012-05-13T06:35:08.011-04:00")) .expiryTime(dateService.iso8601DateParse("2012-05-13T06:35:08.011-04:00"))
.operationName("metadataDelete") .operationName("metadataDelete")
.operation("Deleting metadata for Catalog Item (a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df)") .operation("Deleting metadata for Catalog Item (" + item + ")")
.link(Link.builder() .link(Link.builder()
.rel("task:cancel") .rel("task:cancel")
.href(URI.create("https://vcloudbeta.bluelock.com/api/task/c6dca927-eab4-41fa-ad6a-3ac58602541c/action/cancel")) .href(URI.create(endpoint + "/task/c6dca927-eab4-41fa-ad6a-3ac58602541c/action/cancel"))
.build()) .build())
.owner(Reference.builder() .owner(Reference.builder()
.type("application/vnd.vmware.vcloud.catalogItem+xml") .type("application/vnd.vmware.vcloud.catalogItem+xml")
.name("") .name("")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df")) .href(itemHref)
.build()) .build())
.user(Reference.builder() .user(Reference.builder()
.type("application/vnd.vmware.admin.user+xml") .type("application/vnd.vmware.admin.user+xml")
.name("adk@cloudsoftcorp.com") .name("adk@cloudsoftcorp.com")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/e9eb1b29-0404-4c5e-8ef7-e584acc51da9")) .href(URI.create(endpoint + "/admin/user/e9eb1b29-0404-4c5e-8ef7-e584acc51da9"))
.build()) .build())
.org(Reference.builder() .org(Reference.builder()
.type("application/vnd.vmware.vcloud.org+xml") .type("application/vnd.vmware.vcloud.org+xml")
.name("JClouds") .name("JClouds")
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) .href(URI.create(endpoint + "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.build()) .build())
.build(); .build();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Licensed to jclouds, Inc. (jclouds) under one or more x * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file * regarding copyright ownership. jclouds licenses this file
@ -48,6 +48,7 @@ import org.jclouds.vcloud.director.v1_5.domain.MetadataValue;
import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.domain.Task;
import org.jclouds.vcloud.director.v1_5.domain.Vdc; import org.jclouds.vcloud.director.v1_5.domain.Vdc;
import org.jclouds.vcloud.director.v1_5.domain.org.Org;
import org.jclouds.vcloud.director.v1_5.features.admin.AdminCatalogApi; import org.jclouds.vcloud.director.v1_5.features.admin.AdminCatalogApi;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorApiLiveTest; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorApiLiveTest;
import org.testng.annotations.AfterClass; import org.testng.annotations.AfterClass;
@ -76,34 +77,31 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
private Media media; private Media media;
private CatalogItem catalogItem; private CatalogItem catalogItem;
private Reference catalogRef;
@Override @Override
protected void setupRequiredApis() { protected void setupRequiredApis() {
// TODO why do I need a guard clause here? // TODO why do I need a guard clause here?
if (adminCatalog != null) return; if (adminCatalog != null)
return;
catalogApi = context.getApi().getCatalogApi(); catalogApi = context.getApi().getCatalogApi();
Reference orgRef = Iterables.getFirst(context.getApi().getOrgApi().getOrgList(), null).toAdminReference(endpoint); Org org = context.getApi().getOrgApi().getOrg(Iterables.get(context.getApi().getOrgApi().getOrgList(), 0).getHref());
if (adminContext != null) { if (adminContext != null) {
AdminCatalog newCatalog = AdminCatalog.builder() AdminCatalog newCatalog = AdminCatalog.builder().name(name("Test Catalog "))
.name(name("Test Catalog ")) .description("created by CatalogApiLiveTest").build();
.description("created by CatalogApiLiveTest")
.build();
AdminCatalogApi adminCatalogApi = adminContext.getApi().getCatalogApi(); AdminCatalogApi adminCatalogApi = adminContext.getApi().getCatalogApi();
adminCatalog = adminCatalogApi.createCatalog(orgRef.getHref(), newCatalog); adminCatalog = adminCatalogApi.createCatalogInOrg(newCatalog, org.getId());
catalogRef = find(adminCatalog.getLinks(), and(relEquals("alternate"), typeEquals(VCloudDirectorMediaType.CATALOG))); catalogUrn = catalogApi.get(
find(adminCatalog.getLinks(),
and(relEquals("alternate"), typeEquals(VCloudDirectorMediaType.CATALOG))).getHref()).getId();
Metadata newMetadata = Metadata.builder() Metadata newMetadata = Metadata.builder().entry(MetadataEntry.builder().entry("KEY", "MARMALADE").build())
.entry(MetadataEntry.builder().entry("KEY", "MARMALADE").build())
.build(); .build();
Task mergeCatalogMetadata = adminCatalogApi.getMetadataApi().mergeMetadata(adminCatalog.getHref(), newMetadata); Task mergeCatalogMetadata = adminCatalogApi.getMetadataApi().merge(adminCatalog.getHref(), newMetadata);
checkTask(mergeCatalogMetadata); checkTask(mergeCatalogMetadata);
assertTrue(retryTaskSuccess.apply(mergeCatalogMetadata), String.format(TASK_COMPLETE_TIMELY, "setupRequiredApis")); assertTrue(retryTaskSuccess.apply(mergeCatalogMetadata),
} else { String.format(TASK_COMPLETE_TIMELY, "setupRequiredApis"));
catalogRef = Reference.builder().href(catalogURI).build();
} }
} }
@ -111,7 +109,7 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
public void tearDown() { public void tearDown() {
if (catalogItem != null) { if (catalogItem != null) {
try { try {
catalogApi.deleteCatalogItem(catalogItem.getHref()); catalogApi.deleteItem(catalogItem.getId());
} catch (Exception e) { } catch (Exception e) {
logger.warn(e, "Error when deleting catalog item '%s'", catalogItem.getName()); logger.warn(e, "Error when deleting catalog item '%s'", catalogItem.getName());
} }
@ -126,7 +124,7 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
} }
if (adminContext != null && adminCatalog != null) { if (adminContext != null && adminCatalog != null) {
try { try {
adminContext.getApi().getCatalogApi().deleteCatalog(adminCatalog.getHref()); adminContext.getApi().getCatalogApi().delete(adminCatalog.getId());
} catch (Exception e) { } catch (Exception e) {
logger.warn(e, "Error when deleting catalog '%s'", adminCatalog.getName()); logger.warn(e, "Error when deleting catalog '%s'", adminCatalog.getName());
} }
@ -136,15 +134,15 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "GET /catalog/{id}") @Test(description = "GET /catalog/{id}")
public void testGetCatalog() { public void testGetCatalog() {
Catalog catalog = catalogApi.getCatalog(catalogRef.getHref()); Catalog catalog = catalogApi.get(catalogUrn);
assertNotNull(catalog); assertNotNull(catalog);
// Double check it's pointing at the correct catalog // Double check it's pointing at the correct catalog
assertEquals(catalog.getHref(), catalogRef.getHref()); assertEquals(catalog.getId(), catalogUrn);
} }
@Test(description = "GET /catalogItem/{id}", dependsOnMethods = "testAddCatalogItem") @Test(description = "GET /catalogItem/{id}", dependsOnMethods = "testAddCatalogItem")
public void testGetCatalogItem() { public void testGetCatalogItem() {
CatalogItem catalogItem = catalogApi.getCatalogItem(this.catalogItem.getHref()); CatalogItem catalogItem = catalogApi.getItem(this.catalogItem.getId());
checkCatalogItem(catalogItem); checkCatalogItem(catalogItem);
assertEquals(catalogItem.getEntity().getHref(), this.catalogItem.getEntity().getHref()); assertEquals(catalogItem.getEntity().getHref(), this.catalogItem.getEntity().getHref());
} }
@ -158,24 +156,16 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
assertNotNull(vdc, String.format(OBJ_REQ_LIVE, VDC)); assertNotNull(vdc, String.format(OBJ_REQ_LIVE, VDC));
Link addMedia = find(vdc.getLinks(), and(relEquals("add"), typeEquals(VCloudDirectorMediaType.MEDIA))); Link addMedia = find(vdc.getLinks(), and(relEquals("add"), typeEquals(VCloudDirectorMediaType.MEDIA)));
Media sourceMedia = Media.builder() Media sourceMedia = Media.builder().type(VCloudDirectorMediaType.MEDIA).name("Test media 1").size(iso.length)
.type(VCloudDirectorMediaType.MEDIA) .imageType(Media.ImageType.ISO).description("Test media generated by testCreateMedia()").build();
.name("Test media 1")
.size(iso.length)
.imageType(Media.ImageType.ISO)
.description("Test media generated by testCreateMedia()")
.build();
media = context.getApi().getMediaApi().createMedia(addMedia.getHref(), sourceMedia); media = context.getApi().getMediaApi().createMedia(addMedia.getHref(), sourceMedia);
Checks.checkMediaFor(VCloudDirectorMediaType.MEDIA, media); Checks.checkMediaFor(VCloudDirectorMediaType.MEDIA, media);
CatalogItem editedCatalogItem = CatalogItem.builder() CatalogItem editedCatalogItem = CatalogItem.builder().name("newitem").description("New Item")
.name("newitem") .type(VCloudDirectorMediaType.CATALOG_ITEM).entity(Reference.builder().href(media.getHref()).build())
.description("New Item")
.type(VCloudDirectorMediaType.CATALOG_ITEM)
.entity(Reference.builder().href(media.getHref()).build())
.build(); .build();
catalogItem = catalogApi.addCatalogItem(catalogRef.getHref(), editedCatalogItem); catalogItem = catalogApi.addItem(catalogUrn, editedCatalogItem);
checkCatalogItem(catalogItem); checkCatalogItem(catalogItem);
assertEquals(catalogItem.getName(), "newitem"); assertEquals(catalogItem.getName(), "newitem");
assertEquals(catalogItem.getDescription(), "New Item"); assertEquals(catalogItem.getDescription(), "New Item");
@ -184,7 +174,7 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "PUT /catalogItem/{id}", dependsOnMethods = "testAddCatalogItem") @Test(description = "PUT /catalogItem/{id}", dependsOnMethods = "testAddCatalogItem")
public void testUpdateCatalogItem() { public void testUpdateCatalogItem() {
CatalogItem updatedCatalogItem = CatalogItem.builder().fromCatalogItem(catalogItem).name("UPDATEDNAME").build(); CatalogItem updatedCatalogItem = CatalogItem.builder().fromCatalogItem(catalogItem).name("UPDATEDNAME").build();
catalogItem = catalogApi.updateCatalogItem(catalogItem.getHref(), updatedCatalogItem); catalogItem = catalogApi.updateItem(catalogItem.getId(), updatedCatalogItem);
checkCatalogItem(catalogItem); checkCatalogItem(catalogItem);
assertEquals(catalogItem.getName(), "UPDATEDNAME"); assertEquals(catalogItem.getName(), "UPDATEDNAME");
} }
@ -192,69 +182,70 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
// Note this runs after all the metadata tests // Note this runs after all the metadata tests
@Test(description = "DELETE /catalogItem/{id}", dependsOnMethods = "testDeleteCatalogItemMetadataValue") @Test(description = "DELETE /catalogItem/{id}", dependsOnMethods = "testDeleteCatalogItemMetadataValue")
public void testDeleteCatalogItem() { public void testDeleteCatalogItem() {
catalogApi.deleteCatalogItem(catalogItem.getHref()); catalogApi.deleteItem(catalogItem.getId());
catalogItem = catalogApi.getCatalogItem(catalogItem.getHref()); catalogItem = catalogApi.getItem(catalogItem.getId());
assertNull(catalogItem); assertNull(catalogItem);
} }
@Test(description = "GET /catalog/{id}/metadata") @Test(description = "GET /catalog/{id}/metadata")
public void testGetCatalogMetadata() { public void testGetCatalogMetadata() {
Metadata catalogMetadata = catalogApi.getMetadataApi().getMetadata(catalogRef.getHref()); Metadata catalogMetadata = catalogApi.getMetadataApi().get(catalogApi.get(catalogUrn).getHref());
checkMetadata(catalogMetadata); checkMetadata(catalogMetadata);
} }
@Test(description = "GET /catalog/{id}/metadata/{key}") @Test(description = "GET /catalog/{id}/metadata/{key}")
public void testGetCatalogMetadataValue() { public void testGetCatalogMetadataValue() {
Metadata catalogMetadata = catalogApi.getMetadataApi().getMetadata(catalogRef.getHref()); Metadata catalogMetadata = catalogApi.getMetadataApi().get(catalogApi.get(catalogUrn).getHref());
MetadataEntry existingMetadataEntry = Iterables.find(catalogMetadata.getMetadataEntries(), new Predicate<MetadataEntry>() { MetadataEntry existingMetadataEntry = Iterables.find(catalogMetadata.getMetadataEntries(),
new Predicate<MetadataEntry>() {
@Override @Override
public boolean apply(MetadataEntry input) { public boolean apply(MetadataEntry input) {
return input.getKey().equals("KEY"); return input.getKey().equals("KEY");
} }
}); });
MetadataValue metadataValue = catalogApi.getMetadataApi().getMetadataValue(catalogRef.getHref(), "KEY"); MetadataValue metadataValue = catalogApi.getMetadataApi().getValue(existingMetadataEntry.getHref(), "KEY");
assertEquals(metadataValue.getValue(), existingMetadataEntry.getValue(), assertEquals(metadataValue.getValue(), existingMetadataEntry.getValue(), String.format(CORRECT_VALUE_OBJECT_FMT,
String.format(CORRECT_VALUE_OBJECT_FMT, "Value", "MetadataValue", existingMetadataEntry.getValue(), metadataValue.getValue())); "Value", "MetadataValue", existingMetadataEntry.getValue(), metadataValue.getValue()));
checkMetadataValue(metadataValue); checkMetadataValue(metadataValue);
} }
@Test(description = "GET /catalogItem/{id}/metadata", dependsOnMethods = "testAddCatalogItem") @Test(description = "GET /catalogItem/{id}/metadata", dependsOnMethods = "testAddCatalogItem")
public void testGetCatalogItemMetadata() { public void testGetCatalogItemMetadata() {
Metadata catalogItemMetadata = catalogApi.getCatalogItemMetadataApi().getMetadata(catalogItem.getHref()); Metadata catalogItemMetadata = catalogApi.getItemMetadataApi().get(catalogItem.getHref());
checkMetadata(catalogItemMetadata); checkMetadata(catalogItemMetadata);
} }
@Test(description = "POST /catalogItem/{id}/metadata", dependsOnMethods = "testAddCatalogItem") @Test(description = "POST /catalogItem/{id}/metadata", dependsOnMethods = "testAddCatalogItem")
public void testMergeCatalogItemMetadata() { public void testMergeCatalogItemMetadata() {
Metadata newMetadata = Metadata.builder() Metadata newMetadata = Metadata.builder().entry(MetadataEntry.builder().entry("KEY", "MARMALADE").build())
.entry(MetadataEntry.builder().entry("KEY", "MARMALADE").build()) .entry(MetadataEntry.builder().entry("VEGIMITE", "VALUE").build()).build();
.entry(MetadataEntry.builder().entry("VEGIMITE", "VALUE").build())
.build();
Metadata before = catalogApi.getCatalogItemMetadataApi().getMetadata(catalogItem.getHref()); Metadata before = catalogApi.getItemMetadataApi().get(catalogItem.getHref());
Task mergeCatalogItemMetadata = catalogApi.getCatalogItemMetadataApi().mergeMetadata(catalogItem.getHref(), newMetadata); Task mergeCatalogItemMetadata = catalogApi.getItemMetadataApi().merge(catalogItem.getHref(), newMetadata);
checkTask(mergeCatalogItemMetadata); checkTask(mergeCatalogItemMetadata);
assertTrue(retryTaskSuccess.apply(mergeCatalogItemMetadata), assertTrue(retryTaskSuccess.apply(mergeCatalogItemMetadata),
String.format(TASK_COMPLETE_TIMELY, "mergeCatalogItemMetadata")); String.format(TASK_COMPLETE_TIMELY, "mergeCatalogItemMetadata"));
Metadata mergedCatalogItemMetadata = catalogApi.getCatalogItemMetadataApi().getMetadata(catalogItem.getHref()); Metadata mergedCatalogItemMetadata = catalogApi.getItemMetadataApi().get(catalogItem.getHref());
assertTrue(mergedCatalogItemMetadata.getMetadataEntries().size() > before.getMetadataEntries().size(), assertTrue(mergedCatalogItemMetadata.getMetadataEntries().size() > before.getMetadataEntries().size(),
"Should have added at least one other MetadataEntry to the CatalogItem"); "Should have added at least one other MetadataEntry to the CatalogItem");
MetadataValue keyMetadataValue = catalogApi.getCatalogItemMetadataApi().getMetadataValue(catalogItem.getHref(), "KEY"); MetadataValue keyMetadataValue = catalogApi.getItemMetadataApi().getValue(catalogItem.getHref(), "KEY");
assertEquals(keyMetadataValue.getValue(), "MARMALADE", "The Value of the MetadataValue for KEY should have changed"); assertEquals(keyMetadataValue.getValue(), "MARMALADE",
"The Value of the MetadataValue for KEY should have changed");
checkMetadataValue(keyMetadataValue); checkMetadataValue(keyMetadataValue);
MetadataValue newKeyMetadataValue = catalogApi.getCatalogItemMetadataApi().getMetadataValue(catalogItem.getHref(), "VEGIMITE"); MetadataValue newKeyMetadataValue = catalogApi.getItemMetadataApi().getValue(catalogItem.getHref(), "VEGIMITE");
assertEquals(newKeyMetadataValue.getValue(), "VALUE", "The Value of the MetadataValue for NEW_KEY should have been set"); assertEquals(newKeyMetadataValue.getValue(), "VALUE",
"The Value of the MetadataValue for NEW_KEY should have been set");
checkMetadataValue(newKeyMetadataValue); checkMetadataValue(newKeyMetadataValue);
} }
@Test(description = "GET /catalogItem/{id}/metadata/{key}", dependsOnMethods = "testSetCatalogItemMetadataValue") @Test(description = "GET /catalogItem/{id}/metadata/{key}", dependsOnMethods = "testSetCatalogItemMetadataValue")
public void testGetCatalogItemMetadataValue() { public void testGetCatalogItemMetadataValue() {
MetadataValue metadataValue = catalogApi.getCatalogItemMetadataApi().getMetadataValue(catalogItem.getHref(), "KEY"); MetadataValue metadataValue = catalogApi.getItemMetadataApi().getValue(catalogItem.getHref(), "KEY");
checkMetadataValue(metadataValue); checkMetadataValue(metadataValue);
} }
@ -262,24 +253,26 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
public void testSetCatalogItemMetadataValue() { public void testSetCatalogItemMetadataValue() {
MetadataValue newMetadataValue = MetadataValue.builder().value("NEW").build(); MetadataValue newMetadataValue = MetadataValue.builder().value("NEW").build();
Task setCatalogItemMetadataValue = catalogApi.getCatalogItemMetadataApi().setMetadata(catalogItem.getHref(), "KEY", newMetadataValue); Task setCatalogItemMetadataValue = catalogApi.getItemMetadataApi().putEntry(catalogItem.getHref(), "KEY",
newMetadataValue);
checkTask(setCatalogItemMetadataValue); checkTask(setCatalogItemMetadataValue);
assertTrue(retryTaskSuccess.apply(setCatalogItemMetadataValue), assertTrue(retryTaskSuccess.apply(setCatalogItemMetadataValue),
String.format(TASK_COMPLETE_TIMELY, "setCatalogItemMetadataValue")); String.format(TASK_COMPLETE_TIMELY, "setCatalogItemMetadataValue"));
MetadataValue updatedMetadataValue = catalogApi.getCatalogItemMetadataApi().getMetadataValue(catalogItem.getHref(), "KEY"); MetadataValue updatedMetadataValue = catalogApi.getItemMetadataApi().getValue(catalogItem.getHref(), "KEY");
assertEquals(updatedMetadataValue.getValue(), newMetadataValue.getValue(), assertEquals(updatedMetadataValue.getValue(), newMetadataValue.getValue(), String.format(
String.format(CORRECT_VALUE_OBJECT_FMT, "Value", "MetadataValue", newMetadataValue.getValue(), updatedMetadataValue.getValue())); CORRECT_VALUE_OBJECT_FMT, "Value", "MetadataValue", newMetadataValue.getValue(),
updatedMetadataValue.getValue()));
checkMetadataValue(updatedMetadataValue); checkMetadataValue(updatedMetadataValue);
} }
@Test(description = "DELETE /catalogItem/{id}/metadata/{key}", dependsOnMethods = "testGetCatalogItemMetadataValue") @Test(description = "DELETE /catalogItem/{id}/metadata/{key}", dependsOnMethods = "testGetCatalogItemMetadataValue")
public void testDeleteCatalogItemMetadataValue() { public void testDeleteCatalogItemMetadataValue() {
Task deleteCatalogItemMetadataValue = catalogApi.getCatalogItemMetadataApi().deleteMetadataEntry(catalogItem.getHref(), "KEY"); Task deleteCatalogItemMetadataValue = catalogApi.getItemMetadataApi().deleteEntry(catalogItem.getHref(), "KEY");
checkTask(deleteCatalogItemMetadataValue); checkTask(deleteCatalogItemMetadataValue);
assertTrue(retryTaskSuccess.apply(deleteCatalogItemMetadataValue), assertTrue(retryTaskSuccess.apply(deleteCatalogItemMetadataValue),
String.format(TASK_COMPLETE_TIMELY, "deleteCatalogItemMetadataValue")); String.format(TASK_COMPLETE_TIMELY, "deleteCatalogItemMetadataValue"));
MetadataValue deleted = catalogApi.getMetadataApi().getMetadataValue(catalogItem.getHref(), "KEY"); MetadataValue deleted = catalogApi.getMetadataApi().getValue(catalogItem.getHref(), "KEY");
assertNull(deleted); assertNull(deleted);
} }
} }

View File

@ -150,7 +150,7 @@ public class MediaApiExpectTest extends VCloudDirectorAdminApiExpectTest {
} catch (VCloudDirectorException vde) { } catch (VCloudDirectorException vde) {
assertEquals(vde.getError(), expected); assertEquals(vde.getError(), expected);
} catch (Exception e) { } catch (Exception e) {
fail("Should have thrown a VCloudDirectorException"); fail("Should have thrown a VCloudDirectorException", e);
} }
} }
@ -240,7 +240,7 @@ public class MediaApiExpectTest extends VCloudDirectorAdminApiExpectTest {
Metadata expected = metadata(); Metadata expected = metadata();
assertEquals(api.getMediaApi().getMetadataApi().getMetadata(mediaUri), expected); assertEquals(api.getMediaApi().getMetadataApi().get(mediaUri), expected);
} }
@Test @Test
@ -260,7 +260,7 @@ public class MediaApiExpectTest extends VCloudDirectorAdminApiExpectTest {
Metadata inputMetadata = metadata(); Metadata inputMetadata = metadata();
Task expectedTask = mergeMetadataTask(); Task expectedTask = mergeMetadataTask();
assertEquals(api.getMediaApi().getMetadataApi().mergeMetadata(mediaUri, inputMetadata), expectedTask); assertEquals(api.getMediaApi().getMetadataApi().merge(mediaUri, inputMetadata), expectedTask);
} }
public void testGetMetadataValue() { public void testGetMetadataValue() {
@ -278,7 +278,7 @@ public class MediaApiExpectTest extends VCloudDirectorAdminApiExpectTest {
MetadataValue expected = metadataValue(); MetadataValue expected = metadataValue();
assertEquals(api.getMediaApi().getMetadataApi().getMetadataValue(mediaUri, "key"), expected); assertEquals(api.getMediaApi().getMetadataApi().getValue(mediaUri, "key"), expected);
} }
@Test @Test
@ -299,7 +299,7 @@ public class MediaApiExpectTest extends VCloudDirectorAdminApiExpectTest {
Task expectedTask = setMetadataEntryTask(); Task expectedTask = setMetadataEntryTask();
assertEquals(api.getMediaApi().getMetadataApi().setMetadata(mediaUri, "key", inputMetadataValue), expectedTask); assertEquals(api.getMediaApi().getMetadataApi().putEntry(mediaUri, "key", inputMetadataValue), expectedTask);
} }
@Test @Test
@ -315,9 +315,9 @@ public class MediaApiExpectTest extends VCloudDirectorAdminApiExpectTest {
.xmlFilePayload("/media/deleteMetadataEntryTask.xml", VCloudDirectorMediaType.TASK) .xmlFilePayload("/media/deleteMetadataEntryTask.xml", VCloudDirectorMediaType.TASK)
.httpResponseBuilder().build()); .httpResponseBuilder().build());
Task expectedTask = deleteMetadataEntryTask(); Task expectedTask = deleteEntryTask();
assertEquals(api.getMediaApi().getMetadataApi().deleteMetadataEntry(mediaUri, "key"), expectedTask); assertEquals(api.getMediaApi().getMetadataApi().deleteEntry(mediaUri, "key"), expectedTask);
} }
@Test @Test
@ -723,7 +723,7 @@ public class MediaApiExpectTest extends VCloudDirectorAdminApiExpectTest {
.build(); .build();
} }
public static Task deleteMetadataEntryTask() { public static Task deleteEntryTask() {
return Task.builder() return Task.builder()
.name("task") .name("task")
.id("urn:vcloud:task:c6dca927-eab4-41fa-ad6a-3ac58602541c") .id("urn:vcloud:task:c6dca927-eab4-41fa-ad6a-3ac58602541c")

View File

@ -228,7 +228,7 @@ public class MediaApiLiveTest extends BaseVCloudDirectorApiLiveTest {
assertTrue(media.clone(oldMedia), String.format(OBJ_FIELD_CLONE, MEDIA, "copied media", assertTrue(media.clone(oldMedia), String.format(OBJ_FIELD_CLONE, MEDIA, "copied media",
media.toString(), oldMedia.toString())); media.toString(), oldMedia.toString()));
mediaApi.getMetadataApi().setMetadata(media.getHref(), "key", MetadataValue.builder().value("value").build()); mediaApi.getMetadataApi().putEntry(media.getHref(), "key", MetadataValue.builder().value("value").build());
media = vdcApi.cloneMedia(vdcURI, CloneMediaParams.builder() media = vdcApi.cloneMedia(vdcURI, CloneMediaParams.builder()
.source(Reference.builder().fromEntity(media).build()) .source(Reference.builder().fromEntity(media).build())
@ -284,7 +284,7 @@ public class MediaApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "GET /media/{id}/metadata", dependsOnMethods = { "testSetMetadataValue" }) @Test(description = "GET /media/{id}/metadata", dependsOnMethods = { "testSetMetadataValue" })
public void testGetMetadata() { public void testGetMetadata() {
metadata = mediaApi.getMetadataApi().getMetadata(media.getHref()); metadata = mediaApi.getMetadataApi().get(media.getHref());
// required for testing // required for testing
assertFalse(isEmpty(metadata.getMetadataEntries()), assertFalse(isEmpty(metadata.getMetadataEntries()),
String.format(OBJ_FIELD_REQ_LIVE, MEDIA, "metadata.entries")); String.format(OBJ_FIELD_REQ_LIVE, MEDIA, "metadata.entries"));
@ -300,10 +300,10 @@ public class MediaApiLiveTest extends BaseVCloudDirectorApiLiveTest {
.entries(inputEntries) .entries(inputEntries)
.build(); .build();
Task mergeMetadata = mediaApi.getMetadataApi().mergeMetadata(media.getHref(), inputMetadata); Task mergeMetadata = mediaApi.getMetadataApi().merge(media.getHref(), inputMetadata);
Checks.checkTask(mergeMetadata); Checks.checkTask(mergeMetadata);
assertTrue(retryTaskSuccess.apply(mergeMetadata), String.format(TASK_COMPLETE_TIMELY, "mergeMetadata(new)")); assertTrue(retryTaskSuccess.apply(mergeMetadata), String.format(TASK_COMPLETE_TIMELY, "mergeMetadata(new)"));
metadata = mediaApi.getMetadataApi().getMetadata(media.getHref()); metadata = mediaApi.getMetadataApi().get(media.getHref());
Checks.checkMetadataFor(MEDIA, metadata); Checks.checkMetadataFor(MEDIA, metadata);
checkMetadataContainsEntries(metadata, inputEntries); checkMetadataContainsEntries(metadata, inputEntries);
@ -316,10 +316,10 @@ public class MediaApiLiveTest extends BaseVCloudDirectorApiLiveTest {
.entries(inputEntries) .entries(inputEntries)
.build(); .build();
mergeMetadata = mediaApi.getMetadataApi().mergeMetadata(media.getHref(), inputMetadata); mergeMetadata = mediaApi.getMetadataApi().merge(media.getHref(), inputMetadata);
Checks.checkTask(mergeMetadata); Checks.checkTask(mergeMetadata);
assertTrue(retryTaskSuccess.apply(mergeMetadata), String.format(TASK_COMPLETE_TIMELY, "mergeMetadata(modify)")); assertTrue(retryTaskSuccess.apply(mergeMetadata), String.format(TASK_COMPLETE_TIMELY, "mergeMetadata(modify)"));
metadata = mediaApi.getMetadataApi().getMetadata(media.getHref()); metadata = mediaApi.getMetadataApi().get(media.getHref());
Checks.checkMetadataFor(MEDIA, metadata); Checks.checkMetadataFor(MEDIA, metadata);
checkMetadataContainsEntries(metadata, inputEntries); checkMetadataContainsEntries(metadata, inputEntries);
@ -346,7 +346,7 @@ public class MediaApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "GET /media/{id}/metadata/{key}", dependsOnMethods = { "testSetMetadataValue" }) @Test(description = "GET /media/{id}/metadata/{key}", dependsOnMethods = { "testSetMetadataValue" })
public void testGetMetadataValue() { public void testGetMetadataValue() {
metadataValue = mediaApi.getMetadataApi().getMetadataValue(media.getHref(), "key"); metadataValue = mediaApi.getMetadataApi().getValue(media.getHref(), "key");
Checks.checkMetadataValueFor(MEDIA, metadataValue); Checks.checkMetadataValueFor(MEDIA, metadataValue);
} }
@ -355,27 +355,27 @@ public class MediaApiLiveTest extends BaseVCloudDirectorApiLiveTest {
metadataEntryValue = "value"; metadataEntryValue = "value";
MetadataValue newValue = MetadataValue.builder().value(metadataEntryValue).build(); MetadataValue newValue = MetadataValue.builder().value(metadataEntryValue).build();
Task setMetadataEntry = mediaApi.getMetadataApi().setMetadata(media.getHref(), "key", newValue); Task setMetadataEntry = mediaApi.getMetadataApi().putEntry(media.getHref(), "key", newValue);
Checks.checkTask(setMetadataEntry); Checks.checkTask(setMetadataEntry);
assertTrue(retryTaskSuccess.apply(setMetadataEntry), assertTrue(retryTaskSuccess.apply(setMetadataEntry),
String.format(TASK_COMPLETE_TIMELY, "setMetadataEntry")); String.format(TASK_COMPLETE_TIMELY, "setMetadataEntry"));
metadataValue = mediaApi.getMetadataApi().getMetadataValue(media.getHref(), "key"); metadataValue = mediaApi.getMetadataApi().getValue(media.getHref(), "key");
Checks.checkMetadataValueFor(MEDIA, metadataValue); Checks.checkMetadataValueFor(MEDIA, metadataValue);
} }
@Test(description = "DELETE /media/{id}/metadata/{key}", dependsOnMethods = { "testGetMetadata", "testGetMetadataValue" } ) @Test(description = "DELETE /media/{id}/metadata/{key}", dependsOnMethods = { "testGetMetadata", "testGetMetadataValue" } )
public void testDeleteMetadata() { public void testDeleteMetadata() {
Task deleteMetadataEntry = mediaApi.getMetadataApi().deleteMetadataEntry(media.getHref(), "testKey"); Task deleteEntry = mediaApi.getMetadataApi().deleteEntry(media.getHref(), "testKey");
Checks.checkTask(deleteMetadataEntry); Checks.checkTask(deleteEntry);
assertTrue(retryTaskSuccess.apply(deleteMetadataEntry), assertTrue(retryTaskSuccess.apply(deleteEntry),
String.format(TASK_COMPLETE_TIMELY, "deleteMetadataEntry")); String.format(TASK_COMPLETE_TIMELY, "deleteEntry"));
metadataValue = mediaApi.getMetadataApi().getMetadataValue(media.getHref(), "testKey"); metadataValue = mediaApi.getMetadataApi().getValue(media.getHref(), "testKey");
assertNull(metadataValue, String.format(OBJ_FIELD_ATTRB_DEL, MEDIA, assertNull(metadataValue, String.format(OBJ_FIELD_ATTRB_DEL, MEDIA,
"Metadata", metadataValue != null ? metadataValue.toString() : "", "Metadata", metadataValue != null ? metadataValue.toString() : "",
"MetadataEntry", metadataValue != null ? metadataValue.toString() : "")); "MetadataEntry", metadataValue != null ? metadataValue.toString() : ""));
metadataValue = mediaApi.getMetadataApi().getMetadataValue(media.getHref(), "key"); metadataValue = mediaApi.getMetadataApi().getValue(media.getHref(), "key");
Checks.checkMetadataValueFor(MEDIA, metadataValue); Checks.checkMetadataValueFor(MEDIA, metadataValue);
media = mediaApi.getMedia(media.getHref()); media = mediaApi.getMedia(media.getHref());

View File

@ -158,7 +158,7 @@ public class NetworkApiExpectTest extends VCloudDirectorAdminApiExpectTest {
.entries(ImmutableSet.of(MetadataEntry.builder().entry("key", "value").build())) .entries(ImmutableSet.of(MetadataEntry.builder().entry("key", "value").build()))
.build(); .build();
assertEquals(api.getNetworkApi().getMetadataApi().getMetadata(networkUri), expected); assertEquals(api.getNetworkApi().getMetadataApi().get(networkUri), expected);
} }
@Test @Test
@ -184,7 +184,7 @@ public class NetworkApiExpectTest extends VCloudDirectorAdminApiExpectTest {
.value("value") .value("value")
.build(); .build();
assertEquals(api.getNetworkApi().getMetadataApi().getMetadataValue(networkUri, "KEY"), expected); assertEquals(api.getNetworkApi().getMetadataApi().getValue(networkUri, "KEY"), expected);
} }
public static OrgNetwork orgNetwork() { public static OrgNetwork orgNetwork() {

View File

@ -71,7 +71,7 @@ public class NetworkApiLiveTest extends BaseVCloudDirectorApiLiveTest {
public void cleanUp() { public void cleanUp() {
if (metadataSet) { if (metadataSet) {
try { try {
Task delete = adminContext.getApi().getNetworkApi().getMetadataApi().deleteMetadataEntry(toAdminUri(networkURI), "key"); Task delete = adminContext.getApi().getNetworkApi().getMetadataApi().deleteEntry(toAdminUri(networkURI), "key");
taskDoneEventually(delete); taskDoneEventually(delete);
} catch (Exception e) { } catch (Exception e) {
logger.warn(e, "Error when deleting metadata"); logger.warn(e, "Error when deleting metadata");
@ -95,7 +95,7 @@ public class NetworkApiLiveTest extends BaseVCloudDirectorApiLiveTest {
} }
private void setupMetadata() { private void setupMetadata() {
adminContext.getApi().getNetworkApi().getMetadataApi().setMetadata(toAdminUri(networkURI), adminContext.getApi().getNetworkApi().getMetadataApi().putEntry(toAdminUri(networkURI),
"key", MetadataValue.builder().value("value").build()); "key", MetadataValue.builder().value("value").build());
metadataSet = true; metadataSet = true;
} }
@ -106,7 +106,7 @@ public class NetworkApiLiveTest extends BaseVCloudDirectorApiLiveTest {
setupMetadata(); setupMetadata();
} }
Metadata metadata = networkApi.getMetadataApi().getMetadata(networkURI); Metadata metadata = networkApi.getMetadataApi().get(networkURI);
// required for testing // required for testing
assertFalse(Iterables.isEmpty(metadata.getMetadataEntries()), assertFalse(Iterables.isEmpty(metadata.getMetadataEntries()),
String.format(OBJ_FIELD_REQ_LIVE, NETWORK, "metadata.entries")); String.format(OBJ_FIELD_REQ_LIVE, NETWORK, "metadata.entries"));
@ -128,7 +128,7 @@ public class NetworkApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "GET /network/{id}/metadata/{key}", dependsOnMethods = { "testGetMetadata" }) @Test(description = "GET /network/{id}/metadata/{key}", dependsOnMethods = { "testGetMetadata" })
public void testGetMetadataValue() { public void testGetMetadataValue() {
MetadataValue metadataValue = networkApi.getMetadataApi().getMetadataValue(networkURI, "key"); MetadataValue metadataValue = networkApi.getMetadataApi().getValue(networkURI, "key");
// Check parent type // Check parent type
checkResourceType(metadataValue); checkResourceType(metadataValue);

View File

@ -166,7 +166,7 @@ public class OrgApiExpectTest extends VCloudDirectorAdminApiExpectTest {
.entries(ImmutableSet.of(metadataEntry())) .entries(ImmutableSet.of(metadataEntry()))
.build(); .build();
assertEquals(api.getOrgApi().getMetadataApi().getMetadata(orgUri), expected); assertEquals(api.getOrgApi().getMetadataApi().get(orgUri), expected);
} }
@Test @Test
@ -184,7 +184,7 @@ public class OrgApiExpectTest extends VCloudDirectorAdminApiExpectTest {
MetadataValue expected = metadataValue(); MetadataValue expected = metadataValue();
assertEquals(api.getOrgApi().getMetadataApi().getMetadataValue(orgUri, "KEY"), expected); assertEquals(api.getOrgApi().getMetadataApi().getValue(orgUri, "KEY"), expected);
} }
public static Org org() { public static Org org() {

View File

@ -61,29 +61,26 @@ public class OrgApiLiveTest extends BaseVCloudDirectorApiLiveTest {
*/ */
private OrgApi orgApi; private OrgApi orgApi;
private URI catalogRef;
private String testCatalogId;
@Override @Override
@BeforeClass(alwaysRun = true) @BeforeClass(alwaysRun = true)
public void setupRequiredApis() { public void setupRequiredApis() {
orgApi = context.getApi().getOrgApi(); orgApi = context.getApi().getOrgApi();
testCatalogId = catalogId;
} }
@AfterClass(alwaysRun = true) @AfterClass(alwaysRun = true)
public void cleanUp() throws Exception { public void cleanUp() throws Exception {
if (adminMembersSet) { if (adminMembersSet) {
try { try {
Task delete = adminContext.getApi().getOrgApi().getMetadataApi().deleteMetadataEntry(toAdminUri(orgURI), "KEY"); Task delete = adminContext.getApi().getOrgApi().getMetadataApi().deleteEntry(toAdminUri(orgURI), "KEY");
taskDoneEventually(delete); taskDoneEventually(delete);
} catch (Exception e) { } catch (Exception e) {
logger.warn(e, "Error when deleting metadata entry"); logger.warn(e, "Error when deleting metadata entry");
} }
try { try {
adminContext.getApi().getCatalogApi().deleteCatalog(catalogRef); adminContext.getApi().getCatalogApi().delete(catalogUrn);
} catch (Exception e) { } catch (Exception e) {
logger.warn(e, "Error when deleting catalog'%s': %s", catalogRef); logger.warn(e, "Error when deleting catalog'%s': %s", catalogUrn);
} }
} }
} }
@ -134,17 +131,16 @@ public class OrgApiLiveTest extends BaseVCloudDirectorApiLiveTest {
* If we're running in an admin context, it's cleaner to make temporary entities, plus eliminates the need for configuration * If we're running in an admin context, it's cleaner to make temporary entities, plus eliminates the need for configuration
*/ */
private void setupAdminMembers() { private void setupAdminMembers() {
adminContext.getApi().getOrgApi().getMetadataApi().setMetadata(toAdminUri(orgURI), adminContext.getApi().getOrgApi().getMetadataApi().putEntry(toAdminUri(orgURI),
"KEY", MetadataValue.builder().value("VALUE").build()); "KEY", MetadataValue.builder().value("VALUE").build());
AdminCatalog newCatalog = AdminCatalog.builder() AdminCatalog newCatalog = AdminCatalog.builder()
.name("Test Catalog "+getTestDateTimeStamp()) .name("Test Catalog "+getTestDateTimeStamp())
.description("created by testOrg()") .description("created by testOrg()")
.build(); .build();
newCatalog = adminContext.getApi().getCatalogApi().createCatalog(toAdminUri(orgURI), newCatalog); newCatalog = adminContext.getApi().getCatalogApi().createCatalogInOrg(newCatalog, org.getId());
catalogRef = newCatalog.getHref(); catalogUrn = newCatalog.getId();
testCatalogId = newCatalog.getId().substring("urn:vcloud:catalog:".length());
adminMembersSet = true; adminMembersSet = true;
} }
@ -153,7 +149,7 @@ public class OrgApiLiveTest extends BaseVCloudDirectorApiLiveTest {
public void testGetOrgMetadata() { public void testGetOrgMetadata() {
// Call the method being tested // Call the method being tested
Metadata metadata = orgApi.getMetadataApi().getMetadata(orgURI); Metadata metadata = orgApi.getMetadataApi().get(orgURI);
// NOTE The environment MUST have at one metadata entry for the first organisation configured // NOTE The environment MUST have at one metadata entry for the first organisation configured
@ -166,7 +162,7 @@ public class OrgApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "GET /org/{id}/metadata/{key}", dependsOnMethods = { "testGetOrgMetadata" }) @Test(description = "GET /org/{id}/metadata/{key}", dependsOnMethods = { "testGetOrgMetadata" })
public void testGetOrgMetadataValue() { public void testGetOrgMetadataValue() {
// Call the method being tested // Call the method being tested
MetadataValue value = orgApi.getMetadataApi().getMetadataValue(orgURI, "KEY"); MetadataValue value = orgApi.getMetadataApi().getValue(orgURI, "KEY");
// NOTE The environment MUST have configured the metadata entry as '{ key="KEY", value="VALUE" )' // NOTE The environment MUST have configured the metadata entry as '{ key="KEY", value="VALUE" )'
@ -179,7 +175,7 @@ public class OrgApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "GET /org/{id}/catalog/{catalogId}/controlAccess", dependsOnMethods = { "testGetOrg" }) @Test(description = "GET /org/{id}/catalog/{catalogId}/controlAccess", dependsOnMethods = { "testGetOrg" })
public void testGetControlAccess() { public void testGetControlAccess() {
// Call the method being tested // Call the method being tested
ControlAccessParams params = orgApi.getControlAccess(orgURI, testCatalogId); ControlAccessParams params = orgApi.getControlAccess(orgURI, catalogUrn);
// Check params are well formed // Check params are well formed
checkControlAccessParams(params); checkControlAccessParams(params);
@ -188,10 +184,10 @@ public class OrgApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "POST /org/{id}/catalog/{catalogId}/action/controlAccess", dependsOnMethods = { "testGetControlAccess" }) @Test(description = "POST /org/{id}/catalog/{catalogId}/action/controlAccess", dependsOnMethods = { "testGetControlAccess" })
public void testModifyControlAccess() { public void testModifyControlAccess() {
// Setup params // Setup params
ControlAccessParams params = orgApi.getControlAccess(orgURI, testCatalogId); ControlAccessParams params = orgApi.getControlAccess(orgURI, catalogUrn);
// Call the method being tested // Call the method being tested
ControlAccessParams modified = orgApi.modifyControlAccess(orgURI, testCatalogId, params); ControlAccessParams modified = orgApi.modifyControlAccess(orgURI, catalogUrn, params);
// Check params are well formed // Check params are well formed
checkControlAccessParams(modified); checkControlAccessParams(modified);

View File

@ -743,10 +743,10 @@ public class VAppApiLiveTest extends AbstractVAppApiLiveTest {
key = name("key-"); key = name("key-");
String value = name("value-"); String value = name("value-");
metadataValue = MetadataValue.builder().value(value).build(); metadataValue = MetadataValue.builder().value(value).build();
vAppApi.getMetadataApi().setMetadata(vApp.getHref(), key, metadataValue); vAppApi.getMetadataApi().putEntry(vApp.getHref(), key, metadataValue);
// Retrieve the value, and assert it was set correctly // Retrieve the value, and assert it was set correctly
MetadataValue newMetadataValue = vAppApi.getMetadataApi().getMetadataValue(vApp.getHref(), key); MetadataValue newMetadataValue = vAppApi.getMetadataApi().getValue(vApp.getHref(), key);
// Check the retrieved object is well formed // Check the retrieved object is well formed
checkMetadataValueFor(VAPP, newMetadataValue, value); checkMetadataValueFor(VAPP, newMetadataValue, value);
@ -757,10 +757,10 @@ public class VAppApiLiveTest extends AbstractVAppApiLiveTest {
key = name("key-"); key = name("key-");
String value = name("value-"); String value = name("value-");
metadataValue = MetadataValue.builder().value(value).build(); metadataValue = MetadataValue.builder().value(value).build();
vAppApi.getMetadataApi().setMetadata(vApp.getHref(), key, metadataValue); vAppApi.getMetadataApi().putEntry(vApp.getHref(), key, metadataValue);
// Call the method being tested // Call the method being tested
Metadata metadata = vAppApi.getMetadataApi().getMetadata(vApp.getHref()); Metadata metadata = vAppApi.getMetadataApi().get(vApp.getHref());
checkMetadata(metadata); checkMetadata(metadata);
@ -771,7 +771,7 @@ public class VAppApiLiveTest extends AbstractVAppApiLiveTest {
@Test(description = "GET /vApp/{id}/metadata/{key}", dependsOnMethods = { "testGetMetadata" }) @Test(description = "GET /vApp/{id}/metadata/{key}", dependsOnMethods = { "testGetMetadata" })
public void testGetOrgMetadataValue() { public void testGetOrgMetadataValue() {
// Call the method being tested // Call the method being tested
MetadataValue value = vAppApi.getMetadataApi().getMetadataValue(vApp.getHref(), key); MetadataValue value = vAppApi.getMetadataApi().getValue(vApp.getHref(), key);
String expected = metadataValue.getValue(); String expected = metadataValue.getValue();
@ -782,11 +782,11 @@ public class VAppApiLiveTest extends AbstractVAppApiLiveTest {
@Test(description = "DELETE /vApp/{id}/metadata/{key}", dependsOnMethods = { "testSetMetadataValue" }) @Test(description = "DELETE /vApp/{id}/metadata/{key}", dependsOnMethods = { "testSetMetadataValue" })
public void testDeleteMetadataEntry() { public void testDeleteMetadataEntry() {
// Delete the entry // Delete the entry
Task task = vAppApi.getMetadataApi().deleteMetadataEntry(vApp.getHref(), key); Task task = vAppApi.getMetadataApi().deleteEntry(vApp.getHref(), key);
retryTaskSuccess.apply(task); retryTaskSuccess.apply(task);
// Confirm the entry has been deleted // Confirm the entry has been deleted
Metadata newMetadata = vAppApi.getMetadataApi().getMetadata(vApp.getHref()); Metadata newMetadata = vAppApi.getMetadataApi().get(vApp.getHref());
// Check the retrieved object is well formed // Check the retrieved object is well formed
checkMetadataKeyAbsentFor(VAPP, newMetadata, key); checkMetadataKeyAbsentFor(VAPP, newMetadata, key);
@ -794,7 +794,7 @@ public class VAppApiLiveTest extends AbstractVAppApiLiveTest {
@Test(description = "POST /vApp/{id}/metadata", dependsOnMethods = { "testGetMetadata" }) @Test(description = "POST /vApp/{id}/metadata", dependsOnMethods = { "testGetMetadata" })
public void testMergeMetadata() { public void testMergeMetadata() {
Metadata oldMetadata = vAppApi.getMetadataApi().getMetadata(vApp.getHref()); Metadata oldMetadata = vAppApi.getMetadataApi().get(vApp.getHref());
Map<String, String> oldMetadataMap = Checks.metadataToMap(oldMetadata); Map<String, String> oldMetadataMap = Checks.metadataToMap(oldMetadata);
// Store a value, to be deleted // Store a value, to be deleted
@ -803,11 +803,11 @@ public class VAppApiLiveTest extends AbstractVAppApiLiveTest {
Metadata addedMetadata = Metadata.builder() Metadata addedMetadata = Metadata.builder()
.entry(MetadataEntry.builder().key(key).value(value).build()) .entry(MetadataEntry.builder().key(key).value(value).build())
.build(); .build();
Task task = vAppApi.getMetadataApi().mergeMetadata(vApp.getHref(), addedMetadata); Task task = vAppApi.getMetadataApi().merge(vApp.getHref(), addedMetadata);
retryTaskSuccess.apply(task); retryTaskSuccess.apply(task);
// Confirm the entry contains everything that was there, and everything that was being added // Confirm the entry contains everything that was there, and everything that was being added
Metadata newMetadata = vAppApi.getMetadataApi().getMetadata(vApp.getHref()); Metadata newMetadata = vAppApi.getMetadataApi().get(vApp.getHref());
Map<String, String> expectedMetadataMap = ImmutableMap.<String, String>builder() Map<String, String> expectedMetadataMap = ImmutableMap.<String, String>builder()
.putAll(oldMetadataMap) .putAll(oldMetadataMap)
.put(key, value) .put(key, value)

View File

@ -86,7 +86,7 @@ public class VAppNetworksLiveTest extends AbstractVAppApiLiveTest {
protected void tidyUp() { protected void tidyUp() {
if (key != null) { if (key != null) {
try { try {
Task delete = vAppTemplateApi.getMetadataApi().deleteMetadataEntry(vAppTemplateURI, key); Task delete = vAppTemplateApi.getMetadataApi().deleteEntry(vAppTemplateURI, key);
taskDoneEventually(delete); taskDoneEventually(delete);
} catch (Exception e) { } catch (Exception e) {
logger.warn(e, "Error when deleting metadata entry '%s'", key); logger.warn(e, "Error when deleting metadata entry '%s'", key);

View File

@ -353,11 +353,11 @@ public class VAppTemplateApiExpectTest extends VCloudDirectorAdminApiExpectTest
).getVAppTemplateApi(); ).getVAppTemplateApi();
assertNotNull(api); assertNotNull(api);
Metadata metadata = api.getMetadataApi().getMetadata(uri); Metadata metadata = api.getMetadataApi().get(uri);
assertEquals(metadata, exampleMetadata()); assertEquals(metadata, exampleMetadata());
Task task = api.getMetadataApi().mergeMetadata(uri, exampleMetadata()); Task task = api.getMetadataApi().merge(uri, exampleMetadata());
assertNotNull(task); assertNotNull(task);
} }
@ -370,7 +370,7 @@ public class VAppTemplateApiExpectTest extends VCloudDirectorAdminApiExpectTest
new VcloudHttpRequestPrimer().apiCommand("GET", templateId + "/metadata").acceptMedia(ANY).httpRequestBuilder().build(), new VcloudHttpRequestPrimer().apiCommand("GET", templateId + "/metadata").acceptMedia(ANY).httpRequestBuilder().build(),
new VcloudHttpResponsePrimer().xmlFilePayload("/vapptemplate/error400.xml", ERROR).httpResponseBuilder().statusCode(400).build()).getVAppTemplateApi(); new VcloudHttpResponsePrimer().xmlFilePayload("/vapptemplate/error400.xml", ERROR).httpResponseBuilder().statusCode(400).build()).getVAppTemplateApi();
api.getMetadataApi().getMetadata(uri); api.getMetadataApi().get(uri);
} }
@Test(expectedExceptions = VCloudDirectorException.class) @Test(expectedExceptions = VCloudDirectorException.class)
@ -382,7 +382,7 @@ public class VAppTemplateApiExpectTest extends VCloudDirectorAdminApiExpectTest
new VcloudHttpRequestPrimer().apiCommand("POST", templateId + "/metadata").xmlFilePayload("/vapptemplate/metadata.xml", METADATA).acceptMedia(TASK).httpRequestBuilder().build(), new VcloudHttpRequestPrimer().apiCommand("POST", templateId + "/metadata").xmlFilePayload("/vapptemplate/metadata.xml", METADATA).acceptMedia(TASK).httpRequestBuilder().build(),
new VcloudHttpResponsePrimer().xmlFilePayload("/vapptemplate/error400.xml", ERROR).httpResponseBuilder().statusCode(400).build()).getVAppTemplateApi(); new VcloudHttpResponsePrimer().xmlFilePayload("/vapptemplate/error400.xml", ERROR).httpResponseBuilder().statusCode(400).build()).getVAppTemplateApi();
api.getMetadataApi().mergeMetadata(uri, exampleMetadata()); api.getMetadataApi().merge(uri, exampleMetadata());
} }
public void testVappTemplateMetadataValue() { public void testVappTemplateMetadataValue() {
@ -399,14 +399,14 @@ public class VAppTemplateApiExpectTest extends VCloudDirectorAdminApiExpectTest
).getVAppTemplateApi(); ).getVAppTemplateApi();
assertNotNull(api); assertNotNull(api);
MetadataValue metadata = api.getMetadataApi().getMetadataValue(uri, "12345"); MetadataValue metadata = api.getMetadataApi().getValue(uri, "12345");
assertEquals(metadata, exampleMetadataValue()); assertEquals(metadata, exampleMetadataValue());
Task task = api.getMetadataApi().setMetadata(uri, "12345", exampleMetadataValue()); Task task = api.getMetadataApi().putEntry(uri, "12345", exampleMetadataValue());
assertNotNull(task); assertNotNull(task);
task = api.getMetadataApi().deleteMetadataEntry(uri, "12345"); task = api.getMetadataApi().deleteEntry(uri, "12345");
assertNotNull(task); assertNotNull(task);
} }
@ -418,7 +418,7 @@ public class VAppTemplateApiExpectTest extends VCloudDirectorAdminApiExpectTest
new VcloudHttpRequestPrimer().apiCommand("GET", templateId + "/metadata/12345").acceptMedia(METADATA_ENTRY).httpRequestBuilder().build(), new VcloudHttpRequestPrimer().apiCommand("GET", templateId + "/metadata/12345").acceptMedia(METADATA_ENTRY).httpRequestBuilder().build(),
new VcloudHttpResponsePrimer().xmlFilePayload("/vapptemplate/error403.xml", ERROR).httpResponseBuilder().statusCode(403).build()).getVAppTemplateApi(); new VcloudHttpResponsePrimer().xmlFilePayload("/vapptemplate/error403.xml", ERROR).httpResponseBuilder().statusCode(403).build()).getVAppTemplateApi();
assertNull(api.getMetadataApi().getMetadataValue(uri, "12345")); assertNull(api.getMetadataApi().getValue(uri, "12345"));
} }
@Test(expectedExceptions = VCloudDirectorException.class) @Test(expectedExceptions = VCloudDirectorException.class)
@ -430,7 +430,7 @@ public class VAppTemplateApiExpectTest extends VCloudDirectorAdminApiExpectTest
new VcloudHttpRequestPrimer().apiCommand("PUT", templateId + "/metadata/12345").xmlFilePayload("/vapptemplate/metadataValue.xml", METADATA_ENTRY).acceptMedia(TASK).httpRequestBuilder().build(), new VcloudHttpRequestPrimer().apiCommand("PUT", templateId + "/metadata/12345").xmlFilePayload("/vapptemplate/metadataValue.xml", METADATA_ENTRY).acceptMedia(TASK).httpRequestBuilder().build(),
new VcloudHttpResponsePrimer().xmlFilePayload("/vapptemplate/error400.xml", ERROR).httpResponseBuilder().statusCode(400).build()).getVAppTemplateApi(); new VcloudHttpResponsePrimer().xmlFilePayload("/vapptemplate/error400.xml", ERROR).httpResponseBuilder().statusCode(400).build()).getVAppTemplateApi();
api.getMetadataApi().setMetadata(uri, "12345", exampleMetadataValue()); api.getMetadataApi().putEntry(uri, "12345", exampleMetadataValue());
} }
@Test(expectedExceptions = ResourceNotFoundException.class) @Test(expectedExceptions = ResourceNotFoundException.class)
@ -442,7 +442,7 @@ public class VAppTemplateApiExpectTest extends VCloudDirectorAdminApiExpectTest
new VcloudHttpRequestPrimer().apiCommand("DELETE", templateId + "/metadata/12345").acceptMedia(TASK).httpRequestBuilder().build(), new VcloudHttpRequestPrimer().apiCommand("DELETE", templateId + "/metadata/12345").acceptMedia(TASK).httpRequestBuilder().build(),
new VcloudHttpResponsePrimer().xmlFilePayload("/vapptemplate/error403.xml", ERROR).httpResponseBuilder().statusCode(403).build()).getVAppTemplateApi(); new VcloudHttpResponsePrimer().xmlFilePayload("/vapptemplate/error403.xml", ERROR).httpResponseBuilder().statusCode(403).build()).getVAppTemplateApi();
api.getMetadataApi().deleteMetadataEntry(uri, "12345"); api.getMetadataApi().deleteEntry(uri, "12345");
} }
@Test(expectedExceptions = VCloudDirectorException.class) @Test(expectedExceptions = VCloudDirectorException.class)

View File

@ -91,7 +91,7 @@ public class VAppTemplateApiLiveTest extends AbstractVAppApiLiveTest {
protected void tidyUp() { protected void tidyUp() {
if (key != null) { if (key != null) {
try { try {
Task delete = vAppTemplateApi.getMetadataApi().deleteMetadataEntry(vAppTemplateURI, key); Task delete = vAppTemplateApi.getMetadataApi().deleteEntry(vAppTemplateURI, key);
taskDoneEventually(delete); taskDoneEventually(delete);
} catch (Exception e) { } catch (Exception e) {
logger.warn(e, "Error when deleting metadata entry '%s'", key); logger.warn(e, "Error when deleting metadata entry '%s'", key);
@ -178,7 +178,7 @@ public class VAppTemplateApiLiveTest extends AbstractVAppApiLiveTest {
@Test(description = "GET /vAppTemplate/{id}/metadata", dependsOnMethods = { "testEditMetadataValue" }) @Test(description = "GET /vAppTemplate/{id}/metadata", dependsOnMethods = { "testEditMetadataValue" })
public void testGetVAppTemplateMetadata() { public void testGetVAppTemplateMetadata() {
Metadata metadata = vAppTemplateApi.getMetadataApi().getMetadata(vAppTemplateURI); Metadata metadata = vAppTemplateApi.getMetadataApi().get(vAppTemplateURI);
checkMetadata(metadata); checkMetadata(metadata);
} }
@ -186,10 +186,10 @@ public class VAppTemplateApiLiveTest extends AbstractVAppApiLiveTest {
// implicitly tested by testEditVAppTemplateMetadataValue, which first creates the metadata entry; otherwise no entry may exist // implicitly tested by testEditVAppTemplateMetadataValue, which first creates the metadata entry; otherwise no entry may exist
@Test(description = "GET /vAppTemplate/{id}/metadata/{key}", dependsOnMethods = { "testGetVAppTemplateMetadata" }) @Test(description = "GET /vAppTemplate/{id}/metadata/{key}", dependsOnMethods = { "testGetVAppTemplateMetadata" })
public void testGetMetadataValue() { public void testGetMetadataValue() {
Metadata metadata = vAppTemplateApi.getMetadataApi().getMetadata(vAppTemplateURI); Metadata metadata = vAppTemplateApi.getMetadataApi().get(vAppTemplateURI);
MetadataEntry entry = Iterables.get(metadata.getMetadataEntries(), 0); MetadataEntry entry = Iterables.get(metadata.getMetadataEntries(), 0);
MetadataValue val = vAppTemplateApi.getMetadataApi().getMetadataValue(vAppTemplateURI, entry.getKey()); MetadataValue val = vAppTemplateApi.getMetadataApi().getValue(vAppTemplateURI, entry.getKey());
checkMetadataValue(val); checkMetadataValue(val);
assertEquals(val.getValue(), entry.getValue()); assertEquals(val.getValue(), entry.getValue());
@ -245,7 +245,7 @@ public class VAppTemplateApiLiveTest extends AbstractVAppApiLiveTest {
@Test(description = "POST /vAppTemplate/{id}/metadata", dependsOnMethods = { "testGetVAppTemplate" }) @Test(description = "POST /vAppTemplate/{id}/metadata", dependsOnMethods = { "testGetVAppTemplate" })
public void testEditMetadata() { public void testEditMetadata() {
Metadata oldMetadata = vAppTemplateApi.getMetadataApi().getMetadata(vAppTemplateURI); Metadata oldMetadata = vAppTemplateApi.getMetadataApi().get(vAppTemplateURI);
Map<String,String> oldMetadataMap = metadataToMap(oldMetadata); Map<String,String> oldMetadataMap = metadataToMap(oldMetadata);
key = name("key-"); key = name("key-");
@ -253,10 +253,10 @@ public class VAppTemplateApiLiveTest extends AbstractVAppApiLiveTest {
MetadataEntry metadataEntry = MetadataEntry.builder().entry(key, val).build(); MetadataEntry metadataEntry = MetadataEntry.builder().entry(key, val).build();
Metadata metadata = Metadata.builder().fromMetadata(oldMetadata).entry(metadataEntry).build(); Metadata metadata = Metadata.builder().fromMetadata(oldMetadata).entry(metadataEntry).build();
final Task task = vAppTemplateApi.getMetadataApi().mergeMetadata(vAppTemplateURI, metadata); final Task task = vAppTemplateApi.getMetadataApi().merge(vAppTemplateURI, metadata);
assertTaskSucceeds(task); assertTaskSucceeds(task);
Metadata newMetadata = vAppTemplateApi.getMetadataApi().getMetadata(vAppTemplateURI); Metadata newMetadata = vAppTemplateApi.getMetadataApi().get(vAppTemplateURI);
Map<String,String> expectedMetadataMap = ImmutableMap.<String,String>builder() Map<String,String> expectedMetadataMap = ImmutableMap.<String,String>builder()
.putAll(oldMetadataMap) .putAll(oldMetadataMap)
.put(key, val) .put(key, val)
@ -269,19 +269,19 @@ public class VAppTemplateApiLiveTest extends AbstractVAppApiLiveTest {
val = "new"+val; val = "new"+val;
MetadataValue metadataValue = MetadataValue.builder().value(val).build(); MetadataValue metadataValue = MetadataValue.builder().value(val).build();
final Task task = vAppTemplateApi.getMetadataApi().setMetadata(vAppTemplateURI, key, metadataValue); final Task task = vAppTemplateApi.getMetadataApi().putEntry(vAppTemplateURI, key, metadataValue);
retryTaskSuccess.apply(task); retryTaskSuccess.apply(task);
MetadataValue newMetadataValue = vAppTemplateApi.getMetadataApi().getMetadataValue(vAppTemplateURI, key); MetadataValue newMetadataValue = vAppTemplateApi.getMetadataApi().getValue(vAppTemplateURI, key);
assertEquals(newMetadataValue.getValue(), metadataValue.getValue()); assertEquals(newMetadataValue.getValue(), metadataValue.getValue());
} }
@Test(description = "DELETE /vAppTemplate/{id}/metadata/{key}", dependsOnMethods = { "testGetMetadataValue" }) @Test(description = "DELETE /vAppTemplate/{id}/metadata/{key}", dependsOnMethods = { "testGetMetadataValue" })
public void testDeleteVAppTemplateMetadataValue() { public void testDeleteVAppTemplateMetadataValue() {
final Task deletionTask = vAppTemplateApi.getMetadataApi().deleteMetadataEntry(vAppTemplateURI, key); final Task deletionTask = vAppTemplateApi.getMetadataApi().deleteEntry(vAppTemplateURI, key);
assertTaskSucceeds(deletionTask); assertTaskSucceeds(deletionTask);
Metadata newMetadata = vAppTemplateApi.getMetadataApi().getMetadata(vAppTemplateURI); Metadata newMetadata = vAppTemplateApi.getMetadataApi().get(vAppTemplateURI);
checkMetadataKeyAbsentFor("vAppTemplate", newMetadata, key); checkMetadataKeyAbsentFor("vAppTemplate", newMetadata, key);
key = null; key = null;
} }

View File

@ -356,7 +356,7 @@ public class VdcApiExpectTest extends VCloudDirectorAdminApiExpectTest {
Metadata expected = metadata(); Metadata expected = metadata();
assertEquals(api.getVdcApi().getMetadataApi().getMetadata(vdcUri), expected); assertEquals(api.getVdcApi().getMetadataApi().get(vdcUri), expected);
} }
@Test(enabled = false) @Test(enabled = false)
@ -374,7 +374,7 @@ public class VdcApiExpectTest extends VCloudDirectorAdminApiExpectTest {
MetadataValue expected = metadataValue(); MetadataValue expected = metadataValue();
assertEquals(api.getVdcApi().getMetadataApi().getMetadataValue(vdcUri, "key"), expected); assertEquals(api.getVdcApi().getMetadataApi().getValue(vdcUri, "key"), expected);
} }
public static Vdc getVdc() { public static Vdc getVdc() {

View File

@ -119,7 +119,7 @@ public class VdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
if (metadataSet) { if (metadataSet) {
try { try {
Task delete = adminContext.getApi().getVdcApi().getMetadataApi().deleteMetadataEntry(toAdminUri(vdcURI), "key"); Task delete = adminContext.getApi().getVdcApi().getMetadataApi().deleteEntry(toAdminUri(vdcURI), "key");
taskDoneEventually(delete); taskDoneEventually(delete);
} catch (Exception e) { } catch (Exception e) {
logger.warn(e, "Error deleting metadata entry"); logger.warn(e, "Error deleting metadata entry");
@ -316,7 +316,7 @@ public class VdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
} }
private void setupMetadata() { private void setupMetadata() {
adminContext.getApi().getVdcApi().getMetadataApi().setMetadata(toAdminUri(vdcURI), adminContext.getApi().getVdcApi().getMetadataApi().putEntry(toAdminUri(vdcURI),
"key", MetadataValue.builder().value("value").build()); "key", MetadataValue.builder().value("value").build());
metadataSet = true; metadataSet = true;
} }
@ -327,7 +327,7 @@ public class VdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
setupMetadata(); setupMetadata();
} }
Metadata metadata = vdcApi.getMetadataApi().getMetadata(vdcURI); Metadata metadata = vdcApi.getMetadataApi().get(vdcURI);
// required for testing // required for testing
assertFalse(Iterables.isEmpty(metadata.getMetadataEntries()), assertFalse(Iterables.isEmpty(metadata.getMetadataEntries()),
@ -339,12 +339,12 @@ public class VdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "GET /vdc/{id}/metadata/{key}", dependsOnMethods = { "testGetMetadata" } ) @Test(description = "GET /vdc/{id}/metadata/{key}", dependsOnMethods = { "testGetMetadata" } )
public void testGetMetadataValue() { public void testGetMetadataValue() {
// First find a key // First find a key
Metadata metadata = vdcApi.getMetadataApi().getMetadata(vdcURI); Metadata metadata = vdcApi.getMetadataApi().get(vdcURI);
Map<String, String> metadataMap = Checks.metadataToMap(metadata); Map<String, String> metadataMap = Checks.metadataToMap(metadata);
String key = Iterables.getFirst(metadataMap.keySet(), "MadeUpKey!"); String key = Iterables.getFirst(metadataMap.keySet(), "MadeUpKey!");
String value = metadataMap.get(key); String value = metadataMap.get(key);
MetadataValue metadataValue = vdcApi.getMetadataApi().getMetadataValue(vdcURI, key); MetadataValue metadataValue = vdcApi.getMetadataApi().getValue(vdcURI, key);
Checks.checkMetadataValueFor(VDC, metadataValue, value); Checks.checkMetadataValueFor(VDC, metadataValue, value);
} }

View File

@ -919,10 +919,10 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
key = name("key-"); key = name("key-");
String value = name("value-"); String value = name("value-");
metadataValue = MetadataValue.builder().value(value).build(); metadataValue = MetadataValue.builder().value(value).build();
vmApi.getMetadataApi().setMetadata(vm.getHref(), key, metadataValue); vmApi.getMetadataApi().putEntry(vm.getHref(), key, metadataValue);
// Retrieve the value, and assert it was set correctly // Retrieve the value, and assert it was set correctly
MetadataValue newMetadataValue = vmApi.getMetadataApi().getMetadataValue(vm.getHref(), key); MetadataValue newMetadataValue = vmApi.getMetadataApi().getValue(vm.getHref(), key);
// Check the retrieved object is well formed // Check the retrieved object is well formed
checkMetadataValueFor(VM, newMetadataValue, value); checkMetadataValueFor(VM, newMetadataValue, value);
@ -931,7 +931,7 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
@Test(description = "GET /vApp/{id}/metadata", dependsOnMethods = { "testSetMetadataValue" }) @Test(description = "GET /vApp/{id}/metadata", dependsOnMethods = { "testSetMetadataValue" })
public void testGetMetadata() { public void testGetMetadata() {
// Call the method being tested // Call the method being tested
Metadata metadata = vmApi.getMetadataApi().getMetadata(vm.getHref()); Metadata metadata = vmApi.getMetadataApi().get(vm.getHref());
checkMetadata(metadata); checkMetadata(metadata);
@ -944,10 +944,10 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
key = name("key-"); key = name("key-");
String value = name("value-"); String value = name("value-");
metadataValue = MetadataValue.builder().value(value).build(); metadataValue = MetadataValue.builder().value(value).build();
vmApi.getMetadataApi().setMetadata(vm.getHref(), key, metadataValue); vmApi.getMetadataApi().putEntry(vm.getHref(), key, metadataValue);
// Call the method being tested // Call the method being tested
MetadataValue metadataValue = vmApi.getMetadataApi().getMetadataValue(vm.getHref(), key); MetadataValue metadataValue = vmApi.getMetadataApi().getValue(vm.getHref(), key);
String expected = metadataValue.getValue(); String expected = metadataValue.getValue();
@ -958,11 +958,11 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
@Test(description = "DELETE /vApp/{id}/metadata/{key}", dependsOnMethods = { "testSetMetadataValue" }) @Test(description = "DELETE /vApp/{id}/metadata/{key}", dependsOnMethods = { "testSetMetadataValue" })
public void testDeleteMetadataEntry() { public void testDeleteMetadataEntry() {
// Delete the entry // Delete the entry
Task task = vmApi.getMetadataApi().deleteMetadataEntry(vm.getHref(), key); Task task = vmApi.getMetadataApi().deleteEntry(vm.getHref(), key);
retryTaskSuccess.apply(task); retryTaskSuccess.apply(task);
// Confirm the entry has been deleted // Confirm the entry has been deleted
Metadata newMetadata = vmApi.getMetadataApi().getMetadata(vm.getHref()); Metadata newMetadata = vmApi.getMetadataApi().get(vm.getHref());
// Check the retrieved object is well formed // Check the retrieved object is well formed
checkMetadataKeyAbsentFor(VM, newMetadata, key); checkMetadataKeyAbsentFor(VM, newMetadata, key);
@ -970,7 +970,7 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
@Test(description = "POST /vApp/{id}/metadata", dependsOnMethods = { "testGetMetadata" }) @Test(description = "POST /vApp/{id}/metadata", dependsOnMethods = { "testGetMetadata" })
public void testMergeMetadata() { public void testMergeMetadata() {
Metadata oldMetadata = vmApi.getMetadataApi().getMetadata(vm.getHref()); Metadata oldMetadata = vmApi.getMetadataApi().get(vm.getHref());
Map<String, String> oldMetadataMap = Checks.metadataToMap(oldMetadata); Map<String, String> oldMetadataMap = Checks.metadataToMap(oldMetadata);
// Store a value, to be deleted // Store a value, to be deleted
@ -979,11 +979,11 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
Metadata addedMetadata = Metadata.builder() Metadata addedMetadata = Metadata.builder()
.entry(MetadataEntry.builder().key(key).value(value).build()) .entry(MetadataEntry.builder().key(key).value(value).build())
.build(); .build();
Task task = vmApi.getMetadataApi().mergeMetadata(vm.getHref(), addedMetadata); Task task = vmApi.getMetadataApi().merge(vm.getHref(), addedMetadata);
retryTaskSuccess.apply(task); retryTaskSuccess.apply(task);
// Confirm the entry contains everything that was there, and everything that was being added // Confirm the entry contains everything that was there, and everything that was being added
Metadata newMetadata = vmApi.getMetadataApi().getMetadata(vm.getHref()); Metadata newMetadata = vmApi.getMetadataApi().get(vm.getHref());
Map<String, String> expectedMetadataMap = ImmutableMap.<String, String>builder() Map<String, String> expectedMetadataMap = ImmutableMap.<String, String>builder()
.putAll(oldMetadataMap) .putAll(oldMetadataMap)
.put(key, value) .put(key, value)

View File

@ -18,10 +18,19 @@
*/ */
package org.jclouds.vcloud.director.v1_5.features.admin; package org.jclouds.vcloud.director.v1_5.features.admin;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.ADMIN_CATALOG;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.ADMIN_ORG;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.CATALOG;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.ENTITY;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.ORG;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.OWNER;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.PUBLISH_CATALOG_PARAMS;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.net.URI; import java.net.URI;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminApi; import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminApi;
import org.jclouds.vcloud.director.v1_5.domain.AdminCatalog; import org.jclouds.vcloud.director.v1_5.domain.AdminCatalog;
@ -34,105 +43,159 @@ import org.jclouds.vcloud.director.v1_5.internal.VCloudDirectorAdminApiExpectTes
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.net.HttpHeaders;
/** /**
* Test the {@link AdminCatalogApi} by observing its side effects. * Test the {@link AdminCatalogApi} by observing its side effects.
* *
* @author grkvlt@apache.org * @author grkvlt@apache.org, Adrian Cole
*/ */
@Test(groups = { "unit", "admin" }, singleThreaded = true, testName = "CatalogApiExpectTest") @Test(groups = { "unit", "admin" }, singleThreaded = true, testName = "CatalogApiExpectTest")
public class AdminCatalogApiExpectTest extends VCloudDirectorAdminApiExpectTest { public class AdminCatalogApiExpectTest extends VCloudDirectorAdminApiExpectTest {
private Reference catalogRef = Reference.builder() static String catalog = "7212e451-76e1-4631-b2de-ba1dfd8080e4";
.type("application/vnd.vmware.vcloud.catalog+xml") static String catalogUrn = "urn:vcloud:catalog:" + catalog;
.name("QunyingTestCatalog") static URI adminCatalogHref = URI.create(endpoint + "/admin/catalog/" + catalog);
.href(URI.create(endpoint + "/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) static URI catalogHref = URI.create(endpoint + "/catalog/" + catalog);
HttpRequest get = HttpRequest.builder()
.method("GET")
.endpoint(adminCatalogHref)
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.build();
HttpResponse getResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/admin/catalog.xml", ADMIN_CATALOG + ";version=1.5"))
.build(); .build();
@Test @Test
public void testCreateCatalog() { public void testGetCatalogHref() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, get, getResponse);
new VcloudHttpRequestPrimer() assertEquals(api.getCatalogApi().get(adminCatalogHref), catalog());
.apiCommand("POST", "/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/catalogs")
.xmlFilePayload("/catalog/admin/createCatalogSource.xml", VCloudDirectorMediaType.ADMIN_CATALOG)
.acceptMedia(VCloudDirectorMediaType.ADMIN_CATALOG)
.httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/catalog/admin/createCatalog.xml", VCloudDirectorMediaType.ADMIN_CATALOG)
.httpResponseBuilder().build());
AdminCatalog source = createCatalogSource();
AdminCatalog expected = createCatalog();
assertEquals(api.getCatalogApi().createCatalog(catalogRef.getHref(), source), expected);
} }
// FIXME disabled due to intermittent JXB error: javax.xml.bind.UnmarshalException: HttpRequest resolveCatalog = HttpRequest.builder()
// unexpected element (uri:"http://www.vmware.com/vcloud/v1.5", local:"AdminCatalog"). .method("GET")
// Expected elements are <{http://www.vmware.com/vcloud/v1.5}Catalog>, <{http://www.vmware.com/vcloud/v1.5}CatalogReference>, .endpoint(endpoint + "/entity/" + catalogUrn)
// <{http://www.vmware.com/vcloud/v1.5}Error>,<{http://www.vmware.com/vcloud/v1.5}Link>, .addHeader("Accept", "*/*")
// <{http://www.vmware.com/vcloud/v1.5}Owner>,<{http://www.vmware.com/vcloud/v1.5}Reference>, .addHeader("x-vcloud-authorization", token)
// <{http://www.vmware.com/vcloud/v1.5}RoleReference>,<{http://www.vmware.com/vcloud/v1.5}Task>, .addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
// <{http://www.vmware.com/vcloud/v1.5}VAppReference> .build();
@Test(enabled = false)
public void testGetCatalog() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("GET", "/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")
.acceptAnyMedia()
.httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/catalog/admin/catalog.xml", VCloudDirectorMediaType.ADMIN_CATALOG)
.httpResponseBuilder().build());
AdminCatalog expected = catalog(); String catalogEntity = asString(createXMLBuilder("Entity").a("xmlns", "http://www.vmware.com/vcloud/v1.5")
.a("name", catalogUrn)
.a("id", catalogUrn)
.a("type", ENTITY)
.a("href", endpoint + "/entity/" + catalogUrn)
.e("Link").a("rel", "alternate").a("type", CATALOG).a("href", catalogHref.toString()).up()
.e("Link").a("rel", "alternate").a("type", ADMIN_CATALOG).a("href", adminCatalogHref.toString()).up());
AdminCatalog actual = api.getCatalogApi().getCatalog(catalogRef.getHref()); HttpResponse resolveCatalogResponse = HttpResponse.builder()
assertEquals(actual.getHref(), expected.getHref()); .statusCode(200)
assertEquals(actual.getLinks(), expected.getLinks()); .payload(payloadFromStringWithContentType(catalogEntity, ENTITY + ";version=1.5"))
assertEquals(actual.getTasks(), expected.getTasks()); .build();
System.out.println(actual.getOwner()); @Test
System.out.println(expected.getOwner()); public void testGetCatalogUrn() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, resolveCatalog, resolveCatalogResponse, get, getResponse);
assertEquals(api.getCatalogApi().get(catalogUrn), catalog());
}
Reference actualUser = actual.getOwner().getUser(); static String org = "7212e451-76e1-4631-b2de-asdasdasd";
Reference expectedUser = expected.getOwner().getUser(); static String orgUrn = "urn:vcloud:org:" + org;
assertEquals(actualUser, expectedUser); static URI orgHref = URI.create(endpoint + "/org/" + org);
static URI adminOrgHref = URI.create(endpoint + "/admin/org/" + org);
assertEquals(actual.getOwner(), expected.getOwner()); HttpRequest create = HttpRequest.builder()
.method("POST")
.endpoint(adminOrgHref + "/catalogs")
.addHeader("Accept", ADMIN_CATALOG)
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.payload(payloadFromResourceWithContentType("/catalog/admin/createCatalogSource.xml", VCloudDirectorMediaType.ADMIN_CATALOG))
.build();
assertEquals(api.getCatalogApi().getCatalog(catalogRef.getHref()), expected); HttpResponse createResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/admin/createCatalog.xml", ADMIN_CATALOG + ";version=1.5"))
.build();
@Test
public void testCreateCatalogHref() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, create, createResponse);
assertEquals(api.getCatalogApi().createCatalogInOrg(createCatalogInOrgSource(), adminOrgHref), createCatalogInOrg());
}
HttpRequest resolveOrg = HttpRequest.builder()
.method("GET")
.endpoint(endpoint + "/entity/" + orgUrn)
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.build();
String orgEntity = asString(createXMLBuilder("Entity").a("xmlns", "http://www.vmware.com/vcloud/v1.5")
.a("name", orgUrn)
.a("id", orgUrn)
.a("type", ENTITY)
.a("href", endpoint + "/entity/" + catalogUrn)
.e("Link").a("rel", "alternate").a("type", ORG).a("href", orgHref.toString()).up()
.e("Link").a("rel", "alternate").a("type", ADMIN_ORG).a("href", adminOrgHref.toString()).up());
HttpResponse resolveOrgResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromStringWithContentType(orgEntity, ENTITY + ";version=1.5"))
.build();
@Test
public void testCreateCatalogUrn() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, resolveOrg, resolveOrgResponse, create, createResponse);
assertEquals(api.getCatalogApi().createCatalogInOrg(createCatalogInOrgSource(), orgUrn), createCatalogInOrg());
}
HttpRequest update = HttpRequest.builder()
.method("PUT")
.endpoint(adminCatalogHref)
.addHeader("Accept", ADMIN_CATALOG)
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.payload(payloadFromResourceWithContentType("/catalog/admin/updateCatalogSource.xml", VCloudDirectorMediaType.ADMIN_CATALOG))
.build();
HttpResponse updateResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/admin/updateCatalog.xml", ADMIN_CATALOG + ";version=1.5"))
.build();
@Test
public void testUpdateCatalogHref() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, update, updateResponse);
assertEquals(api.getCatalogApi().update(adminCatalogHref, updateCatalog()), updateCatalog());
} }
@Test @Test
public void testModifyCatalog() { public void testUpdateCatalogUrn() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, resolveCatalog, resolveCatalogResponse, update, updateResponse);
new VcloudHttpRequestPrimer() assertEquals(api.getCatalogApi().update(catalogUrn, updateCatalog()), updateCatalog());
.apiCommand("PUT", "/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")
.xmlFilePayload("/catalog/admin/updateCatalogSource.xml", VCloudDirectorMediaType.ADMIN_CATALOG)
.acceptMedia(VCloudDirectorMediaType.ADMIN_CATALOG)
.httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/catalog/admin/updateCatalog.xml", VCloudDirectorMediaType.ADMIN_CATALOG)
.httpResponseBuilder().build());
AdminCatalog expected = modifyCatalog();
assertEquals(api.getCatalogApi().updateCatalog(catalogRef.getHref(), expected), expected);
} }
@Test HttpRequest getOwner = HttpRequest.builder()
public void testGetOwner() { .method("GET")
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, .endpoint(adminCatalogHref + "/owner")
new VcloudHttpRequestPrimer() .addHeader("Accept", "*/*")
.apiCommand("GET", "/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/owner") .addHeader("x-vcloud-authorization", token)
.acceptAnyMedia() .addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.httpRequestBuilder().build(), .build();
new VcloudHttpResponsePrimer()
.xmlFilePayload("/catalog/admin/owner.xml", VCloudDirectorMediaType.OWNER)
.httpResponseBuilder().build());
Owner expected = owner().toBuilder() HttpResponse getOwnerResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/admin/owner.xml", OWNER + ";version=1.5"))
.build();
Owner expectedGetOwner = owner().toBuilder()
.link(Link.builder() .link(Link.builder()
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4"))
.type("application/vnd.vmware.vcloud.catalog+xml") .type("application/vnd.vmware.vcloud.catalog+xml")
@ -145,21 +208,32 @@ public class AdminCatalogApiExpectTest extends VCloudDirectorAdminApiExpectTest
.build()) .build())
.build(); .build();
assertEquals(api.getCatalogApi().getOwner(catalogRef.getHref()), expected); @Test
public void testGetCatalogOwnerHref() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, getOwner, getOwnerResponse);
assertEquals(api.getCatalogApi().getOwner(adminCatalogHref), expectedGetOwner);
} }
@Test @Test
public void testSetOwner() { public void testGetCatalogOwnerUrn() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, resolveCatalog, resolveCatalogResponse, getOwner, getOwnerResponse);
new VcloudHttpRequestPrimer() assertEquals(api.getCatalogApi().getOwner(catalogUrn), expectedGetOwner);
.apiCommand("PUT", "/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/owner") }
.xmlFilePayload("/catalog/admin/updateOwnerSource.xml", VCloudDirectorMediaType.OWNER)
.acceptAnyMedia()
.httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.httpResponseBuilder().statusCode(204).build());
Owner newOwner = Owner.builder() HttpRequest setOwner = HttpRequest.builder()
.method("PUT")
.endpoint(adminCatalogHref + "/owner")
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.payload(payloadFromResourceWithContentType("/catalog/admin/updateOwnerSource.xml", OWNER + ";version=1.5"))
.build();
HttpResponse setOwnerResponse = HttpResponse.builder()
.statusCode(204)
.build();
Owner ownerToSet = Owner.builder()
.type("application/vnd.vmware.vcloud.owner+xml") .type("application/vnd.vmware.vcloud.owner+xml")
.user(Reference.builder() .user(Reference.builder()
.type("application/vnd.vmware.admin.user+xml") .type("application/vnd.vmware.admin.user+xml")
@ -168,48 +242,80 @@ public class AdminCatalogApiExpectTest extends VCloudDirectorAdminApiExpectTest
.build()) .build())
.build(); .build();
api.getCatalogApi().setOwner(catalogRef.getHref(), newOwner); @Test
public void testSetCatalogOwnerHref() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, setOwner, setOwnerResponse);
api.getCatalogApi().setOwner(adminCatalogHref, ownerToSet);
} }
@Test @Test
public void testPublishCatalog() { public void testSetCatalogOwnerUrn() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, resolveCatalog, resolveCatalogResponse, setOwner, setOwnerResponse);
new VcloudHttpRequestPrimer() api.getCatalogApi().setOwner(catalogUrn, ownerToSet);
.apiCommand("POST", "/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/action/publish") }
.xmlFilePayload("/catalog/admin/publishCatalogParams.xml", VCloudDirectorMediaType.PUBLISH_CATALOG_PARAMS)
.acceptAnyMedia()
.httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.httpResponseBuilder().statusCode(204).build());
PublishCatalogParams params = PublishCatalogParams.builder() HttpRequest publishCatalog = HttpRequest.builder()
.isPublished(true) .method("POST")
.endpoint(adminCatalogHref + "/action/publish")
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.payload(payloadFromResourceWithContentType("/catalog/admin/publishCatalogParams.xml", PUBLISH_CATALOG_PARAMS + ";version=1.5"))
.build(); .build();
api.getCatalogApi().publishCatalog(catalogRef.getHref(), params); HttpResponse publishCatalogResponse = HttpResponse.builder()
.statusCode(204)
.build();
@Test
public void testPublishCatalogHref() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, publishCatalog,
publishCatalogResponse);
api.getCatalogApi().publish(adminCatalogHref, PublishCatalogParams.builder().isPublished(true).build());
} }
@Test @Test
public void testDeleteCatalog() { public void testPublishCatalogUrn() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, resolveCatalog,
new VcloudHttpRequestPrimer() resolveCatalogResponse, publishCatalog, publishCatalogResponse);
.apiCommand("DELETE", "/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4") api.getCatalogApi().publish(catalogUrn, PublishCatalogParams.builder().isPublished(true).build());
.acceptAnyMedia()
.httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.httpResponseBuilder().statusCode(204).build());
api.getCatalogApi().deleteCatalog(catalogRef.getHref());
} }
public static final AdminCatalog createCatalogSource() {
HttpRequest deleteCatalog = HttpRequest.builder()
.method("DELETE")
.endpoint(adminCatalogHref)
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.build();
HttpResponse deleteCatalogResponse = HttpResponse.builder()
.statusCode(204)
.build();
@Test
public void testDeleteCatalogHref() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, deleteCatalog,
deleteCatalogResponse);
api.getCatalogApi().delete(adminCatalogHref);
}
@Test
public void testDeleteCatalogUrn() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, resolveCatalog,
resolveCatalogResponse, deleteCatalog, deleteCatalogResponse);
api.getCatalogApi().delete(catalogUrn);
}
public static final AdminCatalog createCatalogInOrgSource() {
return AdminCatalog.builder() return AdminCatalog.builder()
.name("Test Catalog") .name("Test Catalog")
.description("created by testCreateCatalog()") .description("created by testCreateCatalog()")
.build(); .build();
} }
public static final AdminCatalog createCatalog() { public static final AdminCatalog createCatalogInOrg() {
return AdminCatalog.builder() return AdminCatalog.builder()
.name("Test Catalog") .name("Test Catalog")
.id("urn:vcloud:catalog:c56d9159-7838-446f-bb35-9ee12dfbbef3") .id("urn:vcloud:catalog:c56d9159-7838-446f-bb35-9ee12dfbbef3")
@ -364,7 +470,7 @@ public class AdminCatalogApiExpectTest extends VCloudDirectorAdminApiExpectTest
.build(); .build();
} }
public static final AdminCatalog modifyCatalog() { public static final AdminCatalog updateCatalog() {
return catalog().toBuilder() return catalog().toBuilder()
.name("new QunyingTestCatalog") .name("new QunyingTestCatalog")
.description("new Testing") .description("new Testing")

View File

@ -27,16 +27,20 @@ import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull; import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue; import static org.testng.Assert.assertTrue;
import java.net.URI;
import java.util.Collections; import java.util.Collections;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.AdminCatalog; import org.jclouds.vcloud.director.v1_5.domain.AdminCatalog;
import org.jclouds.vcloud.director.v1_5.domain.Checks; import org.jclouds.vcloud.director.v1_5.domain.Checks;
import org.jclouds.vcloud.director.v1_5.domain.Link; import org.jclouds.vcloud.director.v1_5.domain.Link;
import org.jclouds.vcloud.director.v1_5.domain.Owner; import org.jclouds.vcloud.director.v1_5.domain.Owner;
import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.User; import org.jclouds.vcloud.director.v1_5.domain.User;
import org.jclouds.vcloud.director.v1_5.domain.org.Org;
import org.jclouds.vcloud.director.v1_5.domain.params.PublishCatalogParams; import org.jclouds.vcloud.director.v1_5.domain.params.PublishCatalogParams;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorApiLiveTest; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorApiLiveTest;
import org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates;
import org.testng.annotations.AfterClass; import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -63,7 +67,7 @@ public class AdminCatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
* Shared state between dependant tests. * Shared state between dependant tests.
*/ */
private Reference orgRef; private Org org;
private AdminCatalog catalog; private AdminCatalog catalog;
private Owner owner; private Owner owner;
@ -71,14 +75,14 @@ public class AdminCatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@BeforeClass(alwaysRun = true) @BeforeClass(alwaysRun = true)
protected void setupRequiredApis() { protected void setupRequiredApis() {
catalogApi = adminContext.getApi().getCatalogApi(); catalogApi = adminContext.getApi().getCatalogApi();
orgRef = Iterables.getFirst(context.getApi().getOrgApi().getOrgList(), null).toAdminReference(endpoint); org = context.getApi().getOrgApi().getOrg(Iterables.get(context.getApi().getOrgApi().getOrgList(), 0).getHref());
} }
@AfterClass(alwaysRun = true) @AfterClass(alwaysRun = true)
protected void tidyUp() { protected void tidyUp() {
if (catalog != null) { if (catalog != null) {
try { try {
catalogApi.deleteCatalog(catalog.getHref()); catalogApi.delete(catalog.getId());
} catch (Exception e) { } catch (Exception e) {
logger.warn(e, "Error deleting admin catalog '%s'", catalog.getName()); logger.warn(e, "Error deleting admin catalog '%s'", catalog.getName());
} }
@ -87,11 +91,9 @@ public class AdminCatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "POST /admin/org/{id}/catalogs") @Test(description = "POST /admin/org/{id}/catalogs")
public void testCreateCatalog() { public void testCreateCatalog() {
AdminCatalog newCatalog = AdminCatalog.builder() AdminCatalog newCatalog = AdminCatalog.builder().name(name("Test Catalog "))
.name(name("Test Catalog ")) .description("created by testCreateCatalog()").build();
.description("created by testCreateCatalog()") catalog = catalogApi.createCatalogInOrg(newCatalog, org.getId());
.build();
catalog = catalogApi.createCatalog(orgRef.getHref(), newCatalog);
Checks.checkAdminCatalog(catalog); Checks.checkAdminCatalog(catalog);
@ -100,39 +102,40 @@ public class AdminCatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "GET /admin/catalog/{id}", dependsOnMethods = { "testCreateCatalog" }) @Test(description = "GET /admin/catalog/{id}", dependsOnMethods = { "testCreateCatalog" })
public void testGetCatalog() { public void testGetCatalog() {
catalog = catalogApi.getCatalog(catalog.getHref()); catalog = catalogApi.get(catalog.getId());
Checks.checkAdminCatalog(catalog); Checks.checkAdminCatalog(catalog);
} }
@Test(description = "GET /admin/catalog/{id}/owner", dependsOnMethods = { "testGetCatalog" }) @Test(description = "GET /admin/catalog/{id}/owner", dependsOnMethods = { "testGetCatalog" })
public void testGetCatalogOwner() { public void testGetCatalogOwner() {
owner = catalogApi.getOwner(catalog.getHref()); owner = catalogApi.getOwner(catalog.getId());
Checks.checkOwner(owner); Checks.checkOwner(owner);
} }
@Test(description = "PUT /admin/catalog/{id}/owner", dependsOnMethods = { "testGetCatalog" }) @Test(description = "PUT /admin/catalog/{id}/owner", dependsOnMethods = { "testGetCatalog" })
public void updateCatalogOwner() { public void updateCatalogOwner() {
URI adminOrgHref = Iterables.find(context.getApi().resolveEntity(org.getId()).getLinks(),
LinkPredicates.typeEquals(VCloudDirectorMediaType.ADMIN_ORG)).getHref();
User newOwnerUser = randomTestUser("testUpdateCatalogOwner"); User newOwnerUser = randomTestUser("testUpdateCatalogOwner");
newOwnerUser = adminContext.getApi().getUserApi().createUser(orgRef.getHref(), newOwnerUser); newOwnerUser = adminContext.getApi().getUserApi().createUser(adminOrgHref, newOwnerUser);
assertNotNull(newOwnerUser, "failed to create temp user to test updateCatalogOwner"); assertNotNull(newOwnerUser, "failed to create temp user to test updateCatalogOwner");
Owner oldOwner = owner; Owner oldOwner = owner;
Owner newOwner = Owner.builder() Owner newOwner = Owner.builder().type("application/vnd.vmware.vcloud.owner+xml")
.type("application/vnd.vmware.vcloud.owner+xml") .user(Reference.builder().fromEntity(newOwnerUser).build()).build();
.user(Reference.builder().fromEntity(newOwnerUser).build())
.build();
try { try {
catalogApi.setOwner(catalog.getHref(), newOwner); catalogApi.setOwner(catalog.getId(), newOwner);
owner = catalogApi.getOwner(catalog.getHref()); owner = catalogApi.getOwner(catalog.getId());
Checks.checkOwner(owner); Checks.checkOwner(owner);
assertTrue(equal(owner.toBuilder().links(Collections.<Link>emptySet()).build(), assertTrue(
equal(owner.toBuilder().links(Collections.<Link> emptySet()).build(),
newOwner.toBuilder().user(newOwner.getUser().toBuilder().id(null).build()).build()), newOwner.toBuilder().user(newOwner.getUser().toBuilder().id(null).build()).build()),
String.format(OBJ_FIELD_UPDATABLE, CATALOG, "owner")); String.format(OBJ_FIELD_UPDATABLE, CATALOG, "owner"));
} finally { } finally {
catalogApi.setOwner(catalog.getHref(), oldOwner); catalogApi.setOwner(catalog.getId(), oldOwner);
owner = catalogApi.getOwner(catalog.getHref()); owner = catalogApi.getOwner(catalog.getId());
adminContext.getApi().getUserApi().deleteUser(newOwnerUser.getHref()); adminContext.getApi().getUserApi().deleteUser(newOwnerUser.getHref());
} }
} }
@ -140,72 +143,66 @@ public class AdminCatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "PUT /admin/catalog/{id}", dependsOnMethods = { "testGetCatalogOwner" }) @Test(description = "PUT /admin/catalog/{id}", dependsOnMethods = { "testGetCatalogOwner" })
public void testUpdateCatalog() { public void testUpdateCatalog() {
String oldName = catalog.getName(); String oldName = catalog.getName();
String newName = "new "+oldName; String newName = "new " + oldName;
String oldDescription = catalog.getDescription(); String oldDescription = catalog.getDescription();
String newDescription = "new "+oldDescription; String newDescription = "new " + oldDescription;
// TODO: can we update/manage catalogItems directly like this? or does it just do a merge (like metadata) // TODO: can we update/manage catalogItems directly like this? or does it just do a merge
// CatalogItems oldCatalogItems = catalog.getCatalogItems(); // (like metadata)
// CatalogItems newCatalogItems = CatalogItems.builder().build(); // CatalogItems oldCatalogItems = catalog.getCatalogItems();
// CatalogItems newCatalogItems = CatalogItems.builder().build();
try { try {
catalog = catalog.toBuilder() catalog = catalog.toBuilder().name(newName).description(newDescription)
.name(newName) // .catalogItems(newCatalogItems)
.description(newDescription)
// .catalogItems(newCatalogItems)
.build(); .build();
catalog = catalogApi.updateCatalog(catalog.getHref(), catalog); catalog = catalogApi.update(catalog.getId(), catalog);
assertTrue(equal(catalog.getName(), newName), String.format(OBJ_FIELD_UPDATABLE, CATALOG, "name")); assertTrue(equal(catalog.getName(), newName), String.format(OBJ_FIELD_UPDATABLE, CATALOG, "name"));
assertTrue(equal(catalog.getDescription(), newDescription), assertTrue(equal(catalog.getDescription(), newDescription),
String.format(OBJ_FIELD_UPDATABLE, CATALOG, "description")); String.format(OBJ_FIELD_UPDATABLE, CATALOG, "description"));
// assertTrue(equal(catalog.getCatalogItems(), newCatalogItems), String.format(OBJ_FIELD_UPDATABLE, CATALOG, "catalogItems")); // assertTrue(equal(catalog.getCatalogItems(), newCatalogItems),
// String.format(OBJ_FIELD_UPDATABLE, CATALOG, "catalogItems"));
//TODO negative tests? // TODO negative tests?
Checks.checkAdminCatalog(catalog); Checks.checkAdminCatalog(catalog);
} finally { } finally {
catalog = catalog.toBuilder() catalog = catalog.toBuilder().name(oldName).description(oldDescription)
.name(oldName) // .catalogItems(oldCatalogItems)
.description(oldDescription)
// .catalogItems(oldCatalogItems)
.build(); .build();
catalog = catalogApi.updateCatalog(catalog.getHref(), catalog); catalog = catalogApi.update(catalog.getId(), catalog);
} }
} }
// FIXME fails with a 403 // FIXME fails with a 403
@Test(description = "POST /admin/catalog/{id}/action/publish", dependsOnMethods = { "testUpdateCatalog" } ) @Test(description = "POST /admin/catalog/{id}/action/publish", dependsOnMethods = { "testUpdateCatalog" })
public void testPublishCatalog() { public void testPublishCatalog() {
assertNotNull(catalog, String.format(NOT_NULL_OBJ_FMT, "Catalog")); assertNotNull(catalog, String.format(NOT_NULL_OBJ_FMT, "Catalog"));
assertTrue(!catalog.isPublished(), String.format(OBJ_FIELD_EQ, assertTrue(!catalog.isPublished(),
CATALOG, "isPublished", false, catalog.isPublished())); String.format(OBJ_FIELD_EQ, CATALOG, "isPublished", false, catalog.isPublished()));
PublishCatalogParams params = PublishCatalogParams.builder() PublishCatalogParams params = PublishCatalogParams.builder().isPublished(true).build();
.isPublished(true)
.build();
catalogApi.publishCatalog(catalog.getHref(), params); catalogApi.publish(catalog.getId(), params);
catalog = catalogApi.getCatalog(catalog.getHref()); catalog = catalogApi.get(catalog.getId());
assertTrue(catalog.isPublished(), String.format(OBJ_FIELD_EQ, assertTrue(catalog.isPublished(),
CATALOG, "isPublished", true, catalog.isPublished())); String.format(OBJ_FIELD_EQ, CATALOG, "isPublished", true, catalog.isPublished()));
} }
@Test(description = "DELETE /admin/catalog/{id}", dependsOnMethods = { "testCreateCatalog" } ) @Test(description = "DELETE /admin/catalog/{id}", dependsOnMethods = { "testCreateCatalog" })
public void testDeleteCatalog() { public void testDeleteCatalog() {
// assertEquals(catalog.getCatalogItems().getCatalogItems().size(), 0, // assertEquals(catalog.getCatalogItems().getCatalogItems().size(), 0,
// String.format(OBJ_FIELD_EMPTY_TO_DELETE, "Catalog", "CatalogItems", // String.format(OBJ_FIELD_EMPTY_TO_DELETE, "Catalog", "CatalogItems",
// catalog.getCatalogItems().getCatalogItems().toString())); // catalog.getCatalogItems().getCatalogItems().toString()));
AdminCatalog deleteCatalog = AdminCatalog.builder() AdminCatalog deleteCatalog = AdminCatalog.builder().name(name("Test Catalog "))
.name(name("Test Catalog ")) .description("created by testCreateCatalog()").build();
.description("created by testCreateCatalog()") deleteCatalog = catalogApi.createCatalogInOrg(deleteCatalog, org.getId());
.build(); catalogApi.delete(deleteCatalog.getId());
deleteCatalog = catalogApi.createCatalog(orgRef.getHref(), deleteCatalog);
catalogApi.deleteCatalog(deleteCatalog.getHref());
deleteCatalog = catalogApi.getCatalog(deleteCatalog.getHref()); deleteCatalog = catalogApi.get(deleteCatalog.getId());
assertNull(deleteCatalog, String.format(OBJ_DEL, CATALOG, deleteCatalog != null ? deleteCatalog.toString() : "")); assertNull(deleteCatalog, String.format(OBJ_DEL, CATALOG, deleteCatalog != null ? deleteCatalog.toString() : ""));
} }
} }

View File

@ -74,7 +74,7 @@ public class AdminVdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
public void cleanUp() throws Exception { public void cleanUp() throws Exception {
if (metadataKey != null) { if (metadataKey != null) {
try { try {
Task task = metadataApi.deleteMetadataEntry(adminVdcUri, metadataKey); Task task = metadataApi.deleteEntry(adminVdcUri, metadataKey);
taskDoneEventually(task); taskDoneEventually(task);
} catch (VCloudDirectorException e) { } catch (VCloudDirectorException e) {
logger.warn(e, "Error deleting metadata-value (perhaps it doesn't exist?); continuing..."); logger.warn(e, "Error deleting metadata-value (perhaps it doesn't exist?); continuing...");
@ -169,7 +169,7 @@ public class AdminVdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "GET /admin/vdc/{id}/metadata") @Test(description = "GET /admin/vdc/{id}/metadata")
public void testGetMetadata() throws Exception { public void testGetMetadata() throws Exception {
Metadata metadata = metadataApi.getMetadata(adminVdcUri); Metadata metadata = metadataApi.get(adminVdcUri);
Checks.checkMetadata(metadata); Checks.checkMetadata(metadata);
} }
@ -183,10 +183,10 @@ public class AdminVdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
.entry(MetadataEntry.builder().entry(metadataKey, metadataValue).build()) .entry(MetadataEntry.builder().entry(metadataKey, metadataValue).build())
.build(); .build();
Task task = metadataApi.mergeMetadata(adminVdcUri, metadata); Task task = metadataApi.merge(adminVdcUri, metadata);
assertTaskSucceeds(task); assertTaskSucceeds(task);
MetadataValue modified = metadataApi.getMetadataValue(adminVdcUri, metadataKey); MetadataValue modified = metadataApi.getValue(adminVdcUri, metadataKey);
Checks.checkMetadataValueFor("AdminVdc", modified, metadataValue); Checks.checkMetadataValueFor("AdminVdc", modified, metadataValue);
Checks.checkMetadata(metadata); Checks.checkMetadata(metadata);
} }
@ -194,7 +194,7 @@ public class AdminVdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
// TODO insufficient permissions to test // TODO insufficient permissions to test
@Test(description = "GET /admin/vdc/{id}/metadata/{key}", dependsOnMethods = { "testSetMetadata" }, enabled=false) @Test(description = "GET /admin/vdc/{id}/metadata/{key}", dependsOnMethods = { "testSetMetadata" }, enabled=false)
public void testGetMetadataValue() throws Exception { public void testGetMetadataValue() throws Exception {
MetadataValue retrievedMetadataValue = metadataApi.getMetadataValue(adminVdcUri, metadataKey); MetadataValue retrievedMetadataValue = metadataApi.getValue(adminVdcUri, metadataKey);
Checks.checkMetadataValueFor("AdminVdc", retrievedMetadataValue, metadataValue); Checks.checkMetadataValueFor("AdminVdc", retrievedMetadataValue, metadataValue);
} }
@ -205,10 +205,10 @@ public class AdminVdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
metadataValue = name("value-"); metadataValue = name("value-");
MetadataValue newV = MetadataValue.builder().value(metadataValue).build(); MetadataValue newV = MetadataValue.builder().value(metadataValue).build();
Task task = metadataApi.setMetadata(adminVdcUri, metadataKey, newV); Task task = metadataApi.putEntry(adminVdcUri, metadataKey, newV);
assertTaskSucceeds(task); assertTaskSucceeds(task);
MetadataValue retrievedMetadataValue = metadataApi.getMetadataValue(adminVdcUri, metadataKey); MetadataValue retrievedMetadataValue = metadataApi.getValue(adminVdcUri, metadataKey);
Checks.checkMetadataValueFor("AdminVdc", retrievedMetadataValue, metadataValue); Checks.checkMetadataValueFor("AdminVdc", retrievedMetadataValue, metadataValue);
} }
@ -217,11 +217,11 @@ public class AdminVdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
public void testDeleteMetadataValue() throws Exception { public void testDeleteMetadataValue() throws Exception {
// TODO Remove dependency on other tests; make cleanUp delete a list of metadata entries? // TODO Remove dependency on other tests; make cleanUp delete a list of metadata entries?
Task task = metadataApi.deleteMetadataEntry(adminVdcUri, metadataKey); Task task = metadataApi.deleteEntry(adminVdcUri, metadataKey);
assertTaskSucceeds(task); assertTaskSucceeds(task);
try { try {
metadataApi.getMetadataValue(adminVdcUri, metadataKey); metadataApi.getValue(adminVdcUri, metadataKey);
fail("Retrieval of metadata value "+metadataKey+" should have fail after deletion"); fail("Retrieval of metadata value "+metadataKey+" should have fail after deletion");
} catch (VCloudDirectorException e) { } catch (VCloudDirectorException e) {
// success; should not be accessible // success; should not be accessible

View File

@ -96,6 +96,6 @@ public class GroupApiExpectTest extends VCloudDirectorAdminApiExpectTest {
new VcloudHttpResponsePrimer() new VcloudHttpResponsePrimer()
.httpResponseBuilder().statusCode(204).build()); .httpResponseBuilder().statusCode(204).build());
api.getCatalogApi().deleteCatalog(groupRef.getHref()); api.getGroupApi().deleteGroup(groupRef.getHref());
} }
} }

View File

@ -122,8 +122,7 @@ public abstract class BaseVCloudDirectorApiLiveTest extends BaseContextLiveTest<
protected Session adminSession; protected Session adminSession;
protected Session session; protected Session session;
protected String catalogId; protected String catalogUrn;
protected URI catalogURI;
protected URI vAppTemplateURI; protected URI vAppTemplateURI;
protected URI mediaURI; protected URI mediaURI;
protected URI networkURI; protected URI networkURI;
@ -233,12 +232,8 @@ public abstract class BaseVCloudDirectorApiLiveTest extends BaseContextLiveTest<
.build(); .build();
} }
// TODO change properties to URI, not id
protected void initTestParametersFromPropertiesOrLazyDiscover() { protected void initTestParametersFromPropertiesOrLazyDiscover() {
catalogId = Strings.emptyToNull(System.getProperty("test." + provider + ".catalog-id")); catalogUrn = Strings.emptyToNull(System.getProperty("test." + provider + ".catalog-id"));
if (catalogId != null) {
catalogURI = URI.create(endpoint + "/catalog/" + catalogId);
}
String vAppTemplateId = Strings.emptyToNull(System.getProperty("test." + provider + ".vapptemplate-id")); String vAppTemplateId = Strings.emptyToNull(System.getProperty("test." + provider + ".vapptemplate-id"));
if (vAppTemplateId != null) if (vAppTemplateId != null)
@ -274,10 +269,10 @@ public abstract class BaseVCloudDirectorApiLiveTest extends BaseContextLiveTest<
ReferencePredicates.<Link> typeEquals(VCloudDirectorMediaType.ORG_NETWORK)).getHref(); ReferencePredicates.<Link> typeEquals(VCloudDirectorMediaType.ORG_NETWORK)).getHref();
// FIXME the URI should be opaque // FIXME the URI should be opaque
if (Strings.isNullOrEmpty(catalogId)) { if (Strings.isNullOrEmpty(catalogUrn)) {
String uri = Iterables.find(thisOrg.getLinks(), String uri = Iterables.find(thisOrg.getLinks(),
ReferencePredicates.<Link> typeEquals(VCloudDirectorMediaType.CATALOG)).getHref().toASCIIString(); ReferencePredicates.<Link> typeEquals(VCloudDirectorMediaType.CATALOG)).getHref().toASCIIString();
catalogId = Iterables.getLast(Splitter.on('/').split(uri)); catalogUrn = Iterables.getLast(Splitter.on('/').split(uri));
} }
} }
} }

View File

@ -33,11 +33,13 @@ import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeGroups;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.LinkedListMultimap; import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.net.HttpHeaders; import com.google.common.net.HttpHeaders;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.jamesmurty.utils.XMLBuilder;
/** /**
* Base class for writing vCloud Director REST api expect tests. * Base class for writing vCloud Director REST api expect tests.
@ -187,6 +189,7 @@ public abstract class BaseVCloudDirectorExpectTest<T> extends BaseRestApiExpectT
* *
* @author danikov * @author danikov
*/ */
@Deprecated
public class VcloudHttpRequestPrimer { public class VcloudHttpRequestPrimer {
private Multimap<String, String> headers = LinkedListMultimap.create(); private Multimap<String, String> headers = LinkedListMultimap.create();
private HttpRequest.Builder<?> builder = HttpRequest.builder(); private HttpRequest.Builder<?> builder = HttpRequest.builder();
@ -230,6 +233,7 @@ public abstract class BaseVCloudDirectorExpectTest<T> extends BaseRestApiExpectT
} }
} }
@Deprecated
protected class VcloudHttpResponsePrimer { protected class VcloudHttpResponsePrimer {
private HttpResponse.Builder<?> builder = HttpResponse.builder(); private HttpResponse.Builder<?> builder = HttpResponse.builder();
@ -252,4 +256,21 @@ public abstract class BaseVCloudDirectorExpectTest<T> extends BaseRestApiExpectT
public URI toAdminUri(URI uri) { public URI toAdminUri(URI uri) {
return Reference.builder().href(uri).build().toAdminReference(endpoint).getHref(); return Reference.builder().href(uri).build().toAdminReference(endpoint).getHref();
} }
protected static XMLBuilder createXMLBuilder(String root){
try {
return XMLBuilder.create(root);
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
protected static String asString(XMLBuilder in){
try {
return in.asString();
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
} }