From a24a1e261ea720a96cd01f94e157e73e195b27aa Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Tue, 28 Dec 2010 13:19:21 +0100 Subject: [PATCH] revised links approach for deltacloud so that we can determine which features a collection supports --- .../deltacloud/DeltacloudAsyncClient.java | 38 ++++-- .../jclouds/deltacloud/DeltacloudClient.java | 23 +++- .../collections/DeltacloudCollection.java | 36 ----- .../config/DeltacloudRestClientModule.java | 58 +++++--- .../domain/DeltacloudCollection.java | 124 ++++++++++++++++++ ....java => DeltacloudCollectionHandler.java} | 41 ++++-- .../xml/DeltacloudCollectionsHandler.java | 68 ++++++++++ .../deltacloud/DeltacloudAsyncClientTest.java | 53 ++++++-- .../deltacloud/DeltacloudClientLiveTest.java | 19 ++- .../xml/DeltacloudCollectionsHandlerTest.java | 64 +++++++++ .../deltacloud/xml/LinksHandlerTest.java | 58 -------- .../deltacloud/src/test/resources/links.xml | 28 +++- 12 files changed, 452 insertions(+), 158 deletions(-) delete mode 100644 sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/collections/DeltacloudCollection.java create mode 100644 sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/domain/DeltacloudCollection.java rename sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/xml/{LinksHandler.java => DeltacloudCollectionHandler.java} (51%) mode change 100755 => 100644 create mode 100644 sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/xml/DeltacloudCollectionsHandler.java create mode 100644 sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/xml/DeltacloudCollectionsHandlerTest.java delete mode 100644 sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/xml/LinksHandlerTest.java diff --git a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudAsyncClient.java b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudAsyncClient.java index fd73f50d0d..d3d6eb128b 100644 --- a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudAsyncClient.java +++ b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudAsyncClient.java @@ -20,7 +20,6 @@ package org.jclouds.deltacloud; import java.net.URI; -import java.util.Map; import java.util.Set; import javax.ws.rs.Consumes; @@ -31,19 +30,23 @@ import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.core.MediaType; -import org.jclouds.deltacloud.collections.DeltacloudCollection; +import org.jclouds.deltacloud.collections.HardwareProfiles; import org.jclouds.deltacloud.collections.Images; import org.jclouds.deltacloud.collections.Instances; import org.jclouds.deltacloud.collections.Realms; +import org.jclouds.deltacloud.domain.DeltacloudCollection; +import org.jclouds.deltacloud.domain.HardwareProfile; import org.jclouds.deltacloud.domain.Image; import org.jclouds.deltacloud.domain.Instance; import org.jclouds.deltacloud.domain.Realm; import org.jclouds.deltacloud.options.CreateInstanceOptions; +import org.jclouds.deltacloud.xml.DeltacloudCollectionsHandler; +import org.jclouds.deltacloud.xml.HardwareProfileHandler; +import org.jclouds.deltacloud.xml.HardwareProfilesHandler; import org.jclouds.deltacloud.xml.ImageHandler; import org.jclouds.deltacloud.xml.ImagesHandler; import org.jclouds.deltacloud.xml.InstanceHandler; import org.jclouds.deltacloud.xml.InstancesHandler; -import org.jclouds.deltacloud.xml.LinksHandler; import org.jclouds.deltacloud.xml.RealmHandler; import org.jclouds.deltacloud.xml.RealmsHandler; import org.jclouds.http.filters.BasicAuthentication; @@ -75,8 +78,8 @@ public interface DeltacloudAsyncClient { */ @GET @Path("") - @XMLResponseParser(LinksHandler.class) - ListenableFuture> getCollections(); + @XMLResponseParser(DeltacloudCollectionsHandler.class) + ListenableFuture> getCollections(); /** * @see DeltacloudClient#listRealms @@ -86,7 +89,7 @@ public interface DeltacloudAsyncClient { @Path("") @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) @XMLResponseParser(RealmsHandler.class) - ListenableFuture> listRealms(); + ListenableFuture> listRealms(); /** * @see DeltacloudClient#getRealm @@ -105,7 +108,7 @@ public interface DeltacloudAsyncClient { @Path("") @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) @XMLResponseParser(ImagesHandler.class) - ListenableFuture> listImages(); + ListenableFuture> listImages(); /** * @see DeltacloudClient#getImage @@ -116,6 +119,25 @@ public interface DeltacloudAsyncClient { @XMLResponseParser(ImageHandler.class) ListenableFuture getImage(@EndpointParam URI imageHref); + /** + * @see DeltacloudClient#listHardwareProfiles + */ + @GET + @Endpoint(HardwareProfiles.class) + @Path("") + @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) + @XMLResponseParser(HardwareProfilesHandler.class) + ListenableFuture> listHardwareProfiles(); + + /** + * @see DeltacloudClient#getHardwareProfile + */ + @GET + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @Path("") + @XMLResponseParser(HardwareProfileHandler.class) + ListenableFuture getHardwareProfile(@EndpointParam URI profileHref); + /** * @see DeltacloudClient#listInstances */ @@ -124,7 +146,7 @@ public interface DeltacloudAsyncClient { @Path("") @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) @XMLResponseParser(InstancesHandler.class) - ListenableFuture> listInstances(); + ListenableFuture> listInstances(); /** * @see DeltacloudClient#getInstance diff --git a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudClient.java b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudClient.java index 834038f34c..f38ebbbb95 100644 --- a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudClient.java +++ b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/DeltacloudClient.java @@ -20,12 +20,12 @@ package org.jclouds.deltacloud; import java.net.URI; -import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; -import org.jclouds.deltacloud.collections.DeltacloudCollection; +import org.jclouds.deltacloud.domain.DeltacloudCollection; +import org.jclouds.deltacloud.domain.HardwareProfile; import org.jclouds.deltacloud.domain.Image; import org.jclouds.deltacloud.domain.Instance; import org.jclouds.deltacloud.domain.Realm; @@ -46,9 +46,9 @@ public interface DeltacloudClient { * The result of this entry-point is a set of entry-points into other collections, such as * images, instances, hardware profiles and realms, among others. * - * @return named links to available collections, or empty map, if no resources are found + * @return named links to available collections, or empty set, if no collections are found */ - Map getCollections(); + Set getCollections(); /** * The realms collection will return a set of all realms available to the current user. @@ -78,6 +78,21 @@ public interface DeltacloudClient { */ Image getImage(URI imageHref); + /** + * The hardware profiles collection will return a set of all hardware profiles available to the + * current user. + * + * @return hardware profiles viewable to the user or empty set + */ + Set listHardwareProfiles(); + + /** + * + * @param profileHref + * @return hardware profile or null, if not found + */ + HardwareProfile getHardwareProfile(URI profileHref); + /** * The instances collection will return a set of all instances available to the current user. * diff --git a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/collections/DeltacloudCollection.java b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/collections/DeltacloudCollection.java deleted file mode 100644 index 6767cd083d..0000000000 --- a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/collections/DeltacloudCollection.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.jclouds.deltacloud.collections; - -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.CaseFormat; - -/** - * - * @author Adrian Cole - */ -public enum DeltacloudCollection { - HARDWARE_PROFILES, INSTANCE_STATES, REALMS, - - @Images - IMAGES, - - @Instances - INSTANCES, UNRECOGNIZED; - - public String value() { - return (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_UNDERSCORE, name())); - } - - @Override - public String toString() { - return value(); - } - - public static DeltacloudCollection fromValue(String link) { - try { - return valueOf(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(link, "link"))); - } catch (IllegalArgumentException e) { - return UNRECOGNIZED; - } - } -} \ No newline at end of file diff --git a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/config/DeltacloudRestClientModule.java b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/config/DeltacloudRestClientModule.java index f14d31b28b..66f075e358 100644 --- a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/config/DeltacloudRestClientModule.java +++ b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/config/DeltacloudRestClientModule.java @@ -22,7 +22,8 @@ package org.jclouds.deltacloud.config; import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; import java.net.URI; -import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Set; import java.util.concurrent.atomic.AtomicReference; import javax.inject.Named; @@ -30,10 +31,11 @@ import javax.inject.Singleton; import org.jclouds.deltacloud.DeltacloudAsyncClient; import org.jclouds.deltacloud.DeltacloudClient; -import org.jclouds.deltacloud.collections.DeltacloudCollection; +import org.jclouds.deltacloud.collections.HardwareProfiles; import org.jclouds.deltacloud.collections.Images; import org.jclouds.deltacloud.collections.Instances; import org.jclouds.deltacloud.collections.Realms; +import org.jclouds.deltacloud.domain.DeltacloudCollection; import org.jclouds.deltacloud.handlers.DeltacloudErrorHandler; import org.jclouds.http.HttpErrorHandler; import org.jclouds.http.RequiresHttp; @@ -45,7 +47,9 @@ import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.config.RestClientModule; import org.jclouds.rest.suppliers.RetryOnTimeOutButNotOnAuthorizationExceptionSupplier; +import com.google.common.base.Predicate; import com.google.common.base.Supplier; +import com.google.common.collect.Iterables; import com.google.inject.Provides; /** @@ -77,12 +81,12 @@ public class DeltacloudRestClientModule extends RestClientModule> provideCollections( + protected Supplier> provideCollections( @Named(PROPERTY_SESSION_INTERVAL) long seconds, final DeltacloudClient client) { - return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier>(authException, - seconds, new Supplier>() { + return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier>( + authException, seconds, new Supplier>() { @Override - public Map get() { + public Set get() { return client.getCollections(); } }); @@ -94,27 +98,41 @@ public class DeltacloudRestClientModule extends RestClientModule> collectionSupplier) { - return collectionSupplier.get().get(DeltacloudCollection.IMAGES); + protected URI provideImageCollection(Supplier> collectionSupplier) { + return findCollectionWithRel(collectionSupplier.get(), "images").getHref(); + } + + public static DeltacloudCollection findCollectionWithRel(Iterable iterable, + final String rel) { + try { + return Iterables.find(iterable, new Predicate() { + + @Override + public boolean apply(DeltacloudCollection arg0) { + return arg0.getRel().equals(rel); + } + + }); + } catch (NoSuchElementException e) { + throw new NoSuchElementException("could not find rel " + rel + " in collections " + iterable); + } + } + + @Provides + @HardwareProfiles + protected URI provideHardwareProfileCollection(Supplier> collectionSupplier) { + return findCollectionWithRel(collectionSupplier.get(), "hardware_profiles").getHref(); } - /** - * since the supplier is memoized, and there are no objects created here, this doesn't need to be - * singleton. - */ @Provides @Instances - protected URI provideInstanceCollection(Supplier> collectionSupplier) { - return collectionSupplier.get().get(DeltacloudCollection.INSTANCES); + protected URI provideInstanceCollection(Supplier> collectionSupplier) { + return findCollectionWithRel(collectionSupplier.get(), "instances").getHref(); } - /** - * since the supplier is memoized, and there are no objects created here, this doesn't need to be - * singleton. - */ @Provides @Realms - protected URI provideRealmCollection(Supplier> collectionSupplier) { - return collectionSupplier.get().get(DeltacloudCollection.REALMS); + protected URI provideRealmCollection(Supplier> collectionSupplier) { + return findCollectionWithRel(collectionSupplier.get(), "realms").getHref(); } } diff --git a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/domain/DeltacloudCollection.java b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/domain/DeltacloudCollection.java new file mode 100644 index 0000000000..2590feb81c --- /dev/null +++ b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/domain/DeltacloudCollection.java @@ -0,0 +1,124 @@ +package org.jclouds.deltacloud.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; +import java.util.Set; + +import com.google.common.collect.ImmutableSet; + +/** + * + * @author Adrian Cole + */ +public class DeltacloudCollection { + private final URI href; + private final String rel; + private final Set features; + + public DeltacloudCollection(URI href, String rel) { + this(href, rel, ImmutableSet. of()); + } + + public DeltacloudCollection(URI href, String rel, Set features) { + this.href = checkNotNull(href, "href"); + this.rel = checkNotNull(rel, "rel"); + this.features = ImmutableSet.copyOf(checkNotNull(features, "features")); + } + + public URI getHref() { + return href; + } + + public String getRel() { + return rel; + } + + public Set getFeatures() { + return features; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((features == null) ? 0 : features.hashCode()); + result = prime * result + ((href == null) ? 0 : href.hashCode()); + result = prime * result + ((rel == null) ? 0 : rel.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + DeltacloudCollection other = (DeltacloudCollection) obj; + if (features == null) { + if (other.features != null) + return false; + } else if (!features.equals(other.features)) + return false; + if (href == null) { + if (other.href != null) + return false; + } else if (!href.equals(other.href)) + return false; + if (rel == null) { + if (other.rel != null) + return false; + } else if (!rel.equals(other.rel)) + return false; + return true; + } + + @Override + public String toString() { + return "[href=" + href + ", rel=" + rel + ", features=" + features + "]"; + } + + public static class Feature { + private final String name; + + public Feature(String name) { + this.name = checkNotNull(name, "name"); + } + + public String getName() { + return name; + } + + @Override + public String toString() { + return "[name=" + name + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Feature other = (Feature) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } + } +} \ No newline at end of file diff --git a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/xml/LinksHandler.java b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/xml/DeltacloudCollectionHandler.java old mode 100755 new mode 100644 similarity index 51% rename from sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/xml/LinksHandler.java rename to sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/xml/DeltacloudCollectionHandler.java index e8fdf61c8f..307f23520c --- a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/xml/LinksHandler.java +++ b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/xml/DeltacloudCollectionHandler.java @@ -7,7 +7,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.links/licenses/LICENSE-2.0 + * 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, @@ -21,35 +21,50 @@ package org.jclouds.deltacloud.xml; import java.net.URI; import java.util.Map; +import java.util.Set; -import org.jclouds.deltacloud.collections.DeltacloudCollection; +import org.jclouds.deltacloud.domain.DeltacloudCollection; +import org.jclouds.deltacloud.domain.DeltacloudCollection.Feature; import org.jclouds.http.functions.ParseSax; import org.jclouds.util.Utils; import org.xml.sax.Attributes; import org.xml.sax.SAXException; -import com.google.common.collect.Maps; +import com.google.common.collect.Sets; /** * @author Adrian Cole */ -public class LinksHandler extends ParseSax.HandlerWithResult> { +public class DeltacloudCollectionHandler extends ParseSax.HandlerWithResult { + private URI href; + private String rel; + private Set features = Sets.newLinkedHashSet(); - private Map links = Maps.newLinkedHashMap(); + private DeltacloudCollection realm; - public Map getResult() { - return links; + public DeltacloudCollection getResult() { + return realm; } @Override public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { Map attributes = Utils.cleanseAttributes(attrs); - if (qName.equals("link")) { - String rel = attributes.get("rel"); - if (rel != null) { - DeltacloudCollection link = DeltacloudCollection.fromValue(rel); - links.put(link, URI.create(attributes.get("href"))); - } + if (qName.equalsIgnoreCase("link")) { + this.href = URI.create(attributes.get("href")); + this.rel = attributes.get("rel"); + } else if (qName.equalsIgnoreCase("feature")) { + features.add(new Feature(attributes.get("name"))); } } + + @Override + public void endElement(String uri, String localName, String qName) throws SAXException { + if (qName.equalsIgnoreCase("link")) { + this.realm = new DeltacloudCollection(href, rel, features); + this.href = null; + this.rel = null; + this.features = Sets.newLinkedHashSet(); + } + } + } diff --git a/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/xml/DeltacloudCollectionsHandler.java b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/xml/DeltacloudCollectionsHandler.java new file mode 100644 index 0000000000..c5aad697b8 --- /dev/null +++ b/sandbox/deltacloud/src/main/java/org/jclouds/deltacloud/xml/DeltacloudCollectionsHandler.java @@ -0,0 +1,68 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed 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.deltacloud.xml; + +import java.util.Set; + +import javax.inject.Inject; + +import org.jclouds.deltacloud.domain.DeltacloudCollection; +import org.jclouds.http.functions.ParseSax; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +import com.google.common.collect.Sets; + +/** + * @author Adrian Cole + */ +public class DeltacloudCollectionsHandler extends ParseSax.HandlerWithResult> { + private StringBuilder currentText = new StringBuilder(); + + private Set links = Sets.newLinkedHashSet(); + private final DeltacloudCollectionHandler linkHandler; + + @Inject + public DeltacloudCollectionsHandler(DeltacloudCollectionHandler linkHandler) { + this.linkHandler = linkHandler; + } + + public Set getResult() { + return links; + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { + linkHandler.startElement(uri, localName, qName, attributes); + } + + @Override + public void endElement(String uri, String localName, String qName) throws SAXException { + linkHandler.endElement(uri, localName, qName); + if (qName.equals("link") && currentText.toString().trim().equals("")) { + this.links.add(linkHandler.getResult()); + } + currentText = new StringBuilder(); + } + + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + } +} diff --git a/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudAsyncClientTest.java b/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudAsyncClientTest.java index 8ffb24c98d..91d6c1db78 100644 --- a/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudAsyncClientTest.java +++ b/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudAsyncClientTest.java @@ -24,17 +24,19 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.lang.reflect.Method; import java.net.URI; -import java.util.Map; import java.util.Properties; +import java.util.Set; -import org.jclouds.deltacloud.collections.DeltacloudCollection; import org.jclouds.deltacloud.config.DeltacloudRestClientModule; +import org.jclouds.deltacloud.domain.DeltacloudCollection; import org.jclouds.deltacloud.options.CreateInstanceOptions; +import org.jclouds.deltacloud.xml.DeltacloudCollectionsHandler; +import org.jclouds.deltacloud.xml.HardwareProfileHandler; +import org.jclouds.deltacloud.xml.HardwareProfilesHandler; import org.jclouds.deltacloud.xml.ImageHandler; import org.jclouds.deltacloud.xml.ImagesHandler; import org.jclouds.deltacloud.xml.InstanceHandler; import org.jclouds.deltacloud.xml.InstancesHandler; -import org.jclouds.deltacloud.xml.LinksHandler; import org.jclouds.deltacloud.xml.RealmHandler; import org.jclouds.deltacloud.xml.RealmsHandler; import org.jclouds.http.HttpRequest; @@ -86,7 +88,7 @@ public class DeltacloudAsyncClientTest extends RestClientTest> provideCollections(long seconds, DeltacloudClient client) { + protected Supplier> provideCollections(long seconds, DeltacloudClient client) { return Suppliers.ofInstance(null); } @Override - protected URI provideImageCollection(Supplier> collectionSupplier) { + protected URI provideImageCollection(Supplier> collectionSupplier) { return URI.create("http://localhost:3001/api/images"); } @Override - protected URI provideInstanceCollection(Supplier> collectionSupplier) { + protected URI provideHardwareProfileCollection(Supplier> collectionSupplier) { + return URI.create("http://localhost:3001/api/profiles"); + } + + @Override + protected URI provideInstanceCollection(Supplier> collectionSupplier) { return URI.create("http://localhost:3001/api/instances"); } @Override - protected URI provideRealmCollection(Supplier> collectionSupplier) { + protected URI provideRealmCollection(Supplier> collectionSupplier) { return URI.create("http://localhost:3001/api/realms"); } diff --git a/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudClientLiveTest.java b/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudClientLiveTest.java index 597aa39ed8..4abfe6160f 100644 --- a/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudClientLiveTest.java +++ b/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudClientLiveTest.java @@ -25,14 +25,14 @@ import static org.testng.Assert.assertTrue; import java.io.IOException; import java.net.URI; -import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.logging.Logger; import org.jclouds.Constants; -import org.jclouds.deltacloud.collections.DeltacloudCollection; +import org.jclouds.deltacloud.domain.DeltacloudCollection; +import org.jclouds.deltacloud.domain.HardwareProfile; import org.jclouds.deltacloud.domain.Image; import org.jclouds.deltacloud.domain.Instance; import org.jclouds.deltacloud.domain.InstanceAction; @@ -112,10 +112,8 @@ public class DeltacloudClientLiveTest { @Test public void testGetLinksContainsAll() throws Exception { - Map links = client.getCollections(); + Set links = client.getCollections(); assertNotNull(links); - for (DeltacloudCollection link : DeltacloudCollection.values()) - assert (links.get(link) != null) : link; } public void testListAndGetRealms() throws Exception { @@ -140,6 +138,17 @@ public class DeltacloudClientLiveTest { } } + public void testListAndGetHardwareProfiles() throws Exception { + Set response = client.listHardwareProfiles(); + assert null != response; + long profileCount = response.size(); + assertTrue(profileCount >= 0); + for (HardwareProfile profile : response) { + HardwareProfile newDetails = client.getHardwareProfile(profile.getHref()); + assertEquals(profile, newDetails); + } + } + public void testListAndGetInstances() throws Exception { Set response = client.listInstances(); assert null != response; diff --git a/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/xml/DeltacloudCollectionsHandlerTest.java b/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/xml/DeltacloudCollectionsHandlerTest.java new file mode 100644 index 0000000000..9bf65539e8 --- /dev/null +++ b/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/xml/DeltacloudCollectionsHandlerTest.java @@ -0,0 +1,64 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed 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.deltacloud.xml; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.net.URI; +import java.util.Set; + +import org.jclouds.deltacloud.domain.DeltacloudCollection; +import org.jclouds.deltacloud.domain.DeltacloudCollection.Feature; +import org.jclouds.http.functions.BaseHandlerTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +/** + * Tests behavior of {@code DeltacloudCollectionsHandler} + * + * @author Adrian Cole + */ +@Test(groups = "unit") +public class DeltacloudCollectionsHandlerTest extends BaseHandlerTest { + + public void test() { + InputStream is = getClass().getResourceAsStream("/links.xml"); + Set expects = ImmutableSet.of( + new DeltacloudCollection(URI.create("http://localhost:3001/api/realms"), "realms"), + new DeltacloudCollection(URI.create("http://localhost:3001/api/images"), "images"), + new DeltacloudCollection(URI.create("http://localhost:3001/api/instance_states"), "instance_states"), + new DeltacloudCollection(URI.create("http://localhost:3001/api/instances"), "instances", ImmutableSet + . of(new Feature("hardware_profiles"), new Feature("user_name"), new Feature( + "authentication_key"))), + new DeltacloudCollection(URI.create("http://localhost:3001/api/hardware_profiles"), "hardware_profiles"), + new DeltacloudCollection(URI.create("http://localhost:3001/api/storage_snapshots"), "storage_snapshots"), + new DeltacloudCollection(URI.create("http://localhost:3001/api/storage_volumes"), "storage_volumes"), + new DeltacloudCollection(URI.create("http://localhost:3001/api/keys"), "keys"), new DeltacloudCollection( + URI.create("http://localhost:3001/api/buckets"), "buckets") + + ); + // not sure why this isn"t always automatically called from surefire. + setUpInjector(); + assertEquals(factory.create(injector.getInstance(DeltacloudCollectionsHandler.class)).parse(is), expects); + + } +} diff --git a/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/xml/LinksHandlerTest.java b/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/xml/LinksHandlerTest.java deleted file mode 100644 index 4f8d6da1f6..0000000000 --- a/sandbox/deltacloud/src/test/java/org/jclouds/deltacloud/xml/LinksHandlerTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed 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.deltacloud.xml; - -import static org.testng.Assert.assertEquals; - -import java.io.InputStream; -import java.net.URI; -import java.util.Map; - -import org.jclouds.deltacloud.collections.DeltacloudCollection; -import org.jclouds.http.functions.BaseHandlerTest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; - -/** - * Tests behavior of {@code LinksHandler} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class LinksHandlerTest extends BaseHandlerTest { - - public void test() { - InputStream is = getClass().getResourceAsStream("/links.xml"); - Map expects = ImmutableMap.of(// - DeltacloudCollection.HARDWARE_PROFILES, URI.create("http://fancycloudprovider.com/api/hardware_profiles"),// - DeltacloudCollection.INSTANCE_STATES, URI.create("http://fancycloudprovider.com/api/instance_states"),// - DeltacloudCollection.REALMS, URI.create("http://fancycloudprovider.com/api/realms"),// - DeltacloudCollection.IMAGES, URI.create("http://fancycloudprovider.com/api/images"),// - DeltacloudCollection.INSTANCES, URI.create("http://fancycloudprovider.com/api/instances") - - ); - // not sure why this isn't always automatically called from surefire. - setUpInjector(); - assertEquals(factory.create(injector.getInstance(LinksHandler.class)).parse(is), expects); - - } - -} diff --git a/sandbox/deltacloud/src/test/resources/links.xml b/sandbox/deltacloud/src/test/resources/links.xml index 251d904b05..39e13d2283 100644 --- a/sandbox/deltacloud/src/test/resources/links.xml +++ b/sandbox/deltacloud/src/test/resources/links.xml @@ -1,7 +1,23 @@ - - - - - - + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file