re-order and fix media tests

This commit is contained in:
danikov 2012-03-20 23:37:26 +00:00
parent 58ee8fa1a4
commit 0f5cae3eaf
1 changed files with 21 additions and 17 deletions

View File

@ -45,6 +45,7 @@ import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail; import static org.testng.Assert.fail;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Collections;
import java.util.Set; import java.util.Set;
import org.jclouds.io.Payloads; import org.jclouds.io.Payloads;
@ -115,7 +116,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
Media sourceMedia = Media.builder() Media sourceMedia = Media.builder()
.type(VCloudDirectorMediaType.MEDIA) .type(VCloudDirectorMediaType.MEDIA)
.name("Test media 1") .name("Test media "+random.nextInt())
.size(iso.length) .size(iso.length)
.imageType(Media.ImageType.ISO) .imageType(Media.ImageType.ISO)
.description("Test media generated by testCreateMedia()") .description("Test media generated by testCreateMedia()")
@ -129,6 +130,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
media.getFiles().size())); media.getFiles().size()));
File uploadFile = getFirst(media.getFiles(), null); File uploadFile = getFirst(media.getFiles(), null);
assertNotNull(uploadFile, String.format(OBJ_FIELD_REQ, MEDIA, "files.first")); 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()", assertTrue(equal(uploadFile.getSize(), sourceMedia.getSize()), String.format(OBJ_FIELD_EQ, MEDIA, "uploadFile.size()",
sourceMedia.getSize(), uploadFile.getSize())); sourceMedia.getSize(), uploadFile.getSize()));
@ -144,14 +146,12 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
media = mediaClient.getMedia(media.getHref()); media = mediaClient.getMedia(media.getHref());
if (media.getTasks().size() == 1) { if (media.getTasks().size() == 1) {
Task task = Iterables.getOnlyElement(media.getTasks()); Task uploadTask = Iterables.getOnlyElement(media.getTasks());
assertEquals(task.getStatus(), "running"); 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" }) @Test(testName = "GET /media/{id}", dependsOnMethods = { "testCreateMedia" })
@ -170,7 +170,11 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
dependsOnMethods = { "testGetMedia" }) dependsOnMethods = { "testGetMedia" })
public void testGetMediaOwner() { public void testGetMediaOwner() {
Owner directOwner = mediaClient.getOwner(media.getHref()); Owner directOwner = mediaClient.getOwner(media.getHref());
assertEquals(owner, directOwner, String.format(GETTER_RETURNS_SAME_OBJ, assertEquals(owner.toBuilder()
.user(owner.getUser().toBuilder().id(null).build())
.build(),
directOwner.toBuilder().links(Collections.<Link>emptySet()).build(),
String.format(GETTER_RETURNS_SAME_OBJ,
"getOwner()", "owner", "media.getOwner()", owner.toString(), directOwner.toString())); "getOwner()", "owner", "media.getOwner()", owner.toString(), directOwner.toString()));
// parent type // parent type
@ -187,7 +191,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
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 "+media.getName())
.description("copied by testCloneMedia()") .description("copied by testCloneMedia()")
.build()); .build());
@ -262,7 +266,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
} }
@Test(testName = "GET /media/{id}/metadata", @Test(testName = "GET /media/{id}/metadata",
dependsOnMethods = { "testGetMedia" }) dependsOnMethods = { "testSetMetadataValue" })
public void testGetMetadata() { public void testGetMetadata() {
metadata = mediaClient.getMetadataClient().getMetadata(media.getHref()); metadata = mediaClient.getMetadataClient().getMetadata(media.getHref());
// required for testing // required for testing
@ -273,7 +277,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
} }
@Test(testName = "POST /media/{id}/metadata", @Test(testName = "POST /media/{id}/metadata",
dependsOnMethods = { "testGetMetadata" }) dependsOnMethods = { "testGetMedia" })
public void testMergeMetadata() { public void testMergeMetadata() {
// test new // test new
Set<MetadataEntry> inputEntries = ImmutableSet.of(MetadataEntry.builder().entry("testKey", "testValue").build()); Set<MetadataEntry> 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}", @Test(testName = "GET /media/{id}/metadata/{key}",
dependsOnMethods = { "testMergeMetadata" }) dependsOnMethods = { "testSetMetadataValue" })
public void testGetMetadataValue() { public void testGetMetadataValue() {
metadataValue = mediaClient.getMetadataClient().getMetadataValue(media.getHref(), "key"); metadataValue = mediaClient.getMetadataClient().getMetadataValue(media.getHref(), "key");
Checks.checkMetadataValueFor(MEDIA, metadataValue); Checks.checkMetadataValueFor(MEDIA, metadataValue);
} }
@Test(testName = "PUT /media/{id}/metadata/{key}", @Test(testName = "PUT /media/{id}/metadata/{key}",
dependsOnMethods = { "testGetMetadataValue" }) dependsOnMethods = { "testMergeMetadata" })
public void testSetMetadataValue() { public void testSetMetadataValue() {
metadataEntryValue = "newValue"; metadataEntryValue = "value";
MetadataValue newValue = MetadataValue.builder().value(metadataEntryValue).build(); MetadataValue newValue = MetadataValue.builder().value(metadataEntryValue).build();
Task setMetadataEntry = mediaClient.getMetadataClient().setMetadata(media.getHref(), "key", newValue); 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}", @Test(testName = "DELETE /media/{id}/metadata/{key}",
dependsOnMethods = { "testSetMetadataValue" } ) dependsOnMethods = { "testGetMetadata", "testGetMetadataValue" } )
public void testDeleteMetadata() { public void testDeleteMetadata() {
Task deleteMetadataEntry = mediaClient.getMetadataClient().deleteMetadataEntry(media.getHref(), "testKey"); Task deleteMetadataEntry = mediaClient.getMetadataClient().deleteMetadataEntry(media.getHref(), "testKey");
Checks.checkTask(deleteMetadataEntry); Checks.checkTask(deleteMetadataEntry);