From 0f5cae3eafb1fc5ee7ddd428646a0bc6f1d64e0e Mon Sep 17 00:00:00 2001 From: danikov Date: Tue, 20 Mar 2012 23:37:26 +0000 Subject: [PATCH 1/2] re-order and fix media tests --- .../v1_5/features/MediaClientLiveTest.java | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 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 05ae9aa618..1cbc2de29e 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 @@ -45,6 +45,7 @@ import static org.testng.Assert.assertTrue; import static org.testng.Assert.fail; import java.net.URISyntaxException; +import java.util.Collections; import java.util.Set; import org.jclouds.io.Payloads; @@ -115,7 +116,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { Media sourceMedia = Media.builder() .type(VCloudDirectorMediaType.MEDIA) - .name("Test media 1") + .name("Test media "+random.nextInt()) .size(iso.length) .imageType(Media.ImageType.ISO) .description("Test media generated by testCreateMedia()") @@ -129,6 +130,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { media.getFiles().size())); File uploadFile = getFirst(media.getFiles(), null); assertNotNull(uploadFile, String.format(OBJ_FIELD_REQ, MEDIA, "files.first")); + assertEquals(uploadFile.getSize(), new Long(iso.length)); assertTrue(equal(uploadFile.getSize(), sourceMedia.getSize()), String.format(OBJ_FIELD_EQ, MEDIA, "uploadFile.size()", sourceMedia.getSize(), uploadFile.getSize())); @@ -144,14 +146,12 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { media = mediaClient.getMedia(media.getHref()); if (media.getTasks().size() == 1) { - Task task = Iterables.getOnlyElement(media.getTasks()); - assertEquals(task.getStatus(), "running"); + Task uploadTask = Iterables.getOnlyElement(media.getTasks()); + Checks.checkTask(uploadTask); + assertEquals(uploadTask.getStatus(), "running"); + assertTrue(retryTaskSuccess.apply(uploadTask), String.format(TASK_COMPLETE_TIMELY, "uploadTask")); + media = mediaClient.getMedia(media.getHref()); } - - File file = Iterables.getOnlyElement(media.getFiles()); - assertEquals(file.getSize(), new Long(iso.length)); - assertEquals(file.getBytesTransferred(), new Long(iso.length)); - } @Test(testName = "GET /media/{id}", dependsOnMethods = { "testCreateMedia" }) @@ -170,8 +170,12 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { dependsOnMethods = { "testGetMedia" }) public void testGetMediaOwner() { Owner directOwner = mediaClient.getOwner(media.getHref()); - assertEquals(owner, directOwner, String.format(GETTER_RETURNS_SAME_OBJ, - "getOwner()", "owner", "media.getOwner()", owner.toString(), directOwner.toString())); + assertEquals(owner.toBuilder() + .user(owner.getUser().toBuilder().id(null).build()) + .build(), + directOwner.toBuilder().links(Collections.emptySet()).build(), + String.format(GETTER_RETURNS_SAME_OBJ, + "getOwner()", "owner", "media.getOwner()", owner.toString(), directOwner.toString())); // parent type Checks.checkResourceType(directOwner); @@ -187,7 +191,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { oldMedia = media; media = vdcClient.cloneMedia(vdcURI, CloneMediaParams.builder() .source(Reference.builder().fromEntity(media).build()) - .name("copied test media") + .name("copied "+media.getName()) .description("copied by testCloneMedia()") .build()); @@ -262,7 +266,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { } @Test(testName = "GET /media/{id}/metadata", - dependsOnMethods = { "testGetMedia" }) + dependsOnMethods = { "testSetMetadataValue" }) public void testGetMetadata() { metadata = mediaClient.getMetadataClient().getMetadata(media.getHref()); // required for testing @@ -273,7 +277,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { } @Test(testName = "POST /media/{id}/metadata", - dependsOnMethods = { "testGetMetadata" }) + dependsOnMethods = { "testGetMedia" }) public void testMergeMetadata() { // test new Set inputEntries = ImmutableSet.of(MetadataEntry.builder().entry("testKey", "testValue").build()); @@ -326,16 +330,16 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { } @Test(testName = "GET /media/{id}/metadata/{key}", - dependsOnMethods = { "testMergeMetadata" }) + dependsOnMethods = { "testSetMetadataValue" }) public void testGetMetadataValue() { metadataValue = mediaClient.getMetadataClient().getMetadataValue(media.getHref(), "key"); Checks.checkMetadataValueFor(MEDIA, metadataValue); } @Test(testName = "PUT /media/{id}/metadata/{key}", - dependsOnMethods = { "testGetMetadataValue" }) + dependsOnMethods = { "testMergeMetadata" }) public void testSetMetadataValue() { - metadataEntryValue = "newValue"; + metadataEntryValue = "value"; MetadataValue newValue = MetadataValue.builder().value(metadataEntryValue).build(); Task setMetadataEntry = mediaClient.getMetadataClient().setMetadata(media.getHref(), "key", newValue); @@ -347,7 +351,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { } @Test(testName = "DELETE /media/{id}/metadata/{key}", - dependsOnMethods = { "testSetMetadataValue" } ) + dependsOnMethods = { "testGetMetadata", "testGetMetadataValue" } ) public void testDeleteMetadata() { Task deleteMetadataEntry = mediaClient.getMetadataClient().deleteMetadataEntry(media.getHref(), "testKey"); Checks.checkTask(deleteMetadataEntry); From f0913ee6b49acf1796ea890d09a8ece9314d8eeb Mon Sep 17 00:00:00 2001 From: danikov Date: Tue, 20 Mar 2012 23:55:27 +0000 Subject: [PATCH 2/2] fix cloneMedia (bad path) and deleteMedia (wrong ID) --- .../vcloud/director/v1_5/features/MediaAsyncClient.java | 3 ++- .../vcloud/director/v1_5/features/MediaClientLiveTest.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/MediaAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/MediaAsyncClient.java index 3d6b9ef570..40b698d5f6 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/MediaAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/MediaAsyncClient.java @@ -78,11 +78,12 @@ public interface MediaAsyncClient { * @see MediaClient#cloneMedia(URI, CloneMediaParams) */ @POST + @Path("/action/cloneMedia") @Consumes(VCloudDirectorMediaType.MEDIA) @Produces(VCloudDirectorMediaType.CLONE_MEDIA_PARAMS) @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture cloneMedia(@EndpointParam URI cloneLink, + ListenableFuture cloneMedia(@EndpointParam URI vdcRef, @BinderParam(BindToXMLPayload.class) CloneMediaParams params); /** 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 1cbc2de29e..49a140ac12 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 @@ -398,7 +398,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { Error expected = Error.builder() .message(String.format( "No access to entity \"(com.vmware.vcloud.entity.media:%s)\".", - media.getId())) + media.getId().substring("urn:vcloud:media:".length()))) .majorErrorCode(403) .minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN") .build();