mirror of https://github.com/apache/jclouds.git
re-order and fix media tests
This commit is contained in:
parent
58ee8fa1a4
commit
0f5cae3eaf
|
@ -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,7 +170,11 @@ 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,
|
||||
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()));
|
||||
|
||||
// parent type
|
||||
|
@ -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<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}",
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue