mirror of https://github.com/apache/jclouds.git
Merge pull request #496 from danikov/vclouds-director-bugfixes-3
Issue 830: vCloud director Bugfix
This commit is contained in:
commit
0165724559
|
@ -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<Media> cloneMedia(@EndpointParam URI cloneLink,
|
||||
ListenableFuture<Media> cloneMedia(@EndpointParam URI vdcRef,
|
||||
@BinderParam(BindToXMLPayload.class) CloneMediaParams params);
|
||||
|
||||
/**
|
||||
|
|
|
@ -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.<Link>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<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);
|
||||
|
@ -394,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();
|
||||
|
|
Loading…
Reference in New Issue