mirror of https://github.com/apache/jclouds.git
ensure tests are tidy, consistent, and clean up after themselves
This commit is contained in:
parent
19cd7b4aa3
commit
1b9f29a706
|
@ -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;
|
||||
|
||||
|
@ -88,13 +89,6 @@ 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.
|
||||
*/
|
||||
|
@ -104,6 +98,23 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
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 {
|
||||
assertNotNull(vdcURI, String.format(REF_REQ_LIVE, VDC));
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<String,String> 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")
|
||||
|
|
|
@ -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) {
|
||||
|
@ -112,16 +122,6 @@ public class VdcClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
}
|
||||
}
|
||||
|
||||
@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() {
|
||||
Vdc vdc = vdcClient.getVdc(vdcURI);
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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.<Module> 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()
|
||||
|
|
Loading…
Reference in New Issue