diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminCatalogAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminCatalogAsyncClient.java index b27edc92f2..8a79790c0a 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminCatalogAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminCatalogAsyncClient.java @@ -21,6 +21,7 @@ package org.jclouds.vcloud.director.v1_5.features; import java.net.URI; import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.PUT; import javax.ws.rs.Path; @@ -67,6 +68,15 @@ public interface AdminCatalogAsyncClient { ListenableFuture updateCatalog(@EndpointParam URI catalogRef, @BinderParam(BindToXMLPayload.class) AdminCatalog catalog); + /** + * @see AdminClient#deleteCatalog(URI) + */ + @DELETE + @Consumes + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture deleteCatalog(@EndpointParam URI catalogRef); + /** * @see AdminClient#getOwner(URI) */ diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminCatalogClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminCatalogClient.java index 5a3673aaca..f15fa2375f 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminCatalogClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminCatalogClient.java @@ -58,6 +58,15 @@ public interface AdminCatalogClient { */ AdminCatalog updateCatalog(URI catalogRef, AdminCatalog catalog); + /** + * Deletes a catalog. The catalog could be deleted if it is either published or unpublished. + * + *
+    * DELETE /admin/catalog/{id}
+    * 
+ */ + void deleteCatalog(URI catalogRef); + /** * Retrieves the owner of a catalog. * diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminCatalogClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminCatalogClientExpectTest.java index ae0d374bb6..6d66f34e8a 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminCatalogClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminCatalogClientExpectTest.java @@ -118,6 +118,19 @@ public class AdminCatalogClientExpectTest extends BaseVCloudDirectorRestClientEx client.getAdminCatalogClient().setOwner(catalogRef.getURI(), newOwner); } + @Test + public void testDeleteCatalog() { + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("DELETE", "/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4") + .acceptAnyMedia() + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .httpResponseBuilder().statusCode(204).build()); + + client.getAdminCatalogClient().deleteCatalog(catalogRef.getURI()); + } + public static final AdminCatalog catalog() { return AdminCatalog.builder() .name("QunyingTestCatalog") diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminCatalogClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminCatalogClientLiveTest.java index af2a1c2b74..747b243d06 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminCatalogClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminCatalogClientLiveTest.java @@ -19,18 +19,21 @@ package org.jclouds.vcloud.director.v1_5.features; import static com.google.common.base.Objects.equal; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.GETTER_RETURNS_SAME_OBJ; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_REQ; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_DEL; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_UPDATABLE; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.REF_REQ_LIVE; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; import java.net.URI; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorException; 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.Error; 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.ReferenceType; @@ -145,4 +148,30 @@ public class AdminCatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest catalog = catalogClient.updateCatalog(catalog.getURI(), catalog); } } + + @Test(testName = "DELETE /admin/catalog/{id}", + dependsOnMethods = { "testUpdateCatalog" }, enabled = false ) + public void testDeleteCatalog() { + catalogClient.deleteCatalog(catalogRef.getURI()); + + Error expected = Error.builder() + .message("???") + .majorErrorCode(403) + .minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN") + .build(); + + try { + catalog = catalogClient.getCatalog(catalogRef.getURI()); + fail("Should give HTTP 403 error"); + } catch (VCloudDirectorException vde) { + assertEquals(vde.getError(), expected); + catalog = null; + } catch (Exception e) { + fail("Should have thrown a VCloudDirectorException"); + } + + if (catalog != null) { // guard against NPE on the .toStrings + assertNull(catalog, String.format(OBJ_DEL, CATALOG, catalog.toString())); + } + } }