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 466f799544..732917d92f 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 @@ -19,10 +19,25 @@ 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.*; -import static org.testng.Assert.*; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.GETTER_RETURNS_SAME_OBJ; +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.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.Reference; 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.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -62,16 +76,12 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { /* * Convenience references to API clients. */ - - private URI vdcUri; protected VdcClient vdcClient; protected MediaClient mediaClient; @BeforeClass(inheritGroups = true) @Override public void setupRequiredClients() { - vdcUri = URI.create(endpoint+"/vdc/"+vdcId); - vdcClient = context.getApi().getVdcClient(); mediaClient = context.getApi().getMediaClient(); } @@ -87,8 +97,8 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { @Test(testName = "POST /vdc/{id}/media", enabled = false) public void testCreateMedia() throws URISyntaxException { - assertNotNull(vdcUri, String.format(REF_REQ_LIVE, VDC)); - assertNotNull(vdcClient.getVdc(vdcUri), String.format(OBJ_REQ_LIVE, VDC)); + assertNotNull(vdcURI, String.format(REF_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()); @@ -99,7 +109,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { .imageType(Media.ImageType.ISO) .description("Test media generated by testCreateMedia()") .build(); - media = vdcClient.createMedia(vdcUri, sourceMedia); + media = vdcClient.createMedia(vdcURI, sourceMedia); Checks.checkMediaFor(MEDIA, media); @@ -153,7 +163,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { dependsOnMethods = { "testGetMediaOwner" }, enabled = false) public void testCloneMedia() { oldMedia = media; - media = vdcClient.cloneMedia(vdcUri, CloneMediaParams.builder() + media = vdcClient.cloneMedia(vdcURI, CloneMediaParams.builder() .source(Reference.builder().fromEntity(media).build()) .name("copied test media") .description("copied by testCloneMedia()") @@ -176,7 +186,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { 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()) .name("moved test media") .description("moved by testCloneMedia()") 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 d7614abbe7..49d8799481 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 @@ -54,13 +54,10 @@ public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest { * Convenience reference to API client. */ protected NetworkClient networkClient; - - private URI networkURI; - + @BeforeClass(inheritGroups = true) @Override public void setupRequiredClients() { - networkURI = URI.create(endpoint+"/network/"+networkId); networkClient = context.getApi().getNetworkClient(); } 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 bce9cc1945..7a22cf8fc6 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 @@ -18,14 +18,30 @@ */ 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.assertNotNull; import static org.testng.Assert.assertTrue; 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.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -52,7 +68,6 @@ public class VdcClientLiveTest extends BaseVCloudDirectorClientLiveTest { @BeforeClass(inheritGroups = true) @Override public void setupRequiredClients() { - vdcURI = URI.create(endpoint+"/vdc/"+vdcId); vdcClient = context.getApi().getVdcClient(); } 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 1a4b2cc10c..44083294cf 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 @@ -21,6 +21,8 @@ package org.jclouds.vcloud.director.v1_5.internal; import java.net.URI; import java.util.Properties; +import javax.inject.Inject; + import org.jclouds.compute.BaseVersionedServiceLiveTest; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.predicates.RetryablePredicate; @@ -29,13 +31,23 @@ import org.jclouds.rest.RestContextFactory; import org.jclouds.sshj.config.SshjSshClientModule; import org.jclouds.vcloud.director.v1_5.VCloudDirectorAsyncClient; 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.predicates.ReferenceTypePredicates; import org.jclouds.vcloud.director.v1_5.predicates.TaskSuccess; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; 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.Iterables; +import com.google.common.collect.Lists; import com.google.inject.Module; /** @@ -51,56 +63,69 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ 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 public abstract void setupRequiredClients(); - /** Injected by {@link #setupContext} */ public Predicate retryTaskSuccess; - @Override - @BeforeClass(groups = { "live" }) - protected void setupCredentials() { - 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"); + @Inject + protected void initTaskSuccess(TaskSuccess taskSuccess) { + retryTaskSuccess = new RetryablePredicate(taskSuccess, 1000L); } - - protected RestContext context; + protected RestContext context; + protected Session session; @BeforeClass(groups = { "live" }) public void setupContext() { setupCredentials(); Properties overrides = setupProperties(); - context = new RestContextFactory().createContext(provider, identity, credential, - ImmutableSet. of(new Log4JLoggingModule(), new SshjSshClientModule()), overrides); + context = new RestContextFactory().createContext(provider, identity, credential, ImmutableSet. of( + new Log4JLoggingModule(), new SshjSshClientModule()), overrides); + session = context.getApi().getCurrentSession(); + context.utils().injector().injectMembers(this); + initTestParametersFromPropertiesOrLazyDiscover(); + setupRequiredClients(); + } - TaskSuccess taskSuccess = context.utils().injector().getInstance(TaskSuccess.class); - retryTaskSuccess = new RetryablePredicate(taskSuccess, 1000L); + protected String catalogName; + // 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. nameEquals(session.getOrg())).getHref()); + + if (vdcURI == null) + vdcURI = Iterables.find(thisOrg.getLinks(), + ReferenceTypePredicates. typeEquals(VCloudDirectorMediaType.VDC)).getHref(); + + if (networkURI == null) + networkURI = Iterables.find(thisOrg.getLinks(), + ReferenceTypePredicates. typeEquals(VCloudDirectorMediaType.ORG_NETWORK)).getHref(); + + if (catalogName == null) + catalogName = Iterables.find(thisOrg.getLinks(), + ReferenceTypePredicates. typeEquals(VCloudDirectorMediaType.CATALOG)).getName(); + } } protected void tearDown() {