diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogReference.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogReference.java index bb7ec86e9d..b7b74ac855 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogReference.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogReference.java @@ -6,8 +6,7 @@ import java.net.URI; import javax.xml.bind.annotation.XmlRootElement; - -@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "catalogReference") +@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "CatalogReference") public class CatalogReference extends ReferenceType { @SuppressWarnings("unchecked") @@ -91,7 +90,7 @@ public class CatalogReference extends ReferenceType { return true; if (o == null || getClass() != o.getClass()) return false; - Reference that = Reference.class.cast(o); + CatalogReference that = CatalogReference.class.cast(o); return super.equals(that); } } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Reference.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Reference.java index 33ecf0c234..1e3af67113 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Reference.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Reference.java @@ -85,11 +85,11 @@ public class Reference extends ReferenceType { } @Override - protected Builder fromReferenceType(ReferenceType in) { + public Builder fromReferenceType(ReferenceType in) { return Builder.class.cast(super.fromReferenceType(in)); } - protected Builder fromReference(Reference in) { + public Builder fromReference(Reference in) { return fromReferenceType(in); } } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/CatalogReferences.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/CatalogReferences.java index df3782c805..27f6f05c0a 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/CatalogReferences.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/CatalogReferences.java @@ -23,6 +23,7 @@ import static com.google.common.base.Preconditions.*; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; import java.net.URI; +import java.util.List; import java.util.Set; import javax.xml.bind.annotation.XmlRootElement; @@ -69,6 +70,24 @@ public class CatalogReferences extends QueryResultReferences { return queryResultReferences; } + /** + * @see QueryResultReferences#getReferences() + */ + @Override + public Builder references(List references) { + this.references = references; + return this; + } + + /** + * @see QueryResultReferences#getReferences() + */ + @Override + public Builder reference(CatalogReference reference) { + this.references.add(reference); + return this; + } + /** * @see Container#getName() */ @@ -96,6 +115,15 @@ public class CatalogReferences extends QueryResultReferences { return this; } + /** + * @see Container#getTotal() + */ + @Override + public Builder total(Long total) { + this.total = total; + return this; + } + /** * @see ResourceType#getHref() */ @@ -134,11 +162,11 @@ public class CatalogReferences extends QueryResultReferences { @Override public Builder fromQueryResultReferences(QueryResultReferences in) { - return Builder.class.cast(super.fromContainerType(in)); + return Builder.class.cast(super.fromQueryResultReferences(in)); } public Builder fromCatalogReferences(CatalogReferences in) { - return Builder.class.cast(fromQueryResultReferences(in).references(in.getReferences())); + return fromQueryResultReferences(in); } } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/ContainerType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/ContainerType.java index 21d64907c7..0602dea39b 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/ContainerType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/ContainerType.java @@ -26,6 +26,7 @@ import java.net.URI; import java.util.Set; import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlType; import org.jclouds.vcloud.director.v1_5.domain.Link; import org.jclouds.vcloud.director.v1_5.domain.ResourceType; diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultRecordType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultRecordType.java index c2d0537704..4648ee0047 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultRecordType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultRecordType.java @@ -52,10 +52,7 @@ import com.google.common.collect.Sets; * @author grkvlt@apache.org */ @XmlAccessorType(XmlAccessType.FIELD) -@XmlSeeAlso({ - QueryResultCatalogRecord.class, - QueryResultNetworkRecord.class, -}) +@XmlSeeAlso({ QueryResultCatalogRecord.class, QueryResultNetworkRecord.class }) public class QueryResultRecordType> { public static > Builder builder() { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultReferences.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultReferences.java index af482325ea..869378bc1c 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultReferences.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultReferences.java @@ -21,15 +21,16 @@ package org.jclouds.vcloud.director.v1_5.domain.query; import static com.google.common.base.Objects.*; import static com.google.common.base.Preconditions.*; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; import java.net.URI; import java.util.List; import java.util.Set; import javax.xml.bind.annotation.XmlElementRef; +import javax.xml.bind.annotation.XmlElementRefs; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.jclouds.vcloud.director.v1_5.domain.CatalogReference; import org.jclouds.vcloud.director.v1_5.domain.Link; import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; @@ -120,6 +121,15 @@ public class QueryResultReferences> extends Container return this; } + /** + * @see Container#getTotal() + */ + @Override + public Builder total(Long total) { + this.total = total; + return this; + } + /** * @see ResourceType#getHref() */ @@ -174,7 +184,10 @@ public class QueryResultReferences> extends Container super(href); } - @XmlElementRef(name = "Reference", namespace = VCLOUD_1_5_NS) + // NOTE add other types as they are used. probably not the best way to do this. + @XmlElementRefs({ + @XmlElementRef(type = CatalogReference.class) + }) protected List references; /** diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryAsyncClient.java index 8b99bf4701..cebd6eac94 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryAsyncClient.java @@ -19,15 +19,17 @@ package org.jclouds.vcloud.director.v1_5.features; import javax.ws.rs.Consumes; -import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.QueryParam; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.JAXBResponseParser; +import org.jclouds.rest.annotations.QueryParams; import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.SkipEncoding; import org.jclouds.vcloud.director.v1_5.domain.query.CatalogReferences; +import org.jclouds.vcloud.director.v1_5.domain.query.QueryList; import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecords; import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx; @@ -39,11 +41,27 @@ import com.google.common.util.concurrent.ListenableFuture; * @author grkvlt@apache.org */ @RequestFilters(AddVCloudAuthorizationToRequest.class) +@SkipEncoding({ '=' }) +@SuppressWarnings("rawtypes") public interface QueryAsyncClient { /** * REST API General queries handler. */ + @GET + @Path("/query") + @Consumes + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture queryList(); + + @GET + @Path("/query") + @Consumes + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture queryAll(@QueryParam("type") String type); + @GET @Path("/query") @Consumes @@ -62,6 +80,13 @@ public interface QueryAsyncClient { /** * Retrieves a list of Catalogs by using REST API general QueryHandler. */ + @GET + @Path("/catalogs/query") + @Consumes + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture catalogsQueryAll(); + @GET @Path("/catalogs/query") @Consumes @@ -75,13 +100,20 @@ public interface QueryAsyncClient { @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture catalogsQuery(@QueryParam("page") Integer page, @QueryParam("pageSize") Integer pageSize, - @QueryParam("format") String format, @QueryParam("filter") String filter); + @QueryParam("filter") String filter); @GET @Path("/catalogs/query") @Consumes - @DefaultValue("references") - @QueryParam("format") + @QueryParams(keys = { "format" }, values = { "references" }) + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture catalogReferencesQueryAll(); + + @GET + @Path("/catalogs/query") + @Consumes + @QueryParams(keys = { "format" }, values = { "references" }) @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture catalogReferencesQuery(@QueryParam("filter") String filter); @@ -89,8 +121,7 @@ public interface QueryAsyncClient { @GET @Path("/catalogs/query") @Consumes - @DefaultValue("references") - @QueryParam("format") + @QueryParams(keys = { "format" }, values = { "references" }) @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture catalogReferencesQuery(@QueryParam("page") Integer page, @QueryParam("pageSize") Integer pageSize, diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryClient.java index 39bca1b3f0..9df4ffa54a 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryClient.java @@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; import org.jclouds.vcloud.director.v1_5.domain.query.CatalogReferences; +import org.jclouds.vcloud.director.v1_5.domain.query.QueryList; import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecords; /** @@ -40,6 +41,10 @@ public interface QueryClient { * GET /query * */ + QueryList queryList(); + + QueryResultRecords queryAll(String type); + QueryResultRecords query(String type, String filter); QueryResultRecords query(Integer page, Integer pageSize, String format, String type, String filter); @@ -55,9 +60,13 @@ public interface QueryClient { * GET /catalogs/query * */ + QueryResultRecords catalogsQueryAll(); + QueryResultRecords catalogsQuery(String filter); - QueryResultRecords catalogsQuery(Integer page, Integer pageSize, String format, String filter); + QueryResultRecords catalogsQuery(Integer page, Integer pageSize, String filter); + + CatalogReferences catalogReferencesQueryAll(); CatalogReferences catalogReferencesQuery(String filter); diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java index 7f39cd9484..f3d4084264 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -121,9 +121,9 @@ public class Checks { public static void checkLink(Link link) { // Check required fields assertNotNull(link.getRel(), "The Rel attribute of a Link must be set"); - assertTrue(Link.Rel.ALL.contains(link.getRel()), - String.format("The Rel attribute (%s) of a Link must be one of the allowed list - %s", - link.getRel(), Iterables.toString(Link.Rel.ALL))); + // XXX choose one + assertTrue(Link.Rel.ALL.contains(link.getRel()), String.format("The Rel attribute of a Link must be from the allowed list: %s", Iterables.toString(Link.Rel.ALL))); + assertTrue(Link.Rel.ALL.contains(link.getRel()), String.format("The Rel attribute of a Link cannot be '%s'", link.getRel())); // Check parent type checkReferenceType(link); @@ -132,9 +132,9 @@ public class Checks { public static void checkTask(Task task) { // Check required fields assertNotNull(task.getStatus(), "The Status attribute of a Task must be set"); - assertTrue(Task.Status.ALL.contains(task.getStatus().toString()), - String.format("The Status of a Task (%s) must be one of the allowed list - %s", - task.getStatus().toString(), Iterables.toString(Task.Status.ALL))); + // XXX choose one + assertTrue(Task.Status.ALL.contains(task.getStatus()), String.format("The Status of a Task must be from the allowed list: %s", Iterables.toString(Task.Status.ALL))); + assertTrue(Task.Status.ALL.contains(task.getStatus()), String.format("The Status of a Task cannot be '%s'", task.getStatus())); // Check optional fields // NOTE operation cannot be checked @@ -174,6 +174,24 @@ public class Checks { checkEntityType(file); } + public static void checkMetadata(Metadata metadata) { + Set metadataEntries = metadata.getMetadataEntries(); + if (metadataEntries != null && !metadataEntries.isEmpty()) { + for (MetadataEntry metadataEntry : metadataEntries) checkMetadataEntry(metadataEntry); + } + + // Check parent type + checkResourceType(metadata); + } + + public static void checkMetadataEntry(MetadataEntry metadataEntry) {+ // Check required fields + assertNotNull(metadataEntry.getKey(), "The Key attribute of a MetadataEntry must be set"); + assertNotNull(metadataEntry.getValue(), "The Value attribute of a MetadataEntry must be set"); + + // Check parent type + checkResourceType(metadataEntry); + } + public static void checkProgress(Integer progress) { assertTrue(progress >= 0 && progress <= 100, "The Progress attribute must be between 0 and 100"); } @@ -188,6 +206,27 @@ public class Checks { // NOTE stackTrace cannot be checked } + public static void checkCatalog(Catalog catalog) { + // Check optional elements/attributes + Entity owner = catalog.getOwner(); + if (owner != null) checkEntityType(owner); + CatalogItems catalogItems = catalog.getCatalogItems(); + if (catalogItems != null) { + for (Reference catalogItemReference : catalogItems.getCatalogItems()) { + checkReferenceType(catalogItemReference); + } + } + // NOTE isPublished cannot be checked + + // Check parent type + checkEntityType(catalog); + } + + public static void checkCatalogItem(CatalogItem catalogItem) { + // Check parent type + checkEntityType(catalogItem); + } + public static void checkImageType(String imageType) { assertTrue(Media.ImageType.ALL.contains(imageType), "The Image type of a Media must be one of the allowed list"); diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java index 819d5861c7..3a19a91f3c 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java @@ -18,18 +18,26 @@ */ package org.jclouds.vcloud.director.v1_5.features; -import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkTask; -import static org.testng.Assert.assertFalse; +import static org.jclouds.vcloud.director.v1_5.domain.Checks.*; +import static org.testng.Assert.*; -import java.net.URI; - -import org.jclouds.vcloud.director.v1_5.domain.OrgList; +import org.jclouds.predicates.RetryablePredicate; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorException; +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.domain.MetadataEntry; +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.ReferenceType; import org.jclouds.vcloud.director.v1_5.domain.Task; -import org.jclouds.vcloud.director.v1_5.domain.TasksList; +import org.jclouds.vcloud.director.v1_5.domain.query.CatalogReferences; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest; +import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; import com.google.common.collect.Iterables; /** @@ -40,23 +48,146 @@ import com.google.common.collect.Iterables; @Test(groups = { "live", "apitests" }, testName = "CatalogClientLiveTest") public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest { + private static final String CATALOG_NAME = "QunyingTestCatalog"; // TODO add as test configuration property + /* * Convenience references to API clients. */ - - private final CatalogClient catalogClient = context.getApi().getCatalogClient(); - private final QueryClient queryClient = context.getApi().getQueryClient(); - + + private CatalogClient catalogClient; + private QueryClient queryClient; + /* * Shared state between dependant tests. */ - - private Reference catalogRef; + + private ReferenceType catalogRef; + private ReferenceType catalogItemRef; + private ReferenceType newCatalogItemRef; private Catalog catalog; - + private CatalogItem catalogItem; + private CatalogItem newCatalogItem; + private Metadata catalogMetadata; + + @BeforeGroups(groups = { "live" }) + public void setupClients() { + catalogClient = context.getApi().getCatalogClient(); + queryClient = context.getApi().getQueryClient(); + } + @Test(testName = "GET /catalog/{id}") - public void testGetTaskList() { - catalogRef = null; + public void testGetCatalog() { + CatalogReferences catalogReferences = queryClient.catalogReferencesQuery(String.format("name==%s", CATALOG_NAME)); + assertEquals(Iterables.size(catalogReferences.getReferences()), 1, String.format("The %s Catalog must exist", CATALOG_NAME)); + catalogRef = Iterables.getOnlyElement(catalogReferences.getReferences()); catalog = catalogClient.getCatalog(catalogRef); } + + @Test(testName = "GET /catalogItem/{id}", dependsOnMethods = { "testGetCatalog" }) + public void testGetCatalogItem() { + assertFalse(Iterables.isEmpty(catalog.getCatalogItems().getCatalogItems())); + catalogItemRef = Iterables.get(catalog.getCatalogItems().getCatalogItems(), 0); + catalogItem = catalogClient.getCatalogItem(catalogItemRef); + checkCatalogItem(catalogItem); + } + + // NOTE for this test to work, we need to be able to upload a new vAppTemplate to a vDC first + // NOTE we could do this with a test environment property -Dtest.vcloud-director.vappTemplateId=vapptemplate-abcd + @Test(testName = "POST /catalog/{id}/catalogItems", dependsOnMethods = { "testGetCatalogItem" }, enabled = false) + public void testAddCatalogItem() { + CatalogItem editedCatalogItem = CatalogItem.builder() + .name("newitem") + .description("New Item") + // XXX org.jclouds.vcloud.director.v1_5.VCloudDirectorException: Error: The VCD entity image already exists. + // .entity(Reference.builder().href(catalogItem.getEntity().getHref()).build()) + // XXX org.jclouds.vcloud.director.v1_5.VCloudDirectorException: Error: The VCD entity ubuntu10 already exists. + // .entity(Reference.builder().href(URI.create(endpoint + "/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9")).build()) + .build(); + newCatalogItem = catalogClient.addCatalogItem(catalogRef, editedCatalogItem); + checkCatalogItem(newCatalogItem); + assertEquals(newCatalogItem.getName(), "newitem"); + } + + @Test(testName = "PUT /catalogItem/{id}", dependsOnMethods = { "testAddCatalogItem" }, enabled = false) + public void testUpdateCatalogItem() { + Catalog catalog = catalogClient.getCatalog(catalogRef); + newCatalogItemRef = Iterables.find(catalog.getCatalogItems().getCatalogItems(), new Predicate() { + @Override + public boolean apply(Reference input) { + return input.getHref().equals(newCatalogItem.getHref()); + } + }); + CatalogItem updatedCatalogItem = CatalogItem.builder().fromCatalogItem(catalogItem).name("UPDATEDNAME").build(); + newCatalogItem = catalogClient.updateCatalogItem(catalogRef, updatedCatalogItem); + checkCatalogItem(newCatalogItem); + assertEquals(newCatalogItem.getName(), "UPDATEDNAME"); + } + + @Test(testName = "DELETE /catalogItem/{id}", dependsOnMethods = { "testUpdateCatalogItem" }, enabled = false) + public void testDeleteCatalogItem() { + catalogClient.deleteCatalogItem(newCatalogItemRef); + try { + catalogClient.getCatalogItem(newCatalogItemRef); + fail("The CatalogItem should have been deleted"); + } catch (VCloudDirectorException vcde) { + checkError(vcde.getError()); + assertEquals(vcde.getError().getMajorErrorCode(), Integer.valueOf(403), "The majorErrorCode should be 403 since the item has been deleted"); + } + } + + // NOTE for this test to work, we need to be able to create metadata on a Catalog, specifically { "KEY", "VALUE" } + @Test(testName = "GET /catalog/{id}/metadata", dependsOnMethods = { "testGetCatalog" }, enabled = false) + public void testGetCatalogMetadata() { + catalogMetadata = catalogClient.getCatalogMetadata(catalogRef); + checkMetadata(catalogMetadata); + } + + // NOTE for this test to work, we need to be able to create metadata on a Catalog, specifically { "KEY", "VALUE" } + @Test(testName = "GET /catalog/{id}/metadata/{key}", dependsOnMethods = { "testGetCatalogMetadata" }, enabled = false) + public void testGetCatalogMetadataEntry() { + MetadataEntry existingMetadataEntry = Iterables.find(catalogMetadata.getMetadataEntries(), new Predicate() { + @Override + public boolean apply(MetadataEntry input) { + return input.getKey().equals("KEY"); + } + }); + MetadataEntry metadataEntry = catalogClient.getCatalogMetadataEntry(catalogRef, "KEY"); + assertEquals(existingMetadataEntry.getValue(), metadataEntry.getValue()); + checkMetadataEntry(metadataEntry); + } + + @Test(testName = "POST /catalogItem/{id}/metadata", dependsOnMethods = { "testGetCatalogItem" }) + public void testMergeCatalogItemMetadata() { + Metadata newMetadata = Metadata.builder() + .entry(MetadataEntry.builder().entry("KEY", "VALUE").build()) + .build(); + + Task task = catalogClient.mergeCatalogItemMetadata(catalogItemRef, newMetadata); + // TODO wait until task no longer running... + } + + @Test(testName = "GET /catalogItem/{id}/metadata", dependsOnMethods = { "testMergeCatalogItemMetadata" }) + public void testGetCatalogItemMetadata() { + Metadata metadata = catalogClient.getCatalogItemMetadata(catalogItemRef); + } + + // XXX org.jclouds.vcloud.director.v1_5.VCloudDirectorException: Error: The access to the resource metadata_item with id KEY is forbidden + @Test(testName = "GET /catalog/{id}/metadata/{key}", dependsOnMethods = { "testMergeCatalogItemMetadata" }, enabled = false) + public void testGetCatalogItemMetadataEntry() { + MetadataEntry metadataEntry = catalogClient.getCatalogItemMetadataEntry(catalogItemRef, "KEY"); + } + + @Test(testName = "PUT /catalog/{id}/metadata/{key}", dependsOnMethods = { "testMergeCatalogItemMetadata" }) + public void testSetCatalogItemMetadataEntry() { + MetadataValue newMetadataValue = MetadataValue.builder().value("NEW").build(); + + Task task = catalogClient.setCatalogItemMetadataEntry(catalogItemRef, "KEY", newMetadataValue); + // TODO wait until task no longer running... + } + + @Test(testName = "DELETE /catalog/{id}/metadata/{key}", dependsOnMethods = { "testMergeCatalogItemMetadata" }) + public void testDeleteCatalogItemMetadataEntry() { + Task task = catalogClient.deleteCatalogItemMetadataEntry(catalogItemRef, "KEY"); + // TODO wait until task no longer running... + } } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientLiveTest.java index 8a4392d78b..5173dee544 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientLiveTest.java @@ -18,8 +18,7 @@ */ package org.jclouds.vcloud.director.v1_5.features; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.fail; +import static org.testng.Assert.*; import java.net.URI; @@ -30,15 +29,27 @@ import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; import org.jclouds.vcloud.director.v1_5.domain.OrgNetwork; import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest; +import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; /** - * Tests behavior of {@code NetworkClient} + * Tests behavior of {@link NetworkClient} * * @author danikov */ @Test(groups = { "live", "apitests" }, testName = "NetworkClientLiveTest") public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest { + + /* + * Convenience references to API clients. + */ + + private NetworkClient networkClient; + + @BeforeGroups(groups = { "live" }) + public void setupClients() { + networkClient = context.getApi().getNetworkClient(); + } // @Before populate String networkId = "55a677cf-ab3f-48ae-b880-fab90421980c"; @@ -49,7 +60,7 @@ public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest { Reference networkRef = Reference.builder() .href(URI.create(endpoint + "/network/"+networkId)).build(); - OrgNetwork network = context.getApi().getNetworkClient().getNetwork(networkRef); + OrgNetwork network = networkClient.getNetwork(networkRef); //TODO assert network is valid } @@ -66,7 +77,7 @@ public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest { .build(); try { - context.getApi().getNetworkClient().getNetwork(networkRef); + networkClient.getNetwork(networkRef); fail("Should give HTTP 400 error"); } catch (VCloudDirectorException vde) { assertEquals(vde.getError(), expected); @@ -87,7 +98,7 @@ public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest { .build(); try { - context.getApi().getNetworkClient().getNetwork(networkRef); + networkClient.getNetwork(networkRef); fail("Should give HTTP 403 error"); } catch (VCloudDirectorException vde) { assertEquals(vde.getError(), expected); @@ -108,7 +119,7 @@ public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest { .build(); try { - context.getApi().getNetworkClient().getNetwork(networkRef); + networkClient.getNetwork(networkRef); fail("Should give HTTP 403 error"); } catch (VCloudDirectorException vde) { assertEquals(vde.getError(), expected); @@ -137,7 +148,7 @@ public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest { Reference networkRef = Reference.builder() .href(URI.create(endpoint + "/network/"+networkId)).build(); - MetadataEntry expected = context.getApi().getNetworkClient().getMetadataEntry(networkRef, metadataKey); + MetadataEntry expected = networkClient.getMetadataEntry(networkRef, metadataKey); // assert metadataEntry is valid } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientLiveTest.java index 5d493ea9fc..7973a175ae 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientLiveTest.java @@ -29,6 +29,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Org; import org.jclouds.vcloud.director.v1_5.domain.OrgList; import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest; +import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; import com.google.common.collect.Iterables; @@ -45,7 +46,12 @@ public class OrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { * Convenience references to API clients. */ - private final OrgClient orgClient = context.getApi().getOrgClient(); + private OrgClient orgClient; + + @BeforeGroups(groups = { "live" }) + public void setupClients() { + orgClient = context.getApi().getOrgClient(); + } /* * Shared state between dependant tests. diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientExpectTest.java index 50f1b0cf8c..790fc7ce08 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientExpectTest.java @@ -26,7 +26,9 @@ import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.jclouds.vcloud.director.v1_5.domain.CatalogReference; import org.jclouds.vcloud.director.v1_5.domain.Link; +import org.jclouds.vcloud.director.v1_5.domain.query.CatalogReferences; import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultCatalogRecord; import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecords; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; @@ -43,10 +45,10 @@ import com.google.common.collect.ImmutableMultimap; public class QueryClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { @Test - public void testQueryCatalogNoParam() { + public void testQueryAllCatalogs() { HttpRequest queryRequest = HttpRequest.builder() .method("GET") - .endpoint(URI.create(endpoint + "/catalogs/query?filter=")) + .endpoint(URI.create(endpoint + "/catalogs/query")) .headers(ImmutableMultimap. builder() .put("Accept", "*/*") .put("x-vcloud-authorization", token) @@ -115,7 +117,71 @@ public class QueryClientExpectTest extends BaseVCloudDirectorRestClientExpectTes .build()) .build(); - assertEquals(client.getQueryClient().catalogsQuery(""), expected); + assertEquals(client.getQueryClient().catalogsQueryAll(), expected); + } + + @Test + public void testQueryAllCatalogReferences() { + HttpRequest queryRequest = HttpRequest.builder() + .method("GET") + .endpoint(URI.create(endpoint + "/catalogs/query?format=references")) + .headers(ImmutableMultimap. builder() + .put("Accept", "*/*") + .put("x-vcloud-authorization", token) + .build()) + .build(); + + HttpResponse queryResponse= HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResourceWithContentType("/query/allCatalogReferences.xml", VCloudDirectorMediaType.QUERY_RESULT_RECORDS + ";version=1.5")) + .build(); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, queryRequest, queryResponse); + + CatalogReferences expected = CatalogReferences.builder() + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalogs/query?page=1&pageSize=25&format=references")) + .type("application/vnd.vmware.vcloud.query.references+xml") + .name("catalog") + .page(1) + .pageSize(25) + .total(4L) + .link(Link.builder() + .rel("alternate") + .type("application/vnd.vmware.vcloud.query.records+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalogs/query?page=1&pageSize=25&format=records")) + .build()) + .link(Link.builder() + .rel("alternate") + .type("application/vnd.vmware.vcloud.query.idrecords+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalogs/query?page=1&pageSize=25&format=idrecords")) + .build()) + .reference(CatalogReference.builder() + .type("application/vnd.vmware.vcloud.catalog+xml") + .name("QunyingTestCatalog") + .id("urn:vcloud:catalog:7212e451-76e1-4631-b2de-ba1dfd8080e4") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) + .build()) + .reference(CatalogReference.builder() + .type("application/vnd.vmware.vcloud.catalog+xml") + .name("Public") + .id("urn:vcloud:catalog:9e08c2f6-077a-42ce-bece-d5332e2ebb5c") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c")) + .build()) + .reference(CatalogReference.builder() + .type("application/vnd.vmware.vcloud.catalog+xml") + .name("dantest") + .id("urn:vcloud:catalog:b542aff4-9f97-4f51-a126-4330fbf62f02") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/b542aff4-9f97-4f51-a126-4330fbf62f02")) + .build()) + .reference(CatalogReference.builder() + .type("application/vnd.vmware.vcloud.catalog+xml") + .name("test") + .id("urn:vcloud:catalog:b7289d54-4ca4-497f-9a93-2d4afc97e3da") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/b7289d54-4ca4-497f-9a93-2d4afc97e3da")) + .build()) + .build(); + + assertEquals(client.getQueryClient().catalogReferencesQueryAll(), expected); } } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientLiveTest.java index f90f927e2a..68a4a5e9a9 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientLiveTest.java @@ -18,23 +18,18 @@ */ package org.jclouds.vcloud.director.v1_5.features; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.*; -import static org.jclouds.vcloud.director.v1_5.domain.Checks.*; import static org.testng.Assert.*; import java.net.URI; -import org.jclouds.vcloud.director.v1_5.domain.Metadata; -import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; import org.jclouds.vcloud.director.v1_5.domain.OrgList; 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.TasksList; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest; +import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; -import com.google.common.collect.Iterables; - /** * Tests live behavior of {@link QueryClient}. * @@ -47,8 +42,14 @@ public class QueryClientLiveTest extends BaseVCloudDirectorClientLiveTest { * Convenience references to API clients. */ - private final CatalogClient catalogClient = context.getApi().getCatalogClient(); - private final QueryClient queryClient = context.getApi().getQueryClient(); + private CatalogClient catalogClient; + private QueryClient queryClient; + + @BeforeGroups(groups = { "live" }) + public void setupClients() { + catalogClient = context.getApi().getCatalogClient(); + queryClient = context.getApi().getQueryClient(); + } /* * Shared state between dependant tests. diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientLiveTest.java index 622020fb27..7959c075d2 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientLiveTest.java @@ -18,7 +18,6 @@ */ package org.jclouds.vcloud.director.v1_5.features; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.*; import static org.jclouds.vcloud.director.v1_5.domain.Checks.*; import static org.testng.Assert.*; @@ -29,6 +28,7 @@ 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.TasksList; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest; +import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; import com.google.common.collect.Iterables; @@ -45,8 +45,14 @@ public class TaskClientLiveTest extends BaseVCloudDirectorClientLiveTest { * Convenience references to API clients. */ - private final OrgClient orgClient = context.getApi().getOrgClient(); - private final TaskClient taskClient = context.getApi().getTaskClient(); + private OrgClient orgClient; + private TaskClient taskClient; + + @BeforeGroups(groups = { "live" }) + public void setupClients() { + orgClient = context.getApi().getOrgClient(); + taskClient = context.getApi().getTaskClient(); + } /* * Shared state between dependant tests. diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java index 249f9707ad..5bd2cb9c4b 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java @@ -62,4 +62,3 @@ public class BaseVCloudDirectorClientLiveTest extends BaseVersionedServiceLiveTe } } - diff --git a/labs/vcloud-director/src/test/resources/query/allCatalogReferences.xml b/labs/vcloud-director/src/test/resources/query/allCatalogReferences.xml new file mode 100644 index 0000000000..1f1cd5da90 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/query/allCatalogReferences.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/labs/vcloud-director/src/test/resources/query/queryList.xml b/labs/vcloud-director/src/test/resources/query/queryList.xml new file mode 100644 index 0000000000..7d3c2f01c9 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/query/queryList.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +