refactored base vcloud test class to work when parameters aren't supplied

This commit is contained in:
Adrian Cole 2012-03-07 15:15:14 -08:00
parent 15a297d200
commit 9069f4879c
4 changed files with 103 additions and 56 deletions

View File

@ -19,10 +19,25 @@
package org.jclouds.vcloud.director.v1_5.features; package org.jclouds.vcloud.director.v1_5.features;
import static com.google.common.base.Objects.equal; import static com.google.common.base.Objects.equal;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.*; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.GETTER_RETURNS_SAME_OBJ;
import static org.testng.Assert.*; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_DEL;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_ATTRB_DEL;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_CLONE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_CONTAINS;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_EQ;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_REQ;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_UPDATABLE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.REF_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.TASK_COMPLETE_TIMELY;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
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 java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Set; import java.util.Set;
@ -40,7 +55,6 @@ import org.jclouds.vcloud.director.v1_5.domain.MetadataValue;
import org.jclouds.vcloud.director.v1_5.domain.Owner; 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.Reference;
import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.domain.Task;
import org.jclouds.vcloud.director.v1_5.domain.URISupplier;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -62,16 +76,12 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
/* /*
* Convenience references to API clients. * Convenience references to API clients.
*/ */
private URI vdcUri;
protected VdcClient vdcClient; protected VdcClient vdcClient;
protected MediaClient mediaClient; protected MediaClient mediaClient;
@BeforeClass(inheritGroups = true) @BeforeClass(inheritGroups = true)
@Override @Override
public void setupRequiredClients() { public void setupRequiredClients() {
vdcUri = URI.create(endpoint+"/vdc/"+vdcId);
vdcClient = context.getApi().getVdcClient(); vdcClient = context.getApi().getVdcClient();
mediaClient = context.getApi().getMediaClient(); mediaClient = context.getApi().getMediaClient();
} }
@ -87,8 +97,8 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
@Test(testName = "POST /vdc/{id}/media", enabled = false) @Test(testName = "POST /vdc/{id}/media", enabled = false)
public void testCreateMedia() throws URISyntaxException { public void testCreateMedia() throws URISyntaxException {
assertNotNull(vdcUri, String.format(REF_REQ_LIVE, VDC)); assertNotNull(vdcURI, String.format(REF_REQ_LIVE, VDC));
assertNotNull(vdcClient.getVdc(vdcUri), String.format(OBJ_REQ_LIVE, VDC)); assertNotNull(vdcClient.getVdc(vdcURI), String.format(OBJ_REQ_LIVE, VDC));
java.io.File sourceFile = new java.io.File(getClass().getResource("/media/test.iso").toURI()); java.io.File sourceFile = new java.io.File(getClass().getResource("/media/test.iso").toURI());
@ -99,7 +109,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
.imageType(Media.ImageType.ISO) .imageType(Media.ImageType.ISO)
.description("Test media generated by testCreateMedia()") .description("Test media generated by testCreateMedia()")
.build(); .build();
media = vdcClient.createMedia(vdcUri, sourceMedia); media = vdcClient.createMedia(vdcURI, sourceMedia);
Checks.checkMediaFor(MEDIA, media); Checks.checkMediaFor(MEDIA, media);
@ -153,7 +163,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
dependsOnMethods = { "testGetMediaOwner" }, enabled = false) dependsOnMethods = { "testGetMediaOwner" }, enabled = false)
public void testCloneMedia() { public void testCloneMedia() {
oldMedia = media; oldMedia = media;
media = vdcClient.cloneMedia(vdcUri, CloneMediaParams.builder() media = vdcClient.cloneMedia(vdcURI, CloneMediaParams.builder()
.source(Reference.builder().fromEntity(media).build()) .source(Reference.builder().fromEntity(media).build())
.name("copied test media") .name("copied test media")
.description("copied by testCloneMedia()") .description("copied by testCloneMedia()")
@ -176,7 +186,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
mediaClient.getMetadataClient().setMetadata(media.getHref(), "key", MetadataValue.builder().value("value").build()); mediaClient.getMetadataClient().setMetadata(media.getHref(), "key", MetadataValue.builder().value("value").build());
media = vdcClient.cloneMedia(vdcUri, CloneMediaParams.builder() media = vdcClient.cloneMedia(vdcURI, CloneMediaParams.builder()
.source(Reference.builder().fromEntity(media).build()) .source(Reference.builder().fromEntity(media).build())
.name("moved test media") .name("moved test media")
.description("moved by testCloneMedia()") .description("moved by testCloneMedia()")

View File

@ -55,12 +55,9 @@ public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest {
*/ */
protected NetworkClient networkClient; protected NetworkClient networkClient;
private URI networkURI;
@BeforeClass(inheritGroups = true) @BeforeClass(inheritGroups = true)
@Override @Override
public void setupRequiredClients() { public void setupRequiredClients() {
networkURI = URI.create(endpoint+"/network/"+networkId);
networkClient = context.getApi().getNetworkClient(); networkClient = context.getApi().getNetworkClient();
} }

View File

@ -18,14 +18,30 @@
*/ */
package org.jclouds.vcloud.director.v1_5.features; 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.VCloudDirectorLiveTestConstants.OBJ_FIELD_GTE_0;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_REQ;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.REF_REQ_LIVE;
import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue; import static org.testng.Assert.assertTrue;
import java.net.URI; import java.net.URI;
import org.jclouds.vcloud.director.v1_5.domain.*; import org.jclouds.vcloud.director.v1_5.domain.CaptureVAppParams;
import org.jclouds.vcloud.director.v1_5.domain.Checks;
import org.jclouds.vcloud.director.v1_5.domain.CloneVAppParams;
import org.jclouds.vcloud.director.v1_5.domain.CloneVAppTemplateParams;
import org.jclouds.vcloud.director.v1_5.domain.ComposeVAppParams;
import org.jclouds.vcloud.director.v1_5.domain.InstantiateVAppParams;
import org.jclouds.vcloud.director.v1_5.domain.Metadata;
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.UploadVAppTemplateParams;
import org.jclouds.vcloud.director.v1_5.domain.VApp;
import org.jclouds.vcloud.director.v1_5.domain.VAppTemplate;
import org.jclouds.vcloud.director.v1_5.domain.Vdc;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -52,7 +68,6 @@ public class VdcClientLiveTest extends BaseVCloudDirectorClientLiveTest {
@BeforeClass(inheritGroups = true) @BeforeClass(inheritGroups = true)
@Override @Override
public void setupRequiredClients() { public void setupRequiredClients() {
vdcURI = URI.create(endpoint+"/vdc/"+vdcId);
vdcClient = context.getApi().getVdcClient(); vdcClient = context.getApi().getVdcClient();
} }

View File

@ -21,6 +21,8 @@ package org.jclouds.vcloud.director.v1_5.internal;
import java.net.URI; import java.net.URI;
import java.util.Properties; import java.util.Properties;
import javax.inject.Inject;
import org.jclouds.compute.BaseVersionedServiceLiveTest; import org.jclouds.compute.BaseVersionedServiceLiveTest;
import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
@ -29,13 +31,23 @@ import org.jclouds.rest.RestContextFactory;
import org.jclouds.sshj.config.SshjSshClientModule; import org.jclouds.sshj.config.SshjSshClientModule;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorAsyncClient; import org.jclouds.vcloud.director.v1_5.VCloudDirectorAsyncClient;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Link;
import org.jclouds.vcloud.director.v1_5.domain.Org;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.Session;
import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.domain.Task;
import org.jclouds.vcloud.director.v1_5.predicates.ReferenceTypePredicates;
import org.jclouds.vcloud.director.v1_5.predicates.TaskSuccess; import org.jclouds.vcloud.director.v1_5.predicates.TaskSuccess;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.inject.Module; import com.google.inject.Module;
/** /**
@ -51,56 +63,69 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ
provider = "vcloud-director"; provider = "vcloud-director";
} }
protected String catalogName;
protected String vAppTemplateId;
protected String networkId;
protected String vdcId;
@Override
protected Properties setupProperties() {
Properties overrides= super.setupProperties();
if (catalogName != null)
overrides.setProperty(provider + ".catalog-name", catalogName);
if (vAppTemplateId != null)
overrides.setProperty(provider + ".vapptemplate-id", vAppTemplateId);
if (networkId != null)
overrides.setProperty(provider + ".network-id", networkId);
if (vdcId != null)
overrides.setProperty(provider + ".vdc-id", vdcId);
return overrides;
}
@BeforeClass(inheritGroups = true)
// NOTE Implement as required to populate xxxClient fields, or NOP // NOTE Implement as required to populate xxxClient fields, or NOP
public abstract void setupRequiredClients(); public abstract void setupRequiredClients();
/** Injected by {@link #setupContext} */
public Predicate<Task> retryTaskSuccess; public Predicate<Task> retryTaskSuccess;
@Override @Inject
@BeforeClass(groups = { "live" }) protected void initTaskSuccess(TaskSuccess taskSuccess) {
protected void setupCredentials() { retryTaskSuccess = new RetryablePredicate<Task>(taskSuccess, 1000L);
super.setupCredentials();
catalogName = System.getProperty("test." + provider + ".catalog-name");
vAppTemplateId = System.getProperty("test." + provider + ".vapptemplate-id");
networkId = System.getProperty("test." + provider + ".network-id");
vdcId = System.getProperty("test." + provider + ".vdc-id");
} }
protected RestContext<VCloudDirectorClient, VCloudDirectorAsyncClient> context; protected RestContext<VCloudDirectorClient, VCloudDirectorAsyncClient> context;
protected Session session;
@BeforeClass(groups = { "live" }) @BeforeClass(groups = { "live" })
public void setupContext() { public void setupContext() {
setupCredentials(); setupCredentials();
Properties overrides = setupProperties(); Properties overrides = setupProperties();
context = new RestContextFactory().createContext(provider, identity, credential, context = new RestContextFactory().createContext(provider, identity, credential, ImmutableSet.<Module> of(
ImmutableSet.<Module> of(new Log4JLoggingModule(), new SshjSshClientModule()), overrides); new Log4JLoggingModule(), new SshjSshClientModule()), overrides);
session = context.getApi().getCurrentSession();
context.utils().injector().injectMembers(this);
initTestParametersFromPropertiesOrLazyDiscover();
setupRequiredClients();
}
TaskSuccess taskSuccess = context.utils().injector().getInstance(TaskSuccess.class); protected String catalogName;
retryTaskSuccess = new RetryablePredicate<Task>(taskSuccess, 1000L); // TODO: change to URI, not id
protected String vAppTemplateId;
protected URI networkURI;
protected URI vdcURI;
@SuppressWarnings("unchecked")
protected void initTestParametersFromPropertiesOrLazyDiscover() {
vAppTemplateId = Strings.emptyToNull(System.getProperty("test." + provider + ".vapptemplate-id"));
catalogName = Strings.emptyToNull(System.getProperty("test." + provider + ".catalog-name"));
// TODO: change properties to URI, not id
String vdcId = Strings.emptyToNull(System.getProperty("test." + provider + ".vdc-id"));
if (vdcId != null)
vdcURI = URI.create(endpoint + "/vdc/" + vdcId);
String networkId = Strings.emptyToNull(System.getProperty("test." + provider + ".network-id"));
if (networkId != null)
networkURI = URI.create(endpoint + "/network/" + networkId);
if (Iterables.any(Lists.newArrayList(vAppTemplateId, catalogName, networkURI, vdcURI), Predicates.isNull())) {
Org thisOrg = context.getApi().getOrgClient().getOrg(
Iterables.find(context.getApi().getOrgClient().getOrgList().getOrgs(),
ReferenceTypePredicates.<Reference> nameEquals(session.getOrg())).getHref());
if (vdcURI == null)
vdcURI = Iterables.find(thisOrg.getLinks(),
ReferenceTypePredicates.<Link> typeEquals(VCloudDirectorMediaType.VDC)).getHref();
if (networkURI == null)
networkURI = Iterables.find(thisOrg.getLinks(),
ReferenceTypePredicates.<Link> typeEquals(VCloudDirectorMediaType.ORG_NETWORK)).getHref();
if (catalogName == null)
catalogName = Iterables.find(thisOrg.getLinks(),
ReferenceTypePredicates.<Link> typeEquals(VCloudDirectorMediaType.CATALOG)).getName();
}
} }
protected void tearDown() { protected void tearDown() {