From 7d93887789c2d0156ffe448d41d964251cf1eb06 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 5 Feb 2012 23:10:15 -0800 Subject: [PATCH] example start on a vcloud director client --- .../v1_5/VCloudDirectorAsyncClient.java | 7 + .../director/v1_5/VCloudDirectorClient.java | 9 +- .../v1_5/VCloudDirectorMediaType.java | 3 + .../VCloudDirectorRestClientModule.java | 4 +- .../vcloud/director/v1_5/domain/Org.java | 196 ++++++++++++++++++ .../vcloud/director/v1_5/domain/OrgLink.java | 69 ++++++ .../vcloud/director/v1_5/domain/OrgList.java | 113 ++++++++++ .../v1_5/features/OrgAsyncClient.java | 62 ++++++ .../director/v1_5/features/OrgClient.java | 52 +++++ .../v1_5/features/OrgClientExpectTest.java | 172 +++++++++++++++ .../src/test/resources/org.xml | 12 ++ .../src/test/resources/orglist.xml | 4 + 12 files changed, 701 insertions(+), 2 deletions(-) create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgLink.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgList.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgAsyncClient.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgClient.java create mode 100644 labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientExpectTest.java create mode 100644 labs/vcloud-director/src/test/resources/org.xml create mode 100644 labs/vcloud-director/src/test/resources/orglist.xml 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 6ffa4ed3ba..ba7af5a7c9 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 @@ -18,7 +18,9 @@ */ package org.jclouds.vcloud.director.v1_5; +import org.jclouds.rest.annotations.Delegate; import org.jclouds.vcloud.director.v1_5.domain.Session; +import org.jclouds.vcloud.director.v1_5.features.OrgAsyncClient; import com.google.inject.Provides; @@ -38,4 +40,9 @@ public interface VCloudDirectorAsyncClient { @Provides Session getCurrentSession(); + /** + * @return synchronous access to Org features + */ + @Delegate + OrgAsyncClient getOrgClient(); } 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 429d156572..8be15b1602 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 @@ -21,7 +21,9 @@ package org.jclouds.vcloud.director.v1_5; import java.util.concurrent.TimeUnit; 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.OrgClient; import com.google.inject.Provides; @@ -40,5 +42,10 @@ public interface VCloudDirectorClient { */ @Provides Session getCurrentSession(); - + + /** + * @return synchronous access to Org features + */ + @Delegate + OrgClient getOrgClient(); } 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 88e8632f62..80d37a1ba8 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 @@ -33,5 +33,8 @@ public interface VCloudDirectorMediaType { public final static String NS = "http://www.vmware.com/vcloud/v1.5"; public final static String SESSION_XML = "application/vnd.vmware.vcloud.session+xml"; + + public final static String ORGLIST_XML = "application/vnd.vmware.vcloud.orgList+xml"; + public final static String ORG_XML = "application/vnd.vmware.vcloud.org+xml"; } 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 04d5142f38..73ad9722fe 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 @@ -42,6 +42,8 @@ import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; import org.jclouds.vcloud.director.v1_5.annotations.Login; 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.OrgAsyncClient; +import org.jclouds.vcloud.director.v1_5.features.OrgClient; import org.jclouds.vcloud.director.v1_5.functions.LoginUserInOrgWithPassword; import org.jclouds.vcloud.director.v1_5.handlers.InvalidateSessionAndRetryOn401AndLogoutOnClose; import org.jclouds.vcloud.director.v1_5.handlers.VCloudDirectorErrorHandler; @@ -69,7 +71,7 @@ import com.google.inject.name.Named; public class VCloudDirectorRestClientModule extends RestClientModule { public static final Map, Class> DELEGATE_MAP = ImmutableMap., Class> builder()// - // TODO + .put(OrgClient.class, OrgAsyncClient.class) .build(); public VCloudDirectorRestClientModule() { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java new file mode 100644 index 0000000000..5d0453777e --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java @@ -0,0 +1,196 @@ +/** + * 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 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; + +/** + * Retrieves a list of organizations. + * + * @author Adrian Cole + */ +@XmlRootElement(namespace = NS, name = "Org") +public class Org extends BaseNamedResource { + + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromOrg(this); + } + + public static class Builder extends BaseNamedResource.Builder { + + private String id; + private String description; + private String fullName; + private Set links = Sets.newLinkedHashSet(); + + /** + * @see Org#getId + */ + public Builder id(String id) { + this.id = id; + return this; + } + + /** + * @see Org#getDescription + */ + public Builder description(String description) { + this.description = description; + return this; + } + + /** + * @see Org#getFullName + */ + public Builder fullName(String fullName) { + this.fullName = fullName; + return this; + } + + /** + * @see Org#getOrgs + */ + public Builder links(Set links) { + this.links = Sets.newLinkedHashSet(checkNotNull(links, "links")); + return this; + } + + /** + * @see Org#getOrgs + */ + public Builder addLink(Link org) { + links.add(checkNotNull(org, "org")); + return this; + } + + public Org build() { + return new Org(href, type, name, id, description, fullName, links); + } + + public Builder fromOrg(Org in) { + return id(in.getId()).description(in.getDescription()).fullName(in.getFullName()).links(in.getLinks()); + } + + @Override + public Builder name(String name) { + return Builder.class.cast(super.name(name)); + } + + @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 Org() { + // For JAXB and builder use + } + + private Org(URI href, String type, String name, String id, String description, String fullName, Set links) { + super(href, type, name); + this.id = id; + this.description = description; + this.fullName = fullName; + this.links = ImmutableSet.copyOf(links); + } + + @XmlAttribute + private String id; + @XmlElement(namespace = NS, name = "Description") + private String description; + @XmlElement(namespace = NS, name = "FullName") + private String fullName; + @XmlElement(namespace = NS, name = "Link") + private Set links = Sets.newLinkedHashSet(); + + /** + * + * @return id of the org + */ + public String getId() { + return id; + } + + /** + * + * @return description of the org + */ + public String getDescription() { + return description; + } + + /** + * + * @return fullName of the org + */ + public String getFullName() { + return fullName; + } + + /** + * TODO + */ + public Set getLinks() { + return ImmutableSet.copyOf(links); + } + + @Override + public boolean equals(Object o) { + if (!super.equals(o)) + return false; + Org that = Org.class.cast(o); + return equal(id, that.id) && equal(description, that.description) && equal(fullName, that.fullName) + && equal(links, that.links); + } + + @Override + public int hashCode() { + return super.hashCode() + Objects.hashCode(id, description, fullName, links); + } + + @Override + public ToStringHelper string() { + return super.string().add("id", id).add("description", description).add("fullName", fullName).add("links", links); + } +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgLink.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgLink.java new file mode 100644 index 0000000000..6c819e3188 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgLink.java @@ -0,0 +1,69 @@ +/** + * 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 java.net.URI; + +public class OrgLink extends BaseNamedResource { + + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder toBuilder() { + return Builder.class.cast(new Builder().fromNamedResource(this)); + } + + public static class Builder extends BaseNamedResource.Builder { + + @Override + public OrgLink build() { + return new OrgLink(href, type, name); + } + + @Override + public Builder name(String name) { + return Builder.class.cast(super.name(name)); + } + + @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 OrgLink(URI href, String type, String name) { + super(href, type, name); + } + + private OrgLink() { + // for JAXB + } +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgList.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgList.java new file mode 100644 index 0000000000..b55771766f --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgList.java @@ -0,0 +1,113 @@ +/** + * 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 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; + +/** + * Retrieves a list of organizations. + * + * @author Adrian Cole + */ +@XmlRootElement(namespace = NS, name = "OrgList") +public class OrgList { + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromOrgList(this); + } + + public static class Builder { + + private Set orgs = Sets.newLinkedHashSet(); + + /** + * @see OrgList#getOrgs + */ + public Builder orgs(Set orgs) { + this.orgs = Sets.newLinkedHashSet(checkNotNull(orgs, "orgs")); + return this; + } + + /** + * @see OrgList#getOrgs + */ + public Builder addOrg(OrgLink org) { + orgs.add(checkNotNull(org, "org")); + return this; + } + + public OrgList build() { + return new OrgList(orgs); + } + + public Builder fromOrgList(OrgList in) { + return orgs(in.getOrgs()); + } + } + + private OrgList() { + // For JAXB and builder use + } + + private OrgList(Set orgs) { + this.orgs = ImmutableSet.copyOf(orgs); + } + + @XmlElement(namespace = NS, name = "Org") + private Set orgs = Sets.newLinkedHashSet(); + + public Set getOrgs() { + return ImmutableSet.copyOf(orgs); + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + OrgList that = OrgList.class.cast(o); + return equal(orgs, that.orgs); + } + + @Override + public int hashCode() { + return Objects.hashCode(orgs); + } + + @Override + public String toString() { + return Objects.toStringHelper("").add("orgs", orgs).toString(); + } +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgAsyncClient.java new file mode 100644 index 0000000000..5aea14eb28 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgAsyncClient.java @@ -0,0 +1,62 @@ +/** + * 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.OrgList; +import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; + +import com.google.common.util.concurrent.ListenableFuture; + +/** + + * @see OrgClient + * @author Adrian Cole + */ +@RequestFilters(AddVCloudAuthorizationToRequest.class) +public interface OrgAsyncClient { + + /** + * @see OrgClient#getOrgList + */ + @GET + @Path("/org/") + @Consumes + @JAXBResponseParser + ListenableFuture getOrgList(); + + /** + * @see OrgClient#getOrg + */ + @GET + @Consumes + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getOrg(@EndpointParam URI uri); +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgClient.java new file mode 100644 index 0000000000..3a6d8d50b3 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgClient.java @@ -0,0 +1,52 @@ +/** + * 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.Org; +import org.jclouds.vcloud.director.v1_5.domain.OrgList; + +/** + * Provides synchronous access to Org. + *

+ * + * @see OrgAsyncClient + * @see + * @author Adrian Cole + */ +@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) +public interface OrgClient { + + /** + * Retrieves a list of organizations. + * + * @return a list of organizations + */ + OrgList getOrgList(); + + /** + * Retrieves an organization. + * + * @return the org or null if not found + */ + Org getOrg(URI orgHref); +} diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientExpectTest.java new file mode 100644 index 0000000000..bfc10bfcd7 --- /dev/null +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientExpectTest.java @@ -0,0 +1,172 @@ +/** + * 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.http.HttpRequest; +import org.jclouds.http.HttpResponse; +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.Org; +import org.jclouds.vcloud.director.v1_5.domain.OrgLink; +import org.jclouds.vcloud.director.v1_5.domain.OrgList; +import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMultimap; + +/** + * + * Allows us to test a client via its side effects. + * + * @author Adrian Cole + */ +@Test(groups = "unit", singleThreaded = true, testName = "OrgClientExpectTest") +public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { + + public void testWhenResponseIs2xxLoginReturnsValidOrgList() { + + HttpRequest orgListRequest = HttpRequest.builder().method("GET") + .endpoint(URI.create("http://localhost/api/org/")).headers( + ImmutableMultimap. builder().put("Accept", "*/*").put("x-vcloud-authorization", + token).build()).build(); + + HttpResponse orgListResponse = HttpResponse.builder().statusCode(200) + + .payload( + payloadFromResourceWithContentType("/orglist.xml", VCloudDirectorMediaType.ORGLIST_XML + + ";version=1.5")).build(); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, orgListRequest, + orgListResponse); + + assertEquals(client.getOrgClient().getOrgList(), OrgList.builder().addOrg( + OrgLink.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() + + ); + + } + + // please help solve javax.xml.bind.UnmarshalException + @Test(enabled = false) + public void testWhenResponseIs2xxLoginReturnsValidOrg() { + + URI orgRef = URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"); + + HttpRequest orgRequest = HttpRequest.builder().method("GET").endpoint(orgRef).headers( + ImmutableMultimap. builder().put("Accept", "*/*").put("x-vcloud-authorization", token) + .build()).build(); + + HttpResponse orgResponse = HttpResponse.builder().statusCode(200) + + .payload(payloadFromResourceWithContentType("/org.xml", VCloudDirectorMediaType.ORG_XML + ";version=1.5")) + .build(); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, orgRequest, orgResponse); + + assertEquals( + client.getOrgClient().getOrg(orgRef), + Org + .builder() + .name("JClouds") + .id("urn:vcloud:org:6f312e42-cd2b-488d-a2bb-97519cd57ed0") + .type(VCloudDirectorMediaType.ORG_XML) + .href( + URI + .create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + + .addLink( + Link + .builder() + .rel("down") + .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()) + .addLink( + Link + .builder() + .rel("down") + .type("application/vnd.vmware.vcloud.tasksList+xml") + .href( + URI + .create("https://vcloudbeta.bluelock.com/api/tasksList/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .build()) + .addLink( + Link + .builder() + .rel("down") + .type("application/vnd.vmware.vcloud.catalog+xml") + .name("Public") + .href( + URI + .create("https://vcloudbeta.bluelock.com/api/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c")) + .build()) + .addLink( + Link + .builder() + .rel("down") + .type("application/vnd.vmware.vcloud.controlAccess+xml") + .href( + URI + .create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c/controlAccess/")) + .build()) + .addLink( + Link + .builder() + .rel("down") + .type("application/vnd.vmware.vcloud.orgNetwork+xml") + .name("ilsolation01-Jclouds") + .href( + URI + .create("https://vcloudbeta.bluelock.com/api/network/f3ba8256-6f48-4512-aad6-600e85b4dc38")) + .build()) + .addLink( + Link + .builder() + .rel("down") + .type("application/vnd.vmware.vcloud.orgNetwork+xml") + .name("internet01-Jclouds") + .href( + URI + .create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c")) + .build()) + .addLink( + Link + .builder() + .rel("down") + .type("application/vnd.vmware.vcloud.metadata+xml") + .href( + URI + .create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata")) + .build()).description("").fullName("JClouds").build() + + ); + + } + +} diff --git a/labs/vcloud-director/src/test/resources/org.xml b/labs/vcloud-director/src/test/resources/org.xml new file mode 100644 index 0000000000..941eb7dbd0 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/org.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + JClouds + \ No newline at end of file diff --git a/labs/vcloud-director/src/test/resources/orglist.xml b/labs/vcloud-director/src/test/resources/orglist.xml new file mode 100644 index 0000000000..6d410e86e3 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/orglist.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file