mirror of https://github.com/apache/jclouds.git
tidy up existing tests, add metadata ops
This commit is contained in:
parent
2819a4a467
commit
8f7f9e6988
|
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -49,25 +51,28 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
|
||||||
.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
|
||||||
|
+";version=1.5"))
|
||||||
.build();
|
.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
|
||||||
|
@ -85,13 +90,16 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
|
||||||
|
|
||||||
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
|
||||||
|
.builder()
|
||||||
.name("JClouds")
|
.name("JClouds")
|
||||||
|
.description("")
|
||||||
|
.fullName("JClouds")
|
||||||
.id("urn:vcloud:org:6f312e42-cd2b-488d-a2bb-97519cd57ed0")
|
.id("urn:vcloud:org:6f312e42-cd2b-488d-a2bb-97519cd57ed0")
|
||||||
.type(VCloudDirectorMediaType.ORG_XML)
|
.type(VCloudDirectorMediaType.ORG_XML)
|
||||||
.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"))
|
||||||
|
@ -102,6 +110,7 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
|
||||||
.href(URI.create("https://vcloudbeta.bluelock.com/api/vdc/d16d333b-e3c0-4176-845d-a5ee6392df07"))
|
.href(URI.create("https://vcloudbeta.bluelock.com/api/vdc/d16d333b-e3c0-4176-845d-a5ee6392df07"))
|
||||||
.build())
|
.build())
|
||||||
.link(Link.builder()
|
.link(Link.builder()
|
||||||
|
.rel("down")
|
||||||
.type("application/vnd.vmware.vcloud.tasksList+xml")
|
.type("application/vnd.vmware.vcloud.tasksList+xml")
|
||||||
.href(URI.create("https://vcloudbeta.bluelock.com/api/tasksList/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
|
.href(URI.create("https://vcloudbeta.bluelock.com/api/tasksList/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
|
||||||
.build())
|
.build())
|
||||||
|
@ -120,7 +129,7 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
|
||||||
.rel("down")
|
.rel("down")
|
||||||
.type("application/vnd.vmware.vcloud.orgNetwork+xml")
|
.type("application/vnd.vmware.vcloud.orgNetwork+xml")
|
||||||
.name("ilsolation01-Jclouds")
|
.name("ilsolation01-Jclouds")
|
||||||
.href(URI.create("https://vcloudbeta.bluelock.com/api/network/f3ba8256-6f48-4512-aad6-600e85b4dc38"))
|
.href(URI.create("https://vcloudbeta.bluelock.com/api/network/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
|
||||||
.build())
|
.build())
|
||||||
.link(Link.builder()
|
.link(Link.builder()
|
||||||
.rel("down")
|
.rel("down")
|
||||||
|
@ -133,9 +142,42 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
|
||||||
.type("application/vnd.vmware.vcloud.metadata+xml")
|
.type("application/vnd.vmware.vcloud.metadata+xml")
|
||||||
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata"))
|
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata"))
|
||||||
.build())
|
.build())
|
||||||
.description("")
|
.build();
|
||||||
.fullName("JClouds")
|
|
||||||
.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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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>
|
Loading…
Reference in New Issue