tidy up existing tests, add metadata ops

This commit is contained in:
danikov 2012-02-06 18:10:58 +00:00
parent 2819a4a467
commit 8f7f9e6988
7 changed files with 377 additions and 76 deletions

View File

@ -0,0 +1,91 @@
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 static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NS;
import java.util.Set;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
@XmlRootElement(namespace = NS, name = "MetaDataList")
public class Metadata {
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return new Builder().fromMetadataList(this);
}
public static class Builder {
private Set<MetadataEntry> metadata = Sets.newLinkedHashSet();
/**
* @see OrgList#getOrgs
*/
public Builder metadata(Set<MetadataEntry> orgs) {
this.metadata = Sets.newLinkedHashSet(checkNotNull(orgs, "metadata"));
return this;
}
/**
* @see OrgList#getOrgs
*/
public Builder addMetadata(MetadataEntry org) {
metadata.add(checkNotNull(org, "metadatum"));
return this;
}
public Metadata build() {
return new Metadata(metadata);
}
public Builder fromMetadataList(Metadata in) {
return metadata(in.getMetadata());
}
}
private Metadata() {
// For JAXB and builder use
}
private Metadata(Set<MetadataEntry> orgs) {
this.metadata = ImmutableSet.copyOf(orgs);
}
@XmlElement(namespace = NS, name = "MetaData")
private Set<MetadataEntry> metadata = Sets.newLinkedHashSet();
public Set<MetadataEntry> getMetadata() {
return ImmutableSet.copyOf(metadata);
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
Metadata that = Metadata.class.cast(o);
return equal(metadata, that.metadata);
}
@Override
public int hashCode() {
return Objects.hashCode(metadata);
}
@Override
public String toString() {
return Objects.toStringHelper("").add("metadata", metadata).toString();
}
}

View File

@ -0,0 +1,148 @@
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 static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NS;
import java.net.URI;
import java.util.Set;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
@XmlRootElement(namespace = NS, name = "org/metadata")
public class MetadataEntry extends BaseResource<MetadataEntry> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return new Builder().fromMetadatum(this);
}
public static class Builder extends BaseResource.Builder<MetadataEntry> {
private String key;
private String value;
private Set<Link> links = Sets.newLinkedHashSet();
/**
* @see MetadataEntry#getKey
*/
public Builder key(String key) {
this.key = key;
return this;
}
/**
* @see MetadataEntry#getValue
*/
public Builder value(String value) {
this.value = value;
return this;
}
/**
* @see MetadataEntry#?
*/
public Builder links(Set<Link> links) {
this.links = Sets.newLinkedHashSet(checkNotNull(links, "links"));
return this;
}
/**
* @see MetadataEntry#?
*/
public Builder addLink(Link org) {
links.add(checkNotNull(org, "org"));
return this;
}
public MetadataEntry build() {
return new MetadataEntry(href, type, key, value, links);
}
public Builder fromMetadatum(MetadataEntry in) {
return key(in.getKey()).value(in.getValue());
}
@Override
public Builder href(URI href) {
return Builder.class.cast(super.href(href));
}
@Override
public Builder type(String type) {
return Builder.class.cast(super.type(type));
}
}
private MetadataEntry() {
// For JAXB and builder use
}
private MetadataEntry(URI href, String type, String key, String value, Set<Link> links) {
super(href, type);
this.key = key;
this.value = value;
this.links = ImmutableSet.copyOf(links);
}
@XmlAttribute
private String key;
@XmlElement(namespace = NS, name = "Value")
private String value;
@XmlElement(namespace = NS, name = "Link")
private Set<Link> links = Sets.newLinkedHashSet();
/**
*
* @return key of the entry
*/
public String getKey() {
return key;
}
/**
*
* @return value of the entry
*/
public String getValue() {
return value;
}
/**
* TODO
*/
public Set<Link> getLinks() {
return ImmutableSet.copyOf(links);
}
@Override
public boolean equals(Object o) {
if (!super.equals(o))
return false;
MetadataEntry that = MetadataEntry.class.cast(o);
return equal(key, that.key);
}
@Override
public int hashCode() {
return super.hashCode() + Objects.hashCode(key);
}
@Override
public ToStringHelper string() {
return super.string().add("key", key).add("value", value);
}
}

View File

