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.credential>FIXME_PASSWORD</test.vcloud-director.credential>
<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.media-id></test.vcloud-director.media-id>
<test.vcloud-director.vapptemplate-id></test.vcloud-director.vapptemplate-id>
@ -57,6 +58,11 @@
</properties>
<dependencies>
<dependency>
<groupId>com.jamesmurty.utils</groupId>
<artifactId>java-xmlbuilder</artifactId>
<version>0.4</version>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-compute</artifactId>

View File

@ -40,6 +40,9 @@ public class VCloudDirectorException extends RuntimeException {
private final Error error;
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) {
super(message(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.internal.RestContextImpl;
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.VCloudDirectorAdminAsyncApi;
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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.UserAsyncApi;
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.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.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.VCloudDirectorAsyncApi;
import com.google.common.base.Function;
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
@Singleton
protected Function<Credentials, SessionWithToken> makeSureFilterRetriesOnTimeout(

View File

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

View File

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

View File

@ -25,76 +25,94 @@ import org.jclouds.concurrent.Timeout;
import org.jclouds.rest.annotations.Delegate;
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.Metadata;
/**
* Provides synchronous access to {@link Catalog} objects.
*
* @see CatalogAsyncApi
* @author grkvlt@apache.org
* @author grkvlt@apache.org, Adrian Cole
*/
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public interface CatalogApi {
/**
* Retrieves a catalog.
*
*
* <pre>
* GET /catalog/{id}
* </pre>
*
* @param catalogUri the reference for the catalog
*
* @param catalogUri
* the reference for the catalog
* @return a catalog
*/
Catalog getCatalog(URI catalogUri);
Catalog get(String catalogUrn);
Catalog get(URI catalogHref);
/**
* Creates a catalog item in a catalog.
*
*
* <pre>
* POST /catalog/{id}/catalogItems
* </pre>
*
* @param catalogUri the URI of the catalog
* @param item the catalog item to create
*
* @param catalogUri
* the URI of the catalog
* @param item
* the catalog item to create
* @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.
*
*
* <pre>
* GET /catalogItem/{id}
* </pre>
*
* @param catalogItemRef the reference for the catalog item
* @param catalogItemRef
* the reference for the catalog item
* @return the catalog item
*/
CatalogItem getCatalogItem(URI catalogItemRef);
CatalogItem getItem(String catalogItemUrn);
CatalogItem getItem(URI catalogItemHref);
/**
* Modifies a catalog item.
*
*
* <pre>
* PUT /catalogItem/{id}
* </pre>
*
* @param catalogItemRef the reference for the catalog item
* @param catalogItem the catalog item
*
* @param catalogItemRef
* the reference for the catalog item
* @param catalogItem
* the 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.
*
*
* <pre>
* DELETE /catalogItem/{id}
* </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
@ -106,6 +124,6 @@ public interface CatalogApi {
* @return synchronous access to {@link Metadata.Writeable} features for CatalogItems
*/
@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.domain.Catalog;
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.functions.href.CatalogItemURNToHref;
import org.jclouds.vcloud.director.v1_5.functions.href.CatalogURNToHref;
import com.google.common.util.concurrent.ListenableFuture;
/**
* @see CatalogApi
* @author grkvlt@apache.org
* @author grkvlt@apache.org, Adrian Cole
*/
@RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class)
public interface CatalogAsyncApi {
/**
* Retrieves a catalog.
* @see CatalogApi#get(String)
*/
@GET
@Consumes
@JAXBResponseParser
@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
@Path("/catalogItems")
@Consumes(VCloudDirectorMediaType.CATALOG_ITEM)
@Produces(VCloudDirectorMediaType.CATALOG_ITEM)
@JAXBResponseParser
ListenableFuture<CatalogItem> addCatalogItem(@EndpointParam URI catalogUri,
@BinderParam(BindToXMLPayload.class) CatalogItem catalogItem);
ListenableFuture<CatalogItem> addItem(@EndpointParam(parser = CatalogURNToHref.class) String catalogUrn,
@BinderParam(BindToXMLPayload.class) CatalogItem catalogItem);
/**
* Retrieves a catalog item.
* @see CatalogApi#getItem(String)
*/
@GET
@Consumes
@JAXBResponseParser
@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
@Consumes(VCloudDirectorMediaType.CATALOG_ITEM)
@Produces(VCloudDirectorMediaType.CATALOG_ITEM)
@JAXBResponseParser
ListenableFuture<CatalogItem> updateCatalogItem(@EndpointParam URI catalogItemUri,
@BinderParam(BindToXMLPayload.class) CatalogItem catalogItem);
ListenableFuture<CatalogItem> updateItem(@EndpointParam(parser = CatalogItemURNToHref.class) String catalogItemUrn,
@BinderParam(BindToXMLPayload.class) CatalogItem catalogItem);
/**
* Deletes a catalog item.
* @see CatalogApi#deleteItem(String)
*/
@DELETE
@Consumes
@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
@ -104,8 +154,8 @@ public interface CatalogAsyncApi {
MetadataAsyncApi.Readable getMetadataApi();
/**
* @return asynchronous access to {@link Metadata.Writeable} features for CatalogItems
* @see CatalogApi#getItemMetadataApi
*/
@Delegate
MetadataAsyncApi.Writeable getCatalogItemMetadataApi();
MetadataAsyncApi.Writeable getItemMetadataApi();
}

View File

@ -33,51 +33,51 @@ import org.jclouds.vcloud.director.v1_5.domain.Task;
* @author danikov
*/
public interface MetadataApi {
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public static interface Readable extends MetadataApi {
/**
* Retrieves an list of metadata
*
* @return a list of metadata
*/
Metadata getMetadata(URI uri);
Metadata get(URI uri);
/**
* Retrieves a metadata value
*
* @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)
public static interface Writeable extends Readable {
/**
* Merges the metadata for a media with the information provided.
*
* @return a task. This operation is asynchronous and the user should monitor the returned
* task status in order to check when it is completed.
* @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 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.
* Note: this will replace any existing metadata information
* Sets the metadata for the particular key for the media to the value provided. Note: this
* will replace any existing metadata information
*
* @return a task. This operation is asynchronous and the user should monitor the returned
* task status in order to check when it is completed.
* @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 setMetadata(URI uri, String key, MetadataValue metadataValue);
Task putEntry(URI uri, String key, MetadataValue metadataValue);
/**
* Deletes a metadata entry.
*
* @return a task. This operation is asynchronous and the user should monitor the returned
* task status in order to check when it is completed.
* @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 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
* @author danikov
*/
//TODO: take out the endpoint params and supply them in the Delegate calls.
public interface MetadataAsyncApi {
@RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class)
public static interface Readable extends MetadataAsyncApi {
/**
* @see MetadataApi.Readable#getMetadata(URISupplier)
* @see MetadataApi.Readable#get(URI)
*/
@GET
@Path("/metadata")
@Consumes
@JAXBResponseParser
@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
@Path("/metadata/{key}")
@Consumes
@JAXBResponseParser
@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)
public static interface Writeable extends Readable {
/**
* @see MetadataApi.Writable#mergeMetadata(URI, Metadata))
* @see MetadataApi.Writable#merge(URI, Metadata))
*/
@POST
@Path("/metadata")
@Consumes(VCloudDirectorMediaType.TASK)
@Produces(VCloudDirectorMediaType.METADATA)
@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
@Path("/metadata/{key}")
@Consumes(VCloudDirectorMediaType.TASK)
@Produces(VCloudDirectorMediaType.METADATA_VALUE)
@JAXBResponseParser
ListenableFuture<Task> setMetadata(@EndpointParam URI metaDataUri,
@PathParam("key") String key,
@BinderParam(BindToXMLPayload.class) MetadataValue metadataValue);
// TODO: this is rediculous. get rid of the MetadataValue type, as it is only a string!
ListenableFuture<Task> putEntry(@EndpointParam URI metaDataUri, @PathParam("key") String key,
@BinderParam(BindToXMLPayload.class) MetadataValue metadataValue);
/**
* @see MetadataApi.Writable#deleteMetadataEntry(URISupplier, String))
* @see MetadataApi.Writable#deleteEntry(URI, String))
*/
@DELETE
@Path("/metadata/{key}")
@Consumes(VCloudDirectorMediaType.TASK)
@JAXBResponseParser
ListenableFuture<Task> deleteMetadataEntry(@EndpointParam URI metaDataUri, @PathParam("key") String key);
@DELETE
@Path("/metadata/{key}")
@Consumes(VCloudDirectorMediaType.TASK)
@JAXBResponseParser
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.rest.annotations.Delegate;
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.params.PublishCatalogParams;
import org.jclouds.vcloud.director.v1_5.features.CatalogApi;
@ -33,40 +34,47 @@ import org.jclouds.vcloud.director.v1_5.features.MetadataApi;
* Provides synchronous access to {@link AdminCatalog} objects.
*
* @see AdminCatalogAsyncApi
* @author danikov
* @author danikov, Adrian Cole
*/
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public interface AdminCatalogApi extends CatalogApi {
/**
* Creates a catalog in an organization. The catalog will always be created in unpublished state.
*
*
* <pre>
* POST /admin/org/{id}/catalogs
* </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.
*/
AdminCatalog createCatalog(URI orgRef, AdminCatalog catalog);
AdminCatalog createCatalogInOrg(AdminCatalog catalog, String orgUrn);
AdminCatalog createCatalogInOrg(AdminCatalog catalog, URI adminCatalogHref);
/**
* Retrieves a catalog.
*
*
* <pre>
* GET /admin/catalog/{id}
* </pre>
*
* @param catalogRef the reference for the catalog
*
* @param catalogUrn
* the urn for the catalog
* @return a catalog
*/
@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
* read only value by the server. In order to control publishing settings use the 'publish' action must be used.
* Modifies a catalog. A catalog could be published or unpublished. The IsPublished property is
* treated as a read only value by the server. In order to control publishing settings use the
* 'publish' action must be used.
*
* <pre>
* PUT /admin/catalog/{id}
@ -74,8 +82,10 @@ public interface AdminCatalogApi extends CatalogApi {
*
* @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.
*
@ -83,8 +93,10 @@ public interface AdminCatalogApi extends CatalogApi {
* DELETE /admin/catalog/{id}
* </pre>
*/
void deleteCatalog(URI catalogRef);
void delete(String catalogUrn);
void delete(URI adminCatalogHref);
/**
* Retrieves the owner of a catalog.
*
@ -94,8 +106,10 @@ public interface AdminCatalogApi extends CatalogApi {
*
* @return the owner or null if not found
*/
Owner getOwner(URI catalogRef);
Owner getOwner(String catalogUrn);
Owner getOwner(URI adminCatalogHref);
/**
* Changes owner for catalog.
*
@ -103,15 +117,22 @@ public interface AdminCatalogApi extends CatalogApi {
* PUT /admin/catalog/{id}/owner
* </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);
//TODO: lot of work to pass in a single boolean, would like to polymorphically include something like:
//void publishCatalog(URI catalogRef)
void publish(String catalogUrn, PublishCatalogParams params);
void publish(URI adminCatalogHref, PublishCatalogParams params);
// 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

View File

@ -38,91 +38,165 @@ import org.jclouds.rest.binders.BindToXMLPayload;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
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.Metadata;
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.features.CatalogAsyncApi;
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.functions.href.CatalogURNToAdminHref;
import org.jclouds.vcloud.director.v1_5.functions.href.OrgURNToAdminHref;
import com.google.common.util.concurrent.ListenableFuture;
/**
* @see AdminCatalogApi
* @author danikov
* @author danikov, Adrian Cole
*/
@RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class)
public interface AdminCatalogAsyncApi extends CatalogAsyncApi {
/**
* @see AdminApi#createCatalog(URI, AdminCatalog)
* @see AdminCatalogApi#createCatalogInOrg(AdminCatalog, String)
*/
@POST
@Path("/catalogs")
@Consumes(VCloudDirectorMediaType.ADMIN_CATALOG)
@Produces(VCloudDirectorMediaType.ADMIN_CATALOG)
@JAXBResponseParser
ListenableFuture<AdminCatalog> createCatalog(@EndpointParam URI orgRef,
@BinderParam(BindToXMLPayload.class) AdminCatalog catalog);
ListenableFuture<AdminCatalog> createCatalogInOrg(@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
@GET
@Consumes
@JAXBResponseParser
@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
@Consumes(VCloudDirectorMediaType.ADMIN_CATALOG)
@Produces(VCloudDirectorMediaType.ADMIN_CATALOG)
@JAXBResponseParser
ListenableFuture<AdminCatalog> updateCatalog(@EndpointParam URI catalogRef,
@BinderParam(BindToXMLPayload.class) AdminCatalog catalog);
ListenableFuture<AdminCatalog> update(@EndpointParam(parser = CatalogURNToAdminHref.class) String catalogUrn,
@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
@Consumes
@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
@Path("/owner")
@Consumes
@JAXBResponseParser
@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
@Path("/owner")
@Consumes
@Produces(VCloudDirectorMediaType.OWNER)
@JAXBResponseParser
ListenableFuture<Void> setOwner(@EndpointParam URI catalogRef,
@BinderParam(BindToXMLPayload.class) Owner newOwner);
ListenableFuture<Void> setOwner(@EndpointParam(parser = CatalogURNToAdminHref.class) String catalogUrn,
@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
@Path("/action/publish")
@Consumes
@Produces(VCloudDirectorMediaType.PUBLISH_CATALOG_PARAMS)
@JAXBResponseParser
ListenableFuture<Void> publishCatalog(@EndpointParam URI catalogRef,
@BinderParam(BindToXMLPayload.class) PublishCatalogParams params);
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);
/**
* @return synchronous access to {@link Metadata.Writeable} features

View File

@ -25,9 +25,9 @@ import org.jclouds.concurrent.Timeout;
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
*/
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)

View File

@ -71,7 +71,7 @@ public class AllCatalogItemsInCatalog implements Function<Catalog, Iterable<? ex
@Override
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());

View File

@ -59,7 +59,7 @@ public class AllCatalogsInOrg implements Function<AdminOrg, Iterable<? extends C
new Function<Reference, Future<? extends Catalog>>() {
@Override
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());

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
* under the License.
*/
package org.jclouds.vcloud.director.v1_5.functions;
import java.net.URI;
package org.jclouds.vcloud.director.v1_5.functions.href;
import javax.inject.Inject;
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
public class ReferenceToEndpoint implements Function<Reference, URI> {
@Override
public URI apply(Reference from) {
return from.getHref();
public class OrgURNToHref extends URNToHref {
@Inject
public OrgURNToHref(LoadingCache<String, Entity> resolveEntityCache) {
super(resolveEntityCache);
}
}
@Override
protected String type() {
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")
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 {
VCloudDirectorApi apiWhenSessionsExist = requestSendsResponse(loginRequest, sessionResponse);

View File

@ -18,6 +18,13 @@
*/
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 java.net.URI;
@ -25,7 +32,6 @@ import java.net.URI;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
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.CatalogItem;
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.
*
* @author grkvlt@apache.org
* @author grkvlt@apache.org, Adrian Cole
*/
@Test(groups = { "unit", "user" }, singleThreaded = true, testName = "CatalogApiExpectTest")
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);
HttpRequest get = HttpRequest.builder()
.method("GET")
.endpoint(catalogHref)
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.build();
HttpResponse getResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/catalog.xml", CATALOG + ";version=1.5"))
.build();
@Test
public void testGetCatalog() {
HttpRequest catalogRequest = HttpRequest.builder()
.method("GET")
.endpoint(endpoint + "/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.build();
HttpResponse catalogResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/catalog.xml", VCloudDirectorMediaType.CATALOG + ";version=1.5"))
.build();
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, catalogRequest, catalogResponse);
Catalog expected = catalog();
URI catalogURI = URI.create(endpoint + "/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4");
assertEquals(api.getCatalogApi().getCatalog(catalogURI), expected);
public void testGetCatalogHref() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, get, getResponse);
assertEquals(api.getCatalogApi().get(catalogHref), catalog());
}
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
public void testAddCatalogItem() {
HttpRequest catalogItemRequest = HttpRequest.builder()
public void testGetCatalogUrn() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, resolveCatalog, resolveCatalogResponse, get, getResponse);
assertEquals(api.getCatalogApi().get(catalogUrn), catalog());
}
HttpRequest add = HttpRequest.builder()
.method("POST")
.endpoint(endpoint + "/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/catalogItems")
.endpoint(catalogHref + "/catalogItems")
.addHeader("Accept", "application/vnd.vmware.vcloud.catalogItem+xml")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.payload(payloadFromResourceWithContentType("/catalog/newCatalogItem.xml", VCloudDirectorMediaType.CATALOG_ITEM))
.payload(payloadFromResourceWithContentType("/catalog/newCatalogItem.xml", CATALOG_ITEM))
.build();
HttpResponse catalogItemResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/createdCatalogItem.xml", VCloudDirectorMediaType.CATALOG_ITEM + ";version=1.5"))
HttpResponse addResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/createdCatalogItem.xml", CATALOG_ITEM + ";version=1.5"))
.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")
.description("New Catalog Item")
.entity(ubuntuVappTemplateReference())
.build();
CatalogItem expected = createdCatalogItem();
assertEquals(api.getCatalogApi().addCatalogItem(catalogURI, newItem), expected);
}
@Test
public void testGetCatalogMetadata() {
HttpRequest catalogRequest = HttpRequest.builder()
.method("GET")
.endpoint(endpoint + "/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/metadata")
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build();
HttpResponse catalogResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/catalogMetadata.xml", VCloudDirectorMediaType.METADATA))
.build();
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, catalogRequest, catalogResponse);
URI catalogURI = URI.create(endpoint + "/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4");
Metadata expected = Metadata.builder()
.type("application/vnd.vmware.vcloud.metadata+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/metadata"))
.link(Link.builder()
.rel("up")
.type("application/vnd.vmware.vcloud.catalog+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4"))
.build())
.entries(ImmutableSet.of(metadataEntry()))
.build();
assertEquals(api.getCatalogApi().getMetadataApi().getMetadata(catalogURI), expected);
}
@Test
public void testGetCatalogMetadataEntry() {
HttpRequest catalogRequest = HttpRequest.builder()
.method("GET")
.endpoint(endpoint + "/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/metadata/KEY")
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build();
HttpResponse catalogResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/catalogMetadataValue.xml", VCloudDirectorMediaType.METADATA_VALUE))
.build();
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, catalogRequest, catalogResponse);
URI catalogURI = URI.create(endpoint + "/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4");
MetadataValue expected = metadataValue();
assertEquals(api.getCatalogApi().getMetadataApi().getMetadataValue(catalogURI, "KEY"), expected);
public void testAddCatalogItemHref() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, add, addResponse);
assertEquals(api.getCatalogApi().addItem(catalogHref, newItem), createdCatalogItem());
}
@Test
public void testGetCatalogItem() {
HttpRequest catalogItemRequest = HttpRequest.builder()
public void testAddCatalogItemUrn() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, resolveCatalog, resolveCatalogResponse, add, addResponse);
assertEquals(api.getCatalogApi().addItem(catalogUrn, newItem), createdCatalogItem());
}
HttpRequest getMetadata = HttpRequest.builder()
.method("GET")
.endpoint(endpoint + "/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df")
.endpoint(catalogHref + "/metadata")
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build();
HttpResponse catalogItemResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/catalogItem.xml", VCloudDirectorMediaType.CATALOG_ITEM))
HttpResponse getMetadataResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/catalogMetadata.xml", METADATA))
.build();
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse);
URI catalogItemURI = URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df");
CatalogItem expected = catalogItem();
assertEquals(api.getCatalogApi().getCatalogItem(catalogItemURI), expected);
@Test
public void testGetCatalogMetadataHref() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, getMetadata, getMetadataResponse);
assertEquals(api.getCatalogApi().getMetadataApi().get(catalogHref), metadata());
}
static Metadata metadata() {
return Metadata.builder()
.type("application/vnd.vmware.vcloud.metadata+xml")
.href(URI.create(endpoint + "/catalog/" + catalog + "/metadata"))
.link(Link.builder()
.rel("up")
.type("application/vnd.vmware.vcloud.catalog+xml")
.href(catalogHref)
.build())
.entries(ImmutableSet.of(metadataEntry()))
.build();
}
HttpRequest getMetadataValue = HttpRequest.builder()
.method("GET")
.endpoint(catalogHref + "/metadata/KEY")
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build();
HttpResponse getMetadataValueResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/catalogMetadataValue.xml", METADATA_VALUE))
.build();
@Test
public void testUpdateCatalogItem() {
HttpRequest catalogItemRequest = HttpRequest.builder()
public void testGetCatalogMetadataEntryHref() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, getMetadataValue, getMetadataValueResponse);
assertEquals(api.getCatalogApi().getMetadataApi().getValue(catalogHref, "KEY"), metadataValue());
}
static String item = "a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df";
static URI itemHref = URI.create(endpoint + "/catalogItem/" + item);
static String itemUrn = "urn:vcloud:catalogitem:" + item;
HttpRequest resolveItem = HttpRequest.builder()
.method("GET")
.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("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build();
HttpResponse getItemResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/catalogItem.xml", CATALOG_ITEM))
.build();
@Test
public void testGetCatalogItemHref() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, getItem, getItemResponse);
assertEquals(api.getCatalogApi().getItem(itemHref), catalogItem());
}
@Test
public void testGetCatalogItemUrn() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, resolveItem, resolveItemResponse, getItem, getItemResponse);
assertEquals(api.getCatalogApi().getItem(itemUrn), catalogItem());
}
HttpRequest updateItem = HttpRequest.builder()
.method("PUT")
.endpoint(endpoint + "/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df")
.endpoint(endpoint + "/catalogItem/" + item)
.addHeader("Accept", "application/vnd.vmware.vcloud.catalogItem+xml")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.payload(payloadFromResourceWithContentType("/catalog/updateCatalogItem.xml", VCloudDirectorMediaType.CATALOG_ITEM))
.payload(payloadFromResourceWithContentType("/catalog/updateCatalogItem.xml", CATALOG_ITEM))
.build();
HttpResponse catalogItemResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/updateCatalogItem.xml", VCloudDirectorMediaType.CATALOG_ITEM + ";version=1.5"))
HttpResponse updateItemResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/updateCatalogItem.xml", CATALOG_ITEM + ";version=1.5"))
.build();
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse);
URI catalogItemURI = URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df");
CatalogItem expected = catalogItem();
assertEquals(api.getCatalogApi().updateCatalogItem(catalogItemURI, expected), expected);
@Test
public void testUpdateCatalogItemHref() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, updateItem, updateItemResponse);
assertEquals(api.getCatalogApi().updateItem(itemHref, catalogItem()), catalogItem());
}
@Test
public void testDeleteCatalogItem() {
HttpRequest catalogItemRequest = HttpRequest.builder()
public void testUpdateCatalogItemUrn() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, resolveItem, resolveItemResponse, updateItem, updateItemResponse);
assertEquals(api.getCatalogApi().updateItem(itemUrn, catalogItem()), catalogItem());
}
HttpRequest deleteItem = HttpRequest.builder()
.method("DELETE")
.endpoint(endpoint + "/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df")
.endpoint(endpoint + "/catalogItem/" + item)
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build();
HttpResponse catalogItemResponse = HttpResponse.builder()
HttpResponse deleteItemResponse = HttpResponse.builder()
.statusCode(200)
.build();
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse);
URI catalogItemURI = URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df");
api.getCatalogApi().deleteCatalogItem(catalogItemURI);
@Test
public void testDeleteCatalogItemHref() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, deleteItem, deleteItemResponse);
api.getCatalogApi().deleteItem(itemHref);
}
@Test
public void testGetCatalogItemMetadata() {
HttpRequest catalogItemRequest = HttpRequest.builder()
public void testDeleteCatalogItemUrn() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, resolveItem, resolveItemResponse, deleteItem, deleteItemResponse);
api.getCatalogApi().deleteItem(itemUrn);
}
HttpRequest getItemMetadata = HttpRequest.builder()
.method("GET")
.endpoint(endpoint + "/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df/metadata")
.endpoint(endpoint + "/catalogItem/" + item + "/metadata")
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build();
HttpResponse catalogItemResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/catalogItemMetadata.xml", VCloudDirectorMediaType.METADATA))
HttpResponse getItemMetadataResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/catalogItemMetadata.xml", METADATA))
.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")
.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()
.rel("up")
.type("application/vnd.vmware.vcloud.catalogItem+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df"))
.href(itemHref)
.build())
.entries(ImmutableSet.of(itemMetadataEntry()))
.build();
assertEquals(api.getCatalogApi().getMetadataApi().getMetadata(catalogItemURI), expected);
}
@Test
public void testMergeCatalogItemMetadata() {
HttpRequest catalogItemRequest = HttpRequest.builder()
public void testGetCatalogItemMetadataHref() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, getItemMetadata, getItemMetadataResponse);
assertEquals(api.getCatalogApi().getMetadataApi().get(itemHref), expected);
}
HttpRequest mergeItemMetadata = HttpRequest.builder()
.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("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.payload(payloadFromResourceWithContentType("/catalog/mergeCatalogItemMetadata.xml", VCloudDirectorMediaType.METADATA))
.payload(payloadFromResourceWithContentType("/catalog/mergeCatalogItemMetadata.xml", METADATA))
.build();
HttpResponse catalogItemResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/mergeMetadataTask.xml", VCloudDirectorMediaType.TASK + ";version=1.5"))
HttpResponse mergeItemMetadataResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/mergeMetadataTask.xml", TASK + ";version=1.5"))
.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
public void testGetCatalogItemMetadataEntry() {
HttpRequest catalogItemRequest = HttpRequest.builder()
public void testMergeCatalogItemMetadataHref() {
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")
.endpoint(endpoint + "/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df/metadata/KEY")
.endpoint(endpoint + "/catalogItem/" + item + "/metadata/KEY")
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build();
HttpResponse catalogItemResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/catalogItemMetadataValue.xml", VCloudDirectorMediaType.METADATA_VALUE + ";version=1.5"))
HttpResponse getItemMetadataValueResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/catalogItemMetadataValue.xml", METADATA_VALUE + ";version=1.5"))
.build();
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse);
URI catalogItemURI = URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df");
MetadataValue expected = itemMetadataValue();
assertEquals(api.getCatalogApi().getMetadataApi().getMetadataValue(catalogItemURI, "KEY"), expected);
}
@Test
public void testSetCatalogItemMetadataEntry() {
HttpRequest catalogItemRequest = HttpRequest.builder()
public void testGetCatalogItemMetadataEntryHref() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, getItemMetadataValue, getItemMetadataValueResponse);
assertEquals(api.getCatalogApi().getMetadataApi().getValue(itemHref, "KEY"), itemMetadataValue());
}
HttpRequest putItemMetadata = HttpRequest.builder()
.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("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.payload(payloadFromResourceWithContentType("/catalog/setCatalogItemMetadataValue.xml", VCloudDirectorMediaType.METADATA_VALUE))
.payload(payloadFromResourceWithContentType("/catalog/setCatalogItemMetadataValue.xml", METADATA_VALUE))
.build();
HttpResponse catalogItemResponse = HttpResponse.builder()
HttpResponse putItemMetadataResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/setMetadataValueTask.xml", VCloudDirectorMediaType.TASK + ";version=1.5"))
.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);
}
.payload(payloadFromResourceWithContentType("/catalog/setMetadataValueTask.xml", TASK + ";version=1.5"))
.build();
@Test
public void testDeleteCatalogItemMetadataEntry() {
HttpRequest catalogItemRequest = HttpRequest.builder()
public void testSetCatalogItemMetadataEntryHref() {
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")
.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("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build();
HttpResponse catalogItemResponse = HttpResponse.builder()
HttpResponse deleteItemMetadataEntryResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/deleteMetadataEntryTask.xml", VCloudDirectorMediaType.TASK))
.build();
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse);
URI catalogItemURI = URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df");
Task expected = deleteMetadataEntryTask();
assertEquals(api.getCatalogApi().getCatalogItemMetadataApi().deleteMetadataEntry(catalogItemURI, "KEY"), expected);
.payload(payloadFromResourceWithContentType("/catalog/deleteMetadataEntryTask.xml", TASK))
.build();
@Test
public void testDeleteCatalogItemMetadataEntryHref() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, deleteItemMetadataEntry, deleteItemMetadataEntryResponse);
assertEquals(api.getCatalogApi().getItemMetadataApi().deleteEntry(itemHref, "KEY"), deleteEntryTask());
}
public static final Catalog catalog() {
return Catalog.builder()
.name("QunyingTestCatalog")
.type("application/vnd.vmware.vcloud.catalog+xml")
.id("urn:vcloud:catalog:7212e451-76e1-4631-b2de-ba1dfd8080e4")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4"))
.id(catalogUrn)
.href(catalogHref)
.link(Link.builder()
.rel("up")
.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())
.link(Link.builder()
.rel("add")
.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())
.link(Link.builder()
.rel("down")
.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())
.item(Reference.builder()
.type("application/vnd.vmware.vcloud.catalogItem+xml")
.name("ubuntu10")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df"))
.href(itemHref)
.build())
.item(Reference.builder()
.type("application/vnd.vmware.vcloud.catalogItem+xml")
.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())
.description("Testing")
.isPublished(false)
@ -395,27 +428,27 @@ public class CatalogApiExpectTest extends VCloudDirectorApiExpectTest {
public static CatalogItem createdCatalogItem() {
return CatalogItem.builder()
.name("newCatalogItem")
.id("urn:vcloud:catalogitem:a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df")
.id("urn:vcloud:catalogitem:" + item)
.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()
.rel("up")
.type("application/vnd.vmware.vcloud.catalog+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4"))
.href(catalogHref)
.build())
.link(Link.builder()
.rel("down")
.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())
.link(Link.builder()
.rel("edit")
.type("application/vnd.vmware.vcloud.catalogItem+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df"))
.href(itemHref)
.build())
.link(Link.builder()
.rel("remove")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df"))
.href(itemHref)
.build())
.description("New Catalog Item")
.entity(ubuntuVappTemplateReference())
@ -426,17 +459,17 @@ public class CatalogApiExpectTest extends VCloudDirectorApiExpectTest {
return Reference.builder()
.type("application/vnd.vmware.vcloud.vAppTemplate+xml")
.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();
}
public static MetadataEntry metadataEntry() {
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()
.rel("up")
.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())
.entry("KEY", "VALUE")
.build();
@ -444,11 +477,11 @@ public class CatalogApiExpectTest extends VCloudDirectorApiExpectTest {
public static MetadataEntry itemMetadataEntry() {
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()
.rel("up")
.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())
.entry("KEY", "VALUE")
.build();
@ -456,11 +489,11 @@ public class CatalogApiExpectTest extends VCloudDirectorApiExpectTest {
public static MetadataValue metadataValue() {
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()
.rel("up")
.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())
.value("VALUE")
.build();
@ -468,11 +501,11 @@ public class CatalogApiExpectTest extends VCloudDirectorApiExpectTest {
public static MetadataValue itemMetadataValue() {
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()
.rel("up")
.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())
.value("VALUE")
.build();
@ -481,27 +514,27 @@ public class CatalogApiExpectTest extends VCloudDirectorApiExpectTest {
public static CatalogItem catalogItem() {
return CatalogItem.builder()
.name("ubuntu10")
.id("urn:vcloud:catalogitem:a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df")
.id("urn:vcloud:catalogitem:" + item)
.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()
.rel("up")
.type("application/vnd.vmware.vcloud.catalog+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4"))
.href(catalogHref)
.build())
.link(Link.builder()
.rel("down")
.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())
.link(Link.builder()
.rel("edit")
.type("application/vnd.vmware.vcloud.catalogItem+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df"))
.href(itemHref)
.build())
.link(Link.builder()
.rel("remove")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df"))
.href(itemHref)
.build())
.description("For testing")
.entity(ubuntuVappTemplateReference())
@ -513,30 +546,30 @@ public class CatalogApiExpectTest extends VCloudDirectorApiExpectTest {
.name("task")
.id("urn:vcloud:task:c6dca927-eab4-41fa-ad6a-3ac58602541c")
.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")
.startTime(dateService.iso8601DateParse("2012-02-13T06:35:08.011-05:00"))
.expiryTime(dateService.iso8601DateParse("2012-05-13T06:35:08.011-04:00"))
.operationName("metadataUpdate")
.operation("Updating metadata for Catalog Item (a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df)")
.operation("Updating metadata for Catalog Item (" + item + ")")
.link(Link.builder()
.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())
.owner(Reference.builder()
.type("application/vnd.vmware.vcloud.catalogItem+xml")
.name("")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df"))
.href(itemHref)
.build())
.user(Reference.builder()
.type("application/vnd.vmware.admin.user+xml")
.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())
.org(Reference.builder()
.type("application/vnd.vmware.vcloud.org+xml")
.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();
}
@ -546,63 +579,63 @@ public class CatalogApiExpectTest extends VCloudDirectorApiExpectTest {
.name("task")
.id("urn:vcloud:task:c6dca927-eab4-41fa-ad6a-3ac58602541c")
.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")
.startTime(dateService.iso8601DateParse("2012-02-13T06:35:08.011-05:00"))
.expiryTime(dateService.iso8601DateParse("2012-05-13T06:35:08.011-04:00"))
.operationName("metadataSet")
.operation("Setting metadata for Catalog Item (a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df)")
.operation("Setting metadata for Catalog Item (" + item + ")")
.link(Link.builder()
.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())
.owner(Reference.builder()
.type("application/vnd.vmware.vcloud.catalogItem+xml")
.name("")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df"))
.href(itemHref)
.build())
.user(Reference.builder()
.type("application/vnd.vmware.admin.user+xml")
.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())
.org(Reference.builder()
.type("application/vnd.vmware.vcloud.org+xml")
.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();
}
public static Task deleteMetadataEntryTask() {
public static Task deleteEntryTask() {
return Task.builder()
.name("task")
.id("urn:vcloud:task:c6dca927-eab4-41fa-ad6a-3ac58602541c")
.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")
.startTime(dateService.iso8601DateParse("2012-02-13T06:35:08.011-05:00"))
.expiryTime(dateService.iso8601DateParse("2012-05-13T06:35:08.011-04:00"))
.operationName("metadataDelete")
.operation("Deleting metadata for Catalog Item (a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df)")
.operation("Deleting metadata for Catalog Item (" + item + ")")
.link(Link.builder()
.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())
.owner(Reference.builder()
.type("application/vnd.vmware.vcloud.catalogItem+xml")
.name("")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df"))
.href(itemHref)
.build())
.user(Reference.builder()
.type("application/vnd.vmware.admin.user+xml")
.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())
.org(Reference.builder()
.type("application/vnd.vmware.vcloud.org+xml")
.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();
}

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
* distributed with this work for additional information
* 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.Task;
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.internal.BaseVCloudDirectorApiLiveTest;
import org.testng.annotations.AfterClass;
@ -76,57 +77,54 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
private Media media;
private CatalogItem catalogItem;
private Reference catalogRef;
@Override
protected void setupRequiredApis() {
// TODO why do I need a guard clause here?
if (adminCatalog != null) return;
if (adminCatalog != null)
return;
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) {
AdminCatalog newCatalog = AdminCatalog.builder()
.name(name("Test Catalog "))
.description("created by CatalogApiLiveTest")
.build();
AdminCatalog newCatalog = AdminCatalog.builder().name(name("Test Catalog "))
.description("created by CatalogApiLiveTest").build();
AdminCatalogApi adminCatalogApi = adminContext.getApi().getCatalogApi();
adminCatalog = adminCatalogApi.createCatalog(orgRef.getHref(), newCatalog);
catalogRef = find(adminCatalog.getLinks(), and(relEquals("alternate"), typeEquals(VCloudDirectorMediaType.CATALOG)));
Metadata newMetadata = Metadata.builder()
.entry(MetadataEntry.builder().entry("KEY", "MARMALADE").build())
.build();
Task mergeCatalogMetadata = adminCatalogApi.getMetadataApi().mergeMetadata(adminCatalog.getHref(), newMetadata);
adminCatalog = adminCatalogApi.createCatalogInOrg(newCatalog, org.getId());
catalogUrn = catalogApi.get(
find(adminCatalog.getLinks(),
and(relEquals("alternate"), typeEquals(VCloudDirectorMediaType.CATALOG))).getHref()).getId();
Metadata newMetadata = Metadata.builder().entry(MetadataEntry.builder().entry("KEY", "MARMALADE").build())
.build();
Task mergeCatalogMetadata = adminCatalogApi.getMetadataApi().merge(adminCatalog.getHref(), newMetadata);
checkTask(mergeCatalogMetadata);
assertTrue(retryTaskSuccess.apply(mergeCatalogMetadata), String.format(TASK_COMPLETE_TIMELY, "setupRequiredApis"));
} else {
catalogRef = Reference.builder().href(catalogURI).build();
assertTrue(retryTaskSuccess.apply(mergeCatalogMetadata),
String.format(TASK_COMPLETE_TIMELY, "setupRequiredApis"));
}
}
@AfterClass(alwaysRun = true)
public void tearDown() {
if (catalogItem != null) {
try {
catalogApi.deleteCatalogItem(catalogItem.getHref());
catalogApi.deleteItem(catalogItem.getId());
} catch (Exception e) {
logger.warn(e, "Error when deleting catalog item '%s'", catalogItem.getName());
}
}
if (media != null) {
try {
Task delete = context.getApi().getMediaApi().deleteMedia(media.getHref());
taskDoneEventually(delete);
Task delete = context.getApi().getMediaApi().deleteMedia(media.getHref());
taskDoneEventually(delete);
} catch (Exception e) {
logger.warn(e, "Error when deleting media '%s'", media.getName());
}
}
if (adminContext != null && adminCatalog != null) {
try {
adminContext.getApi().getCatalogApi().deleteCatalog(adminCatalog.getHref());
adminContext.getApi().getCatalogApi().delete(adminCatalog.getId());
} catch (Exception e) {
logger.warn(e, "Error when deleting catalog '%s'", adminCatalog.getName());
}
@ -136,15 +134,15 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "GET /catalog/{id}")
public void testGetCatalog() {
Catalog catalog = catalogApi.getCatalog(catalogRef.getHref());
Catalog catalog = catalogApi.get(catalogUrn);
assertNotNull(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")
public void testGetCatalogItem() {
CatalogItem catalogItem = catalogApi.getCatalogItem(this.catalogItem.getHref());
CatalogItem catalogItem = catalogApi.getItem(this.catalogItem.getId());
checkCatalogItem(catalogItem);
assertEquals(catalogItem.getEntity().getHref(), this.catalogItem.getEntity().getHref());
}
@ -152,39 +150,31 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "POST /catalog/{id}/catalogItems")
public void testAddCatalogItem() {
assertNotNull(vdcURI, String.format(REF_REQ_LIVE, VDC));
byte[] iso = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
Vdc vdc = context.getApi().getVdcApi().getVdc(vdcURI);
assertNotNull(vdc, String.format(OBJ_REQ_LIVE, VDC));
Link addMedia = find(vdc.getLinks(), and(relEquals("add"), typeEquals(VCloudDirectorMediaType.MEDIA)));
Media sourceMedia = Media.builder()
.type(VCloudDirectorMediaType.MEDIA)
.name("Test media 1")
.size(iso.length)
.imageType(Media.ImageType.ISO)
.description("Test media generated by testCreateMedia()")
.build();
Media sourceMedia = Media.builder().type(VCloudDirectorMediaType.MEDIA).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);
Checks.checkMediaFor(VCloudDirectorMediaType.MEDIA, media);
CatalogItem editedCatalogItem = CatalogItem.builder()
.name("newitem")
.description("New Item")
.type(VCloudDirectorMediaType.CATALOG_ITEM)
.entity(Reference.builder().href(media.getHref()).build())
.build();
catalogItem = catalogApi.addCatalogItem(catalogRef.getHref(), editedCatalogItem);
CatalogItem editedCatalogItem = CatalogItem.builder().name("newitem").description("New Item")
.type(VCloudDirectorMediaType.CATALOG_ITEM).entity(Reference.builder().href(media.getHref()).build())
.build();
catalogItem = catalogApi.addItem(catalogUrn, editedCatalogItem);
checkCatalogItem(catalogItem);
assertEquals(catalogItem.getName(), "newitem");
assertEquals(catalogItem.getDescription(), "New Item");
}
@Test(description = "PUT /catalogItem/{id}", dependsOnMethods = "testAddCatalogItem")
public void testUpdateCatalogItem() {
public void testUpdateCatalogItem() {
CatalogItem updatedCatalogItem = CatalogItem.builder().fromCatalogItem(catalogItem).name("UPDATEDNAME").build();
catalogItem = catalogApi.updateCatalogItem(catalogItem.getHref(), updatedCatalogItem);
catalogItem = catalogApi.updateItem(catalogItem.getId(), updatedCatalogItem);
checkCatalogItem(catalogItem);
assertEquals(catalogItem.getName(), "UPDATEDNAME");
}
@ -192,69 +182,70 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
// Note this runs after all the metadata tests
@Test(description = "DELETE /catalogItem/{id}", dependsOnMethods = "testDeleteCatalogItemMetadataValue")
public void testDeleteCatalogItem() {
catalogApi.deleteCatalogItem(catalogItem.getHref());
catalogItem = catalogApi.getCatalogItem(catalogItem.getHref());
catalogApi.deleteItem(catalogItem.getId());
catalogItem = catalogApi.getItem(catalogItem.getId());
assertNull(catalogItem);
}
@Test(description = "GET /catalog/{id}/metadata")
public void testGetCatalogMetadata() {
Metadata catalogMetadata = catalogApi.getMetadataApi().getMetadata(catalogRef.getHref());
Metadata catalogMetadata = catalogApi.getMetadataApi().get(catalogApi.get(catalogUrn).getHref());
checkMetadata(catalogMetadata);
}
@Test(description = "GET /catalog/{id}/metadata/{key}")
public void testGetCatalogMetadataValue() {
Metadata catalogMetadata = catalogApi.getMetadataApi().getMetadata(catalogRef.getHref());
MetadataEntry existingMetadataEntry = Iterables.find(catalogMetadata.getMetadataEntries(), new Predicate<MetadataEntry>() {
@Override
public boolean apply(MetadataEntry input) {
return input.getKey().equals("KEY");
}
});
MetadataValue metadataValue = catalogApi.getMetadataApi().getMetadataValue(catalogRef.getHref(), "KEY");
assertEquals(metadataValue.getValue(), existingMetadataEntry.getValue(),
String.format(CORRECT_VALUE_OBJECT_FMT, "Value", "MetadataValue", existingMetadataEntry.getValue(), metadataValue.getValue()));
Metadata catalogMetadata = catalogApi.getMetadataApi().get(catalogApi.get(catalogUrn).getHref());
MetadataEntry existingMetadataEntry = Iterables.find(catalogMetadata.getMetadataEntries(),
new Predicate<MetadataEntry>() {
@Override
public boolean apply(MetadataEntry input) {
return input.getKey().equals("KEY");
}
});
MetadataValue metadataValue = catalogApi.getMetadataApi().getValue(existingMetadataEntry.getHref(), "KEY");
assertEquals(metadataValue.getValue(), existingMetadataEntry.getValue(), String.format(CORRECT_VALUE_OBJECT_FMT,
"Value", "MetadataValue", existingMetadataEntry.getValue(), metadataValue.getValue()));
checkMetadataValue(metadataValue);
}
@Test(description = "GET /catalogItem/{id}/metadata", dependsOnMethods = "testAddCatalogItem")
public void testGetCatalogItemMetadata() {
Metadata catalogItemMetadata = catalogApi.getCatalogItemMetadataApi().getMetadata(catalogItem.getHref());
Metadata catalogItemMetadata = catalogApi.getItemMetadataApi().get(catalogItem.getHref());
checkMetadata(catalogItemMetadata);
}
@Test(description = "POST /catalogItem/{id}/metadata", dependsOnMethods = "testAddCatalogItem")
public void testMergeCatalogItemMetadata() {
Metadata newMetadata = Metadata.builder()
.entry(MetadataEntry.builder().entry("KEY", "MARMALADE").build())
.entry(MetadataEntry.builder().entry("VEGIMITE", "VALUE").build())
.build();
Metadata newMetadata = Metadata.builder().entry(MetadataEntry.builder().entry("KEY", "MARMALADE").build())
.entry(MetadataEntry.builder().entry("VEGIMITE", "VALUE").build()).build();
Metadata before = catalogApi.getCatalogItemMetadataApi().getMetadata(catalogItem.getHref());
Task mergeCatalogItemMetadata = catalogApi.getCatalogItemMetadataApi().mergeMetadata(catalogItem.getHref(), newMetadata);
Metadata before = catalogApi.getItemMetadataApi().get(catalogItem.getHref());
Task mergeCatalogItemMetadata = catalogApi.getItemMetadataApi().merge(catalogItem.getHref(), newMetadata);
checkTask(mergeCatalogItemMetadata);
assertTrue(retryTaskSuccess.apply(mergeCatalogItemMetadata),
String.format(TASK_COMPLETE_TIMELY, "mergeCatalogItemMetadata"));
Metadata mergedCatalogItemMetadata = catalogApi.getCatalogItemMetadataApi().getMetadata(catalogItem.getHref());
String.format(TASK_COMPLETE_TIMELY, "mergeCatalogItemMetadata"));
Metadata mergedCatalogItemMetadata = catalogApi.getItemMetadataApi().get(catalogItem.getHref());
assertTrue(mergedCatalogItemMetadata.getMetadataEntries().size() > before.getMetadataEntries().size(),
"Should have added at least one other MetadataEntry to the CatalogItem");
MetadataValue keyMetadataValue = catalogApi.getCatalogItemMetadataApi().getMetadataValue(catalogItem.getHref(), "KEY");
assertEquals(keyMetadataValue.getValue(), "MARMALADE", "The Value of the MetadataValue for KEY should have changed");
checkMetadataValue(keyMetadataValue);
MetadataValue newKeyMetadataValue = catalogApi.getCatalogItemMetadataApi().getMetadataValue(catalogItem.getHref(), "VEGIMITE");
"Should have added at least one other MetadataEntry to the CatalogItem");
assertEquals(newKeyMetadataValue.getValue(), "VALUE", "The Value of the MetadataValue for NEW_KEY should have been set");
MetadataValue keyMetadataValue = catalogApi.getItemMetadataApi().getValue(catalogItem.getHref(), "KEY");
assertEquals(keyMetadataValue.getValue(), "MARMALADE",
"The Value of the MetadataValue for KEY should have changed");
checkMetadataValue(keyMetadataValue);
MetadataValue newKeyMetadataValue = catalogApi.getItemMetadataApi().getValue(catalogItem.getHref(), "VEGIMITE");
assertEquals(newKeyMetadataValue.getValue(), "VALUE",
"The Value of the MetadataValue for NEW_KEY should have been set");
checkMetadataValue(newKeyMetadataValue);
}
@Test(description = "GET /catalogItem/{id}/metadata/{key}", dependsOnMethods = "testSetCatalogItemMetadataValue")
public void testGetCatalogItemMetadataValue() {
MetadataValue metadataValue = catalogApi.getCatalogItemMetadataApi().getMetadataValue(catalogItem.getHref(), "KEY");
public void testGetCatalogItemMetadataValue() {
MetadataValue metadataValue = catalogApi.getItemMetadataApi().getValue(catalogItem.getHref(), "KEY");
checkMetadataValue(metadataValue);
}
@ -262,24 +253,26 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
public void testSetCatalogItemMetadataValue() {
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);
assertTrue(retryTaskSuccess.apply(setCatalogItemMetadataValue),
String.format(TASK_COMPLETE_TIMELY, "setCatalogItemMetadataValue"));
MetadataValue updatedMetadataValue = catalogApi.getCatalogItemMetadataApi().getMetadataValue(catalogItem.getHref(), "KEY");
assertEquals(updatedMetadataValue.getValue(), newMetadataValue.getValue(),
String.format(CORRECT_VALUE_OBJECT_FMT, "Value", "MetadataValue", newMetadataValue.getValue(), updatedMetadataValue.getValue()));
assertTrue(retryTaskSuccess.apply(setCatalogItemMetadataValue),
String.format(TASK_COMPLETE_TIMELY, "setCatalogItemMetadataValue"));
MetadataValue updatedMetadataValue = catalogApi.getItemMetadataApi().getValue(catalogItem.getHref(), "KEY");
assertEquals(updatedMetadataValue.getValue(), newMetadataValue.getValue(), String.format(
CORRECT_VALUE_OBJECT_FMT, "Value", "MetadataValue", newMetadataValue.getValue(),
updatedMetadataValue.getValue()));
checkMetadataValue(updatedMetadataValue);
}
@Test(description = "DELETE /catalogItem/{id}/metadata/{key}", dependsOnMethods = "testGetCatalogItemMetadataValue")
public void testDeleteCatalogItemMetadataValue() {
Task deleteCatalogItemMetadataValue = catalogApi.getCatalogItemMetadataApi().deleteMetadataEntry(catalogItem.getHref(), "KEY");
Task deleteCatalogItemMetadataValue = catalogApi.getItemMetadataApi().deleteEntry(catalogItem.getHref(), "KEY");
checkTask(deleteCatalogItemMetadataValue);
assertTrue(retryTaskSuccess.apply(deleteCatalogItemMetadataValue),
String.format(TASK_COMPLETE_TIMELY, "deleteCatalogItemMetadataValue"));
MetadataValue deleted = catalogApi.getMetadataApi().getMetadataValue(catalogItem.getHref(), "KEY");
assertTrue(retryTaskSuccess.apply(deleteCatalogItemMetadataValue),
String.format(TASK_COMPLETE_TIMELY, "deleteCatalogItemMetadataValue"));
MetadataValue deleted = catalogApi.getMetadataApi().getValue(catalogItem.getHref(), "KEY");
assertNull(deleted);
}
}

View File

@ -150,7 +150,7 @@ public class MediaApiExpectTest extends VCloudDirectorAdminApiExpectTest {
} catch (VCloudDirectorException vde) {
assertEquals(vde.getError(), expected);
} 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();
assertEquals(api.getMediaApi().getMetadataApi().getMetadata(mediaUri), expected);
assertEquals(api.getMediaApi().getMetadataApi().get(mediaUri), expected);
}
@Test
@ -260,7 +260,7 @@ public class MediaApiExpectTest extends VCloudDirectorAdminApiExpectTest {
Metadata inputMetadata = metadata();
Task expectedTask = mergeMetadataTask();
assertEquals(api.getMediaApi().getMetadataApi().mergeMetadata(mediaUri, inputMetadata), expectedTask);
assertEquals(api.getMediaApi().getMetadataApi().merge(mediaUri, inputMetadata), expectedTask);
}
public void testGetMetadataValue() {
@ -278,7 +278,7 @@ public class MediaApiExpectTest extends VCloudDirectorAdminApiExpectTest {
MetadataValue expected = metadataValue();
assertEquals(api.getMediaApi().getMetadataApi().getMetadataValue(mediaUri, "key"), expected);
assertEquals(api.getMediaApi().getMetadataApi().getValue(mediaUri, "key"), expected);
}
@Test
@ -299,7 +299,7 @@ public class MediaApiExpectTest extends VCloudDirectorAdminApiExpectTest {
Task expectedTask = setMetadataEntryTask();
assertEquals(api.getMediaApi().getMetadataApi().setMetadata(mediaUri, "key", inputMetadataValue), expectedTask);
assertEquals(api.getMediaApi().getMetadataApi().putEntry(mediaUri, "key", inputMetadataValue), expectedTask);
}
@Test
@ -315,9 +315,9 @@ public class MediaApiExpectTest extends VCloudDirectorAdminApiExpectTest {
.xmlFilePayload("/media/deleteMetadataEntryTask.xml", VCloudDirectorMediaType.TASK)
.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
@ -723,7 +723,7 @@ public class MediaApiExpectTest extends VCloudDirectorAdminApiExpectTest {
.build();
}
public static Task deleteMetadataEntryTask() {
public static Task deleteEntryTask() {
return Task.builder()
.name("task")
.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",
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()
.source(Reference.builder().fromEntity(media).build())
@ -284,7 +284,7 @@ public class MediaApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "GET /media/{id}/metadata", dependsOnMethods = { "testSetMetadataValue" })
public void testGetMetadata() {
metadata = mediaApi.getMetadataApi().getMetadata(media.getHref());
metadata = mediaApi.getMetadataApi().get(media.getHref());
// required for testing
assertFalse(isEmpty(metadata.getMetadataEntries()),
String.format(OBJ_FIELD_REQ_LIVE, MEDIA, "metadata.entries"));
@ -300,10 +300,10 @@ public class MediaApiLiveTest extends BaseVCloudDirectorApiLiveTest {
.entries(inputEntries)
.build();
Task mergeMetadata = mediaApi.getMetadataApi().mergeMetadata(media.getHref(), inputMetadata);
Task mergeMetadata = mediaApi.getMetadataApi().merge(media.getHref(), inputMetadata);
Checks.checkTask(mergeMetadata);
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);
checkMetadataContainsEntries(metadata, inputEntries);
@ -316,10 +316,10 @@ public class MediaApiLiveTest extends BaseVCloudDirectorApiLiveTest {
.entries(inputEntries)
.build();
mergeMetadata = mediaApi.getMetadataApi().mergeMetadata(media.getHref(), inputMetadata);
mergeMetadata = mediaApi.getMetadataApi().merge(media.getHref(), inputMetadata);
Checks.checkTask(mergeMetadata);
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);
checkMetadataContainsEntries(metadata, inputEntries);
@ -346,7 +346,7 @@ public class MediaApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "GET /media/{id}/metadata/{key}", dependsOnMethods = { "testSetMetadataValue" })
public void testGetMetadataValue() {
metadataValue = mediaApi.getMetadataApi().getMetadataValue(media.getHref(), "key");
metadataValue = mediaApi.getMetadataApi().getValue(media.getHref(), "key");
Checks.checkMetadataValueFor(MEDIA, metadataValue);
}
@ -355,27 +355,27 @@ public class MediaApiLiveTest extends BaseVCloudDirectorApiLiveTest {
metadataEntryValue = "value";
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);
assertTrue(retryTaskSuccess.apply(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);
}
@Test(description = "DELETE /media/{id}/metadata/{key}", dependsOnMethods = { "testGetMetadata", "testGetMetadataValue" } )
public void testDeleteMetadata() {
Task deleteMetadataEntry = mediaApi.getMetadataApi().deleteMetadataEntry(media.getHref(), "testKey");
Checks.checkTask(deleteMetadataEntry);
assertTrue(retryTaskSuccess.apply(deleteMetadataEntry),
String.format(TASK_COMPLETE_TIMELY, "deleteMetadataEntry"));
Task deleteEntry = mediaApi.getMetadataApi().deleteEntry(media.getHref(), "testKey");
Checks.checkTask(deleteEntry);
assertTrue(retryTaskSuccess.apply(deleteEntry),
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,
"Metadata", 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);
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()))
.build();
assertEquals(api.getNetworkApi().getMetadataApi().getMetadata(networkUri), expected);
assertEquals(api.getNetworkApi().getMetadataApi().get(networkUri), expected);
}
@Test
@ -184,7 +184,7 @@ public class NetworkApiExpectTest extends VCloudDirectorAdminApiExpectTest {
.value("value")
.build();
assertEquals(api.getNetworkApi().getMetadataApi().getMetadataValue(networkUri, "KEY"), expected);
assertEquals(api.getNetworkApi().getMetadataApi().getValue(networkUri, "KEY"), expected);
}
public static OrgNetwork orgNetwork() {

View File

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

View File

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

View File

@ -61,29 +61,26 @@ public class OrgApiLiveTest extends BaseVCloudDirectorApiLiveTest {
*/
private OrgApi orgApi;
private URI catalogRef;
private String testCatalogId;
@Override
@BeforeClass(alwaysRun = true)
public void setupRequiredApis() {
orgApi = context.getApi().getOrgApi();
testCatalogId = catalogId;
}
@AfterClass(alwaysRun = true)
public void cleanUp() throws Exception {
if (adminMembersSet) {
try {
Task delete = adminContext.getApi().getOrgApi().getMetadataApi().deleteMetadataEntry(toAdminUri(orgURI), "KEY");
Task delete = adminContext.getApi().getOrgApi().getMetadataApi().deleteEntry(toAdminUri(orgURI), "KEY");
taskDoneEventually(delete);
} catch (Exception e) {
logger.warn(e, "Error when deleting metadata entry");
}
try {
adminContext.getApi().getCatalogApi().deleteCatalog(catalogRef);
adminContext.getApi().getCatalogApi().delete(catalogUrn);
} 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
*/
private void setupAdminMembers() {
adminContext.getApi().getOrgApi().getMetadataApi().setMetadata(toAdminUri(orgURI),
adminContext.getApi().getOrgApi().getMetadataApi().putEntry(toAdminUri(orgURI),
"KEY", MetadataValue.builder().value("VALUE").build());
AdminCatalog newCatalog = AdminCatalog.builder()
.name("Test Catalog "+getTestDateTimeStamp())
.description("created by testOrg()")
.build();
newCatalog = adminContext.getApi().getCatalogApi().createCatalog(toAdminUri(orgURI), newCatalog);
newCatalog = adminContext.getApi().getCatalogApi().createCatalogInOrg(newCatalog, org.getId());
catalogRef = newCatalog.getHref();
testCatalogId = newCatalog.getId().substring("urn:vcloud:catalog:".length());
catalogUrn = newCatalog.getId();
adminMembersSet = true;
}
@ -153,7 +149,7 @@ public class OrgApiLiveTest extends BaseVCloudDirectorApiLiveTest {
public void testGetOrgMetadata() {
// 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
@ -166,7 +162,7 @@ public class OrgApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "GET /org/{id}/metadata/{key}", dependsOnMethods = { "testGetOrgMetadata" })
public void testGetOrgMetadataValue() {
// 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" )'
@ -179,7 +175,7 @@ public class OrgApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "GET /org/{id}/catalog/{catalogId}/controlAccess", dependsOnMethods = { "testGetOrg" })
public void testGetControlAccess() {
// Call the method being tested
ControlAccessParams params = orgApi.getControlAccess(orgURI, testCatalogId);
ControlAccessParams params = orgApi.getControlAccess(orgURI, catalogUrn);
// Check params are well formed
checkControlAccessParams(params);
@ -188,10 +184,10 @@ public class OrgApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "POST /org/{id}/catalog/{catalogId}/action/controlAccess", dependsOnMethods = { "testGetControlAccess" })
public void testModifyControlAccess() {
// Setup params
ControlAccessParams params = orgApi.getControlAccess(orgURI, testCatalogId);
ControlAccessParams params = orgApi.getControlAccess(orgURI, catalogUrn);
// Call the method being tested
ControlAccessParams modified = orgApi.modifyControlAccess(orgURI, testCatalogId, params);
ControlAccessParams modified = orgApi.modifyControlAccess(orgURI, catalogUrn, params);
// Check params are well formed
checkControlAccessParams(modified);

View File

@ -743,10 +743,10 @@ public class VAppApiLiveTest extends AbstractVAppApiLiveTest {
key = name("key-");
String value = name("value-");
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
MetadataValue newMetadataValue = vAppApi.getMetadataApi().getMetadataValue(vApp.getHref(), key);
MetadataValue newMetadataValue = vAppApi.getMetadataApi().getValue(vApp.getHref(), key);
// Check the retrieved object is well formed
checkMetadataValueFor(VAPP, newMetadataValue, value);
@ -757,10 +757,10 @@ public class VAppApiLiveTest extends AbstractVAppApiLiveTest {
key = name("key-");
String value = name("value-");
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
Metadata metadata = vAppApi.getMetadataApi().getMetadata(vApp.getHref());
Metadata metadata = vAppApi.getMetadataApi().get(vApp.getHref());
checkMetadata(metadata);
@ -771,7 +771,7 @@ public class VAppApiLiveTest extends AbstractVAppApiLiveTest {
@Test(description = "GET /vApp/{id}/metadata/{key}", dependsOnMethods = { "testGetMetadata" })
public void testGetOrgMetadataValue() {
// 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();
@ -782,11 +782,11 @@ public class VAppApiLiveTest extends AbstractVAppApiLiveTest {
@Test(description = "DELETE /vApp/{id}/metadata/{key}", dependsOnMethods = { "testSetMetadataValue" })
public void testDeleteMetadataEntry() {
// Delete the entry
Task task = vAppApi.getMetadataApi().deleteMetadataEntry(vApp.getHref(), key);
Task task = vAppApi.getMetadataApi().deleteEntry(vApp.getHref(), key);
retryTaskSuccess.apply(task);
// 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
checkMetadataKeyAbsentFor(VAPP, newMetadata, key);
@ -794,7 +794,7 @@ public class VAppApiLiveTest extends AbstractVAppApiLiveTest {
@Test(description = "POST /vApp/{id}/metadata", dependsOnMethods = { "testGetMetadata" })
public void testMergeMetadata() {
Metadata oldMetadata = vAppApi.getMetadataApi().getMetadata(vApp.getHref());
Metadata oldMetadata = vAppApi.getMetadataApi().get(vApp.getHref());
Map<String, String> oldMetadataMap = Checks.metadataToMap(oldMetadata);
// Store a value, to be deleted
@ -803,11 +803,11 @@ public class VAppApiLiveTest extends AbstractVAppApiLiveTest {
Metadata addedMetadata = Metadata.builder()
.entry(MetadataEntry.builder().key(key).value(value).build())
.build();
Task task = vAppApi.getMetadataApi().mergeMetadata(vApp.getHref(), addedMetadata);
Task task = vAppApi.getMetadataApi().merge(vApp.getHref(), addedMetadata);
retryTaskSuccess.apply(task);
// 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()
.putAll(oldMetadataMap)
.put(key, value)

View File

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

View File

@ -353,11 +353,11 @@ public class VAppTemplateApiExpectTest extends VCloudDirectorAdminApiExpectTest
).getVAppTemplateApi();
assertNotNull(api);
Metadata metadata = api.getMetadataApi().getMetadata(uri);
Metadata metadata = api.getMetadataApi().get(uri);
assertEquals(metadata, exampleMetadata());
Task task = api.getMetadataApi().mergeMetadata(uri, exampleMetadata());
Task task = api.getMetadataApi().merge(uri, exampleMetadata());
assertNotNull(task);
}
@ -370,7 +370,7 @@ public class VAppTemplateApiExpectTest extends VCloudDirectorAdminApiExpectTest
new VcloudHttpRequestPrimer().apiCommand("GET", templateId + "/metadata").acceptMedia(ANY).httpRequestBuilder().build(),
new VcloudHttpResponsePrimer().xmlFilePayload("/vapptemplate/error400.xml", ERROR).httpResponseBuilder().statusCode(400).build()).getVAppTemplateApi();
api.getMetadataApi().getMetadata(uri);
api.getMetadataApi().get(uri);
}
@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 VcloudHttpResponsePrimer().xmlFilePayload("/vapptemplate/error400.xml", ERROR).httpResponseBuilder().statusCode(400).build()).getVAppTemplateApi();
api.getMetadataApi().mergeMetadata(uri, exampleMetadata());
api.getMetadataApi().merge(uri, exampleMetadata());
}
public void testVappTemplateMetadataValue() {
@ -399,14 +399,14 @@ public class VAppTemplateApiExpectTest extends VCloudDirectorAdminApiExpectTest
).getVAppTemplateApi();
assertNotNull(api);
MetadataValue metadata = api.getMetadataApi().getMetadataValue(uri, "12345");
MetadataValue metadata = api.getMetadataApi().getValue(uri, "12345");
assertEquals(metadata, exampleMetadataValue());
Task task = api.getMetadataApi().setMetadata(uri, "12345", exampleMetadataValue());
Task task = api.getMetadataApi().putEntry(uri, "12345", exampleMetadataValue());
assertNotNull(task);
task = api.getMetadataApi().deleteMetadataEntry(uri, "12345");
task = api.getMetadataApi().deleteEntry(uri, "12345");
assertNotNull(task);
}
@ -418,7 +418,7 @@ public class VAppTemplateApiExpectTest extends VCloudDirectorAdminApiExpectTest
new VcloudHttpRequestPrimer().apiCommand("GET", templateId + "/metadata/12345").acceptMedia(METADATA_ENTRY).httpRequestBuilder().build(),
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)
@ -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 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)
@ -442,7 +442,7 @@ public class VAppTemplateApiExpectTest extends VCloudDirectorAdminApiExpectTest
new VcloudHttpRequestPrimer().apiCommand("DELETE", templateId + "/metadata/12345").acceptMedia(TASK).httpRequestBuilder().build(),
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)

View File

@ -91,7 +91,7 @@ public class VAppTemplateApiLiveTest extends AbstractVAppApiLiveTest {
protected void tidyUp() {
if (key != null) {
try {
Task delete = vAppTemplateApi.getMetadataApi().deleteMetadataEntry(vAppTemplateURI, key);
Task delete = vAppTemplateApi.getMetadataApi().deleteEntry(vAppTemplateURI, key);
taskDoneEventually(delete);
} catch (Exception e) {
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" })
public void testGetVAppTemplateMetadata() {
Metadata metadata = vAppTemplateApi.getMetadataApi().getMetadata(vAppTemplateURI);
Metadata metadata = vAppTemplateApi.getMetadataApi().get(vAppTemplateURI);
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
@Test(description = "GET /vAppTemplate/{id}/metadata/{key}", dependsOnMethods = { "testGetVAppTemplateMetadata" })
public void testGetMetadataValue() {
Metadata metadata = vAppTemplateApi.getMetadataApi().getMetadata(vAppTemplateURI);
Metadata metadata = vAppTemplateApi.getMetadataApi().get(vAppTemplateURI);
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);
assertEquals(val.getValue(), entry.getValue());
@ -245,7 +245,7 @@ public class VAppTemplateApiLiveTest extends AbstractVAppApiLiveTest {
@Test(description = "POST /vAppTemplate/{id}/metadata", dependsOnMethods = { "testGetVAppTemplate" })
public void testEditMetadata() {
Metadata oldMetadata = vAppTemplateApi.getMetadataApi().getMetadata(vAppTemplateURI);
Metadata oldMetadata = vAppTemplateApi.getMetadataApi().get(vAppTemplateURI);
Map<String,String> oldMetadataMap = metadataToMap(oldMetadata);
key = name("key-");
@ -253,10 +253,10 @@ public class VAppTemplateApiLiveTest extends AbstractVAppApiLiveTest {
MetadataEntry metadataEntry = MetadataEntry.builder().entry(key, val).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);
Metadata newMetadata = vAppTemplateApi.getMetadataApi().getMetadata(vAppTemplateURI);
Metadata newMetadata = vAppTemplateApi.getMetadataApi().get(vAppTemplateURI);
Map<String,String> expectedMetadataMap = ImmutableMap.<String,String>builder()
.putAll(oldMetadataMap)
.put(key, val)
@ -269,19 +269,19 @@ public class VAppTemplateApiLiveTest extends AbstractVAppApiLiveTest {
val = "new"+val;
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);
MetadataValue newMetadataValue = vAppTemplateApi.getMetadataApi().getMetadataValue(vAppTemplateURI, key);
MetadataValue newMetadataValue = vAppTemplateApi.getMetadataApi().getValue(vAppTemplateURI, key);
assertEquals(newMetadataValue.getValue(), metadataValue.getValue());
}
@Test(description = "DELETE /vAppTemplate/{id}/metadata/{key}", dependsOnMethods = { "testGetMetadataValue" })
public void testDeleteVAppTemplateMetadataValue() {
final Task deletionTask = vAppTemplateApi.getMetadataApi().deleteMetadataEntry(vAppTemplateURI, key);
final Task deletionTask = vAppTemplateApi.getMetadataApi().deleteEntry(vAppTemplateURI, key);
assertTaskSucceeds(deletionTask);
Metadata newMetadata = vAppTemplateApi.getMetadataApi().getMetadata(vAppTemplateURI);
Metadata newMetadata = vAppTemplateApi.getMetadataApi().get(vAppTemplateURI);
checkMetadataKeyAbsentFor("vAppTemplate", newMetadata, key);
key = null;
}

View File

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

View File

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

View File

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

View File

@ -18,10 +18,19 @@
*/
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 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.admin.VCloudDirectorAdminApi;
import org.jclouds.vcloud.director.v1_5.domain.AdminCatalog;
@ -34,132 +43,197 @@ import org.jclouds.vcloud.director.v1_5.internal.VCloudDirectorAdminApiExpectTes
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.common.net.HttpHeaders;
/**
* 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")
public class AdminCatalogApiExpectTest extends VCloudDirectorAdminApiExpectTest {
private Reference catalogRef = Reference.builder()
.type("application/vnd.vmware.vcloud.catalog+xml")
.name("QunyingTestCatalog")
.href(URI.create(endpoint + "/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4"))
.build();
static String catalog = "7212e451-76e1-4631-b2de-ba1dfd8080e4";
static String catalogUrn = "urn:vcloud:catalog:" + catalog;
static URI adminCatalogHref = URI.create(endpoint + "/admin/catalog/" + catalog);
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();
@Test
public void testGetCatalogHref() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, get, getResponse);
assertEquals(api.getCatalogApi().get(adminCatalogHref), catalog());
}
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()
.e("Link").a("rel", "alternate").a("type", ADMIN_CATALOG).a("href", adminCatalogHref.toString()).up());
HttpResponse resolveCatalogResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromStringWithContentType(catalogEntity, ENTITY + ";version=1.5"))
.build();
@Test
public void testCreateCatalog() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse,
new VcloudHttpRequestPrimer()
.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);
public void testGetCatalogUrn() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, resolveCatalog, resolveCatalogResponse, get, getResponse);
assertEquals(api.getCatalogApi().get(catalogUrn), catalog());
}
static String org = "7212e451-76e1-4631-b2de-asdasdasd";
static String orgUrn = "urn:vcloud:org:" + org;
static URI orgHref = URI.create(endpoint + "/org/" + org);
static URI adminOrgHref = URI.create(endpoint + "/admin/org/" + org);
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();
// FIXME disabled due to intermittent JXB error: javax.xml.bind.UnmarshalException:
// unexpected element (uri:"http://www.vmware.com/vcloud/v1.5", local:"AdminCatalog").
// Expected elements are <{http://www.vmware.com/vcloud/v1.5}Catalog>, <{http://www.vmware.com/vcloud/v1.5}CatalogReference>,
// <{http://www.vmware.com/vcloud/v1.5}Error>,<{http://www.vmware.com/vcloud/v1.5}Link>,
// <{http://www.vmware.com/vcloud/v1.5}Owner>,<{http://www.vmware.com/vcloud/v1.5}Reference>,
// <{http://www.vmware.com/vcloud/v1.5}RoleReference>,<{http://www.vmware.com/vcloud/v1.5}Task>,
// <{http://www.vmware.com/vcloud/v1.5}VAppReference>
@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());
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();
AdminCatalog expected = catalog();
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
public void testUpdateCatalogUrn() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, resolveCatalog, resolveCatalogResponse, update, updateResponse);
assertEquals(api.getCatalogApi().update(catalogUrn, updateCatalog()), updateCatalog());
}
HttpRequest getOwner = HttpRequest.builder()
.method("GET")
.endpoint(adminCatalogHref + "/owner")
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.build();
AdminCatalog actual = api.getCatalogApi().getCatalog(catalogRef.getHref());
assertEquals(actual.getHref(), expected.getHref());
assertEquals(actual.getLinks(), expected.getLinks());
assertEquals(actual.getTasks(), expected.getTasks());
System.out.println(actual.getOwner());
System.out.println(expected.getOwner());
Reference actualUser = actual.getOwner().getUser();
Reference expectedUser = expected.getOwner().getUser();
assertEquals(actualUser, expectedUser);
assertEquals(actual.getOwner(), expected.getOwner());
assertEquals(api.getCatalogApi().getCatalog(catalogRef.getHref()), expected);
HttpResponse getOwnerResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/admin/owner.xml", OWNER + ";version=1.5"))
.build();
Owner expectedGetOwner = owner().toBuilder()
.link(Link.builder()
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4"))
.type("application/vnd.vmware.vcloud.catalog+xml")
.rel("up")
.build())
.link(Link.builder()
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/owner"))
.type("application/vnd.vmware.vcloud.owner+xml")
.rel("edit")
.build())
.build();
@Test
public void testGetCatalogOwnerHref() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, getOwner, getOwnerResponse);
assertEquals(api.getCatalogApi().getOwner(adminCatalogHref), expectedGetOwner);
}
@Test
public void testModifyCatalog() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse,
new VcloudHttpRequestPrimer()
.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);
public void testGetCatalogOwnerUrn() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, resolveCatalog, resolveCatalogResponse, getOwner, getOwnerResponse);
assertEquals(api.getCatalogApi().getOwner(catalogUrn), expectedGetOwner);
}
@Test
public void testGetOwner() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("GET", "/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/owner")
.acceptAnyMedia()
.httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/catalog/admin/owner.xml", VCloudDirectorMediaType.OWNER)
.httpResponseBuilder().build());
Owner expected = owner().toBuilder()
.link(Link.builder()
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4"))
.type("application/vnd.vmware.vcloud.catalog+xml")
.rel("up")
.build())
.link(Link.builder()
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/owner"))
.type("application/vnd.vmware.vcloud.owner+xml")
.rel("edit")
.build())
.build();
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();
assertEquals(api.getCatalogApi().getOwner(catalogRef.getHref()), expected);
}
HttpResponse setOwnerResponse = HttpResponse.builder()
.statusCode(204)
.build();
@Test
public void testSetOwner() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse,
new VcloudHttpRequestPrimer()
.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()
Owner ownerToSet = Owner.builder()
.type("application/vnd.vmware.vcloud.owner+xml")
.user(Reference.builder()
.type("application/vnd.vmware.admin.user+xml")
@ -167,49 +241,81 @@ public class AdminCatalogApiExpectTest extends VCloudDirectorAdminApiExpectTest
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/e9eb1b29-0404-4c5e-8ef7-e584acc51da9"))
.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
public void testPublishCatalog() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse,
new VcloudHttpRequestPrimer()
.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()
.isPublished(true)
public void testSetCatalogOwnerUrn() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, resolveCatalog, resolveCatalogResponse, setOwner, setOwnerResponse);
api.getCatalogApi().setOwner(catalogUrn, ownerToSet);
}
HttpRequest publishCatalog = HttpRequest.builder()
.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();
HttpResponse publishCatalogResponse = HttpResponse.builder()
.statusCode(204)
.build();
api.getCatalogApi().publishCatalog(catalogRef.getHref(), params);
}
@Test
public void testDeleteCatalog() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("DELETE", "/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")
.acceptAnyMedia()
.httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.httpResponseBuilder().statusCode(204).build());
api.getCatalogApi().deleteCatalog(catalogRef.getHref());
public void testPublishCatalogHref() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, publishCatalog,
publishCatalogResponse);
api.getCatalogApi().publish(adminCatalogHref, PublishCatalogParams.builder().isPublished(true).build());
}
@Test
public void testPublishCatalogUrn() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, resolveCatalog,
resolveCatalogResponse, publishCatalog, publishCatalogResponse);
api.getCatalogApi().publish(catalogUrn, PublishCatalogParams.builder().isPublished(true).build());
}
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 createCatalogSource() {
public static final AdminCatalog createCatalogInOrgSource() {
return AdminCatalog.builder()
.name("Test Catalog")
.description("created by testCreateCatalog()")
.build();
}
public static final AdminCatalog createCatalog() {
public static final AdminCatalog createCatalogInOrg() {
return AdminCatalog.builder()
.name("Test Catalog")
.id("urn:vcloud:catalog:c56d9159-7838-446f-bb35-9ee12dfbbef3")
@ -364,7 +470,7 @@ public class AdminCatalogApiExpectTest extends VCloudDirectorAdminApiExpectTest
.build();
}
public static final AdminCatalog modifyCatalog() {
public static final AdminCatalog updateCatalog() {
return catalog().toBuilder()
.name("new QunyingTestCatalog")
.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.assertTrue;
import java.net.URI;
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.Checks;
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.Reference;
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.internal.BaseVCloudDirectorApiLiveTest;
import org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@ -50,7 +54,7 @@ import com.google.common.collect.Iterables;
*/
@Test(groups = { "live", "admin" }, singleThreaded = true, testName = "CatalogApiLiveTest")
public class AdminCatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
public static final String CATALOG = "admin catalog";
/*
@ -63,7 +67,7 @@ public class AdminCatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
* Shared state between dependant tests.
*/
private Reference orgRef;
private Org org;
private AdminCatalog catalog;
private Owner owner;
@ -71,141 +75,134 @@ public class AdminCatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@BeforeClass(alwaysRun = true)
protected void setupRequiredApis() {
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)
protected void tidyUp() {
if (catalog != null) {
try {
catalogApi.deleteCatalog(catalog.getHref());
catalogApi.delete(catalog.getId());
} catch (Exception e) {
logger.warn(e, "Error deleting admin catalog '%s'", catalog.getName());
}
}
}
@Test(description = "POST /admin/org/{id}/catalogs")
public void testCreateCatalog() {
AdminCatalog newCatalog = AdminCatalog.builder()
.name(name("Test Catalog "))
.description("created by testCreateCatalog()")
.build();
catalog = catalogApi.createCatalog(orgRef.getHref(), newCatalog);
AdminCatalog newCatalog = AdminCatalog.builder().name(name("Test Catalog "))
.description("created by testCreateCatalog()").build();
catalog = catalogApi.createCatalogInOrg(newCatalog, org.getId());
Checks.checkAdminCatalog(catalog);
// FIXME: documentation suggests we should wait for a task here
}
@Test(description = "GET /admin/catalog/{id}", dependsOnMethods = { "testCreateCatalog" })
public void testGetCatalog() {
catalog = catalogApi.getCatalog(catalog.getHref());
catalog = catalogApi.get(catalog.getId());
Checks.checkAdminCatalog(catalog);
}
@Test(description = "GET /admin/catalog/{id}/owner", dependsOnMethods = { "testGetCatalog" })
public void testGetCatalogOwner() {
owner = catalogApi.getOwner(catalog.getHref());
owner = catalogApi.getOwner(catalog.getId());
Checks.checkOwner(owner);
}
@Test(description = "PUT /admin/catalog/{id}/owner", dependsOnMethods = { "testGetCatalog" })
public void updateCatalogOwner() {
URI adminOrgHref = Iterables.find(context.getApi().resolveEntity(org.getId()).getLinks(),
LinkPredicates.typeEquals(VCloudDirectorMediaType.ADMIN_ORG)).getHref();
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");
Owner oldOwner = owner;
Owner newOwner = Owner.builder()
.type("application/vnd.vmware.vcloud.owner+xml")
.user(Reference.builder().fromEntity(newOwnerUser).build())
.build();
Owner newOwner = Owner.builder().type("application/vnd.vmware.vcloud.owner+xml")
.user(Reference.builder().fromEntity(newOwnerUser).build()).build();
try {
catalogApi.setOwner(catalog.getHref(), newOwner);
owner = catalogApi.getOwner(catalog.getHref());
catalogApi.setOwner(catalog.getId(), newOwner);
owner = catalogApi.getOwner(catalog.getId());
Checks.checkOwner(owner);
assertTrue(equal(owner.toBuilder().links(Collections.<Link>emptySet()).build(),
newOwner.toBuilder().user(newOwner.getUser().toBuilder().id(null).build()).build()),
String.format(OBJ_FIELD_UPDATABLE, CATALOG, "owner"));
assertTrue(
equal(owner.toBuilder().links(Collections.<Link> emptySet()).build(),
newOwner.toBuilder().user(newOwner.getUser().toBuilder().id(null).build()).build()),
String.format(OBJ_FIELD_UPDATABLE, CATALOG, "owner"));
} finally {
catalogApi.setOwner(catalog.getHref(), oldOwner);
owner = catalogApi.getOwner(catalog.getHref());
catalogApi.setOwner(catalog.getId(), oldOwner);
owner = catalogApi.getOwner(catalog.getId());
adminContext.getApi().getUserApi().deleteUser(newOwnerUser.getHref());
}
}
@Test(description = "PUT /admin/catalog/{id}", dependsOnMethods = { "testGetCatalogOwner" })
public void testUpdateCatalog() {
String oldName = catalog.getName();
String newName = "new "+oldName;
String newName = "new " + oldName;
String oldDescription = catalog.getDescription();
String newDescription = "new "+oldDescription;
// TODO: can we update/manage catalogItems directly like this? or does it just do a merge (like metadata)
// CatalogItems oldCatalogItems = catalog.getCatalogItems();
// CatalogItems newCatalogItems = CatalogItems.builder().build();
String newDescription = "new " + oldDescription;
// TODO: can we update/manage catalogItems directly like this? or does it just do a merge
// (like metadata)
// CatalogItems oldCatalogItems = catalog.getCatalogItems();
// CatalogItems newCatalogItems = CatalogItems.builder().build();
try {
catalog = catalog.toBuilder()
.name(newName)
.description(newDescription)
// .catalogItems(newCatalogItems)
.build();
catalog = catalogApi.updateCatalog(catalog.getHref(), catalog);
catalog = catalog.toBuilder().name(newName).description(newDescription)
// .catalogItems(newCatalogItems)
.build();
catalog = catalogApi.update(catalog.getId(), catalog);
assertTrue(equal(catalog.getName(), newName), String.format(OBJ_FIELD_UPDATABLE, CATALOG, "name"));
assertTrue(equal(catalog.getDescription(), newDescription),
String.format(OBJ_FIELD_UPDATABLE, CATALOG, "description"));
// assertTrue(equal(catalog.getCatalogItems(), newCatalogItems), String.format(OBJ_FIELD_UPDATABLE, CATALOG, "catalogItems"));
//TODO negative tests?
String.format(OBJ_FIELD_UPDATABLE, CATALOG, "description"));
// assertTrue(equal(catalog.getCatalogItems(), newCatalogItems),
// String.format(OBJ_FIELD_UPDATABLE, CATALOG, "catalogItems"));
// TODO negative tests?
Checks.checkAdminCatalog(catalog);
} finally {
catalog = catalog.toBuilder()
.name(oldName)
.description(oldDescription)
// .catalogItems(oldCatalogItems)
.build();
catalog = catalogApi.updateCatalog(catalog.getHref(), catalog);
catalog = catalog.toBuilder().name(oldName).description(oldDescription)
// .catalogItems(oldCatalogItems)
.build();
catalog = catalogApi.update(catalog.getId(), catalog);
}
}
// 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() {
assertNotNull(catalog, String.format(NOT_NULL_OBJ_FMT, "Catalog"));
assertTrue(!catalog.isPublished(), String.format(OBJ_FIELD_EQ,
CATALOG, "isPublished", false, catalog.isPublished()));
PublishCatalogParams params = PublishCatalogParams.builder()
.isPublished(true)
.build();
catalogApi.publishCatalog(catalog.getHref(), params);
catalog = catalogApi.getCatalog(catalog.getHref());
assertTrue(catalog.isPublished(), String.format(OBJ_FIELD_EQ,
CATALOG, "isPublished", true, catalog.isPublished()));
assertTrue(!catalog.isPublished(),
String.format(OBJ_FIELD_EQ, CATALOG, "isPublished", false, catalog.isPublished()));
PublishCatalogParams params = PublishCatalogParams.builder().isPublished(true).build();
catalogApi.publish(catalog.getId(), params);
catalog = catalogApi.get(catalog.getId());
assertTrue(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() {
// assertEquals(catalog.getCatalogItems().getCatalogItems().size(), 0,
// String.format(OBJ_FIELD_EMPTY_TO_DELETE, "Catalog", "CatalogItems",
// catalog.getCatalogItems().getCatalogItems().toString()));
AdminCatalog deleteCatalog = AdminCatalog.builder()
.name(name("Test Catalog "))
.description("created by testCreateCatalog()")
.build();
deleteCatalog = catalogApi.createCatalog(orgRef.getHref(), deleteCatalog);
catalogApi.deleteCatalog(deleteCatalog.getHref());
deleteCatalog = catalogApi.getCatalog(deleteCatalog.getHref());
// assertEquals(catalog.getCatalogItems().getCatalogItems().size(), 0,
// String.format(OBJ_FIELD_EMPTY_TO_DELETE, "Catalog", "CatalogItems",
// catalog.getCatalogItems().getCatalogItems().toString()));
AdminCatalog deleteCatalog = AdminCatalog.builder().name(name("Test Catalog "))
.description("created by testCreateCatalog()").build();
deleteCatalog = catalogApi.createCatalogInOrg(deleteCatalog, org.getId());
catalogApi.delete(deleteCatalog.getId());
deleteCatalog = catalogApi.get(deleteCatalog.getId());
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 {
if (metadataKey != null) {
try {
Task task = metadataApi.deleteMetadataEntry(adminVdcUri, metadataKey);
Task task = metadataApi.deleteEntry(adminVdcUri, metadataKey);
taskDoneEventually(task);
} catch (VCloudDirectorException e) {
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")
public void testGetMetadata() throws Exception {
Metadata metadata = metadataApi.getMetadata(adminVdcUri);
Metadata metadata = metadataApi.get(adminVdcUri);
Checks.checkMetadata(metadata);
}
@ -183,10 +183,10 @@ public class AdminVdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
.entry(MetadataEntry.builder().entry(metadataKey, metadataValue).build())
.build();
Task task = metadataApi.mergeMetadata(adminVdcUri, metadata);
Task task = metadataApi.merge(adminVdcUri, metadata);
assertTaskSucceeds(task);
MetadataValue modified = metadataApi.getMetadataValue(adminVdcUri, metadataKey);
MetadataValue modified = metadataApi.getValue(adminVdcUri, metadataKey);
Checks.checkMetadataValueFor("AdminVdc", modified, metadataValue);
Checks.checkMetadata(metadata);
}
@ -194,7 +194,7 @@ public class AdminVdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
// TODO insufficient permissions to test
@Test(description = "GET /admin/vdc/{id}/metadata/{key}", dependsOnMethods = { "testSetMetadata" }, enabled=false)
public void testGetMetadataValue() throws Exception {
MetadataValue retrievedMetadataValue = metadataApi.getMetadataValue(adminVdcUri, metadataKey);
MetadataValue retrievedMetadataValue = metadataApi.getValue(adminVdcUri, metadataKey);
Checks.checkMetadataValueFor("AdminVdc", retrievedMetadataValue, metadataValue);
}
@ -205,10 +205,10 @@ public class AdminVdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
metadataValue = name("value-");
MetadataValue newV = MetadataValue.builder().value(metadataValue).build();
Task task = metadataApi.setMetadata(adminVdcUri, metadataKey, newV);
Task task = metadataApi.putEntry(adminVdcUri, metadataKey, newV);
assertTaskSucceeds(task);
MetadataValue retrievedMetadataValue = metadataApi.getMetadataValue(adminVdcUri, metadataKey);
MetadataValue retrievedMetadataValue = metadataApi.getValue(adminVdcUri, metadataKey);
Checks.checkMetadataValueFor("AdminVdc", retrievedMetadataValue, metadataValue);
}
@ -217,11 +217,11 @@ public class AdminVdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
public void testDeleteMetadataValue() throws Exception {
// 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);
try {
metadataApi.getMetadataValue(adminVdcUri, metadataKey);
metadataApi.getValue(adminVdcUri, metadataKey);
fail("Retrieval of metadata value "+metadataKey+" should have fail after deletion");
} catch (VCloudDirectorException e) {
// success; should not be accessible

View File

@ -96,6 +96,6 @@ public class GroupApiExpectTest extends VCloudDirectorAdminApiExpectTest {
new VcloudHttpResponsePrimer()
.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 session;
protected String catalogId;
protected URI catalogURI;
protected String catalogUrn;
protected URI vAppTemplateURI;
protected URI mediaURI;
protected URI networkURI;
@ -233,12 +232,8 @@ public abstract class BaseVCloudDirectorApiLiveTest extends BaseContextLiveTest<
.build();
}
// TODO change properties to URI, not id
protected void initTestParametersFromPropertiesOrLazyDiscover() {
catalogId = Strings.emptyToNull(System.getProperty("test." + provider + ".catalog-id"));
if (catalogId != null) {
catalogURI = URI.create(endpoint + "/catalog/" + catalogId);
}
catalogUrn = Strings.emptyToNull(System.getProperty("test." + provider + ".catalog-id"));
String vAppTemplateId = Strings.emptyToNull(System.getProperty("test." + provider + ".vapptemplate-id"));
if (vAppTemplateId != null)
@ -274,10 +269,10 @@ public abstract class BaseVCloudDirectorApiLiveTest extends BaseContextLiveTest<
ReferencePredicates.<Link> typeEquals(VCloudDirectorMediaType.ORG_NETWORK)).getHref();
// FIXME the URI should be opaque
if (Strings.isNullOrEmpty(catalogId)) {
if (Strings.isNullOrEmpty(catalogUrn)) {
String uri = Iterables.find(thisOrg.getLinks(),
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.testng.annotations.BeforeGroups;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.Multimap;
import com.google.common.net.HttpHeaders;
import com.google.inject.Guice;
import com.jamesmurty.utils.XMLBuilder;
/**
* Base class for writing vCloud Director REST api expect tests.
@ -187,6 +189,7 @@ public abstract class BaseVCloudDirectorExpectTest<T> extends BaseRestApiExpectT
*
* @author danikov
*/
@Deprecated
public class VcloudHttpRequestPrimer {
private Multimap<String, String> headers = LinkedListMultimap.create();
private HttpRequest.Builder<?> builder = HttpRequest.builder();
@ -230,6 +233,7 @@ public abstract class BaseVCloudDirectorExpectTest<T> extends BaseRestApiExpectT
}
}
@Deprecated
protected class VcloudHttpResponsePrimer {
private HttpResponse.Builder<?> builder = HttpResponse.builder();
@ -252,4 +256,21 @@ public abstract class BaseVCloudDirectorExpectTest<T> extends BaseRestApiExpectT
public URI toAdminUri(URI uri) {
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);
}
}
}