From 0ff51f36ce07b46b81c010e7abca8d6146fb5b37 Mon Sep 17 00:00:00 2001 From: danikov Date: Thu, 9 Feb 2012 19:07:51 +0000 Subject: [PATCH 01/30] initial tests --- .../v1_5/features/MediaClientExpectTest.java | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java new file mode 100644 index 0000000000..a0ce34ef34 --- /dev/null +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java @@ -0,0 +1,93 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + *(Link.builder().regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless(Link.builder().required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.vcloud.director.v1_5.features; + +import static org.testng.Assert.assertEquals; + +import java.net.URI; + +import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.jclouds.vcloud.director.v1_5.domain.Link; +import org.jclouds.vcloud.director.v1_5.domain.Media; +import org.jclouds.vcloud.director.v1_5.domain.Metadata; +import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; +import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; +import org.testng.annotations.Test; + +/** + * Allows us to test a client via its side effects. + * + * @author danikov + */ +@Test(groups = "unit", singleThreaded = true, testName = "NetworkClientExpectTest") +public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { + + @Test + public void testWhenResponseIs2xxLoginReturnsValidMedia() { + URI mediaRef = URI.create("https://vcloudbeta.bluelock.com/api/media/KEY"); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + getStandardRequest("GET", mediaRef), + getStandardPayloadResponse("/media/media.xml", VCloudDirectorMediaType.MEDIA_XML)); + + Media expected = Media + .builder() + .build(); + + assertEquals(client.getMediaClient().getMedia(mediaRef), expected); + } + + @Test + public void testWhenResponseIs2xxLoginReturnsValidMetadata() { + URI mediaRef = URI.create("https://vcloudbeta.bluelock.com/api/media/KEY"); + URI metaRef = URI.create(mediaRef.toASCIIString()+"/metadata/"); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + getStandardRequest("GET", metaRef), + getStandardPayloadResponse("/media/metadata.xml", VCloudDirectorMediaType.METADATA_XML)); + + Metadata expected = Metadata.builder() + .type("application/vnd.vmware.vcloud.metadata+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/media/KEY/metadata")) + .link(Link.builder() + .rel("up") + .type("application/vnd.vmware.vcloud.network+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/media/KEY")) + .build()) + .build(); + + assertEquals(client.getMediaClient().getMetadata(mediaRef), expected); + } + + @Test(enabled=false) // No metadata in exemplar xml... + public void testWhenResponseIs2xxLoginReturnsValidMetadataEntry() { + URI metadataRef = URI.create( + "https://vcloudbeta.bluelock.com/api/media/KEY/metadata/KEY"); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + getStandardRequest("GET", metadataRef), + getStandardPayloadResponse("/media/metadataEntry.xml", VCloudDirectorMediaType.METADATAENTRY_XML)); + + MetadataEntry expected = MetadataEntry.builder() + .build(); + + assertEquals(client.getMediaClient().getMetadataEntry(metadataRef), expected); + } +} From f3543a4c233de61e3a84b366ecab337d1c1a4ff5 Mon Sep 17 00:00:00 2001 From: danikov Date: Thu, 9 Feb 2012 19:08:14 +0000 Subject: [PATCH 02/30] domain objects --- .../vcloud/director/v1_5/domain/File.java | 300 ++++++++++++++++++ .../director/v1_5/domain/FilesList.java | 159 ++++++++++ .../vcloud/director/v1_5/domain/Media.java | 230 ++++++++++++++ .../vcloud/director/v1_5/domain/Owner.java | 199 ++++++++++++ .../v1_5/domain/ResourceEntityType.java | 265 ++++++++++++++++ 5 files changed, 1153 insertions(+) create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/File.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/FilesList.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Media.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Owner.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceEntityType.java diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/File.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/File.java new file mode 100644 index 0000000000..ea9369ecb1 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/File.java @@ -0,0 +1,300 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.vcloud.director.v1_5.domain; + +import static com.google.common.base.Objects.equal; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; +import java.util.Set; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlSchemaType; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.adapters.NormalizedStringAdapter; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; + +import com.google.common.base.Objects; +import com.google.common.collect.Sets; + + +/** + * + * Represents a file to be transferred (uploaded or downloaded). + * + * + *

Java class for File complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="File">
+ *   <complexContent>
+ *     <extension base="{http://www.vmware.com/vcloud/v1.5}EntityType">
+ *       <attribute name="size" type="{http://www.w3.org/2001/XMLSchema}long" />
+ *       <attribute name="bytesTransferred" type="{http://www.w3.org/2001/XMLSchema}long" />
+ *       <attribute name="checksum" type="{http://www.w3.org/2001/XMLSchema}normalizedString" />
+ *       <anyAttribute processContents='lax' namespace='##other'/>
+ *     </extension>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "File") +public class File + extends EntityType + +{ + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromFile(this); + } + + public static class Builder extends EntityType.Builder { + + private Long size; + private Long bytesTransferred; + private String checksum; + + /** + * @see File#getSize() + */ + public Builder size(Long size) { + this.size = size; + return this; + } + + /** + * @see File#getBytesTransferred() + */ + public Builder bytesTransferred(Long bytesTransferred) { + this.bytesTransferred = bytesTransferred; + return this; + } + + /** + * @see File#getChecksum() + */ + public Builder checksum(String checksum) { + this.checksum = checksum; + return this; + } + + + public File build() { + File file = new File(); + file.setSize(size); + file.setBytesTransferred(bytesTransferred); + file.setChecksum(checksum); + return file; + } + + + /** + * @see EntityType#getId() + */ + @Override + public Builder id(String id) { + this.id = id; + return this; + } + + /** + * @see EntityType#getTasksInProgress() + */ + @Override + public Builder tasksInProgress(TasksInProgress tasksInProgress) { + this.tasksInProgress = tasksInProgress; + return this; + } + + /** + * @see ReferenceType#getHref() + */ + @Override + public Builder href(URI href) { + this.href = href; + return this; + } + + /** + * @see ReferenceType#getType() + */ + @Override + public Builder type(String type) { + this.type = type; + return this; + } + + /** + * @see ReferenceType#getLinks() + */ + @Override + public Builder links(Set links) { + this.links = Sets.newLinkedHashSet(checkNotNull(links, "links")); + return this; + } + + /** + * @see ReferenceType#getLinks() + */ + @Override + public Builder link(Link link) { + this.links.add(checkNotNull(link, "link")); + return this; + } + + + @Override + public Builder fromEntityType(EntityType in) { + return Builder.class.cast(super.fromEntityType(in)); + } + public Builder fromFile(File in) { + return fromEntityType(in) + .size(in.getSize()) + .bytesTransferred(in.getBytesTransferred()) + .checksum(in.getChecksum()); + } + } + + private File() { + // For JAXB and builder use + } + + + + @XmlAttribute + protected Long size; + @XmlAttribute + protected Long bytesTransferred; + @XmlAttribute + @XmlJavaTypeAdapter(NormalizedStringAdapter.class) + @XmlSchemaType(name = "normalizedString") + protected String checksum; + + /** + * Gets the value of the size property. + * + * @return + * possible object is + * {@link Long } + * + */ + public Long getSize() { + return size; + } + + /** + * Sets the value of the size property. + * + * @param value + * allowed object is + * {@link Long } + * + */ + public void setSize(Long value) { + this.size = value; + } + + /** + * Gets the value of the bytesTransferred property. + * + * @return + * possible object is + * {@link Long } + * + */ + public Long getBytesTransferred() { + return bytesTransferred; + } + + /** + * Sets the value of the bytesTransferred property. + * + * @param value + * allowed object is + * {@link Long } + * + */ + public void setBytesTransferred(Long value) { + this.bytesTransferred = value; + } + + /** + * Gets the value of the checksum property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getChecksum() { + return checksum; + } + + /** + * Sets the value of the checksum property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setChecksum(String value) { + this.checksum = value; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + File that = File.class.cast(o); + return equal(size, that.size) && + equal(bytesTransferred, that.bytesTransferred) && + equal(checksum, that.checksum); + } + + @Override + public int hashCode() { + return Objects.hashCode(size, + bytesTransferred, + checksum); + } + + @Override + public String toString() { + return Objects.toStringHelper("") + .add("size", size) + .add("bytesTransferred", bytesTransferred) + .add("checksum", checksum).toString(); + } + +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/FilesList.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/FilesList.java new file mode 100644 index 0000000000..39c7eff127 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/FilesList.java @@ -0,0 +1,159 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.vcloud.director.v1_5.domain; + +import static com.google.common.base.Objects.equal; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlType; + +import com.google.common.base.Objects; + + +/** + * + * Represents a list of files to be transferred (uploaded + * or downloaded). + * + * + *

Java class for FilesList complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="FilesList">
+ *   <complexContent>
+ *     <extension base="{http://www.vmware.com/vcloud/v1.5}VCloudExtensibleType">
+ *       <sequence>
+ *         <element name="File" type="{http://www.vmware.com/vcloud/v1.5}FileType" maxOccurs="unbounded"/>
+ *       </sequence>
+ *       <anyAttribute processContents='lax' namespace='##other'/>
+ *     </extension>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "FilesList", propOrder = { + "file" +}) +public class FilesList { + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromFilesList(this); + } + + public static class Builder { + + private List files; + + /** + * @see FilesList#getFile() + */ + public Builder file(List file) { + this.files = file; + return this; + } + + + public FilesList build() { + FilesList filesList = new FilesList(files); + return filesList; + } + + + public Builder fromFilesList(FilesList in) { + return file(in.getFile()); + } + } + + private FilesList() { + // For JAXB and builder use + } + + private FilesList(List files) { + this.files = files; + } + + + @XmlElement(name = "File", required = true) + protected List files; + + /** + * Gets the value of the file property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the file property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getFile().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link FileType } + * + * + */ + public List getFile() { + if (files == null) { + files = new ArrayList(); + } + return this.files; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + FilesList that = FilesList.class.cast(o); + return equal(files, that.files); + } + + @Override + public int hashCode() { + return Objects.hashCode(files); + } + + @Override + public String toString() { + return Objects.toStringHelper("") + .add("file", files).toString(); + } + +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Media.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Media.java new file mode 100644 index 0000000000..e9f9a256d8 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Media.java @@ -0,0 +1,230 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.vcloud.director.v1_5.domain; + +import static com.google.common.base.Objects.equal; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlType; + +import com.google.common.base.Objects; + + +/** + * + * Represents a media. + * + * + *

Java class for Media complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="Media">
+ *   <complexContent>
+ *     <extension base="{http://www.vmware.com/vcloud/v1.5}ResourceEntityType">
+ *       <sequence>
+ *         <element name="Owner" type="{http://www.vmware.com/vcloud/v1.5}OwnerType" minOccurs="0"/>
+ *       </sequence>
+ *       <attribute name="imageType" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *       <attribute name="size" use="required" type="{http://www.w3.org/2001/XMLSchema}long" />
+ *       <anyAttribute processContents='lax' namespace='##other'/>
+ *     </extension>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "Media", propOrder = { + "owner" +}) +public class Media + extends ResourceEntityType + +{ + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromMedia(this); + } + + public static class Builder extends ResourceEntityType.Builder { + + private Owner owner; + private String imageType; + private long size; + + /** + * @see Media#getOwner() + */ + public Builder owner(Owner owner) { + this.owner = owner; + return this; + } + + /** + * @see Media#getImageType() + */ + public Builder imageType(String imageType) { + this.imageType = imageType; + return this; + } + + /** + * @see Media#getSize() + */ + public Builder size(long size) { + this.size = size; + return this; + } + + + public Media build() { + Media media = new Media(); + media.setOwner(owner); + media.setImageType(imageType); + media.setSize(size); + return media; + } + + + @Override + public Builder fromResourceEntityType(ResourceEntityType in) { + return Builder.class.cast(super.fromResourceEntityType(in)); + } + public Builder fromMedia(Media in) { + return fromResourceEntityType(in) + .owner(in.getOwner()) + .imageType(in.getImageType()) + .size(in.getSize()); + } + } + + public Media() { + super(); + } + + @XmlElement(name = "Owner") + protected Owner owner; + @XmlAttribute(required = true) + protected String imageType; + @XmlAttribute(required = true) + protected long size; + + /** + * Gets the value of the owner property. + * + * @return + * possible object is + * {@link Owner } + * + */ + public Owner getOwner() { + return owner; + } + + /** + * Sets the value of the owner property. + * + * @param value + * allowed object is + * {@link Owner } + * + */ + public void setOwner(Owner value) { + this.owner = value; + } + + /** + * Gets the value of the imageType property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getImageType() { + return imageType; + } + + /** + * Sets the value of the imageType property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setImageType(String value) { + this.imageType = value; + } + + /** + * Gets the value of the size property. + * + */ + public long getSize() { + return size; + } + + /** + * Sets the value of the size property. + * + */ + public void setSize(long value) { + this.size = value; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Media that = Media.class.cast(o); + return equal(owner, that.owner) && + equal(imageType, that.imageType) && + equal(size, that.size); + } + + @Override + public int hashCode() { + return Objects.hashCode(owner, + imageType, + size); + } + + @Override + public String toString() { + return Objects.toStringHelper("") + .add("owner", owner) + .add("imageType", imageType) + .add("size", size).toString(); + } + +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Owner.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Owner.java new file mode 100644 index 0000000000..642bd159ff --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Owner.java @@ -0,0 +1,199 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.vcloud.director.v1_5.domain; + +import static com.google.common.base.Objects.equal; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; +import java.util.Set; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlType; + +import com.google.common.base.Objects; +import com.google.common.collect.Sets; + + +/** + * + * Represents the owner of this entity. + * + * + *

Java class for Owner complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="Owner">
+ *   <complexContent>
+ *     <extension base="{http://www.vmware.com/vcloud/v1.5}ResourceType">
+ *       <sequence>
+ *         <element name="User" type="{http://www.vmware.com/vcloud/v1.5}ReferenceType"/>
+ *       </sequence>
+ *       <anyAttribute processContents='lax' namespace='##other'/>
+ *     </extension>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "Owner", propOrder = { + "user" +}) +public class Owner + extends ResourceType + +{ + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromOwner(this); + } + + public static class Builder extends ResourceType.Builder { + + private Reference user; + + /** + * @see Owner#getUser() + */ + public Builder user(Reference user) { + this.user = user; + return this; + } + + + public Owner build() { + Owner owner = new Owner(); + owner.setUser(user); + return owner; + } + + + /** + * @see ResourceType#getHref() + */ + @Override + public Builder href(URI href) { + super.href(href); + return this; + } + + /** + * @see ResourceType#getType() + */ + @Override + public Builder type(String type) { + super.type(type); + return this; + } + + /** + * @see ResourceType#getLinks() + */ + @Override + public Builder links(Set links) { + super.links(Sets.newLinkedHashSet(checkNotNull(links, "links"))); + return this; + } + + /** + * @see ResourceType#getLinks() + */ + @Override + public Builder link(Link link) { + super.link(link); + return this; + } + + + @Override + public Builder fromResourceType(ResourceType in) { + return Builder.class.cast(super.fromResourceType(in)); + } + public Builder fromOwner(Owner in) { + return fromResourceType(in) + .user(in.getUser()); + } + } + + private Owner() { + // For JAXB and builder use + } + + + + @XmlElement(name = "User", required = true) + protected Reference user; + + /** + * Gets the value of the user property. + * + * @return + * possible object is + * {@link Reference } + * + */ + public Reference getUser() { + return user; + } + + /** + * Sets the value of the user property. + * + * @param value + * allowed object is + * {@link Reference } + * + */ + public void setUser(Reference value) { + this.user = value; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Owner that = Owner.class.cast(o); + return equal(user, that.user); + } + + @Override + public int hashCode() { + return Objects.hashCode(user); + } + + @Override + public String toString() { + return Objects.toStringHelper("") + .add("user", user).toString(); + } + +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceEntityType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceEntityType.java new file mode 100644 index 0000000000..56c9ac6ea0 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceEntityType.java @@ -0,0 +1,265 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.vcloud.director.v1_5.domain; + +import static com.google.common.base.Objects.equal; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; +import java.util.Set; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlType; + +import com.google.common.base.Objects; +import com.google.common.collect.Sets; + + +/** + * + * Base type that represents a resource entity such as a vApp + * template or virtual media. + * + * + *

Java class for ResourceEntity complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="ResourceEntity">
+ *   <complexContent>
+ *     <extension base="{http://www.vmware.com/vcloud/v1.5}EntityType">
+ *       <sequence>
+ *         <element name="Files" type="{http://www.vmware.com/vcloud/v1.5}FilesListType" minOccurs="0"/>
+ *       </sequence>
+ *       <attribute name="status" type="{http://www.w3.org/2001/XMLSchema}int" />
+ *       <anyAttribute processContents='lax' namespace='##other'/>
+ *     </extension>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "ResourceEntity", propOrder = { + "files" +}) +//@XmlSeeAlso({ +// MediaType.class, +// VAppTemplateType.class, +// AbstractVAppType.class, +// NetworkPoolType.class +//}) +public class ResourceEntityType> extends EntityType { + + public static > Builder builder() { + return new Builder(); + } + + @Override + public Builder toBuilder() { + return new Builder().fromResourceEntityType(this); + } + + public static class Builder> extends EntityType.Builder { + + private FilesList files; + private Integer status; + + /** + * @see ResourceEntityType#getFiles() + */ + public Builder files(FilesList files) { + this.files = files; + return this; + } + + /** + * @see ResourceEntityType#getStatus() + */ + public Builder status(Integer status) { + this.status = status; + return this; + } + + + public ResourceEntityType build() { + ResourceEntityType resourceEntity = new ResourceEntityType(); + resourceEntity.setFiles(files); + resourceEntity.setStatus(status); + return resourceEntity; + } + + + /** + * @see EntityType#getId() + */ + @Override + public Builder id(String id) { + this.id = id; + return this; + } + + /** + * @see EntityType#getTasksInProgress() + */ + @Override + public Builder tasksInProgress(TasksInProgress tasksInProgress) { + this.tasksInProgress = tasksInProgress; + return this; + } + + /** + * @see ReferenceType#getHref() + */ + @Override + public Builder href(URI href) { + this.href = href; + return this; + } + + /** + * @see ReferenceType#getType() + */ + @Override + public Builder type(String type) { + this.type = type; + return this; + } + + /** + * @see ReferenceType#getLinks() + */ + @Override + public Builder links(Set links) { + this.links = Sets.newLinkedHashSet(checkNotNull(links, "links")); + return this; + } + + /** + * @see ReferenceType#getLinks() + */ + @Override + public Builder link(Link link) { + this.links.add(checkNotNull(link, "link")); + return this; + } + + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + @Override + public Builder fromResourceType(ResourceType in) { + return Builder.class.cast(super.fromResourceType(in)); + } + + public Builder fromResourceEntityType(ResourceEntityType in) { + return fromResourceType(in) + .files(in.getFiles()) + .status(in.getStatus()); + } + } + + public ResourceEntityType() { + } + + @XmlElement(name = "Files") + protected FilesList files; + @XmlAttribute + protected Integer status; + + /** + * Gets the value of the files property. + * + * @return + * possible object is + * {@link FilesList } + * + */ + public FilesList getFiles() { + return files; + } + + /** + * Sets the value of the files property. + * + * @param value + * allowed object is + * {@link FilesList } + * + */ + public void setFiles(FilesList value) { + this.files = value; + } + + /** + * Gets the value of the status property. + * + * @return + * possible object is + * {@link Integer } + * + */ + public Integer getStatus() { + return status; + } + + /** + * Sets the value of the status property. + * + * @param value + * allowed object is + * {@link Integer } + * + */ + public void setStatus(Integer value) { + this.status = value; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + ResourceEntityType that = ResourceEntityType.class.cast(o); + return equal(files, that.files) && + equal(status, that.status); + } + + @Override + public int hashCode() { + return Objects.hashCode(files, + status); + } + + @Override + public String toString() { + return Objects.toStringHelper("") + .add("files", files) + .add("status", status).toString(); + } + +} From 1972886598b8ffc4494dd79472d18ee3b94bb161 Mon Sep 17 00:00:00 2001 From: danikov Date: Wed, 15 Feb 2012 00:58:39 +0000 Subject: [PATCH 03/30] media type Conflicts: labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java --- .../jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java index 4e8fb0cf83..6c313c1454 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java @@ -63,6 +63,8 @@ public class VCloudDirectorMediaType { public static final String PROPERTY = "application/vnd.vmware.vcloud.property+xml"; + public static final String MEDIA_XML = "application/vnd.vmware.vcloud.media+xml"; + public static final List ALL = Arrays.asList( SESSION, ERROR, ORG_LIST, METADATA, METADATA_ENTRY, METADATA_VALUE, ORG, TASKS_LIST, TASK, ORG_NETWORK, From 4654d4c193f4760e38257f5e46070bb294b7759c Mon Sep 17 00:00:00 2001 From: danikov Date: Thu, 9 Feb 2012 19:12:01 +0000 Subject: [PATCH 04/30] initial clients --- .../v1_5/features/MediaAsyncClient.java | 84 +++++++++++++++++++ .../director/v1_5/features/MediaClient.java | 76 +++++++++++++++++ 2 files changed, 160 insertions(+) create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/MediaAsyncClient.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/MediaClient.java 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 new file mode 100644 index 0000000000..384f112a2c --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/MediaAsyncClient.java @@ -0,0 +1,84 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.vcloud.director.v1_5.features; + +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +import org.jclouds.rest.annotations.EndpointParam; +import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.JAXBResponseParser; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.vcloud.director.v1_5.domain.Media; +import org.jclouds.vcloud.director.v1_5.domain.Metadata; +import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; +import org.jclouds.vcloud.director.v1_5.domain.Owner; +import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; + +import com.google.common.util.concurrent.ListenableFuture; + +/** + * @see MediaClient + * @author danikov + */ +@RequestFilters(AddVCloudAuthorizationToRequest.class) +public interface MediaAsyncClient { + + /** + * @see MediaClient#getMedia() + */ + @GET + @Consumes + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getMedia(@EndpointParam URI mediaRef); + + /** + * @see MediaClient#getMedia() + */ + @GET + @Path("/owner/") + @Consumes + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getOwner(@EndpointParam URI mediaRef); + + /** + * @see MediaClient#getMetadata() + */ + @GET + @Path("/metadata/") + @Consumes + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getMetadata(@EndpointParam URI mediaRef); + + /** + * @see MediaClient#getMetadataEntry() + */ + @GET + @Consumes + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getMetadataEntry(@EndpointParam URI metaDataRef); +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/MediaClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/MediaClient.java new file mode 100644 index 0000000000..c21a8d8787 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/MediaClient.java @@ -0,0 +1,76 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.vcloud.director.v1_5.features; + +import java.net.URI; +import java.util.concurrent.TimeUnit; + +import org.jclouds.concurrent.Timeout; +import org.jclouds.vcloud.director.v1_5.domain.Media; +import org.jclouds.vcloud.director.v1_5.domain.Metadata; +import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; +import org.jclouds.vcloud.director.v1_5.domain.Owner; + +/** + * Provides synchronous access to Media. + *

