diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientLiveTest.java index 5cd6d27157..43dad42c11 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientLiveTest.java @@ -65,6 +65,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.Vdc; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest; +import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -87,14 +88,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { */ protected VdcClient vdcClient; protected MediaClient mediaClient; - - @Override - @BeforeClass(alwaysRun = true) - public void setupRequiredClients() { - vdcClient = context.getApi().getVdcClient(); - mediaClient = context.getApi().getMediaClient(); - } - + /* * Shared state between dependent tests. */ @@ -103,6 +97,23 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { private Metadata metadata; private MetadataValue metadataValue; private String metadataEntryValue = "value"; + + @Override + @BeforeClass(alwaysRun = true) + public void setupRequiredClients() { + vdcClient = context.getApi().getVdcClient(); + mediaClient = context.getApi().getMediaClient(); + } + + @AfterClass(alwaysRun = true) + protected void tidyUp() { + if (media != null) { + assertTaskSucceeds(mediaClient.deleteMedia(media.getHref())); + } + if (oldMedia != null) { + assertTaskSucceeds(mediaClient.deleteMedia(oldMedia.getHref())); + } + } @Test(description = "POST /vdc/{id}/media") public void testCreateMedia() throws URISyntaxException { @@ -419,5 +430,8 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { deleteMedia = mediaClient.deleteMedia(oldMedia.getHref()); Checks.checkTask(deleteMedia); + assertTrue(retryTaskSuccess.apply(deleteMedia), + String.format(TASK_COMPLETE_TIMELY, "deleteMedia")); + oldMedia = null; } } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppTemplateClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppTemplateClientLiveTest.java index 081e484d47..1f1b2a9982 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppTemplateClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppTemplateClientLiveTest.java @@ -65,6 +65,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.domain.VAppTemplate; import org.jclouds.vcloud.director.v1_5.domain.ovf.Envelope; import org.jclouds.vcloud.director.v1_5.domain.ovf.NetworkSection; +import org.testng.annotations.AfterClass; import org.testng.annotations.Test; import com.google.common.base.Function; @@ -81,6 +82,16 @@ import com.google.common.collect.Iterables; @Test(groups = { "live", "user", "vapptemplate" }, singleThreaded = true, testName = "VAppTemplateClientLiveTest") public class VAppTemplateClientLiveTest extends AbstractVAppClientLiveTest { + private String key; + private String val; + + @AfterClass(alwaysRun = true) + protected void tidyUp() { + if (key != null) { + assertTaskSucceeds(vAppTemplateClient.getMetadataClient().deleteMetadataEntry(vAppTemplateURI, key)); + } + } + // FIXME cloneVAppTemplate is giving back 500 error private VAppTemplate cloneVAppTemplate(boolean waitForTask) throws Exception { CloneVAppTemplateParams cloneVAppTemplateParams = CloneVAppTemplateParams.builder() @@ -228,13 +239,11 @@ public class VAppTemplateClientLiveTest extends AbstractVAppClientLiveTest { @Test(description = "POST /vAppTemplate/{id}/metadata", dependsOnMethods = { "testGetVAppTemplate" }) public void testEditMetadata() { - // TODO Cleanup after ourselves.. - Metadata oldMetadata = vAppTemplateClient.getMetadataClient().getMetadata(vAppTemplateURI); Map oldMetadataMap = metadataToMap(oldMetadata); - String key = name("key-"); - String val = name("value-"); + key = name("key-"); + val = name("value-"); MetadataEntry metadataEntry = MetadataEntry.builder().entry(key, val).build(); Metadata metadata = Metadata.builder().fromMetadata(oldMetadata).entry(metadataEntry).build(); @@ -251,10 +260,7 @@ public class VAppTemplateClientLiveTest extends AbstractVAppClientLiveTest { @Test(description = "PUT /vAppTemplate/{id}/metadata/{key}", dependsOnMethods = { "testEditMetadata" }) public void testEditMetadataValue() { - // TODO Cleanup after ourselves.. - - String key = name("key-"); - String val = name("value-"); + val = "new"+val; MetadataValue metadataValue = MetadataValue.builder().value(val).build(); final Task task = vAppTemplateClient.getMetadataClient().setMetadata(vAppTemplateURI, key, metadataValue); @@ -266,19 +272,12 @@ public class VAppTemplateClientLiveTest extends AbstractVAppClientLiveTest { @Test(description = "DELETE /vAppTemplate/{id}/metadata/{key}", dependsOnMethods = { "testGetMetadataValue" }) public void testDeleteVAppTemplateMetadataValue() { - // First store a value - String key = name("key-"); - MetadataValue metadataValue = MetadataValue.builder().value("myval").build(); - final Task task = vAppTemplateClient.getMetadataClient().setMetadata(vAppTemplateURI, key, metadataValue); - retryTaskSuccess.apply(task); - - // Then delete the entry final Task deletionTask = vAppTemplateClient.getMetadataClient().deleteMetadataEntry(vAppTemplateURI, key); retryTaskSuccess.apply(deletionTask); - // Then confirm the entry is not there Metadata newMetadata = vAppTemplateClient.getMetadataClient().getMetadata(vAppTemplateURI); checkMetadataKeyAbsentFor("vAppTemplate", newMetadata, key); + key = null; } @Test(description = "PUT /vAppTemplate/{id}/guestCustomizationSection") diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VdcClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VdcClientLiveTest.java index 89b90fe777..6724b662fa 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VdcClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VdcClientLiveTest.java @@ -85,6 +85,16 @@ public class VdcClientLiveTest extends BaseVCloudDirectorClientLiveTest { private VAppTemplate uploadedVAppTemplate; private boolean metadataSet = false; + @Override + @BeforeClass(alwaysRun = true) + public void setupRequiredClients() { + vdcClient = context.getApi().getVdcClient(); + vappTemplateClient = context.getApi().getVAppTemplateClient(); + vappClient = context.getApi().getVAppClient(); + + assertNotNull(vdcURI, String.format(REF_REQ_LIVE, VDC)); + } + @AfterClass(alwaysRun = true) public void cleanUp() throws Exception { if (clonedVAppTemplate != null) { @@ -111,16 +121,6 @@ public class VdcClientLiveTest extends BaseVCloudDirectorClientLiveTest { .deleteMetadataEntry(toAdminUri(vdcURI), "key"); } } - - @Override - @BeforeClass(alwaysRun = true) - public void setupRequiredClients() { - vdcClient = context.getApi().getVdcClient(); - vappTemplateClient = context.getApi().getVAppTemplateClient(); - vappClient = context.getApi().getVAppClient(); - - assertNotNull(vdcURI, String.format(REF_REQ_LIVE, VDC)); - } @Test(description = "GET /vdc/{id}") public void testGetVdc() { diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminCatalogClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminCatalogClientLiveTest.java index 4b10c69e74..70d8b54233 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminCatalogClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminCatalogClientLiveTest.java @@ -23,6 +23,7 @@ import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.N import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_DEL; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_EQ; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_UPDATABLE; +import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkError; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNull; @@ -79,6 +80,20 @@ public class AdminCatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest orgRef = Iterables.getFirst(context.getApi().getOrgClient().getOrgList().getOrgs(), null).toAdminReference(endpoint); } + @AfterClass(alwaysRun = true) + protected void tidyUp() { + if (catalog != null) { + catalogClient.deleteCatalog(catalog.getHref()); + try { + catalogClient.getCatalog(catalog.getHref()); + fail("The Catalog 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"); + } + } + } + @Test(description = "POST /admin/org/{id}/catalogs") public void testCreateCatalog() { AdminCatalog newCatalog = AdminCatalog.builder() @@ -224,11 +239,4 @@ public class AdminCatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest assertNull(deleteCatalog, String.format(OBJ_DEL, CATALOG, deleteCatalog.toString())); } } - - @AfterClass - protected void tidyUp() { - if (catalog != null) { - catalogClient.deleteCatalog(catalog.getHref()); - } - } } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/UserClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/UserClientLiveTest.java index fc0044748f..93ad4f0ef9 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/UserClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/UserClientLiveTest.java @@ -217,7 +217,7 @@ public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest { dependsOnMethods = { "testCreateUser" } ) public void testDeleteUser() { // Create a user to be deleted (so we remove dependencies on test ordering) - User newUser = randomTestUser("testDeleteUser"); + User newUser = randomTestUser("testDeleteUser"+getTestDateTimeStamp()); User userToBeDeleted = userClient.createUser(orgRef.getHref(), newUser); // Delete the user 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 1471fb62fc..d40b9cc13c 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 @@ -74,7 +74,6 @@ import org.jclouds.vcloud.director.v1_5.predicates.TaskStatusEquals; import org.jclouds.vcloud.director.v1_5.predicates.TaskSuccess; import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorAsyncClient; import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorClient; -import org.testng.annotations.AfterClass; import org.testng.annotations.AfterSuite; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeSuite; @@ -141,6 +140,8 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ private static VCloudDirectorTestSession testSession; + private static String testStamp; + @BeforeClass(alwaysRun = true) protected void setupDateService() { dateService = Guice.createInjector().getInstance(DateService.class); @@ -197,8 +198,12 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ setupRequiredClients(); } - public static String datetimeStamp() { - return new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); + public static String getTestDateTimeStamp() { + if (testStamp == null) { + testStamp = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); + } + + return testStamp; } public Reference getRoleReferenceFor(String name) { @@ -217,7 +222,7 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ public User randomTestUser(String prefix, Reference role) { return User.builder() - .name(name(prefix)+datetimeStamp()) + .name(name(prefix)+getTestDateTimeStamp()) .fullName("testFullName") .emailAddress("test@test.com") .telephone("555-1234") diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/VCloudDirectorTestSession.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/VCloudDirectorTestSession.java index 053871ab5e..940d18fccd 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/VCloudDirectorTestSession.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/VCloudDirectorTestSession.java @@ -101,7 +101,7 @@ public class VCloudDirectorTestSession { Reference orgAdmin = user.getRole(); assertTrue(equal(orgAdmin.getName(), DefaultRoles.ORG_ADMIN), "must give org admin or user-only credentials"); - String adminIdentity = "testAdmin"+BaseVCloudDirectorClientLiveTest.datetimeStamp(); + String adminIdentity = "testAdmin"+BaseVCloudDirectorClientLiveTest.getTestDateTimeStamp(); String adminCredential = "testAdminPassword"; createdAdminUser = rootContext.getAdminContext().getApi().getUserClient().createUser(orgRef.getHref(), User.builder() @@ -117,7 +117,7 @@ public class VCloudDirectorTestSession { adminContext = VCloudDirectorContext.class.cast(new RestContextFactory().createContext(provider, adminIdentity, adminCredential, ImmutableSet. of( new Log4JLoggingModule(), new SshjSshClientModule()), overrides)).getAdminContext(); - String userIdentity = "test"+BaseVCloudDirectorClientLiveTest.datetimeStamp(); + String userIdentity = "test"+BaseVCloudDirectorClientLiveTest.getTestDateTimeStamp(); String userCredential = "testPassword"; createdUser = adminContext.getApi().getUserClient().createUser(orgRef.getHref(), User.builder()