From db528408e3c486ddea6003ac06ce2865f815c0f4 Mon Sep 17 00:00:00 2001 From: danikov Date: Thu, 23 Feb 2012 13:46:24 +0000 Subject: [PATCH 1/7] fix domain object inheritance --- .../vcloud/director/v1_5/domain/Media.java | 15 +++++++++++++-- .../vcloud/director/v1_5/domain/Owner.java | 8 +++++++- .../v1_5/domain/ResourceEntityType.java | 18 ++++++++++++++---- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Media.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Media.java index aadde7aedb..e9370582df 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Media.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Media.java @@ -92,10 +92,17 @@ public class Media extends ResourceEntityType { @Override public Media build() { - Media media = new Media(); + Media media = new Media(href, name); media.setOwner(owner); media.setImageType(imageType); media.setSize(size); + media.setFiles(files); + media.setStatus(status); + media.setDescription(description); + media.setTasksInProgress(tasksInProgress); + media.setId(id); + media.setType(type); + media.setLinks(links); return media; } @@ -200,7 +207,11 @@ public class Media extends ResourceEntityType { } public Media() { - super(); + // for JAXB + } + + protected Media(URI href, String name) { + super(href, name); } @XmlElement(namespace = VCLOUD_1_5_NS, name = "Owner") diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Owner.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Owner.java index 88e392cfd3..18708835c9 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Owner.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Owner.java @@ -89,8 +89,10 @@ public class Owner public Owner build() { - Owner owner = new Owner(); + Owner owner = new Owner(href); owner.setUser(user); + owner.setType(type); + owner.setLinks(links); return owner; } @@ -145,6 +147,10 @@ public class Owner private Owner() { // For JAXB and builder use } + + private Owner(URI href) { + super(href); + } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceEntityType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceEntityType.java index d72a21523c..43bfebe723 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceEntityType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceEntityType.java @@ -54,8 +54,8 @@ public class ResourceEntityType> extends EntityT public static class Builder> extends EntityType.Builder { - private FilesList files; - private Integer status; + protected FilesList files; + protected Integer status; /** * @see ResourceEntityType#getFiles() @@ -75,9 +75,14 @@ public class ResourceEntityType> extends EntityT @Override public ResourceEntityType build() { - ResourceEntityType resourceEntity = new ResourceEntityType(); + ResourceEntityType resourceEntity = new ResourceEntityType(href, name); resourceEntity.setFiles(files); resourceEntity.setStatus(status); + resourceEntity.setDescription(description); + resourceEntity.setTasksInProgress(tasksInProgress); + resourceEntity.setId(id); + resourceEntity.setType(type); + resourceEntity.setLinks(links); return resourceEntity; } @@ -135,6 +140,7 @@ public class ResourceEntityType> extends EntityT return this; } + @SuppressWarnings("unchecked") @Override public Builder fromResourceType(ResourceType in) { return Builder.class.cast(super.fromResourceType(in)); @@ -145,9 +151,13 @@ public class ResourceEntityType> extends EntityT } } - public ResourceEntityType() { + protected ResourceEntityType() { // for JAXB } + + protected ResourceEntityType(URI href, String name) { + super(href, name); + } @XmlElement(name = "Files") protected FilesList files; From ae308cb1fdebba0525aeac6c9615fea9a6a7d38f Mon Sep 17 00:00:00 2001 From: danikov Date: Thu, 23 Feb 2012 13:46:40 +0000 Subject: [PATCH 2/7] extract out/stub checks --- .../vcloud/director/v1_5/domain/Checks.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java index 9577ed4933..bf7ad4133c 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java @@ -22,6 +22,8 @@ import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.C import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.MUST_BE_WELL_FORMED_FMT; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.MUST_CONTAIN_FMT; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.NOT_NULL_OBJECT_FMT; +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.REQUIRED_VALUE_FMT; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.REQUIRED_VALUE_OBJECT_FMT; import static org.testng.Assert.assertEquals; @@ -368,4 +370,25 @@ public class Checks { public static void checkIpAddress(String ip) { InetAddresses.isInetAddress(ip); } + } + + public static void checkVApp(VApp vApp) { + // TODO Auto-generated method stub + + } + + public static void checkVAppTemplate(VAppTemplate template) { + // TODO Auto-generated method stub + + } + + public static void checkMediaFor(String client, Media media) { + // required + assertNotNull(media.getImageType(), String.format(OBJ_FIELD_REQ, client, "imageType")); + Checks.checkImageType(media.getImageType()); + assertNotNull(media.getSize(), String.format(OBJ_FIELD_REQ, client, "size")); + assertTrue(media.getSize() >= 0, String.format(OBJ_FIELD_GTE_0, client, "size", media.getSize())); + + // parent type + Checks.checkResourceEntityType(media); } From 1387d9f704b99f65c31ed4a9ab56e16c70f95f4e Mon Sep 17 00:00:00 2001 From: danikov Date: Thu, 23 Feb 2012 13:47:11 +0000 Subject: [PATCH 3/7] remove unused code, replace TODOs with task checking --- .../v1_5/features/CatalogClientLiveTest.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java index 7f18addf5a..20e027b519 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java @@ -34,6 +34,7 @@ import static org.testng.Assert.fail; import org.jclouds.vcloud.director.v1_5.VCloudDirectorException; import org.jclouds.vcloud.director.v1_5.domain.Catalog; import org.jclouds.vcloud.director.v1_5.domain.CatalogItem; +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.Metadata; import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; @@ -63,7 +64,6 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest { private CatalogClient catalogClient; private QueryClient queryClient; - private MediaClient mediaClient; /* * Shared state between dependant tests. @@ -81,7 +81,6 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest { public void setupRequiredClients() { catalogClient = context.getApi().getCatalogClient(); queryClient = context.getApi().getQueryClient(); - mediaClient = context.getApi().getMediaClient(); } private Metadata catalogItemMetadata; @@ -227,9 +226,9 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest { Task setCatalogItemMetadataValue = catalogClient.setCatalogItemMetadataValue(catalogItemRef, "KEY", newMetadataValue); checkTask(setCatalogItemMetadataValue); - // TODO requires code from dan to be merged -// assertTrue(taskTester.apply(setCatalogItemMetadataValue.getHref()), -// String.format(TASK_COMPLETE_TIMELY, "setCatalogItemMetadataValue")); + Checks.checkTask(setCatalogItemMetadataValue); + assertTrue(retryTaskSuccess.apply(setCatalogItemMetadataValue.getHref()), + String.format(TASK_COMPLETE_TIMELY, "setCatalogItemMetadataValue")); MetadataValue updatedMetadataValue = catalogClient.getCatalogItemMetadataValue(catalogItemRef, "KEY"); assertEquals(updatedMetadataValue.getValue(), newMetadataValue.getValue(), @@ -241,9 +240,9 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest { public void testDeleteCatalogItemMetadataValue() { Task deleteCatalogItemMetadataValue = catalogClient.deleteCatalogItemMetadataValue(catalogItemRef, "KEY"); checkTask(deleteCatalogItemMetadataValue); - // TODO requires code from dan to be merged -// assertTrue(taskTester.apply(deleteCatalogItemMetadataValue.getHref()), -// String.format(TASK_COMPLETE_TIMELY, "deleteCatalogItemMetadataValue")); + Checks.checkTask(deleteCatalogItemMetadataValue); + assertTrue(retryTaskSuccess.apply(deleteCatalogItemMetadataValue.getHref()), + String.format(TASK_COMPLETE_TIMELY, "deleteCatalogItemMetadataValue")); try { catalogClient.getCatalogItemMetadataValue(catalogItemRef, "KEY"); fail("The CatalogItem MetadataValue for KEY should have been deleted"); @@ -269,8 +268,8 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest { deleteAllCatalogItemMetadata(catalogItemRef); Metadata newMetadata = Metadata.builder().entry(MetadataEntry.builder().entry("KEY", "VALUE").build()).build(); Task mergeCatalogItemMetadata = catalogClient.mergeCatalogItemMetadata(catalogItemRef, newMetadata); - // TODO requires code from dan to be merged -// assertTrue(taskTester.apply(mergeCatalogItemMetadata.getHref()), -// String.format(TASK_COMPLETE_TIMELY, "mergeCatalogItemMetadata")); + Checks.checkTask(mergeCatalogItemMetadata); + assertTrue(retryTaskSuccess.apply(mergeCatalogItemMetadata.getHref()), + String.format(TASK_COMPLETE_TIMELY, "mergeCatalogItemMetadata")); } } From 099f9137d037cedc43c556f8923eabec0e459992 Mon Sep 17 00:00:00 2001 From: danikov Date: Thu, 23 Feb 2012 13:47:30 +0000 Subject: [PATCH 4/7] fix update media expect test --- .../vcloud/director/v1_5/features/MediaClientExpectTest.java | 5 ++--- .../vcloud-director/src/test/resources/media/updateMedia.xml | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java index 230c04ed73..097a1415fe 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java @@ -158,8 +158,7 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes } } - // TODO: fix this - @Test( enabled=false ) + @Test public void testUpdateMedia() { URI mediaUri = URI.create(endpoint + "/media/794eb334-754e-4917-b5a0-5df85cbd61d1"); @@ -383,7 +382,6 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes .build()) .link(Link.builder() .rel("remove") - .type("application/vnd.vmware.vcloud.metadata+xml") .href(URI.create("https://mycloud.greenhousedata.com/api/media/c93e5cdc-f29a-4749-8ed2-093df04cc75e")) .build()) .link(Link.builder() @@ -403,6 +401,7 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes .build()) .description("new test description") .owner(Owner.builder() + .type("application/vnd.vmware.vcloud.owner+xml") .user(Reference.builder() .type("application/vnd.vmware.admin.user+xml") .name("dan") diff --git a/labs/vcloud-director/src/test/resources/media/updateMedia.xml b/labs/vcloud-director/src/test/resources/media/updateMedia.xml index b7cbb05257..62b5ef625f 100644 --- a/labs/vcloud-director/src/test/resources/media/updateMedia.xml +++ b/labs/vcloud-director/src/test/resources/media/updateMedia.xml @@ -10,4 +10,4 @@ - \ No newline at end of file + From 2ff4e8317cf1308f58177da3bc19252a24469fa4 Mon Sep 17 00:00:00 2001 From: danikov Date: Thu, 23 Feb 2012 13:48:09 +0000 Subject: [PATCH 5/7] use extracted checks, nicer test names --- .../v1_5/features/MediaClientLiveTest.java | 120 +++++++----------- 1 file changed, 45 insertions(+), 75 deletions(-) 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 ece8c196d7..ecfe5c39d4 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 @@ -22,17 +22,13 @@ 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_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_ATTRB_REQ; 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_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_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.jclouds.vcloud.director.v1_5.domain.Checks.checkResourceType; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotNull; @@ -75,18 +71,24 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { * Convenience references to API clients. */ + private Reference mediaRef; protected MediaClient mediaClient; @BeforeClass(inheritGroups = true) @Override public void setupRequiredClients() { + mediaRef = Reference.builder() + .type("application/vnd.vmware.vcloud.media+xml") + .name("") + .href(URI.create(endpoint+"/media/" + mediaId)) + .id(mediaId) + .build(); mediaClient = context.getApi().getMediaClient(); } /* * Shared state between dependent tests. */ - private Reference mediaRef; private Media media; private Owner owner; private Metadata metadata; @@ -95,17 +97,12 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { @BeforeGroups(groups = { "live" }) public void createReferenceData() { - mediaRef = Reference.builder() - .type("application/vnd.vmware.vcloud.media+xml") - .name("") - .href(URI.create(endpoint+"/media/" + mediaId)) - .id(mediaId) - .build(); + // FIXME: don't want to be modifying anything here! mediaClient.setMetadata(mediaRef, "key", MetadataValue.builder().value("value").build()); } @Test(testName = "GET /media/{id}") - public void testWhenResponseIs2xxLoginReturnsValidMedia() { + public void testGetMedia() { // required for testing assertNotNull(mediaRef, String.format(REF_REQ_LIVE, MEDIA)); @@ -117,20 +114,12 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { assertNotNull(owner, String.format(OBJ_FIELD_REQ_LIVE, MEDIA, "owner")); Checks.checkResourceType(media.getOwner()); - // parent type - Checks.checkResourceEntityType(media); - - // required - String imageType = media.getImageType(); - Checks.checkImageType(imageType); - Long size = media.getSize(); - assertNotNull(size, String.format(OBJ_FIELD_REQ, MEDIA, "size")); - assertTrue(size >= 0, String.format(OBJ_FIELD_GTE_0, MEDIA, "size", size)); + Checks.checkMediaFor(MEDIA, media); } @Test(testName = "GET /media/{id}/owner", - dependsOnMethods = { "testWhenResponseIs2xxLoginReturnsValidMedia" }) - public void testWhenResponseIs2xxLoginReturnsValidMediaOwner() { + dependsOnMethods = { "testGetMedia" }) + public void testGetMediaOwner() { Owner directOwner = mediaClient.getOwner(mediaRef); assertEquals(owner, directOwner, String.format(GETTER_RETURNS_SAME_OBJ, "getOwner()", "owner", "media.getOwner()", owner.toString(), directOwner.toString())); @@ -144,8 +133,8 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { } @Test(testName = "PUT /media/{id}", - dependsOnMethods = { "testWhenResponseIs2xxLoginReturnsValidMedia" }) - public void testWhenResponseIs2xxLoginReturnsValidNetwork() { + dependsOnMethods = { "testGetMedia" }) + public void testSetMedia() { String oldName = media.getName(); String newName = "new "+oldName; String oldDescription = media.getDescription(); @@ -164,11 +153,10 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { //TODO negative tests? - // ensure media remains valid - testWhenResponseIs2xxLoginReturnsValidMedia(); + Checks.checkMediaFor(MEDIA, media); - media.setName(newName); - media.setDescription(newDescription); + media.setName(oldName); + media.setDescription(oldDescription); updateMedia = mediaClient.updateMedia(mediaRef, media); Checks.checkTask(updateMedia); @@ -177,31 +165,19 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { } @Test(testName = "GET /media/{id}/metadata", - dependsOnMethods = { "testWhenResponseIs2xxLoginReturnsValidMedia" }) - public void testWhenResponseIs2xxLoginReturnsValidMetadata() { + dependsOnMethods = { "testGetMedia" }) + public void testGetMetadata() { metadata = mediaClient.getMetadata(mediaRef); // required for testing assertFalse(Iterables.isEmpty(metadata.getMetadataEntries()), String.format(OBJ_FIELD_REQ_LIVE, MEDIA, "metadata.entries")); - // parent type - checkResourceType(metadata); - - for (MetadataEntry entry : metadata.getMetadataEntries()) { - // required elements and attributes - assertNotNull(entry.getKey(), - String.format(OBJ_FIELD_ATTRB_REQ, MEDIA, "MetadataEntry", metadataValue, "key")); - assertNotNull(entry.getValue(), - String.format(OBJ_FIELD_ATTRB_REQ, MEDIA, "MetadataEntry", metadataValue, "value")); - - // parent type - checkResourceType(entry); - } + Checks.checkMetadataFor(MEDIA, metadata); } @Test(testName = "POST /media/{id}/metadata", - dependsOnMethods = { "testWhenResponseIs2xxLoginReturnsValidMetadata" }) - public void testWhenResponseIs2xxLoginMergedMetadata() { + dependsOnMethods = { "testGetMetadata" }) + public void testMergeMetadata() { // test new Set inputEntries = ImmutableSet.of(MetadataEntry.builder().entry("testKey", "testValue").build()); Metadata inputMetadata = Metadata.builder() @@ -212,9 +188,11 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { Checks.checkTask(mergeMetadata); assertTrue(retryTaskSuccess.apply(mergeMetadata.getHref()), String.format(TASK_COMPLETE_TIMELY, "mergeMetadata(new)")); metadata = mediaClient.getMetadata(mediaRef); + Checks.checkMetadataFor(MEDIA, metadata); checkMetadataContainsEntries(metadata, inputEntries); - testWhenResponseIs2xxLoginReturnsValidMetadata(); + media = mediaClient.getMedia(mediaRef); + Checks.checkMediaFor(MEDIA, media); // test modify inputEntries = ImmutableSet.of(MetadataEntry.builder().entry("testKey", "new testValue").build()); @@ -226,9 +204,11 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { Checks.checkTask(mergeMetadata); assertTrue(retryTaskSuccess.apply(mergeMetadata.getHref()), String.format(TASK_COMPLETE_TIMELY, "mergeMetadata(modify)")); metadata = mediaClient.getMetadata(mediaRef); + Checks.checkMetadataFor(MEDIA, metadata); checkMetadataContainsEntries(metadata, inputEntries); - testWhenResponseIs2xxLoginReturnsValidMetadata(); + media = mediaClient.getMedia(mediaRef); + Checks.checkMediaFor(MEDIA, media); } private void checkMetadataContainsEntries(Metadata metadata, Set entries) { @@ -249,25 +229,15 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { } @Test(testName = "GET /media/{id}/metadata/{key}", - dependsOnMethods = { "testWhenResponseIs2xxLoginMergedMetadata" }) - public void testWhenResponseIs2xxLoginReturnsValidMetadataValue() { + dependsOnMethods = { "testMergeMetadata" }) + public void testGetMetadataValue() { metadataValue = mediaClient.getMetadataValue(mediaRef, "key"); - - // Check parent type - checkResourceType(metadataValue); - - // Check required elements and attributes - String value = metadataValue.getValue(); - assertNotNull(value, - String.format(OBJ_FIELD_ATTRB_REQ, MEDIA, "MetadataEntry", - metadataValue.toString(), metadataEntryValue.toString())); - assertEquals(value, metadataEntryValue, - String.format(OBJ_FIELD_EQ, MEDIA, "metadataEntry.value", metadataEntryValue, value)); + Checks.checkMetadataValueFor(MEDIA, metadataValue); } @Test(testName = "PUT /media/{id}/metadata/{key}", - dependsOnMethods = { "testWhenResponseIs2xxLoginReturnsValidMetadataValue" }) - public void testWhenResponseIs2xxLoginUpdatesMetadataEntry() { + dependsOnMethods = { "testGetMetadataValue" }) + public void testSetMetadataValue() { metadataEntryValue = "newValue"; MetadataValue newValue = MetadataValue.builder().value(metadataEntryValue).build(); @@ -276,14 +246,12 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { assertTrue(retryTaskSuccess.apply(setMetadataEntry.getHref()), String.format(TASK_COMPLETE_TIMELY, "setMetadataEntry")); metadataValue = mediaClient.getMetadataValue(mediaRef, "key"); - - // ensure metadataEntry remains valid - testWhenResponseIs2xxLoginReturnsValidMetadataValue(); + Checks.checkMetadataValueFor(MEDIA, metadataValue); } @Test(testName = "DELETE /media/{id}/metadata/{key}", - dependsOnMethods = { "testWhenResponseIs2xxLoginUpdatesMetadataEntry" } ) - public void testWhenResponseIs2xxLoginDeletesMetadataEntry() { + dependsOnMethods = { "testSetMetadataValue" } ) + public void testDeleteMetadata() { Task deleteMetadataEntry = mediaClient.deleteMetadataEntry(mediaRef, "testKey"); Checks.checkTask(deleteMetadataEntry); assertTrue(retryTaskSuccess.apply(deleteMetadataEntry.getHref()), @@ -311,14 +279,16 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { "metadataEntry", metadataValue.toString())); } - // ensure metadata and media remains valid - testWhenResponseIs2xxLoginReturnsValidMetadata(); - testWhenResponseIs2xxLoginReturnsValidMedia(); - } - @Test(testName = "DELETE /media/{id}", - dependsOnMethods = { "testWhenResponseIs2xxLoginDeletesMetadataEntry" } ) - public void testWhenResponseIs2xxLoginDeletesMedia() { + metadataValue = mediaClient.getMetadataValue(mediaRef, "key"); + Checks.checkMetadataValueFor(MEDIA, metadataValue); + media = mediaClient.getMedia(mediaRef); + Checks.checkMediaFor(MEDIA, media); + } + + @Test(testName = "DELETE /media/{id}", + dependsOnMethods = { "testDeleteMetadata" } ) + public void testDeleteMedia() { Task deleteMedia = mediaClient.deleteMedia(mediaRef); Checks.checkTask(deleteMedia); assertTrue(retryTaskSuccess.apply(deleteMedia.getHref()), From e199b2bc5d9e0098279f65f11f9f4c26ccbd66c2 Mon Sep 17 00:00:00 2001 From: danikov Date: Thu, 23 Feb 2012 13:48:33 +0000 Subject: [PATCH 6/7] deprecate old 'standard' req/resp methods --- .../BaseVCloudDirectorRestClientExpectTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java index 75c4a4ea49..d76fb1bea1 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java @@ -81,28 +81,34 @@ public class BaseVCloudDirectorRestClientExpectTest extends BaseRestClientExpect credential = password; } + @Deprecated protected HttpRequest getStandardRequest(String method, String path) { return getStandardRequest(method, path, VCloudDirectorMediaType.ANY); } + @Deprecated protected HttpRequest getStandardRequest(String method, URI uri) { return getStandardRequest(method, uri, VCloudDirectorMediaType.ANY); } + @Deprecated protected HttpRequest getStandardRequest(String method, String path, String mediaType) { return getStandardRequest(method, URI.create(endpoint + path), VCloudDirectorMediaType.ANY); } + @Deprecated protected HttpRequest getStandardPayloadRequest(String method, String command, String relativeFilePath, String postMediaType) { return getStandardPayloadRequest(method, URI.create(endpoint + command), relativeFilePath, postMediaType); } + @Deprecated protected HttpRequest getStandardPayloadRequest(String method, URI uri, String relativeFilePath, String postMediaType) { return getStandardRequestWithPayload(method, uri, VCloudDirectorMediaType.ANY, relativeFilePath, postMediaType); } + @Deprecated protected HttpRequest getStandardRequest(String method, URI uri, String mediaType) { return HttpRequest.builder() .method(method) @@ -114,19 +120,23 @@ public class BaseVCloudDirectorRestClientExpectTest extends BaseRestClientExpect .build(); } + @Deprecated protected HttpRequest getStandardRequestWithPayload(String method, String path, String relativeFilePath, String mediaType) { return getStandardRequestWithPayload(method, path, VCloudDirectorMediaType.ANY, relativeFilePath, mediaType); } + @Deprecated protected HttpRequest getStandardRequestWithPayload(String method, URI uri, String relativeFilePath, String mediaType) { return getStandardRequestWithPayload(method, uri, VCloudDirectorMediaType.ANY, relativeFilePath, mediaType); } + @Deprecated protected HttpRequest getStandardRequestWithPayload(String method, String path, String acceptType, String relativeFilePath, String mediaType) { URI uri = URI.create(endpoint + path); return getStandardRequestWithPayload(method, uri, acceptType, relativeFilePath, mediaType); } + @Deprecated protected HttpRequest getStandardRequestWithPayload(String method, URI uri, String acceptType, String relativeFilePath, String mediaType) { return HttpRequest.builder() .method(method) @@ -139,10 +149,12 @@ public class BaseVCloudDirectorRestClientExpectTest extends BaseRestClientExpect .build(); } + @Deprecated protected HttpResponse getStandardPayloadResponse(String relativeFilePath, String mediaType) { return getStandardPayloadResponse(200, relativeFilePath, mediaType); } + @Deprecated protected HttpResponse getStandardPayloadResponse(int statusCode, String relativeFilePath, String mediaType) { return HttpResponse.builder() .statusCode(statusCode) From 4dc708c494e727c681993114b9a58bf68b1cfa2a Mon Sep 17 00:00:00 2001 From: danikov Date: Thu, 23 Feb 2012 14:15:40 +0000 Subject: [PATCH 7/7] fix misaligned braces --- .../java/org/jclouds/vcloud/director/v1_5/domain/Checks.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java index bf7ad4133c..6308e7addf 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java @@ -370,7 +370,6 @@ public class Checks { public static void checkIpAddress(String ip) { InetAddresses.isInetAddress(ip); } - } public static void checkVApp(VApp vApp) { // TODO Auto-generated method stub @@ -391,4 +390,5 @@ public class Checks { // parent type Checks.checkResourceEntityType(media); + } }