Merge pull request #496 from danikov/vclouds-director-bugfixes-3

Issue 830: vCloud director Bugfix
This commit is contained in:
Adrian Cole 2012-03-20 17:35:15 -07:00
commit 0165724559
2 changed files with 24 additions and 19 deletions

View File

@ -78,11 +78,12 @@ public interface MediaAsyncClient {
* @see MediaClient#cloneMedia(URI, CloneMediaParams) * @see MediaClient#cloneMedia(URI, CloneMediaParams)
*/ */
@POST @POST
@Path("/action/cloneMedia")
@Consumes(VCloudDirectorMediaType.MEDIA) @Consumes(VCloudDirectorMediaType.MEDIA)
@Produces(VCloudDirectorMediaType.CLONE_MEDIA_PARAMS) @Produces(VCloudDirectorMediaType.CLONE_MEDIA_PARAMS)
@JAXBResponseParser @JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class) @ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<Media> cloneMedia(@EndpointParam URI cloneLink, ListenableFuture<Media> cloneMedia(@EndpointParam URI vdcRef,
@BinderParam(BindToXMLPayload.class) CloneMediaParams params); @BinderParam(BindToXMLPayload.class) CloneMediaParams params);
/** /**

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,8 +170,12 @@ 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()
"getOwner()", "owner", "media.getOwner()", owner.toString(), directOwner.toString())); .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 // parent type
Checks.checkResourceType(directOwner); Checks.checkResourceType(directOwner);
@ -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);
@ -394,7 +398,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
Error expected = Error.builder() Error expected = Error.builder()
.message(String.format( .message(String.format(
"No access to entity \"(com.vmware.vcloud.entity.media:%s)\".", "No access to entity \"(com.vmware.vcloud.entity.media:%s)\".",
media.getId())) media.getId().substring("urn:vcloud:media:".length())))
.majorErrorCode(403) .majorErrorCode(403)
.minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN") .minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN")
.build(); .build();