+ * + * @see MediaAsyncClient + * @see + * @author danikov + */ +@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) +public interface MediaClient { + + /** + * Retrieves a media. + * + * @return the media or null if not found + */ + Media getMedia(URI mediaRef); + + /** + * Retrieves an owner. + * + * @return the owner or null if not found + */ + Owner getOwner(URI mediaRef); + + /** + * Retrieves an list of the media's metadata + * + * @return a list of metadata + */ + Metadata getMetadata(URI mediaRef); + + /** + * Retrieves a metadata entry + * + * @return the metadata entry, or null if not found + */ + MetadataEntry getMetadataEntry(URI metaDataRef); + + // TODO +// PUT /media/{id} Updates the name/description of a media. +// DELETE /media/{id} Deletes a media. +// POST /media/{id}/metadata Merges the metadata for a media with the information provided. +// PUT /media/{id}/metadata/{key} Sets the metadata for the particular key for the media to the value provided. +// DELETE /media/{id}/metadata/{key} Deletes the metadata for the particular key for the media + +} From 9730649e320d8972981289bd46bf9d3617e46584 Mon Sep 17 00:00:00 2001 From: danikov Date: Thu, 9 Feb 2012 19:12:10 +0000 Subject: [PATCH 05/30] wiring --- .../jclouds/vcloud/director/v1_5/VCloudDirectorClient.java | 6 ++++++ .../v1_5/config/VCloudDirectorRestClientModule.java | 3 +++ 2 files changed, 9 insertions(+) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java index 4ac6d277b0..64f37c7324 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java @@ -24,6 +24,7 @@ import org.jclouds.concurrent.Timeout; import org.jclouds.rest.annotations.Delegate; import org.jclouds.vcloud.director.v1_5.domain.Session; import org.jclouds.vcloud.director.v1_5.features.CatalogClient; +import org.jclouds.vcloud.director.v1_5.features.MediaClient; import org.jclouds.vcloud.director.v1_5.features.NetworkClient; import org.jclouds.vcloud.director.v1_5.features.OrgClient; import org.jclouds.vcloud.director.v1_5.features.TaskClient; @@ -70,4 +71,9 @@ public interface VCloudDirectorClient { @Delegate CatalogClient getCatalogClient(); + /** + * @return synchronous access to Media features + */ + @Delegate + MediaClient getMediaClient(); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java index 522137d648..104fb3f359 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java @@ -44,6 +44,8 @@ import org.jclouds.vcloud.director.v1_5.domain.Session; import org.jclouds.vcloud.director.v1_5.domain.SessionWithToken; import org.jclouds.vcloud.director.v1_5.features.CatalogAsyncClient; import org.jclouds.vcloud.director.v1_5.features.CatalogClient; +import org.jclouds.vcloud.director.v1_5.features.MediaAsyncClient; +import org.jclouds.vcloud.director.v1_5.features.MediaClient; import org.jclouds.vcloud.director.v1_5.features.NetworkAsyncClient; import org.jclouds.vcloud.director.v1_5.features.NetworkClient; import org.jclouds.vcloud.director.v1_5.features.OrgAsyncClient; @@ -80,6 +82,7 @@ public class VCloudDirectorRestClientModule extends RestClientModule Date: Thu, 9 Feb 2012 19:43:35 +0000 Subject: [PATCH 06/30] add the rest of the methods --- .../v1_5/features/MediaAsyncClient.java | 49 +++++++++++++++++++ .../director/v1_5/features/MediaClient.java | 40 ++++++++++++--- 2 files changed, 83 insertions(+), 6 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 384f112a2c..112e5c7f15 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 @@ -21,18 +21,23 @@ package org.jclouds.vcloud.director.v1_5.features; import java.net.URI; import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; import javax.ws.rs.Path; import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.JAXBResponseParser; +import org.jclouds.rest.annotations.PayloadParam; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.vcloud.director.v1_5.domain.Media; import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; import org.jclouds.vcloud.director.v1_5.domain.Owner; +import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; import com.google.common.util.concurrent.ListenableFuture; @@ -53,6 +58,23 @@ public interface MediaAsyncClient { @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture getMedia(@EndpointParam URI mediaRef); + /** + * @see MediaClient#updateMedia() + */ + @PUT + @Consumes + @JAXBResponseParser + ListenableFuture updateMedia(@EndpointParam URI mediaRef, + @PayloadParam("Media") Media media); + + /** + * @see MediaClient#deleteMedia() + */ + @DELETE + @Consumes + @JAXBResponseParser + ListenableFuture deleteMedia(@EndpointParam URI mediaRef); + /** * @see MediaClient#getMedia() */ @@ -72,6 +94,15 @@ public interface MediaAsyncClient { @JAXBResponseParser @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture getMetadata(@EndpointParam URI mediaRef); + + /** + * @see MediaClient#updateMetadata() + */ + @POST + @Consumes + @JAXBResponseParser + ListenableFuture updateMetadata(@EndpointParam URI mediaRef, + @PayloadParam("Metadata") Metadata metadata); /** * @see MediaClient#getMetadataEntry() @@ -81,4 +112,22 @@ public interface MediaAsyncClient { @JAXBResponseParser @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture getMetadataEntry(@EndpointParam URI metaDataRef); + + /** + * @see MediaClient#updateMedia() + */ + @PUT + @Consumes + @JAXBResponseParser + ListenableFuture updateMetadataEntry(@EndpointParam URI metaDataRef, + @PayloadParam("MetadataEntry") MetadataEntry metadataEntry); + + /** + * @see MediaClient#deleteMetadataEntry() + */ + @DELETE + @Consumes + @JAXBResponseParser + ListenableFuture deleteMetadataEntry(@EndpointParam URI metaDataRef); + } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/MediaClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/MediaClient.java index c21a8d8787..f666d4244a 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/MediaClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/MediaClient.java @@ -26,6 +26,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Media; import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; import org.jclouds.vcloud.director.v1_5.domain.Owner; +import org.jclouds.vcloud.director.v1_5.domain.Task; /** * Provides synchronous access to Media. @@ -45,6 +46,19 @@ public interface MediaClient { */ Media getMedia(URI mediaRef); + /** + * Updates the name/description of a media. + * + * @return a task. This operation is asynchronous and the user should monitor the returned + * task status in order to check when it is completed. + */ + Task updateMedia(URI mediaRef, Media media); + + /** + * Deletes a media. + */ + void deleteMedia(URI mediaRef); + /** * Retrieves an owner. * @@ -58,6 +72,13 @@ public interface MediaClient { * @return a list of metadata */ Metadata getMetadata(URI mediaRef); + /** + * Merges the metadata for a media with the information provided. + * + * @return a task. This operation is asynchronous and the user should monitor the returned + * task status in order to check when it is completed. + */ + Task updateMetadata(URI mediaRef, Metadata metadata); /** * Retrieves a metadata entry @@ -66,11 +87,18 @@ public interface MediaClient { */ MetadataEntry getMetadataEntry(URI metaDataRef); - // TODO -// PUT /media/{id} Updates the name/description of a media. -// DELETE /media/{id} Deletes a media. -// POST /media/{id}/metadata Merges the metadata for a media with the information provided. -// PUT /media/{id}/metadata/{key} Sets the metadata for the particular key for the media to the value provided. -// DELETE /media/{id}/metadata/{key} Deletes the metadata for the particular key for the media + /** + * Sets the metadata for the particular key for the media to the value provided + * + * @return a task. This operation is asynchronous and the user should monitor the returned + * task status in order to check when it is completed. + */ + Task updateMetadataEntry(URI metaDataRef, MetadataEntry metadataEntry); + + /** + * Deletes a metadata entry. + */ + void deleteMetadataEntry(URI metaDataRef); + } From a714329609328c07a45001eb5606be3f91724592 Mon Sep 17 00:00:00 2001 From: danikov Date: Fri, 10 Feb 2012 13:24:15 +0000 Subject: [PATCH 07/30] exemplar xml --- .../src/test/resources/media/media.xml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 labs/vcloud-director/src/test/resources/media/media.xml diff --git a/labs/vcloud-director/src/test/resources/media/media.xml b/labs/vcloud-director/src/test/resources/media/media.xml new file mode 100644 index 0000000000..cf0caa5498 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/media/media.xml @@ -0,0 +1,13 @@ + + + + + + + + + Windows 2003 R2 Disk2 Standard 32bit & 64bit + + + + From d39ebdc3d2d5548623bc1384a1d3d07da9e58ebb Mon Sep 17 00:00:00 2001 From: danikov Date: Mon, 13 Feb 2012 14:55:20 +0000 Subject: [PATCH 08/30] add some negative tests --- .../v1_5/features/MediaClientExpectTest.java | 137 +++++++++++++++++- 1 file changed, 131 insertions(+), 6 deletions(-) diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java index a0ce34ef34..3a7340e068 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java @@ -28,6 +28,8 @@ import org.jclouds.vcloud.director.v1_5.domain.Link; import org.jclouds.vcloud.director.v1_5.domain.Media; import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; +import org.jclouds.vcloud.director.v1_5.domain.Owner; +import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; import org.testng.annotations.Test; @@ -41,17 +43,91 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes @Test public void testWhenResponseIs2xxLoginReturnsValidMedia() { - URI mediaRef = URI.create("https://vcloudbeta.bluelock.com/api/media/KEY"); + URI mediaUri = URI.create(endpoint + "/media/794eb334-754e-4917-b5a0-5df85cbd61d1"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, - getStandardRequest("GET", mediaRef), + getStandardRequest("GET", mediaUri), getStandardPayloadResponse("/media/media.xml", VCloudDirectorMediaType.MEDIA_XML)); - Media expected = Media - .builder() - .build(); + Media expected = media(); - assertEquals(client.getMediaClient().getMedia(mediaRef), expected); + assertEquals(client.getMediaClient().getMedia(mediaUri), expected); + } + + public void testWhenResponseIs400ForInvalidNetworkId() { + URI mediaUri = URI.create(endpoint + "/media/NOTAUUID"); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + getStandardRequest("GET", mediaUri), + getStandardPayloadResponse(400, "/media/error400.xml", VCloudDirectorMediaType.ERROR)); + + Error expected = Error.builder() + .message("validation error on field 'id': String value has invalid format or length") + .majorErrorCode(400) + .minorErrorCode("BAD_REQUEST") + .build(); + + Reference mediaRef = Reference.builder().href(mediaUri).build(); + try { + client.getMediaClient().getMedia(mediaRef); + fail("Should give HTTP 400 error"); + } catch (VCloudDirectorException vde) { + assertEquals(vde.getError(), expected); + } catch (Exception e) { + fail("Should have thrown a VCloudDirectorException"); + } + } + + @Test + public void testWhenResponseIs403ForCatalogIdUsedAsMediaId() { + URI mediaUri = URI.create(endpoint + "/media/e9cd3387-ac57-4d27-a481-9bee75e0690f"); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + getStandardRequest("GET", mediaUri), + getStandardPayloadResponse(403, "/media/error403-catalog.xml", VCloudDirectorMediaType.ERROR)); + + Error expected = Error.builder() + .message("This operation is denied.") + .majorErrorCode(403) + .minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN") + .build(); + + Reference mediaRef = Reference.builder().href(mediaUri).build(); + + try { + client.getMediaClient().getMedia(mediaRef); + fail("Should give HTTP 403 error"); + } catch (VCloudDirectorException vde) { + assertEquals(vde.getError(), expected); + } catch (Exception e) { + fail("Should have thrown a VCloudDirectorException"); + } + } + + @Test + public void testWhenResponseIs403ForFakeNetworkId() { + URI mediaUri = URI.create(endpoint + "/media/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + getStandardRequest("GET", mediaUri), + getStandardPayloadResponse(403, "/media/error403-fake.xml", VCloudDirectorMediaType.ERROR)); + + Error expected = Error.builder() + .message("No access to entity \"(com.vmware.vcloud.entity.media:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee)\"") + .majorErrorCode(403) + .minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN") + .build(); + + Reference mediaRef = Reference.builder().href(mediaUri).build(); + + try { + client.getMediaClient().getMedia(mediaRef); + fail("Should give HTTP 403 error"); + } catch (VCloudDirectorException vde) { + assertEquals(vde.getError(), expected); + } catch (Exception e) { + fail("Should have thrown a VCloudDirectorException"); + } } @Test @@ -90,4 +166,53 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes assertEquals(client.getMediaClient().getMetadataEntry(metadataRef), expected); } + + private static Media media() { + return Media.builder() + .size(175163392) + .imageType("iso") + .status(1) + .name("DansTestMedia") + .id("urn:vcloud:media:794eb334-754e-4917-b5a0-5df85cbd61d1") + .href(URI.create("https://mycloud.greenhousedata.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1")) + .link(Link.builder() + .rel("up") + .type("application/vnd.vmware.vcloud.vdc+xml") + .href(URI.create("https://mycloud.greenhousedata.com/api/vdc/e9cd3387-ac57-4d27-a481-9bee75e0690f")) + .build()) + .link(Link.builder() + .rel("catalogItem") + .type("application/vnd.vmware.vcloud.catalogItem+xml") + .href(URI.create("https://mycloud.greenhousedata.com/api/catalogItem/1979d680-304e-4118-9283-9210c3b3ed8d")) + .build()) + .link(Link.builder() + .rel("remove") + .href(URI.create("https://mycloud.greenhousedata.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1")) + .build()) + .link(Link.builder() + .rel("edit") + .type("application/vnd.vmware.vcloud.media+xml") + .href(URI.create("https://mycloud.greenhousedata.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1")) + .build()) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.vcloud.owner+xml") + .href(URI.create("https://mycloud.greenhousedata.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1/owner")) + .build()) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.vcloud.metadata+xml") + .href(URI.create("https://mycloud.greenhousedata.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1/metadata")) + .build()) + .description("Windows 2003 R2 Disk2 Standard 32bit & 64bit") + .owner(Owner.builder() + .type("application/vnd.vmware.vcloud.owner+xml") + .user(Reference.builder() + .type("application/vnd.vmware.admin.user+xml") + .name("acole") + .href(URI.create("https://mycloud.greenhousedata.com/api/admin/user/c090335b-708c-4c1c-9e3d-89560d002120")) + .build()) + .build()) + .build(); + } } From d9c76fef308a223ff05675d2d5b3527b172796c2 Mon Sep 17 00:00:00 2001 From: danikov Date: Mon, 13 Feb 2012 14:55:39 +0000 Subject: [PATCH 09/30] add overriding/inheriting builder methods --- .../vcloud/director/v1_5/domain/Media.java | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Media.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Media.java index e9f9a256d8..cbcd292807 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Media.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Media.java @@ -21,6 +21,9 @@ package org.jclouds.vcloud.director.v1_5.domain; import static com.google.common.base.Objects.equal; +import java.net.URI; +import java.util.Set; + import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; @@ -111,6 +114,94 @@ public class Media media.setSize(size); return media; } + + /** + * @see ResourceEntityType#getFiles() + */ + public Builder files(FilesList files) { + super.files(files); + return this; + } + + /** + * @see ResourceEntityType#getStatus() + */ + public Builder status(Integer status) { + super.status(status); + return this; + } + + /** + * @see EntityType#getName() + */ + @Override + public Builder name(String name) { + super.name(name); + return this; + } + + /** + * @see EntityType#getDescription() + */ + @Override + public Builder description(String description) { + super.description(description); + return this; + } + + /** + * @see EntityType#getId() + */ + @Override + public Builder id(String id) { + super.id(id); + return this; + } + + /** + * @see EntityType#getTasksInProgress() + */ + @Override + public Builder tasksInProgress(TasksInProgress tasksInProgress) { + super.tasksInProgress(tasksInProgress); + return this; + } + + /** + * @see ReferenceType#getHref() + */ + @Override + public Builder href(URI href) { + super.href(href); + return this; + } + + /** + * @see ReferenceType#getType() + */ + @Override + public Builder type(String type) { + super.type(type); + return this; + } + + /** + * @see ReferenceType#getLinks() + */ + @Override + public Builder links(Set links) { + super.links(links); + return this; + } + + /** + * @see ReferenceType#getLinks() + */ + @Override + public Builder link(Link link) { + super.link(link); + return this; + } @Override From 58d08637f826047aa3920e6a2f358c2ca2de5fc0 Mon Sep 17 00:00:00 2001 From: danikov Date: Mon, 13 Feb 2012 14:56:20 +0000 Subject: [PATCH 10/30] add supporting exemplar xml --- .../vcloud-director/src/test/resources/media/error400.xml | 8 ++++++++ .../src/test/resources/media/error403-catalog.xml | 8 ++++++++ .../src/test/resources/media/error403-fake.xml | 8 ++++++++ 3 files changed, 24 insertions(+) create mode 100644 labs/vcloud-director/src/test/resources/media/error400.xml create mode 100644 labs/vcloud-director/src/test/resources/media/error403-catalog.xml create mode 100644 labs/vcloud-director/src/test/resources/media/error403-fake.xml diff --git a/labs/vcloud-director/src/test/resources/media/error400.xml b/labs/vcloud-director/src/test/resources/media/error400.xml new file mode 100644 index 0000000000..6d89bd48b4 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/media/error400.xml @@ -0,0 +1,8 @@ +HTTP/1.1 400 Bad Request +Date: Mon, 13 Feb 2012 14:52:25 GMT +Content-Type: application/vnd.vmware.vcloud.error+xml;version=1.5 +Date: Mon, 13 Feb 2012 14:52:25 GMT +Content-Length: 401 + + + diff --git a/labs/vcloud-director/src/test/resources/media/error403-catalog.xml b/labs/vcloud-director/src/test/resources/media/error403-catalog.xml new file mode 100644 index 0000000000..ce45419e82 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/media/error403-catalog.xml @@ -0,0 +1,8 @@ +HTTP/1.1 403 Forbidden +Date: Mon, 13 Feb 2012 14:51:28 GMT +Content-Type: application/vnd.vmware.vcloud.error+xml;version=1.5 +Date: Mon, 13 Feb 2012 14:51:28 GMT +Content-Length: 450 + + + diff --git a/labs/vcloud-director/src/test/resources/media/error403-fake.xml b/labs/vcloud-director/src/test/resources/media/error403-fake.xml new file mode 100644 index 0000000000..ebfd422830 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/media/error403-fake.xml @@ -0,0 +1,8 @@ +HTTP/1.1 403 Forbidden +Date: Mon, 13 Feb 2012 14:54:07 GMT +Content-Type: application/vnd.vmware.vcloud.error+xml;version=1.5 +Date: Mon, 13 Feb 2012 14:54:07 GMT +Content-Length: 450 + + + From ebe40565f8a6c5b1ef764e521825b603cffaefee Mon Sep 17 00:00:00 2001 From: danikov Date: Mon, 13 Feb 2012 15:12:49 +0000 Subject: [PATCH 11/30] add link to javadoc --- .../org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java index 64f37c7324..ba56248922 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java @@ -72,7 +72,7 @@ public interface VCloudDirectorClient { CatalogClient getCatalogClient(); /** - * @return synchronous access to Media features + * @return synchronous access to {@link Media} features */ @Delegate MediaClient getMediaClient(); From 4a882982098483b9070539cba7c526689c19b8e0 Mon Sep 17 00:00:00 2001 From: danikov Date: Mon, 13 Feb 2012 15:13:17 +0000 Subject: [PATCH 12/30] ditch refs for uric, correct constant usage --- .../v1_5/features/MediaClientExpectTest.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java index 3a7340e068..680ee0850e 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java @@ -19,11 +19,14 @@ package org.jclouds.vcloud.director.v1_5.features; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.fail; import java.net.URI; import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorException; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.jclouds.vcloud.director.v1_5.domain.Error; import org.jclouds.vcloud.director.v1_5.domain.Link; import org.jclouds.vcloud.director.v1_5.domain.Media; import org.jclouds.vcloud.director.v1_5.domain.Metadata; @@ -67,9 +70,8 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes .minorErrorCode("BAD_REQUEST") .build(); - Reference mediaRef = Reference.builder().href(mediaUri).build(); try { - client.getMediaClient().getMedia(mediaRef); + client.getMediaClient().getMedia(mediaUri); fail("Should give HTTP 400 error"); } catch (VCloudDirectorException vde) { assertEquals(vde.getError(), expected); @@ -92,10 +94,8 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes .minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN") .build(); - Reference mediaRef = Reference.builder().href(mediaUri).build(); - try { - client.getMediaClient().getMedia(mediaRef); + client.getMediaClient().getMedia(mediaUri); fail("Should give HTTP 403 error"); } catch (VCloudDirectorException vde) { assertEquals(vde.getError(), expected); @@ -118,10 +118,8 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes .minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN") .build(); - Reference mediaRef = Reference.builder().href(mediaUri).build(); - try { - client.getMediaClient().getMedia(mediaRef); + client.getMediaClient().getMedia(mediaUri); fail("Should give HTTP 403 error"); } catch (VCloudDirectorException vde) { assertEquals(vde.getError(), expected); @@ -137,7 +135,7 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, getStandardRequest("GET", metaRef), - getStandardPayloadResponse("/media/metadata.xml", VCloudDirectorMediaType.METADATA_XML)); + getStandardPayloadResponse("/media/metadata.xml", VCloudDirectorMediaType.METADATA)); Metadata expected = Metadata.builder() .type("application/vnd.vmware.vcloud.metadata+xml") @@ -159,7 +157,7 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, getStandardRequest("GET", metadataRef), - getStandardPayloadResponse("/media/metadataEntry.xml", VCloudDirectorMediaType.METADATAENTRY_XML)); + getStandardPayloadResponse("/media/metadataEntry.xml", VCloudDirectorMediaType.METADATA_ENTRY)); MetadataEntry expected = MetadataEntry.builder() .build(); From 42d151e604d2190fc150c022d1870497588895ab Mon Sep 17 00:00:00 2001 From: danikov Date: Mon, 13 Feb 2012 15:15:06 +0000 Subject: [PATCH 13/30] add links to javadoc --- .../director/v1_5/VCloudDirectorAsyncClient.java | 14 ++++++++++---- .../vcloud/director/v1_5/VCloudDirectorClient.java | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorAsyncClient.java index 9eb3e15dc4..d52451b1b9 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorAsyncClient.java @@ -43,26 +43,32 @@ public interface VCloudDirectorAsyncClient { Session getCurrentSession(); /** - * @return asynchronous access to Org features + * @return asynchronous access to {@link Org} features */ @Delegate OrgAsyncClient getOrgClient(); /** - * @return asynchronous access to Task features + * @return asynchronous access to {@link Task} features */ @Delegate TaskAsyncClient getTaskClient(); /** - * @return asynchronous access to Network features + * @return asynchronous access to {@link Network} features */ @Delegate NetworkAsyncClient getNetworkClient(); /** - * @return asynchronous access to Catalog features + * @return asynchronous access to {@link Catalog} features */ @Delegate CatalogAsyncClient getCatalogClient(); + + /** + * @return asynchronous access to {@link Media} features + */ + @Delegate + CatalogAsyncClient getMediaClient(); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java index ba56248922..096e0737c5 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java @@ -60,7 +60,7 @@ public interface VCloudDirectorClient { TaskClient getTaskClient(); /** - * @return synchronous access to Network features + * @return synchronous access to {@link Network} features */ @Delegate NetworkClient getNetworkClient(); From 9d64aa5ae7cf5156d8d47ed5427a55edb5a3be40 Mon Sep 17 00:00:00 2001 From: danikov Date: Mon, 13 Feb 2012 16:43:06 +0000 Subject: [PATCH 14/30] test update to test owner and use refs again --- .../v1_5/features/MediaClientExpectTest.java | 64 +++++++++++++------ 1 file changed, 46 insertions(+), 18 deletions(-) diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java index 680ee0850e..736e40609a 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java @@ -53,11 +53,13 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes getStandardPayloadResponse("/media/media.xml", VCloudDirectorMediaType.MEDIA_XML)); Media expected = media(); + + Reference mediaRef = Reference.builder().href(mediaUri).build(); - assertEquals(client.getMediaClient().getMedia(mediaUri), expected); + assertEquals(client.getMediaClient().getMedia(mediaRef), expected); } - public void testWhenResponseIs400ForInvalidNetworkId() { + public void testWhenResponseIs400ForInvalidMediaId() { URI mediaUri = URI.create(endpoint + "/media/NOTAUUID"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, @@ -69,9 +71,11 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes .majorErrorCode(400) .minorErrorCode("BAD_REQUEST") .build(); + + Reference mediaRef = Reference.builder().href(mediaUri).build(); try { - client.getMediaClient().getMedia(mediaUri); + client.getMediaClient().getMedia(mediaRef); fail("Should give HTTP 400 error"); } catch (VCloudDirectorException vde) { assertEquals(vde.getError(), expected); @@ -89,13 +93,15 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes getStandardPayloadResponse(403, "/media/error403-catalog.xml", VCloudDirectorMediaType.ERROR)); Error expected = Error.builder() - .message("This operation is denied.") + .message("No access to entity \"(com.vmware.vcloud.entity.media:e9cd3387-ac57-4d27-a481-9bee75e0690f)\".") .majorErrorCode(403) .minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN") .build(); + + Reference mediaRef = Reference.builder().href(mediaUri).build(); try { - client.getMediaClient().getMedia(mediaUri); + client.getMediaClient().getMedia(mediaRef); fail("Should give HTTP 403 error"); } catch (VCloudDirectorException vde) { assertEquals(vde.getError(), expected); @@ -105,7 +111,7 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes } @Test - public void testWhenResponseIs403ForFakeNetworkId() { + public void testWhenResponseIs403ForFakeMediaId() { URI mediaUri = URI.create(endpoint + "/media/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, @@ -113,13 +119,15 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes getStandardPayloadResponse(403, "/media/error403-fake.xml", VCloudDirectorMediaType.ERROR)); Error expected = Error.builder() - .message("No access to entity \"(com.vmware.vcloud.entity.media:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee)\"") + .message("No access to entity \"(com.vmware.vcloud.entity.media:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee)\".") .majorErrorCode(403) .minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN") .build(); + + Reference mediaRef = Reference.builder().href(mediaUri).build(); try { - client.getMediaClient().getMedia(mediaUri); + client.getMediaClient().getMedia(mediaRef); fail("Should give HTTP 403 error"); } catch (VCloudDirectorException vde) { assertEquals(vde.getError(), expected); @@ -128,22 +136,40 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes } } + @Test + public void testWhenResponseIs2xxLoginReturnsValidOwner() { + URI mediaUri = URI.create(endpoint + "/media/794eb334-754e-4917-b5a0-5df85cbd61d1"); + URI metadataUri = URI.create(mediaUri.toASCIIString()+"/owner"); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + getStandardRequest("GET", metadataUri), + getStandardPayloadResponse("/media/owner.xml", VCloudDirectorMediaType.OWNER)); + + Owner expected = media().getOwner(); + + Reference mediaRef = Reference.builder().href(mediaUri).build(); + + assertEquals(client.getMediaClient().getOwner(mediaRef), expected); + } + @Test public void testWhenResponseIs2xxLoginReturnsValidMetadata() { - URI mediaRef = URI.create("https://vcloudbeta.bluelock.com/api/media/KEY"); - URI metaRef = URI.create(mediaRef.toASCIIString()+"/metadata/"); + URI mediaUri = URI.create("https://vcloudbeta.bluelock.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1"); + URI metadataUri = URI.create(mediaUri.toASCIIString()+"/metadata"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, - getStandardRequest("GET", metaRef), + getStandardRequest("GET", metadataUri), getStandardPayloadResponse("/media/metadata.xml", VCloudDirectorMediaType.METADATA)); + Reference mediaRef = Reference.builder().href(mediaUri).build(); + Metadata expected = Metadata.builder() .type("application/vnd.vmware.vcloud.metadata+xml") - .href(URI.create("https://vcloudbeta.bluelock.com/api/media/KEY/metadata")) + .href(URI.create("https://vcloudbeta.bluelock.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1/metadata")) .link(Link.builder() .rel("up") - .type("application/vnd.vmware.vcloud.network+xml") - .href(URI.create("https://vcloudbeta.bluelock.com/api/media/KEY")) + .type("application/vnd.vmware.vcloud.media+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1")) .build()) .build(); @@ -152,17 +178,19 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes @Test(enabled=false) // No metadata in exemplar xml... public void testWhenResponseIs2xxLoginReturnsValidMetadataEntry() { - URI metadataRef = URI.create( - "https://vcloudbeta.bluelock.com/api/media/KEY/metadata/KEY"); + URI mediaUri = URI.create("https://vcloudbeta.bluelock.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1"); + URI metadataUri = URI.create(mediaUri.toASCIIString()+"/metadata/key"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, - getStandardRequest("GET", metadataRef), + getStandardRequest("GET", metadataUri), getStandardPayloadResponse("/media/metadataEntry.xml", VCloudDirectorMediaType.METADATA_ENTRY)); MetadataEntry expected = MetadataEntry.builder() .build(); + + Reference mediaRef = Reference.builder().href(mediaUri).build(); - assertEquals(client.getMediaClient().getMetadataEntry(metadataRef), expected); + assertEquals(client.getMediaClient().getMetadataEntry(mediaRef, "key"), expected); } private static Media media() { From 2a88eaba72305bc33ffce6edb0dba5c1afd11ce0 Mon Sep 17 00:00:00 2001 From: danikov Date: Mon, 13 Feb 2012 16:43:38 +0000 Subject: [PATCH 15/30] strip out curl data + 2 new exemplar xml --- labs/vcloud-director/src/test/resources/media/error400.xml | 6 ------ .../src/test/resources/media/error403-catalog.xml | 6 ------ .../src/test/resources/media/error403-fake.xml | 6 ------ labs/vcloud-director/src/test/resources/media/metadata.xml | 4 ++++ labs/vcloud-director/src/test/resources/media/owner.xml | 5 +++++ 5 files changed, 9 insertions(+), 18 deletions(-) create mode 100644 labs/vcloud-director/src/test/resources/media/metadata.xml create mode 100644 labs/vcloud-director/src/test/resources/media/owner.xml diff --git a/labs/vcloud-director/src/test/resources/media/error400.xml b/labs/vcloud-director/src/test/resources/media/error400.xml index 6d89bd48b4..981f249e85 100644 --- a/labs/vcloud-director/src/test/resources/media/error400.xml +++ b/labs/vcloud-director/src/test/resources/media/error400.xml @@ -1,8 +1,2 @@ -HTTP/1.1 400 Bad Request -Date: Mon, 13 Feb 2012 14:52:25 GMT -Content-Type: application/vnd.vmware.vcloud.error+xml;version=1.5 -Date: Mon, 13 Feb 2012 14:52:25 GMT -Content-Length: 401 - diff --git a/labs/vcloud-director/src/test/resources/media/error403-catalog.xml b/labs/vcloud-director/src/test/resources/media/error403-catalog.xml index ce45419e82..f1f0b7fee5 100644 --- a/labs/vcloud-director/src/test/resources/media/error403-catalog.xml +++ b/labs/vcloud-director/src/test/resources/media/error403-catalog.xml @@ -1,8 +1,2 @@ -HTTP/1.1 403 Forbidden -Date: Mon, 13 Feb 2012 14:51:28 GMT -Content-Type: application/vnd.vmware.vcloud.error+xml;version=1.5 -Date: Mon, 13 Feb 2012 14:51:28 GMT -Content-Length: 450 - diff --git a/labs/vcloud-director/src/test/resources/media/error403-fake.xml b/labs/vcloud-director/src/test/resources/media/error403-fake.xml index ebfd422830..3b582f3c0c 100644 --- a/labs/vcloud-director/src/test/resources/media/error403-fake.xml +++ b/labs/vcloud-director/src/test/resources/media/error403-fake.xml @@ -1,8 +1,2 @@ -HTTP/1.1 403 Forbidden -Date: Mon, 13 Feb 2012 14:54:07 GMT -Content-Type: application/vnd.vmware.vcloud.error+xml;version=1.5 -Date: Mon, 13 Feb 2012 14:54:07 GMT -Content-Length: 450 - diff --git a/labs/vcloud-director/src/test/resources/media/metadata.xml b/labs/vcloud-director/src/test/resources/media/metadata.xml new file mode 100644 index 0000000000..4ff6274ff6 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/media/metadata.xml @@ -0,0 +1,4 @@ + + + + diff --git a/labs/vcloud-director/src/test/resources/media/owner.xml b/labs/vcloud-director/src/test/resources/media/owner.xml new file mode 100644 index 0000000000..fe6c4228ff --- /dev/null +++ b/labs/vcloud-director/src/test/resources/media/owner.xml @@ -0,0 +1,5 @@ + + + + + From 35318568b0bcacac68bb4f82772b4e7e9188749a Mon Sep 17 00:00:00 2001 From: danikov Date: Wed, 15 Feb 2012 01:19:30 +0000 Subject: [PATCH 16/30] add owner xml type Conflicts: labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java --- .../jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java index 6c313c1454..4572decf73 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java @@ -65,6 +65,8 @@ public class VCloudDirectorMediaType { public static final String MEDIA_XML = "application/vnd.vmware.vcloud.media+xml"; + public static final String OWNER = "application/vnd.vmware.vcloud.owner+xml"; + public static final List ALL = Arrays.asList( SESSION, ERROR, ORG_LIST, METADATA, METADATA_ENTRY, METADATA_VALUE, ORG, TASKS_LIST, TASK, ORG_NETWORK, From 336c780713bc8cdbf025a17625be5a7063e61d39 Mon Sep 17 00:00:00 2001 From: danikov Date: Mon, 13 Feb 2012 16:44:26 +0000 Subject: [PATCH 17/30] update client to use references, pathparams, etc. --- .../v1_5/features/MediaAsyncClient.java | 48 ++++++++++--------- .../director/v1_5/features/MediaClient.java | 20 ++++---- 2 files changed, 36 insertions(+), 32 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 112e5c7f15..df53a62d2b 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 @@ -18,27 +18,28 @@ */ package org.jclouds.vcloud.director.v1_5.features; -import java.net.URI; - import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.PUT; import javax.ws.rs.Path; +import javax.ws.rs.PathParam; import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.JAXBResponseParser; import org.jclouds.rest.annotations.PayloadParam; import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.vcloud.director.v1_5.domain.Media; import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; import org.jclouds.vcloud.director.v1_5.domain.Owner; +import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; +import org.jclouds.vcloud.director.v1_5.functions.ReferenceToEndpoint; +import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx; import com.google.common.util.concurrent.ListenableFuture; @@ -50,50 +51,50 @@ import com.google.common.util.concurrent.ListenableFuture; public interface MediaAsyncClient { /** - * @see MediaClient#getMedia() + * @see MediaClient#getMedia(ReferenceType) */ @GET @Consumes @JAXBResponseParser - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getMedia(@EndpointParam URI mediaRef); + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture getMedia(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType mediaRef); /** - * @see MediaClient#updateMedia() + * @see MediaClient#updateMedia(ReferenceType, Media)) */ @PUT @Consumes @JAXBResponseParser - ListenableFuture updateMedia(@EndpointParam URI mediaRef, + ListenableFuture updateMedia(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType mediaRef, @PayloadParam("Media") Media media); /** - * @see MediaClient#deleteMedia() + * @see MediaClient#deleteMedia(ReferenceType)) */ @DELETE @Consumes @JAXBResponseParser - ListenableFuture deleteMedia(@EndpointParam URI mediaRef); + ListenableFuture deleteMedia(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType mediaRef); /** - * @see MediaClient#getMedia() + * @see MediaClient#getOwner(ReferenceType) */ @GET - @Path("/owner/") + @Path("/owner") @Consumes @JAXBResponseParser - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getOwner(@EndpointParam URI mediaRef); + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture getOwner(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType mediaRef); /** * @see MediaClient#getMetadata() */ @GET - @Path("/metadata/") + @Path("/metadata") @Consumes @JAXBResponseParser - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getMetadata(@EndpointParam URI mediaRef); + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture getMetadata(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType mediaRef); /** * @see MediaClient#updateMetadata() @@ -101,7 +102,7 @@ public interface MediaAsyncClient { @POST @Consumes @JAXBResponseParser - ListenableFuture updateMetadata(@EndpointParam URI mediaRef, + ListenableFuture updateMetadata(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType mediaRef, @PayloadParam("Metadata") Metadata metadata); /** @@ -110,8 +111,9 @@ public interface MediaAsyncClient { @GET @Consumes @JAXBResponseParser - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getMetadataEntry(@EndpointParam URI metaDataRef); + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture getMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType mediaRef, + @PathParam("key") String key); /** * @see MediaClient#updateMedia() @@ -119,7 +121,8 @@ public interface MediaAsyncClient { @PUT @Consumes @JAXBResponseParser - ListenableFuture updateMetadataEntry(@EndpointParam URI metaDataRef, + ListenableFuture updateMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType metaDataRef, + @PathParam("key") String key, @PayloadParam("MetadataEntry") MetadataEntry metadataEntry); /** @@ -128,6 +131,7 @@ public interface MediaAsyncClient { @DELETE @Consumes @JAXBResponseParser - ListenableFuture deleteMetadataEntry(@EndpointParam URI metaDataRef); + ListenableFuture deleteMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType metaDataRef, + @PathParam("key") String key); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/MediaClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/MediaClient.java index f666d4244a..7b5511521d 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/MediaClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/MediaClient.java @@ -18,7 +18,6 @@ */ package org.jclouds.vcloud.director.v1_5.features; -import java.net.URI; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; @@ -26,6 +25,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Media; import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; import org.jclouds.vcloud.director.v1_5.domain.Owner; +import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; import org.jclouds.vcloud.director.v1_5.domain.Task; /** @@ -44,7 +44,7 @@ public interface MediaClient { * * @return the media or null if not found */ - Media getMedia(URI mediaRef); + Media getMedia(ReferenceType mediaRef); /** * Updates the name/description of a media. @@ -52,40 +52,40 @@ public interface MediaClient { * @return a task. This operation is asynchronous and the user should monitor the returned * task status in order to check when it is completed. */ - Task updateMedia(URI mediaRef, Media media); + Task updateMedia(ReferenceType mediaRef, Media media); /** * Deletes a media. */ - void deleteMedia(URI mediaRef); + void deleteMedia(ReferenceType mediaRef); /** * Retrieves an owner. * * @return the owner or null if not found */ - Owner getOwner(URI mediaRef); + Owner getOwner(ReferenceType mediaRef); /** * Retrieves an list of the media's metadata * * @return a list of metadata */ - Metadata getMetadata(URI mediaRef); + Metadata getMetadata(ReferenceType mediaRef); /** * Merges the metadata for a media with the information provided. * * @return a task. This operation is asynchronous and the user should monitor the returned * task status in order to check when it is completed. */ - Task updateMetadata(URI mediaRef, Metadata metadata); + Task updateMetadata(ReferenceType mediaRef, Metadata metadata); /** * Retrieves a metadata entry * * @return the metadata entry, or null if not found */ - MetadataEntry getMetadataEntry(URI metaDataRef); + MetadataEntry getMetadataEntry(ReferenceType mediaRef, String key); /** * Sets the metadata for the particular key for the media to the value provided @@ -93,12 +93,12 @@ public interface MediaClient { * @return a task. This operation is asynchronous and the user should monitor the returned * task status in order to check when it is completed. */ - Task updateMetadataEntry(URI metaDataRef, MetadataEntry metadataEntry); + Task updateMetadataEntry(ReferenceType mediaRef, String key, MetadataEntry metadataEntry); /** * Deletes a metadata entry. */ - void deleteMetadataEntry(URI metaDataRef); + void deleteMetadataEntry(ReferenceType mediaRef, String key); } From 121d88121a00db9dc1d6ab0a2a044516170e455d Mon Sep 17 00:00:00 2001 From: danikov Date: Mon, 13 Feb 2012 16:45:50 +0000 Subject: [PATCH 18/30] corrected renaming typo --- .../java/org/jclouds/vcloud/director/v1_5/domain/FilesList.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/FilesList.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/FilesList.java index 39c7eff127..57825ab852 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/FilesList.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/FilesList.java @@ -59,7 +59,7 @@ import com.google.common.base.Objects; */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "FilesList", propOrder = { - "file" + "files" }) public class FilesList { public static Builder builder() { From cefbe01e5381813af7be7421f0b7bd77b0672a0d Mon Sep 17 00:00:00 2001 From: danikov Date: Mon, 13 Feb 2012 16:46:15 +0000 Subject: [PATCH 19/30] fix xml annotations --- .../org/jclouds/vcloud/director/v1_5/domain/Media.java | 9 +++++---- .../org/jclouds/vcloud/director/v1_5/domain/Owner.java | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Media.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Media.java index cbcd292807..2c9077b665 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Media.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Media.java @@ -20,6 +20,7 @@ package org.jclouds.vcloud.director.v1_5.domain; import static com.google.common.base.Objects.equal; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.VCLOUD_1_5_NS; import java.net.URI; import java.util.Set; @@ -28,6 +29,7 @@ import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; import com.google.common.base.Objects; @@ -60,9 +62,8 @@ import com.google.common.base.Objects; * */ @XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "Media", propOrder = { - "owner" -}) +@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "Media") +@XmlType(propOrder = {"owner"}) public class Media extends ResourceEntityType @@ -220,7 +221,7 @@ public class Media super(); } - @XmlElement(name = "Owner") + @XmlElement(namespace = VCLOUD_1_5_NS, name = "Owner") protected Owner owner; @XmlAttribute(required = true) protected String imageType; diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Owner.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Owner.java index 642bd159ff..88e392cfd3 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Owner.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Owner.java @@ -28,6 +28,7 @@ import java.util.Set; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; import com.google.common.base.Objects; @@ -59,9 +60,8 @@ import com.google.common.collect.Sets; * */ @XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "Owner", propOrder = { - "user" -}) +@XmlRootElement(name = "Owner") +@XmlType(propOrder = {"user"}) public class Owner extends ResourceType From eb2e5943028f43919084e9324b7ab06d53de2f03 Mon Sep 17 00:00:00 2001 From: danikov Date: Tue, 14 Feb 2012 20:01:18 +0000 Subject: [PATCH 20/30] add some more expect tests --- .../v1_5/features/MediaClientExpectTest.java | 170 +++++++++++++++--- 1 file changed, 147 insertions(+), 23 deletions(-) diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java index 736e40609a..3d560f6ea3 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java @@ -31,8 +31,10 @@ import org.jclouds.vcloud.director.v1_5.domain.Link; import org.jclouds.vcloud.director.v1_5.domain.Media; import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; +import org.jclouds.vcloud.director.v1_5.domain.MetadataValue; import org.jclouds.vcloud.director.v1_5.domain.Owner; import org.jclouds.vcloud.director.v1_5.domain.Reference; +import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; import org.testng.annotations.Test; @@ -50,7 +52,7 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, getStandardRequest("GET", mediaUri), - getStandardPayloadResponse("/media/media.xml", VCloudDirectorMediaType.MEDIA_XML)); + getStandardPayloadResponse("/media/media.xml", VCloudDirectorMediaType.MEDIA)); Media expected = media(); @@ -137,19 +139,35 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes } @Test - public void testWhenResponseIs2xxLoginReturnsValidOwner() { + public void testWhenResponseIs2xxLoginUpdateReturnsValidMedia() { URI mediaUri = URI.create(endpoint + "/media/794eb334-754e-4917-b5a0-5df85cbd61d1"); - URI metadataUri = URI.create(mediaUri.toASCIIString()+"/owner"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, - getStandardRequest("GET", metadataUri), - getStandardPayloadResponse("/media/owner.xml", VCloudDirectorMediaType.OWNER)); + getStandardPayloadRequest("PUT", mediaUri, + "/media/media.xml", VCloudDirectorMediaType.MEDIA), + getStandardPayloadResponse("/media/media.xml", VCloudDirectorMediaType.MEDIA)); - Owner expected = media().getOwner(); + Media expected = media(); + Reference mediaRef = Reference.builder().href(mediaUri).build(); + + assertEquals(client.getMediaClient().updateMedia(mediaRef, expected), expected); + } + + @Test + public void testWhenResponseIs2xxLoginDeleteMediaReturnsValidTask() { + URI mediaUri = URI.create(endpoint + "/media/794eb334-754e-4917-b5a0-5df85cbd61d1"); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + getStandardRequest("DELETE", mediaUri), + getStandardPayloadResponse("/media/deleteMediaTask.xml", VCloudDirectorMediaType.TASK)); + + Task expected = Task.builder() + + .build(); Reference mediaRef = Reference.builder().href(mediaUri).build(); - assertEquals(client.getMediaClient().getOwner(mediaRef), expected); + assertEquals(client.getMediaClient().deleteMedia(mediaRef), expected); } @Test @@ -163,19 +181,29 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes Reference mediaRef = Reference.builder().href(mediaUri).build(); - Metadata expected = Metadata.builder() - .type("application/vnd.vmware.vcloud.metadata+xml") - .href(URI.create("https://vcloudbeta.bluelock.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1/metadata")) - .link(Link.builder() - .rel("up") - .type("application/vnd.vmware.vcloud.media+xml") - .href(URI.create("https://vcloudbeta.bluelock.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1")) - .build()) - .build(); + Metadata expected = metadata(); assertEquals(client.getMediaClient().getMetadata(mediaRef), expected); } + @Test + public void testWhenResponseIs2xxLoginMergeMetadataReturnsValidTask() { + URI mediaUri = URI.create("https://vcloudbeta.bluelock.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1"); + URI metadataUri = URI.create(mediaUri.toASCIIString()+"/metadata"); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + getStandardPayloadRequest("POST", metadataUri, "/media/metadata.xml", VCloudDirectorMediaType.METADATA), + getStandardPayloadResponse("/media/mergeMetadataTask.xml", VCloudDirectorMediaType.TASK)); + + Reference mediaRef = Reference.builder().href(mediaUri).build(); + Metadata inputMetadata = metadata(); + Task expectedTask = Task.builder() + + .build(); + + assertEquals(client.getMediaClient().mergeMetadata(mediaRef, inputMetadata), expectedTask); + } + @Test(enabled=false) // No metadata in exemplar xml... public void testWhenResponseIs2xxLoginReturnsValidMetadataEntry() { URI mediaUri = URI.create("https://vcloudbeta.bluelock.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1"); @@ -193,6 +221,86 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes assertEquals(client.getMediaClient().getMetadataEntry(mediaRef, "key"), expected); } + @Test + public void testWhenResponseIs2xxLoginSetMetadataReturnsValidTask() { + URI mediaUri = URI.create("https://vcloudbeta.bluelock.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1"); + URI setMetadataUri = URI.create(mediaUri.toASCIIString()+"/metadata/key"); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + getStandardPayloadRequest("PUT", setMetadataUri, VCloudDirectorMediaType.TASK, + "/media/setMetadata.xml", VCloudDirectorMediaType.METADATA_VALUE), + getStandardPayloadResponse("/media/setMetadataTask.xml", VCloudDirectorMediaType.TASK)); + + Reference mediaRef = Reference.builder().href(mediaUri).build(); + MetadataValue inputMetadataValue = MetadataValue.builder().value("value").build(); + + Task expectedTask = Task.builder() + .status("running") + .startTime(dateService.iso8601DateParse("2012-02-13T06:35:08.011-05:00")) + .operationName("metadataSet") + .operation("Setting metadata for Media (794eb334-754e-4917-b5a0-5df85cbd61d1)") + .expiryTime(dateService.iso8601DateParse("2012-05-13T06:35:08.011-04:00")) + .name("Task") + .id("urn:vcloud:task:c6dca927-eab4-41fa-ad6a-3ac58602541c") + .type("application/vnd.vmware.vcloud.task+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/task/c6dca927-eab4-41fa-ad6a-3ac58602541c")) + .link(Link.builder() + .rel("task:cancel") + .href(URI.create("https://vcloudbeta.bluelock.com/api/task/c6dca927-eab4-41fa-ad6a-3ac58602541c/action/cancel")) + .build()) + .owner(Reference.builder() + .type("application/vnd.vmware.vcloud.media+xml") + .name("") + .href(URI.create("https://vcloudbeta.bluelock.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1")) + .build()) + .user(Reference.builder() + .type("application/vnd.vmware.admin.user+xml") + .name("adk@cloudsoftcorp.com") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/e9eb1b29-0404-4c5e-8ef7-e584acc51da9")) + .build()) + .org(Reference.builder() + .type("application/vnd.vmware.vcloud.org+xml") + .name("JClouds") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .build()) + .build(); + + assertEquals(client.getMediaClient().setMetadata(mediaRef, "key", inputMetadataValue), expectedTask); + } + + @Test + public void testWhenResponseIs2xxLoginDeleteMetadataReturnsValidTask() { + URI mediaUri = URI.create("https://vcloudbeta.bluelock.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1"); + URI setMetadataUri = URI.create(mediaUri.toASCIIString()+"/metadata/key"); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + getStandardRequest("DELETE", setMetadataUri), + getStandardPayloadResponse("/media/deleteMetadataTask.xml", VCloudDirectorMediaType.TASK)); + + Reference mediaRef = Reference.builder().href(mediaUri).build(); + Task expectedTask = Task.builder() + + .build(); + + assertEquals(client.getMediaClient().deleteMetadataEntry(mediaRef, "key"), expectedTask); + } + + @Test + public void testWhenResponseIs2xxLoginReturnsValidOwner() { + URI mediaUri = URI.create(endpoint + "/media/794eb334-754e-4917-b5a0-5df85cbd61d1"); + URI metadataUri = URI.create(mediaUri.toASCIIString()+"/owner"); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + getStandardRequest("GET", metadataUri), + getStandardPayloadResponse("/media/owner.xml", VCloudDirectorMediaType.OWNER)); + + Owner expected = owner(); + + Reference mediaRef = Reference.builder().href(mediaUri).build(); + + assertEquals(client.getMediaClient().getOwner(mediaRef), expected); + } + private static Media media() { return Media.builder() .size(175163392) @@ -231,13 +339,29 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes .href(URI.create("https://mycloud.greenhousedata.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1/metadata")) .build()) .description("Windows 2003 R2 Disk2 Standard 32bit & 64bit") - .owner(Owner.builder() - .type("application/vnd.vmware.vcloud.owner+xml") - .user(Reference.builder() - .type("application/vnd.vmware.admin.user+xml") - .name("acole") - .href(URI.create("https://mycloud.greenhousedata.com/api/admin/user/c090335b-708c-4c1c-9e3d-89560d002120")) - .build()) + .owner(owner()) + .build(); + } + + private static Owner owner() { + return Owner.builder() + .type("application/vnd.vmware.vcloud.owner+xml") + .user(Reference.builder() + .type("application/vnd.vmware.admin.user+xml") + .name("acole") + .href(URI.create("https://mycloud.greenhousedata.com/api/admin/user/c090335b-708c-4c1c-9e3d-89560d002120")) + .build()) + .build(); + } + + private static Metadata metadata() { + return Metadata.builder() + .type("application/vnd.vmware.vcloud.metadata+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1/metadata")) + .link(Link.builder() + .rel("up") + .type("application/vnd.vmware.vcloud.media+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1")) .build()) .build(); } From 1cc094a95eca653fc15574fa85fdf9540f2d989a Mon Sep 17 00:00:00 2001 From: danikov Date: Tue, 14 Feb 2012 20:01:33 +0000 Subject: [PATCH 21/30] rename media type --- .../jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java index 4572decf73..32739a389f 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java @@ -63,7 +63,7 @@ public class VCloudDirectorMediaType { public static final String PROPERTY = "application/vnd.vmware.vcloud.property+xml"; - public static final String MEDIA_XML = "application/vnd.vmware.vcloud.media+xml"; + public static final String MEDIA = "application/vnd.vmware.vcloud.media+xml"; public static final String OWNER = "application/vnd.vmware.vcloud.owner+xml"; From 6145da9cfb5696e29ae676806e74f328419429b2 Mon Sep 17 00:00:00 2001 From: danikov Date: Tue, 14 Feb 2012 20:02:01 +0000 Subject: [PATCH 22/30] correct return types and annotations --- .../v1_5/features/MediaAsyncClient.java | 51 ++++++++++++------- .../director/v1_5/features/MediaClient.java | 15 ++++-- 2 files changed, 42 insertions(+), 24 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 df53a62d2b..89de50a001 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 @@ -25,15 +25,19 @@ import javax.ws.rs.POST; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.JAXBResponseParser; -import org.jclouds.rest.annotations.PayloadParam; import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.binders.BindToXMLPayload; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; import org.jclouds.vcloud.director.v1_5.domain.Media; import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; +import org.jclouds.vcloud.director.v1_5.domain.MetadataValue; import org.jclouds.vcloud.director.v1_5.domain.Owner; import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; import org.jclouds.vcloud.director.v1_5.domain.Task; @@ -63,18 +67,21 @@ public interface MediaAsyncClient { * @see MediaClient#updateMedia(ReferenceType, Media)) */ @PUT - @Consumes + @Consumes(VCloudDirectorMediaType.TASK) + @Produces(VCloudDirectorMediaType.MEDIA) @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture updateMedia(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType mediaRef, - @PayloadParam("Media") Media media); + @BinderParam(BindToXMLPayload.class) Media media); /** * @see MediaClient#deleteMedia(ReferenceType)) */ @DELETE - @Consumes + @Consumes(VCloudDirectorMediaType.TASK) @JAXBResponseParser - ListenableFuture deleteMedia(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType mediaRef); + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture deleteMedia(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType mediaRef); /** * @see MediaClient#getOwner(ReferenceType) @@ -87,7 +94,7 @@ public interface MediaAsyncClient { ListenableFuture getOwner(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType mediaRef); /** - * @see MediaClient#getMetadata() + * @see MediaClient#getMetadata(ReferenceType)) */ @GET @Path("/metadata") @@ -97,41 +104,47 @@ public interface MediaAsyncClient { ListenableFuture getMetadata(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType mediaRef); /** - * @see MediaClient#updateMetadata() + * @see MediaClient#mergeMetadata(ReferenceType, Metadata)) */ @POST - @Consumes + @Consumes(VCloudDirectorMediaType.TASK) + @Produces(VCloudDirectorMediaType.METADATA) @JAXBResponseParser - ListenableFuture updateMetadata(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType mediaRef, - @PayloadParam("Metadata") Metadata metadata); + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture mergeMetadata(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType mediaRef, + @BinderParam(BindToXMLPayload.class) Metadata metadata); /** - * @see MediaClient#getMetadataEntry() + * @see MediaClient#getMetadataEntry(ReferenceType, String)) */ @GET @Consumes @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture getMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType mediaRef, - @PathParam("key") String key); + @BinderParam(BindToXMLPayload.class) String key); /** - * @see MediaClient#updateMedia() + * @see MediaClient#setMetadata(ReferenceType, String, MetadataEntry)) */ @PUT - @Consumes + @Path("/metadata/{key}") + @Consumes(VCloudDirectorMediaType.TASK) + @Produces(VCloudDirectorMediaType.METADATA_VALUE) @JAXBResponseParser - ListenableFuture updateMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType metaDataRef, + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture setMetadata(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType metaDataRef, @PathParam("key") String key, - @PayloadParam("MetadataEntry") MetadataEntry metadataEntry); + @BinderParam(BindToXMLPayload.class) MetadataValue metadataValue); /** - * @see MediaClient#deleteMetadataEntry() + * @see MediaClient#deleteMetadataEntry(ReferenceType, String)) */ @DELETE - @Consumes + @Consumes(VCloudDirectorMediaType.TASK) @JAXBResponseParser - ListenableFuture deleteMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType metaDataRef, + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture deleteMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType metaDataRef, @PathParam("key") String key); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/MediaClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/MediaClient.java index 7b5511521d..5bf1a06a64 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/MediaClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/MediaClient.java @@ -24,6 +24,7 @@ import org.jclouds.concurrent.Timeout; import org.jclouds.vcloud.director.v1_5.domain.Media; import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; +import org.jclouds.vcloud.director.v1_5.domain.MetadataValue; import org.jclouds.vcloud.director.v1_5.domain.Owner; import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; import org.jclouds.vcloud.director.v1_5.domain.Task; @@ -57,7 +58,7 @@ public interface MediaClient { /** * Deletes a media. */ - void deleteMedia(ReferenceType mediaRef); + Task deleteMedia(ReferenceType mediaRef); /** * Retrieves an owner. @@ -78,7 +79,7 @@ public interface MediaClient { * @return a task. This operation is asynchronous and the user should monitor the returned * task status in order to check when it is completed. */ - Task updateMetadata(ReferenceType mediaRef, Metadata metadata); + Task mergeMetadata(ReferenceType mediaRef, Metadata metadata); /** * Retrieves a metadata entry @@ -88,17 +89,21 @@ public interface MediaClient { MetadataEntry getMetadataEntry(ReferenceType mediaRef, String key); /** - * Sets the metadata for the particular key for the media to the value provided + * Sets the metadata for the particular key for the media to the value provided. + * Note: this will replace any existing metadata information * * @return a task. This operation is asynchronous and the user should monitor the returned * task status in order to check when it is completed. */ - Task updateMetadataEntry(ReferenceType mediaRef, String key, MetadataEntry metadataEntry); + Task setMetadata(ReferenceType mediaRef, String key, MetadataValue metadataEntry); /** * Deletes a metadata entry. + * + * @return a task. This operation is asynchronous and the user should monitor the returned + * task status in order to check when it is completed. */ - void deleteMetadataEntry(ReferenceType mediaRef, String key); + Task deleteMetadataEntry(ReferenceType mediaRef, String key); } From 03adca22e4223ae7bb77a81c55bd7ba1039c2098 Mon Sep 17 00:00:00 2001 From: danikov Date: Tue, 14 Feb 2012 20:02:15 +0000 Subject: [PATCH 23/30] exemplar xml for setMetadata --- .../src/test/resources/media/setMetadata.xml | 4 ++++ .../src/test/resources/media/setMetadataTask.xml | 7 +++++++ 2 files changed, 11 insertions(+) create mode 100644 labs/vcloud-director/src/test/resources/media/setMetadata.xml create mode 100644 labs/vcloud-director/src/test/resources/media/setMetadataTask.xml diff --git a/labs/vcloud-director/src/test/resources/media/setMetadata.xml b/labs/vcloud-director/src/test/resources/media/setMetadata.xml new file mode 100644 index 0000000000..67ab204e23 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/media/setMetadata.xml @@ -0,0 +1,4 @@ + + + value + \ No newline at end of file diff --git a/labs/vcloud-director/src/test/resources/media/setMetadataTask.xml b/labs/vcloud-director/src/test/resources/media/setMetadataTask.xml new file mode 100644 index 0000000000..d412e893a8 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/media/setMetadataTask.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file From dfa766d207a913671648f9b2af75e1bf93ec99a6 Mon Sep 17 00:00:00 2001 From: danikov Date: Wed, 15 Feb 2012 00:45:46 +0000 Subject: [PATCH 24/30] tweaked xml file --- labs/vcloud-director/src/test/resources/media/setMetadata.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/labs/vcloud-director/src/test/resources/media/setMetadata.xml b/labs/vcloud-director/src/test/resources/media/setMetadata.xml index 67ab204e23..275e5b4b62 100644 --- a/labs/vcloud-director/src/test/resources/media/setMetadata.xml +++ b/labs/vcloud-director/src/test/resources/media/setMetadata.xml @@ -1,4 +1,4 @@ - + value - \ No newline at end of file + From 72a494d1d6a4d20194266a6ee6b09e8994f4d167 Mon Sep 17 00:00:00 2001 From: danikov Date: Wed, 15 Feb 2012 00:46:26 +0000 Subject: [PATCH 25/30] improved expect test --- .../v1_5/features/MediaClientExpectTest.java | 187 ++++++++++++------ 1 file changed, 123 insertions(+), 64 deletions(-) diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java index 3d560f6ea3..20d1ca8b96 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java @@ -51,8 +51,13 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes URI mediaUri = URI.create(endpoint + "/media/794eb334-754e-4917-b5a0-5df85cbd61d1"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, - getStandardRequest("GET", mediaUri), - getStandardPayloadResponse("/media/media.xml", VCloudDirectorMediaType.MEDIA)); + new VcloudHttpRequestPrimer() + .apiCommand("GET", "/media/794eb334-754e-4917-b5a0-5df85cbd61d1") + .acceptAnyMedia() + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/media/media.xml", VCloudDirectorMediaType.MEDIA) + .httpResponseBuilder().build()); Media expected = media(); @@ -65,8 +70,13 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes URI mediaUri = URI.create(endpoint + "/media/NOTAUUID"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, - getStandardRequest("GET", mediaUri), - getStandardPayloadResponse(400, "/media/error400.xml", VCloudDirectorMediaType.ERROR)); + new VcloudHttpRequestPrimer() + .apiCommand("GET", "/media/NOTAUUID") + .acceptAnyMedia() + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/media/error400.xml", VCloudDirectorMediaType.ERROR) + .httpResponseBuilder().statusCode(400).build()); Error expected = Error.builder() .message("validation error on field 'id': String value has invalid format or length") @@ -91,8 +101,13 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes URI mediaUri = URI.create(endpoint + "/media/e9cd3387-ac57-4d27-a481-9bee75e0690f"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, - getStandardRequest("GET", mediaUri), - getStandardPayloadResponse(403, "/media/error403-catalog.xml", VCloudDirectorMediaType.ERROR)); + new VcloudHttpRequestPrimer() + .apiCommand("GET", "/media/e9cd3387-ac57-4d27-a481-9bee75e0690f") + .acceptAnyMedia() + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/media/error403-catalog.xml", VCloudDirectorMediaType.ERROR) + .httpResponseBuilder().statusCode(403).build()); Error expected = Error.builder() .message("No access to entity \"(com.vmware.vcloud.entity.media:e9cd3387-ac57-4d27-a481-9bee75e0690f)\".") @@ -117,8 +132,13 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes URI mediaUri = URI.create(endpoint + "/media/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, - getStandardRequest("GET", mediaUri), - getStandardPayloadResponse(403, "/media/error403-fake.xml", VCloudDirectorMediaType.ERROR)); + new VcloudHttpRequestPrimer() + .apiCommand("GET", "/media/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee") + .acceptAnyMedia() + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/media/error403-fake.xm", VCloudDirectorMediaType.ERROR) + .httpResponseBuilder().statusCode(403).build()); Error expected = Error.builder() .message("No access to entity \"(com.vmware.vcloud.entity.media:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee)\".") @@ -142,10 +162,15 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes public void testWhenResponseIs2xxLoginUpdateReturnsValidMedia() { URI mediaUri = URI.create(endpoint + "/media/794eb334-754e-4917-b5a0-5df85cbd61d1"); - VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, - getStandardPayloadRequest("PUT", mediaUri, - "/media/media.xml", VCloudDirectorMediaType.MEDIA), - getStandardPayloadResponse("/media/media.xml", VCloudDirectorMediaType.MEDIA)); + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("PUT", "/media/794eb334-754e-4917-b5a0-5df85cbd61d1") + .xmlFilePayload("/media/media.xml", VCloudDirectorMediaType.MEDIA) + .acceptMedia(VCloudDirectorMediaType.MEDIA) + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/media/media.xml", VCloudDirectorMediaType.MEDIA) + .httpResponseBuilder().build()); Media expected = media(); Reference mediaRef = Reference.builder().href(mediaUri).build(); @@ -158,8 +183,13 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes URI mediaUri = URI.create(endpoint + "/media/794eb334-754e-4917-b5a0-5df85cbd61d1"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, - getStandardRequest("DELETE", mediaUri), - getStandardPayloadResponse("/media/deleteMediaTask.xml", VCloudDirectorMediaType.TASK)); + new VcloudHttpRequestPrimer() + .apiCommand("DELETE", "/media/794eb334-754e-4917-b5a0-5df85cbd61d1") + .acceptAnyMedia() + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/media/deleteMediaTask.xml", VCloudDirectorMediaType.TASK) + .httpResponseBuilder().build()); Task expected = Task.builder() @@ -173,11 +203,15 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes @Test public void testWhenResponseIs2xxLoginReturnsValidMetadata() { URI mediaUri = URI.create("https://vcloudbeta.bluelock.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1"); - URI metadataUri = URI.create(mediaUri.toASCIIString()+"/metadata"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, - getStandardRequest("GET", metadataUri), - getStandardPayloadResponse("/media/metadata.xml", VCloudDirectorMediaType.METADATA)); + new VcloudHttpRequestPrimer() + .apiCommand("GET", "/media/794eb334-754e-4917-b5a0-5df85cbd61d1/metadata") + .acceptAnyMedia() + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/media/metadata.xml", VCloudDirectorMediaType.METADATA) + .httpResponseBuilder().build()); Reference mediaRef = Reference.builder().href(mediaUri).build(); @@ -189,11 +223,16 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes @Test public void testWhenResponseIs2xxLoginMergeMetadataReturnsValidTask() { URI mediaUri = URI.create("https://vcloudbeta.bluelock.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1"); - URI metadataUri = URI.create(mediaUri.toASCIIString()+"/metadata"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, - getStandardPayloadRequest("POST", metadataUri, "/media/metadata.xml", VCloudDirectorMediaType.METADATA), - getStandardPayloadResponse("/media/mergeMetadataTask.xml", VCloudDirectorMediaType.TASK)); + new VcloudHttpRequestPrimer() + .apiCommand("POST", "/media/794eb334-754e-4917-b5a0-5df85cbd61d1/metadata") + .xmlFilePayload("/media/metadata.xml", VCloudDirectorMediaType.METADATA) + .acceptMedia(VCloudDirectorMediaType.TASK) + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/media/mergeMetadataTask.xml", VCloudDirectorMediaType.TASK) + .httpResponseBuilder().build()); Reference mediaRef = Reference.builder().href(mediaUri).build(); Metadata inputMetadata = metadata(); @@ -207,11 +246,15 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes @Test(enabled=false) // No metadata in exemplar xml... public void testWhenResponseIs2xxLoginReturnsValidMetadataEntry() { URI mediaUri = URI.create("https://vcloudbeta.bluelock.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1"); - URI metadataUri = URI.create(mediaUri.toASCIIString()+"/metadata/key"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, - getStandardRequest("GET", metadataUri), - getStandardPayloadResponse("/media/metadataEntry.xml", VCloudDirectorMediaType.METADATA_ENTRY)); + new VcloudHttpRequestPrimer() + .apiCommand("GET", "/media/794eb334-754e-4917-b5a0-5df85cbd61d1/metadata/key") + .acceptAnyMedia() + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/media/metadataEntry.xml", VCloudDirectorMediaType.METADATA_ENTRY) + .httpResponseBuilder().build()); MetadataEntry expected = MetadataEntry.builder() .build(); @@ -223,47 +266,22 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes @Test public void testWhenResponseIs2xxLoginSetMetadataReturnsValidTask() { - URI mediaUri = URI.create("https://vcloudbeta.bluelock.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1"); - URI setMetadataUri = URI.create(mediaUri.toASCIIString()+"/metadata/key"); + URI mediaUri = URI.create("https://vcloudbeta.bluelock.com/api/media/"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, - getStandardPayloadRequest("PUT", setMetadataUri, VCloudDirectorMediaType.TASK, - "/media/setMetadata.xml", VCloudDirectorMediaType.METADATA_VALUE), - getStandardPayloadResponse("/media/setMetadataTask.xml", VCloudDirectorMediaType.TASK)); + new VcloudHttpRequestPrimer() + .apiCommand("PUT", "/media/794eb334-754e-4917-b5a0-5df85cbd61d1/metadata/key") + .xmlFilePayload("/media/setMetadata.xml", VCloudDirectorMediaType.METADATA_VALUE) + .acceptMedia(VCloudDirectorMediaType.TASK) + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/media/setMetadataTask.xml", VCloudDirectorMediaType.TASK) + .httpResponseBuilder().build()); Reference mediaRef = Reference.builder().href(mediaUri).build(); MetadataValue inputMetadataValue = MetadataValue.builder().value("value").build(); - Task expectedTask = Task.builder() - .status("running") - .startTime(dateService.iso8601DateParse("2012-02-13T06:35:08.011-05:00")) - .operationName("metadataSet") - .operation("Setting metadata for Media (794eb334-754e-4917-b5a0-5df85cbd61d1)") - .expiryTime(dateService.iso8601DateParse("2012-05-13T06:35:08.011-04:00")) - .name("Task") - .id("urn:vcloud:task:c6dca927-eab4-41fa-ad6a-3ac58602541c") - .type("application/vnd.vmware.vcloud.task+xml") - .href(URI.create("https://vcloudbeta.bluelock.com/api/task/c6dca927-eab4-41fa-ad6a-3ac58602541c")) - .link(Link.builder() - .rel("task:cancel") - .href(URI.create("https://vcloudbeta.bluelock.com/api/task/c6dca927-eab4-41fa-ad6a-3ac58602541c/action/cancel")) - .build()) - .owner(Reference.builder() - .type("application/vnd.vmware.vcloud.media+xml") - .name("") - .href(URI.create("https://vcloudbeta.bluelock.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1")) - .build()) - .user(Reference.builder() - .type("application/vnd.vmware.admin.user+xml") - .name("adk@cloudsoftcorp.com") - .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/e9eb1b29-0404-4c5e-8ef7-e584acc51da9")) - .build()) - .org(Reference.builder() - .type("application/vnd.vmware.vcloud.org+xml") - .name("JClouds") - .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) - .build()) - .build(); + Task expectedTask = setMetadataTask(); assertEquals(client.getMediaClient().setMetadata(mediaRef, "key", inputMetadataValue), expectedTask); } @@ -271,11 +289,15 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes @Test public void testWhenResponseIs2xxLoginDeleteMetadataReturnsValidTask() { URI mediaUri = URI.create("https://vcloudbeta.bluelock.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1"); - URI setMetadataUri = URI.create(mediaUri.toASCIIString()+"/metadata/key"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, - getStandardRequest("DELETE", setMetadataUri), - getStandardPayloadResponse("/media/deleteMetadataTask.xml", VCloudDirectorMediaType.TASK)); + new VcloudHttpRequestPrimer() + .apiCommand("DELETE", "/media/794eb334-754e-4917-b5a0-5df85cbd61d1/metadata/key") + .acceptAnyMedia() + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/media/deleteMetadataTask.xml", VCloudDirectorMediaType.TASK) + .httpResponseBuilder().build()); Reference mediaRef = Reference.builder().href(mediaUri).build(); Task expectedTask = Task.builder() @@ -288,11 +310,15 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes @Test public void testWhenResponseIs2xxLoginReturnsValidOwner() { URI mediaUri = URI.create(endpoint + "/media/794eb334-754e-4917-b5a0-5df85cbd61d1"); - URI metadataUri = URI.create(mediaUri.toASCIIString()+"/owner"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, - getStandardRequest("GET", metadataUri), - getStandardPayloadResponse("/media/owner.xml", VCloudDirectorMediaType.OWNER)); + new VcloudHttpRequestPrimer() + .apiCommand("GET", "/media/794eb334-754e-4917-b5a0-5df85cbd61d1/owner") + .acceptAnyMedia() + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/media/owner.xml", VCloudDirectorMediaType.OWNER) + .httpResponseBuilder().build()); Owner expected = owner(); @@ -365,4 +391,37 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes .build()) .build(); } + + private Task setMetadataTask() { + return Task.builder() + .status("running") + .startTime(dateService.iso8601DateParse("2012-02-13T06:35:08.011-05:00")) + .operationName("metadataSet") + .operation("Setting metadata for Media (794eb334-754e-4917-b5a0-5df85cbd61d1)") + .expiryTime(dateService.iso8601DateParse("2012-05-13T06:35:08.011-04:00")) + .name("task") + .id("urn:vcloud:task:c6dca927-eab4-41fa-ad6a-3ac58602541c") + .type("application/vnd.vmware.vcloud.task+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/task/c6dca927-eab4-41fa-ad6a-3ac58602541c")) + .link(Link.builder() + .rel("task:cancel") + .href(URI.create("https://vcloudbeta.bluelock.com/api/task/c6dca927-eab4-41fa-ad6a-3ac58602541c/action/cancel")) + .build()) + .owner(Reference.builder() + .type("application/vnd.vmware.vcloud.media+xml") + .name("") + .href(URI.create("https://vcloudbeta.bluelock.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1")) + .build()) + .user(Reference.builder() + .type("application/vnd.vmware.admin.user+xml") + .name("adk@cloudsoftcorp.com") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/e9eb1b29-0404-4c5e-8ef7-e584acc51da9")) + .build()) + .org(Reference.builder() + .type("application/vnd.vmware.vcloud.org+xml") + .name("JClouds") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .build()) + .build(); + } } From d0a164f5f5269c26421bb13589769f2151224039 Mon Sep 17 00:00:00 2001 From: danikov Date: Wed, 15 Feb 2012 01:21:15 +0000 Subject: [PATCH 26/30] update ALL media type --- .../jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java index 32739a389f..372122582d 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java @@ -70,6 +70,7 @@ public class VCloudDirectorMediaType { public static final List ALL = Arrays.asList( SESSION, ERROR, ORG_LIST, METADATA, METADATA_ENTRY, METADATA_VALUE, ORG, TASKS_LIST, TASK, ORG_NETWORK, - CATALOG, CATALOG_ITEM, CATALOG_ITEMS, CATALOGS_LIST, PROPERTY + CATALOG, CATALOG_ITEM, CATALOG_ITEMS, CATALOGS_LIST, PROPERTY, + MEDIA, OWNER ); } From c378fef2410e1de51e0e6ea92ea19519573e6d40 Mon Sep 17 00:00:00 2001 From: danikov Date: Wed, 15 Feb 2012 02:51:15 +0000 Subject: [PATCH 27/30] fix and update expect test --- .../v1_5/features/MediaClientExpectTest.java | 202 +++++++++++++++--- 1 file changed, 176 insertions(+), 26 deletions(-) diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java index 20d1ca8b96..cddac2c6c7 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java @@ -137,7 +137,7 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes .acceptAnyMedia() .httpRequestBuilder().build(), new VcloudHttpResponsePrimer() - .xmlFilePayload("/media/error403-fake.xm", VCloudDirectorMediaType.ERROR) + .xmlFilePayload("/media/error403-fake.xml", VCloudDirectorMediaType.ERROR) .httpResponseBuilder().statusCode(403).build()); Error expected = Error.builder() @@ -165,17 +165,18 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, new VcloudHttpRequestPrimer() .apiCommand("PUT", "/media/794eb334-754e-4917-b5a0-5df85cbd61d1") - .xmlFilePayload("/media/media.xml", VCloudDirectorMediaType.MEDIA) - .acceptMedia(VCloudDirectorMediaType.MEDIA) + .xmlFilePayload("/media/updateMedia.xml", VCloudDirectorMediaType.MEDIA) + .acceptMedia(VCloudDirectorMediaType.TASK) .httpRequestBuilder().build(), new VcloudHttpResponsePrimer() - .xmlFilePayload("/media/media.xml", VCloudDirectorMediaType.MEDIA) + .xmlFilePayload("/media/updateMediaTask.xml", VCloudDirectorMediaType.TASK) .httpResponseBuilder().build()); - Media expected = media(); + Media update = updateMedia(); + Task expected = updateMediaTask(); Reference mediaRef = Reference.builder().href(mediaUri).build(); - assertEquals(client.getMediaClient().updateMedia(mediaRef, expected), expected); + assertEquals(client.getMediaClient().updateMedia(mediaRef, update), expected); } @Test @@ -185,16 +186,13 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, new VcloudHttpRequestPrimer() .apiCommand("DELETE", "/media/794eb334-754e-4917-b5a0-5df85cbd61d1") - .acceptAnyMedia() + .acceptMedia(VCloudDirectorMediaType.TASK) .httpRequestBuilder().build(), new VcloudHttpResponsePrimer() .xmlFilePayload("/media/deleteMediaTask.xml", VCloudDirectorMediaType.TASK) .httpResponseBuilder().build()); - Task expected = Task.builder() - - .build(); - + Task expected = deleteMediaTask(); Reference mediaRef = Reference.builder().href(mediaUri).build(); assertEquals(client.getMediaClient().deleteMedia(mediaRef), expected); @@ -236,14 +234,11 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes Reference mediaRef = Reference.builder().href(mediaUri).build(); Metadata inputMetadata = metadata(); - Task expectedTask = Task.builder() - - .build(); + Task expectedTask = mergeMetadataTask(); assertEquals(client.getMediaClient().mergeMetadata(mediaRef, inputMetadata), expectedTask); } - @Test(enabled=false) // No metadata in exemplar xml... public void testWhenResponseIs2xxLoginReturnsValidMetadataEntry() { URI mediaUri = URI.create("https://vcloudbeta.bluelock.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1"); @@ -256,8 +251,7 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes .xmlFilePayload("/media/metadataEntry.xml", VCloudDirectorMediaType.METADATA_ENTRY) .httpResponseBuilder().build()); - MetadataEntry expected = MetadataEntry.builder() - .build(); + MetadataEntry expected = metadataEntry(); Reference mediaRef = Reference.builder().href(mediaUri).build(); @@ -266,7 +260,7 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes @Test public void testWhenResponseIs2xxLoginSetMetadataReturnsValidTask() { - URI mediaUri = URI.create("https://vcloudbeta.bluelock.com/api/media/"); + URI mediaUri = URI.create("https://vcloudbeta.bluelock.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, new VcloudHttpRequestPrimer() @@ -281,28 +275,26 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes Reference mediaRef = Reference.builder().href(mediaUri).build(); MetadataValue inputMetadataValue = MetadataValue.builder().value("value").build(); - Task expectedTask = setMetadataTask(); + Task expectedTask = setMetadataEntryTask(); assertEquals(client.getMediaClient().setMetadata(mediaRef, "key", inputMetadataValue), expectedTask); } @Test - public void testWhenResponseIs2xxLoginDeleteMetadataReturnsValidTask() { + public void testWhenResponseIs2xxLoginDeleteMetadataEntryReturnsValidTask() { URI mediaUri = URI.create("https://vcloudbeta.bluelock.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, new VcloudHttpRequestPrimer() .apiCommand("DELETE", "/media/794eb334-754e-4917-b5a0-5df85cbd61d1/metadata/key") - .acceptAnyMedia() + .acceptMedia(VCloudDirectorMediaType.TASK) .httpRequestBuilder().build(), new VcloudHttpResponsePrimer() - .xmlFilePayload("/media/deleteMetadataTask.xml", VCloudDirectorMediaType.TASK) + .xmlFilePayload("/media/deleteMetadataEntryTask.xml", VCloudDirectorMediaType.TASK) .httpResponseBuilder().build()); Reference mediaRef = Reference.builder().href(mediaUri).build(); - Task expectedTask = Task.builder() - - .build(); + Task expectedTask = deleteMetadataEntryTask(); assertEquals(client.getMediaClient().deleteMetadataEntry(mediaRef, "key"), expectedTask); } @@ -369,6 +361,86 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes .build(); } + private static Media updateMedia() { + return Media.builder() + .size(175163392) + .imageType("iso") + .owner(Owner.builder() + .user(Reference.builder() + .type("application/vnd.vmware.admin.user+xml") + .name("acole") + .href(URI.create("https://mycloud.greenhousedata.com/api/admin/user/c090335b-708c-4c1c-9e3d-89560d002120")) + .build()) + .build()) + .build(); + } + + private static Task updateMediaTask() { + return Task.builder() + .name("task") + .id("urn:vcloud:task:c6dca927-eab4-41fa-ad6a-3ac58602541c") + .type("application/vnd.vmware.vcloud.task+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/task/c6dca927-eab4-41fa-ad6a-3ac58602541c")) + .status("running") + .startTime(dateService.iso8601DateParse("2012-02-13T06:35:08.011-05:00")) + .expiryTime(dateService.iso8601DateParse("2012-05-13T06:35:08.011-04:00")) + .operationName("mediaUpdate") + .operation("Updating Media (794eb334-754e-4917-b5a0-5df85cbd61d1)") + .link(Link.builder() + .rel("task:cancel") + .href(URI.create("https://vcloudbeta.bluelock.com/api/task/c6dca927-eab4-41fa-ad6a-3ac58602541c/action/cancel")) + .build()) + .owner(Reference.builder() + .type("application/vnd.vmware.vcloud.media+xml") + .name("") + .href(URI.create("https://vcloudbeta.bluelock.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1")) + .build()) + .user(Reference.builder() + .type("application/vnd.vmware.admin.user+xml") + .name("adk@cloudsoftcorp.com") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/e9eb1b29-0404-4c5e-8ef7-e584acc51da9")) + .build()) + .org(Reference.builder() + .type("application/vnd.vmware.vcloud.org+xml") + .name("JClouds") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .build()) + .build(); + } + + public static Task deleteMediaTask() { + return Task.builder() + .name("task") + .id("urn:vcloud:task:c6dca927-eab4-41fa-ad6a-3ac58602541c") + .type("application/vnd.vmware.vcloud.task+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/task/c6dca927-eab4-41fa-ad6a-3ac58602541c")) + .status("running") + .startTime(dateService.iso8601DateParse("2012-02-13T06:35:08.011-05:00")) + .expiryTime(dateService.iso8601DateParse("2012-05-13T06:35:08.011-04:00")) + .operationName("mediaDelete") + .operation("Deleting Media (794eb334-754e-4917-b5a0-5df85cbd61d1)") + .link(Link.builder() + .rel("task:cancel") + .href(URI.create("https://vcloudbeta.bluelock.com/api/task/c6dca927-eab4-41fa-ad6a-3ac58602541c/action/cancel")) + .build()) + .owner(Reference.builder() + .type("application/vnd.vmware.vcloud.media+xml") + .name("") + .href(URI.create("https://vcloudbeta.bluelock.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1")) + .build()) + .user(Reference.builder() + .type("application/vnd.vmware.admin.user+xml") + .name("adk@cloudsoftcorp.com") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/e9eb1b29-0404-4c5e-8ef7-e584acc51da9")) + .build()) + .org(Reference.builder() + .type("application/vnd.vmware.vcloud.org+xml") + .name("JClouds") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .build()) + .build(); + } + private static Owner owner() { return Owner.builder() .type("application/vnd.vmware.vcloud.owner+xml") @@ -389,10 +461,55 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes .type("application/vnd.vmware.vcloud.media+xml") .href(URI.create("https://vcloudbeta.bluelock.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1")) .build()) + .entry(MetadataEntry.builder().key("key").value("value").build()) .build(); } - private Task setMetadataTask() { + private static MetadataEntry metadataEntry() { + return MetadataEntry.builder() + .href(URI.create("https://vcloudbeta.bluelock.com/api/cmedia/794eb334-754e-4917-b5a0-5df85cbd61d1/metadata/key")) + .link(Link.builder() + .rel("up") + .type("application/vnd.vmware.vcloud.metadata+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1/metadata")) + .build()) + .key("key").value("value").build(); + } + + private Task mergeMetadataTask() { + return Task.builder() + .status("running") + .startTime(dateService.iso8601DateParse("2012-02-13T06:35:08.011-05:00")) + .operationName("metadataMerge") + .operation("Merging metadata for Media (794eb334-754e-4917-b5a0-5df85cbd61d1)") + .expiryTime(dateService.iso8601DateParse("2012-05-13T06:35:08.011-04:00")) + .name("task") + .id("urn:vcloud:task:c6dca927-eab4-41fa-ad6a-3ac58602541c") + .type("application/vnd.vmware.vcloud.task+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/task/c6dca927-eab4-41fa-ad6a-3ac58602541c")) + .link(Link.builder() + .rel("task:cancel") + .href(URI.create("https://vcloudbeta.bluelock.com/api/task/c6dca927-eab4-41fa-ad6a-3ac58602541c/action/cancel")) + .build()) + .owner(Reference.builder() + .type("application/vnd.vmware.vcloud.media+xml") + .name("") + .href(URI.create("https://vcloudbeta.bluelock.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1")) + .build()) + .user(Reference.builder() + .type("application/vnd.vmware.admin.user+xml") + .name("adk@cloudsoftcorp.com") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/e9eb1b29-0404-4c5e-8ef7-e584acc51da9")) + .build()) + .org(Reference.builder() + .type("application/vnd.vmware.vcloud.org+xml") + .name("JClouds") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .build()) + .build(); + } + + private Task setMetadataEntryTask() { return Task.builder() .status("running") .startTime(dateService.iso8601DateParse("2012-02-13T06:35:08.011-05:00")) @@ -424,4 +541,37 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes .build()) .build(); } + + public static Task deleteMetadataEntryTask() { + return Task.builder() + .name("task") + .id("urn:vcloud:task:c6dca927-eab4-41fa-ad6a-3ac58602541c") + .type("application/vnd.vmware.vcloud.task+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/task/c6dca927-eab4-41fa-ad6a-3ac58602541c")) + .status("running") + .startTime(dateService.iso8601DateParse("2012-02-13T06:35:08.011-05:00")) + .expiryTime(dateService.iso8601DateParse("2012-05-13T06:35:08.011-04:00")) + .operationName("metadataDelete") + .operation("Deleting metadata for Media (794eb334-754e-4917-b5a0-5df85cbd61d1)") + .link(Link.builder() + .rel("task:cancel") + .href(URI.create("https://vcloudbeta.bluelock.com/api/task/c6dca927-eab4-41fa-ad6a-3ac58602541c/action/cancel")) + .build()) + .owner(Reference.builder() + .type("application/vnd.vmware.vcloud.media+xml") + .name("") + .href(URI.create("https://vcloudbeta.bluelock.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1")) + .build()) + .user(Reference.builder() + .type("application/vnd.vmware.admin.user+xml") + .name("adk@cloudsoftcorp.com") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/e9eb1b29-0404-4c5e-8ef7-e584acc51da9")) + .build()) + .org(Reference.builder() + .type("application/vnd.vmware.vcloud.org+xml") + .name("JClouds") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .build()) + .build(); + } } From a90f92490c9977685cc72073fb6e5fa7d55c6e9d Mon Sep 17 00:00:00 2001 From: danikov Date: Wed, 15 Feb 2012 02:51:32 +0000 Subject: [PATCH 28/30] add and update supporting xml --- .../src/test/resources/media/deleteMediaTask.xml | 7 +++++++ .../src/test/resources/media/deleteMetadataEntryTask.xml | 7 +++++++ .../src/test/resources/media/mergeMetadataTask.xml | 7 +++++++ .../vcloud-director/src/test/resources/media/metadata.xml | 8 ++++++-- .../src/test/resources/media/metadataEntry.xml | 6 ++++++ .../src/test/resources/media/updateMedia.xml | 6 ++++++ .../src/test/resources/media/updateMediaTask.xml | 7 +++++++ 7 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 labs/vcloud-director/src/test/resources/media/deleteMediaTask.xml create mode 100644 labs/vcloud-director/src/test/resources/media/deleteMetadataEntryTask.xml create mode 100644 labs/vcloud-director/src/test/resources/media/mergeMetadataTask.xml create mode 100644 labs/vcloud-director/src/test/resources/media/metadataEntry.xml create mode 100644 labs/vcloud-director/src/test/resources/media/updateMedia.xml create mode 100644 labs/vcloud-director/src/test/resources/media/updateMediaTask.xml diff --git a/labs/vcloud-director/src/test/resources/media/deleteMediaTask.xml b/labs/vcloud-director/src/test/resources/media/deleteMediaTask.xml new file mode 100644 index 0000000000..570f815a23 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/media/deleteMediaTask.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/labs/vcloud-director/src/test/resources/media/deleteMetadataEntryTask.xml b/labs/vcloud-director/src/test/resources/media/deleteMetadataEntryTask.xml new file mode 100644 index 0000000000..1baaa50850 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/media/deleteMetadataEntryTask.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/labs/vcloud-director/src/test/resources/media/mergeMetadataTask.xml b/labs/vcloud-director/src/test/resources/media/mergeMetadataTask.xml new file mode 100644 index 0000000000..62cac4b7a2 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/media/mergeMetadataTask.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/labs/vcloud-director/src/test/resources/media/metadata.xml b/labs/vcloud-director/src/test/resources/media/metadata.xml index 4ff6274ff6..f74560ced5 100644 --- a/labs/vcloud-director/src/test/resources/media/metadata.xml +++ b/labs/vcloud-director/src/test/resources/media/metadata.xml @@ -1,4 +1,8 @@ - - + + + + key + value + diff --git a/labs/vcloud-director/src/test/resources/media/metadataEntry.xml b/labs/vcloud-director/src/test/resources/media/metadataEntry.xml new file mode 100644 index 0000000000..0f10d4743e --- /dev/null +++ b/labs/vcloud-director/src/test/resources/media/metadataEntry.xml @@ -0,0 +1,6 @@ + + + + key + value + diff --git a/labs/vcloud-director/src/test/resources/media/updateMedia.xml b/labs/vcloud-director/src/test/resources/media/updateMedia.xml new file mode 100644 index 0000000000..8bd62506bd --- /dev/null +++ b/labs/vcloud-director/src/test/resources/media/updateMedia.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/labs/vcloud-director/src/test/resources/media/updateMediaTask.xml b/labs/vcloud-director/src/test/resources/media/updateMediaTask.xml new file mode 100644 index 0000000000..9f8c0aff5c --- /dev/null +++ b/labs/vcloud-director/src/test/resources/media/updateMediaTask.xml @@ -0,0 +1,7 @@ + + + + + + + From 057850438b6de931c40d46fbe74ec6d960557753 Mon Sep 17 00:00:00 2001 From: danikov Date: Wed, 15 Feb 2012 02:52:06 +0000 Subject: [PATCH 29/30] update clients to use Reference --- .../v1_5/features/MediaAsyncClient.java | 43 ++++++++++--------- .../director/v1_5/features/MediaClient.java | 20 ++++----- 2 files changed, 33 insertions(+), 30 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 89de50a001..39ef53d650 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 @@ -39,7 +39,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; import org.jclouds.vcloud.director.v1_5.domain.MetadataValue; import org.jclouds.vcloud.director.v1_5.domain.Owner; -import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; +import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; import org.jclouds.vcloud.director.v1_5.functions.ReferenceToEndpoint; @@ -55,77 +55,79 @@ import com.google.common.util.concurrent.ListenableFuture; public interface MediaAsyncClient { /** - * @see MediaClient#getMedia(ReferenceType) + * @see MediaClient#getMedia(Reference) */ @GET @Consumes @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture getMedia(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType mediaRef); + ListenableFuture getMedia(@EndpointParam(parser = ReferenceToEndpoint.class) Reference mediaRef); /** - * @see MediaClient#updateMedia(ReferenceType, Media)) + * @see MediaClient#updateMedia(Reference, Media)) */ @PUT @Consumes(VCloudDirectorMediaType.TASK) @Produces(VCloudDirectorMediaType.MEDIA) @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture updateMedia(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType mediaRef, + ListenableFuture updateMedia(@EndpointParam(parser = ReferenceToEndpoint.class) Reference mediaRef, @BinderParam(BindToXMLPayload.class) Media media); /** - * @see MediaClient#deleteMedia(ReferenceType)) + * @see MediaClient#deleteMedia(Reference)) */ @DELETE @Consumes(VCloudDirectorMediaType.TASK) @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture deleteMedia(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType mediaRef); + ListenableFuture deleteMedia(@EndpointParam(parser = ReferenceToEndpoint.class) Reference mediaRef); /** - * @see MediaClient#getOwner(ReferenceType) + * @see MediaClient#getOwner(Reference) */ @GET @Path("/owner") @Consumes @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture getOwner(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType mediaRef); + ListenableFuture getOwner(@EndpointParam(parser = ReferenceToEndpoint.class) Reference mediaRef); /** - * @see MediaClient#getMetadata(ReferenceType)) + * @see MediaClient#getMetadata(Reference)) */ @GET @Path("/metadata") @Consumes @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture getMetadata(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType mediaRef); + ListenableFuture getMetadata(@EndpointParam(parser = ReferenceToEndpoint.class) Reference mediaRef); /** - * @see MediaClient#mergeMetadata(ReferenceType, Metadata)) + * @see MediaClient#mergeMetadata(Reference, Metadata)) */ @POST + @Path("/metadata") @Consumes(VCloudDirectorMediaType.TASK) @Produces(VCloudDirectorMediaType.METADATA) @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture mergeMetadata(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType mediaRef, + ListenableFuture mergeMetadata(@EndpointParam(parser = ReferenceToEndpoint.class) Reference mediaRef, @BinderParam(BindToXMLPayload.class) Metadata metadata); /** - * @see MediaClient#getMetadataEntry(ReferenceType, String)) + * @see MediaClient#getMetadataEntry(Reference, String)) */ @GET + @Path("/metadata/{key}") @Consumes @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture getMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType mediaRef, - @BinderParam(BindToXMLPayload.class) String key); + ListenableFuture getMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) Reference mediaRef, + @PathParam("key") String key); /** - * @see MediaClient#setMetadata(ReferenceType, String, MetadataEntry)) + * @see MediaClient#setMetadata(Reference, String, MetadataEntry)) */ @PUT @Path("/metadata/{key}") @@ -133,18 +135,19 @@ public interface MediaAsyncClient { @Produces(VCloudDirectorMediaType.METADATA_VALUE) @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture setMetadata(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType metaDataRef, + ListenableFuture setMetadata(@EndpointParam(parser = ReferenceToEndpoint.class) Reference metaDataRef, @PathParam("key") String key, @BinderParam(BindToXMLPayload.class) MetadataValue metadataValue); /** - * @see MediaClient#deleteMetadataEntry(ReferenceType, String)) + * @see MediaClient#deleteMetadataEntry(Reference, String)) */ @DELETE + @Path("/metadata/{key}") @Consumes(VCloudDirectorMediaType.TASK) @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture deleteMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType metaDataRef, + ListenableFuture deleteMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) Reference metaDataRef, @PathParam("key") String key); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/MediaClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/MediaClient.java index 5bf1a06a64..92d539a019 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/MediaClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/MediaClient.java @@ -26,7 +26,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; import org.jclouds.vcloud.director.v1_5.domain.MetadataValue; import org.jclouds.vcloud.director.v1_5.domain.Owner; -import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; +import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.domain.Task; /** @@ -45,7 +45,7 @@ public interface MediaClient { * * @return the media or null if not found */ - Media getMedia(ReferenceType mediaRef); + Media getMedia(Reference mediaRef); /** * Updates the name/description of a media. @@ -53,40 +53,40 @@ public interface MediaClient { * @return a task. This operation is asynchronous and the user should monitor the returned * task status in order to check when it is completed. */ - Task updateMedia(ReferenceType mediaRef, Media media); + Task updateMedia(Reference mediaRef, Media media); /** * Deletes a media. */ - Task deleteMedia(ReferenceType mediaRef); + Task deleteMedia(Reference mediaRef); /** * Retrieves an owner. * * @return the owner or null if not found */ - Owner getOwner(ReferenceType mediaRef); + Owner getOwner(Reference mediaRef); /** * Retrieves an list of the media's metadata * * @return a list of metadata */ - Metadata getMetadata(ReferenceType mediaRef); + Metadata getMetadata(Reference mediaRef); /** * Merges the metadata for a media with the information provided. * * @return a task. This operation is asynchronous and the user should monitor the returned * task status in order to check when it is completed. */ - Task mergeMetadata(ReferenceType mediaRef, Metadata metadata); + Task mergeMetadata(Reference mediaRef, Metadata metadata); /** * Retrieves a metadata entry * * @return the metadata entry, or null if not found */ - MetadataEntry getMetadataEntry(ReferenceType mediaRef, String key); + MetadataEntry getMetadataEntry(Reference mediaRef, String key); /** * Sets the metadata for the particular key for the media to the value provided. @@ -95,7 +95,7 @@ public interface MediaClient { * @return a task. This operation is asynchronous and the user should monitor the returned * task status in order to check when it is completed. */ - Task setMetadata(ReferenceType mediaRef, String key, MetadataValue metadataEntry); + Task setMetadata(Reference mediaRef, String key, MetadataValue metadataEntry); /** * Deletes a metadata entry. @@ -103,7 +103,7 @@ public interface MediaClient { * @return a task. This operation is asynchronous and the user should monitor the returned * task status in order to check when it is completed. */ - Task deleteMetadataEntry(ReferenceType mediaRef, String key); + Task deleteMetadataEntry(Reference mediaRef, String key); } From fbc82c5f46f4e29095f828a759053c4845abf80c Mon Sep 17 00:00:00 2001 From: danikov Date: Wed, 15 Feb 2012 02:52:26 +0000 Subject: [PATCH 30/30] bugfix: use LinkedListMultiMap to guarantee header order --- .../internal/BaseVCloudDirectorRestClientExpectTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java index 05c85183a8..75c4a4ea49 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java @@ -18,8 +18,8 @@ */ package org.jclouds.vcloud.director.v1_5.internal; -import static org.testng.Assert.assertNotNull; import static com.google.common.base.Preconditions.checkNotNull; +import static org.testng.Assert.assertNotNull; import java.net.URI; @@ -31,8 +31,8 @@ import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; import org.testng.annotations.BeforeGroups; -import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.LinkedListMultimap; import com.google.common.collect.Multimap; import com.google.inject.Guice; @@ -158,7 +158,7 @@ public class BaseVCloudDirectorRestClientExpectTest extends BaseRestClientExpect * */ protected class VcloudHttpRequestPrimer { - private Multimap headers = ArrayListMultimap.create(); + private Multimap headers = LinkedListMultimap.create(); private HttpRequest.Builder builder = HttpRequest.builder(); public VcloudHttpRequestPrimer() {