@ -22,6 +22,8 @@ import java.net.URI;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
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.Org; import org.jclouds.vcloud.director.v1_5.domain.Org;
import org.jclouds.vcloud.director.v1_5.domain.OrgList; import org.jclouds.vcloud.director.v1_5.domain.OrgList;
@ -49,4 +51,18 @@ public interface OrgClient {
* @return the org or null if not found * @return the org or null if not found
*/ */
Org getOrg(URI orgHref); Org getOrg(URI orgHref);
/**
* Retrieves an list of the organization's metadata
*
* @return a list of metadata
*/
Metadata getMetadata(URI orgRef);
/**
* Retrieves a metadata
*
* @return the metadata or null if not found
*/
MetadataEntry getMetadataEntry(URI metaDataRef);
} }

View File

@ -27,6 +27,8 @@ import org.jclouds.http.HttpResponse;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; 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.Link;
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.Org; import org.jclouds.vcloud.director.v1_5.domain.Org;
import org.jclouds.vcloud.director.v1_5.domain.OrgList; import org.jclouds.vcloud.director.v1_5.domain.OrgList;
import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.domain.Reference;
@ -45,29 +47,32 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
@Test @Test
public void testWhenResponseIs2xxLoginReturnsValidOrgList() { public void testWhenResponseIs2xxLoginReturnsValidOrgList() {
HttpRequest orgListRequest = HttpRequest.builder() HttpRequest orgListRequest = HttpRequest.builder()
.method("GET") .method("GET")
.endpoint(URI.create("http://localhost/api/org/")) .endpoint(URI.create("http://localhost/api/org/"))
.headers(ImmutableMultimap.<String, String> builder() .headers(ImmutableMultimap.<String, String> builder()
.put("Accept", "*/*") .put("Accept", "*/*")
.put("x-vcloud-authorization", token) .put("x-vcloud-authorization",token)
.build()) .build())
.build(); .build();
HttpResponse orgListResponse = HttpResponse.builder() HttpResponse orgListResponse = HttpResponse.builder()
.statusCode(200) .statusCode(200)
.payload(payloadFromResourceWithContentType("/orglist.xml", VCloudDirectorMediaType.ORGLIST_XML + ";version=1.5")) .payload(payloadFromResourceWithContentType("/org/orglist.xml", VCloudDirectorMediaType.ORGLIST_XML
.build(); +";version=1.5"))
.build();
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, orgListRequest, orgListResponse); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, orgListRequest,
orgListResponse);
assertEquals(client.getOrgClient().getOrgList(), OrgList.builder() OrgList actual = OrgList.builder()
.org(Reference.builder() .org(OrgLink.builder()
.type("application/vnd.vmware.vcloud.org+xml") .type("application/vnd.vmware.vcloud.org+xml")
.name("JClouds") .name("JClouds")
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.build()) .build())
.build() .build();
);
assertEquals(client.getOrgClient().getOrgList(), actual);
} }
@Test @Test
@ -75,67 +80,104 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
URI orgRef = URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"); URI orgRef = URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0");
HttpRequest orgRequest = HttpRequest.builder() HttpRequest orgRequest = HttpRequest.builder()
.method("GET") .method("GET")
.endpoint(orgRef) .endpoint(orgRef)
.headers(ImmutableMultimap.<String, String> builder() .headers(ImmutableMultimap.<String, String> builder()
.put("Accept", "*/*") .put("Accept", "*/*")
.put("x-vcloud-authorization", token) .put("x-vcloud-authorization", token)
.build()) .build())
.build(); .build();
HttpResponse orgResponse = HttpResponse.builder() HttpResponse orgResponse = HttpResponse.builder()
.statusCode(200) .statusCode(200)
.payload(payloadFromResourceWithContentType("/org.xml", VCloudDirectorMediaType.ORG_XML + ";version=1.5")) .payload(payloadFromResourceWithContentType("/org/org.xml", VCloudDirectorMediaType.ORG_XML + ";version=1.5"))
.build(); .build();
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, orgRequest, orgResponse); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, orgRequest, orgResponse);
assertEquals(client.getOrgClient().getOrg(orgRef), Org.builder() Org actual = Org
.name("JClouds") .builder()
.id("urn:vcloud:org:6f312e42-cd2b-488d-a2bb-97519cd57ed0") .name("JClouds")
.type(VCloudDirectorMediaType.ORG_XML) .description("")
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) .fullName("JClouds")
.link(Link.builder() .id("urn:vcloud:org:6f312e42-cd2b-488d-a2bb-97519cd57ed0")
.rel("down") .type(VCloudDirectorMediaType.ORG_XML)
.type("application/vnd.vmware.vcloud.vdc+xml") .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.name("Cluster01-JClouds") .link(Link.builder()
.href(URI.create("https://vcloudbeta.bluelock.com/api/vdc/d16d333b-e3c0-4176-845d-a5ee6392df07")) .rel("down")
.build()) .type("application/vnd.vmware.vcloud.vdc+xml")
.link(Link.builder() .name("Cluster01-JClouds")
.type("application/vnd.vmware.vcloud.tasksList+xml") .href(URI.create("https://vcloudbeta.bluelock.com/api/vdc/d16d333b-e3c0-4176-845d-a5ee6392df07"))
.href(URI.create("https://vcloudbeta.bluelock.com/api/tasksList/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) .build())
.build()) .link(Link.builder()
.link(Link.builder() .rel("down")
.rel("down") .type("application/vnd.vmware.vcloud.tasksList+xml")
.type("application/vnd.vmware.vcloud.catalog+xml") .href(URI.create("https://vcloudbeta.bluelock.com/api/tasksList/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.name("Public") .build())
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c")) .link(Link.builder()
.build()) .rel("down")
.link(Link.builder() .type("application/vnd.vmware.vcloud.catalog+xml")
.rel("down") .name("Public")
.type("application/vnd.vmware.vcloud.controlAccess+xml") .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c"))
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c/controlAccess/")) .build())
.build()) .link(Link.builder()
.link(Link.builder() .rel("down")
.rel("down") .type("application/vnd.vmware.vcloud.controlAccess+xml")
.type("application/vnd.vmware.vcloud.orgNetwork+xml") .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c/controlAccess/"))
.name("ilsolation01-Jclouds") .build())
.href(URI.create("https://vcloudbeta.bluelock.com/api/network/f3ba8256-6f48-4512-aad6-600e85b4dc38")) .link(Link.builder()
.build()) .rel("down")
.link(Link.builder() .type("application/vnd.vmware.vcloud.orgNetwork+xml")
.rel("down") .name("ilsolation01-Jclouds")
.type("application/vnd.vmware.vcloud.orgNetwork+xml") .href(URI.create("https://vcloudbeta.bluelock.com/api/network/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.name("internet01-Jclouds") .build())
.href(URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c")) .link(Link.builder()
.build()) .rel("down")
.link(Link.builder() .type("application/vnd.vmware.vcloud.orgNetwork+xml")
.rel("down") .name("internet01-Jclouds")
.type("application/vnd.vmware.vcloud.metadata+xml") .href(URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c"))
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata")) .build())
.build()) .link(Link.builder()
.description("") .rel("down")
.fullName("JClouds") .type("application/vnd.vmware.vcloud.metadata+xml")
.build() .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata"))
); .build())
.build();
assertEquals(client.getOrgClient().getOrg(orgRef), actual);
}
@Test
public void testWhenResponseIs2xxLoginReturnsValidMetadataList() {
URI orgRef = URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0");
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
getStandardRequest("GET", orgRef),
getStandardPaylodResponse("/orglist.xml"));
Metadata actual = Metadata.builder()
// .link(Link.builder()
// .rel("up")
// .type("application/vnd.vmware.vcloud.vdc+xml")
// .name("Cluster01-JClouds")
// .href(URI.create("https://vcloudbeta.bluelock.com/api/vdc/d16d333b-e3c0-4176-845d-a5ee6392df07"))
// .build())
.build();
assertEquals(client.getOrgClient().getMetadata(orgRef), actual);
}
@Test(enabled=false)
public void testWhenResponseIs2xxLoginReturnsValidMetadata() {
URI metadataRef = URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadataKEY");
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
getStandardRequest("GET", metadataRef),
getStandardPaylodResponse("/org/metadata.xml"));
MetadataEntry actual = MetadataEntry.builder()
.build();
assertEquals(client.getOrgClient().getMetadataEntry(metadataRef), actual);
} }
} }

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<Metadata xmlns="http://www.vmware.com/vcloud/v1.5" type="application/vnd.vmware.vcloud.metadata+xml" href="https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://vcloudbeta.bluelock.com/api/v1.5/schema/master.xsd">
<Link rel="up" type="application/vnd.vmware.vcloud.org+xml" href="https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"/>
</Metadata>