mirror of https://github.com/apache/jclouds.git
revised links approach for deltacloud so that we can determine which features a collection supports
This commit is contained in:
parent
9b2f8138cf
commit
a24a1e261e
|
@ -20,7 +20,6 @@
|
||||||
package org.jclouds.deltacloud;
|
package org.jclouds.deltacloud;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
|
@ -31,19 +30,23 @@ import javax.ws.rs.POST;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.core.MediaType;
|
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.Images;
|
||||||
import org.jclouds.deltacloud.collections.Instances;
|
import org.jclouds.deltacloud.collections.Instances;
|
||||||
import org.jclouds.deltacloud.collections.Realms;
|
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.Image;
|
||||||
import org.jclouds.deltacloud.domain.Instance;
|
import org.jclouds.deltacloud.domain.Instance;
|
||||||
import org.jclouds.deltacloud.domain.Realm;
|
import org.jclouds.deltacloud.domain.Realm;
|
||||||
import org.jclouds.deltacloud.options.CreateInstanceOptions;
|
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.ImageHandler;
|
||||||
import org.jclouds.deltacloud.xml.ImagesHandler;
|
import org.jclouds.deltacloud.xml.ImagesHandler;
|
||||||
import org.jclouds.deltacloud.xml.InstanceHandler;
|
import org.jclouds.deltacloud.xml.InstanceHandler;
|
||||||
import org.jclouds.deltacloud.xml.InstancesHandler;
|
import org.jclouds.deltacloud.xml.InstancesHandler;
|
||||||
import org.jclouds.deltacloud.xml.LinksHandler;
|
|
||||||
import org.jclouds.deltacloud.xml.RealmHandler;
|
import org.jclouds.deltacloud.xml.RealmHandler;
|
||||||
import org.jclouds.deltacloud.xml.RealmsHandler;
|
import org.jclouds.deltacloud.xml.RealmsHandler;
|
||||||
import org.jclouds.http.filters.BasicAuthentication;
|
import org.jclouds.http.filters.BasicAuthentication;
|
||||||
|
@ -75,8 +78,8 @@ public interface DeltacloudAsyncClient {
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("")
|
@Path("")
|
||||||
@XMLResponseParser(LinksHandler.class)
|
@XMLResponseParser(DeltacloudCollectionsHandler.class)
|
||||||
ListenableFuture<Map<DeltacloudCollection, URI>> getCollections();
|
ListenableFuture<? extends Set<? extends DeltacloudCollection>> getCollections();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see DeltacloudClient#listRealms
|
* @see DeltacloudClient#listRealms
|
||||||
|
@ -86,7 +89,7 @@ public interface DeltacloudAsyncClient {
|
||||||
@Path("")
|
@Path("")
|
||||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||||
@XMLResponseParser(RealmsHandler.class)
|
@XMLResponseParser(RealmsHandler.class)
|
||||||
ListenableFuture<? extends Set<Realm>> listRealms();
|
ListenableFuture<? extends Set<? extends Realm>> listRealms();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see DeltacloudClient#getRealm
|
* @see DeltacloudClient#getRealm
|
||||||
|
@ -105,7 +108,7 @@ public interface DeltacloudAsyncClient {
|
||||||
@Path("")
|
@Path("")
|
||||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||||
@XMLResponseParser(ImagesHandler.class)
|
@XMLResponseParser(ImagesHandler.class)
|
||||||
ListenableFuture<? extends Set<Image>> listImages();
|
ListenableFuture<? extends Set<? extends Image>> listImages();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see DeltacloudClient#getImage
|
* @see DeltacloudClient#getImage
|
||||||
|
@ -116,6 +119,25 @@ public interface DeltacloudAsyncClient {
|
||||||
@XMLResponseParser(ImageHandler.class)
|
@XMLResponseParser(ImageHandler.class)
|
||||||
ListenableFuture<Image> getImage(@EndpointParam URI imageHref);
|
ListenableFuture<Image> getImage(@EndpointParam URI imageHref);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DeltacloudClient#listHardwareProfiles
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Endpoint(HardwareProfiles.class)
|
||||||
|
@Path("")
|
||||||
|
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||||
|
@XMLResponseParser(HardwareProfilesHandler.class)
|
||||||
|
ListenableFuture<? extends Set<? extends HardwareProfile>> listHardwareProfiles();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DeltacloudClient#getHardwareProfile
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
|
@Path("")
|
||||||
|
@XMLResponseParser(HardwareProfileHandler.class)
|
||||||
|
ListenableFuture<HardwareProfile> getHardwareProfile(@EndpointParam URI profileHref);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see DeltacloudClient#listInstances
|
* @see DeltacloudClient#listInstances
|
||||||
*/
|
*/
|
||||||
|
@ -124,7 +146,7 @@ public interface DeltacloudAsyncClient {
|
||||||
@Path("")
|
@Path("")
|
||||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||||
@XMLResponseParser(InstancesHandler.class)
|
@XMLResponseParser(InstancesHandler.class)
|
||||||
ListenableFuture<? extends Set<Instance>> listInstances();
|
ListenableFuture<? extends Set<? extends Instance>> listInstances();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see DeltacloudClient#getInstance
|
* @see DeltacloudClient#getInstance
|
||||||
|
|
|
@ -20,12 +20,12 @@
|
||||||
package org.jclouds.deltacloud;
|
package org.jclouds.deltacloud;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.jclouds.concurrent.Timeout;
|
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.Image;
|
||||||
import org.jclouds.deltacloud.domain.Instance;
|
import org.jclouds.deltacloud.domain.Instance;
|
||||||
import org.jclouds.deltacloud.domain.Realm;
|
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
|
* 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.
|
* 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<DeltacloudCollection, URI> getCollections();
|
Set<? extends DeltacloudCollection> getCollections();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The realms collection will return a set of all realms available to the current user.
|
* 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);
|
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<? extends HardwareProfile> 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.
|
* The instances collection will return a set of all instances available to the current user.
|
||||||
*
|
*
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -22,7 +22,8 @@ package org.jclouds.deltacloud.config;
|
||||||
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
|
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Map;
|
import java.util.NoSuchElementException;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
@ -30,10 +31,11 @@ import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.deltacloud.DeltacloudAsyncClient;
|
import org.jclouds.deltacloud.DeltacloudAsyncClient;
|
||||||
import org.jclouds.deltacloud.DeltacloudClient;
|
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.Images;
|
||||||
import org.jclouds.deltacloud.collections.Instances;
|
import org.jclouds.deltacloud.collections.Instances;
|
||||||
import org.jclouds.deltacloud.collections.Realms;
|
import org.jclouds.deltacloud.collections.Realms;
|
||||||
|
import org.jclouds.deltacloud.domain.DeltacloudCollection;
|
||||||
import org.jclouds.deltacloud.handlers.DeltacloudErrorHandler;
|
import org.jclouds.deltacloud.handlers.DeltacloudErrorHandler;
|
||||||
import org.jclouds.http.HttpErrorHandler;
|
import org.jclouds.http.HttpErrorHandler;
|
||||||
import org.jclouds.http.RequiresHttp;
|
import org.jclouds.http.RequiresHttp;
|
||||||
|
@ -45,7 +47,9 @@ import org.jclouds.rest.ConfiguresRestClient;
|
||||||
import org.jclouds.rest.config.RestClientModule;
|
import org.jclouds.rest.config.RestClientModule;
|
||||||
import org.jclouds.rest.suppliers.RetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
|
import org.jclouds.rest.suppliers.RetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,12 +81,12 @@ public class DeltacloudRestClientModule extends RestClientModule<DeltacloudClien
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
protected Supplier<Map<DeltacloudCollection, URI>> provideCollections(
|
protected Supplier<Set<? extends DeltacloudCollection>> provideCollections(
|
||||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final DeltacloudClient client) {
|
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final DeltacloudClient client) {
|
||||||
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<DeltacloudCollection, URI>>(authException,
|
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Set<? extends DeltacloudCollection>>(
|
||||||
seconds, new Supplier<Map<DeltacloudCollection, URI>>() {
|
authException, seconds, new Supplier<Set<? extends DeltacloudCollection>>() {
|
||||||
@Override
|
@Override
|
||||||
public Map<DeltacloudCollection, URI> get() {
|
public Set<? extends DeltacloudCollection> get() {
|
||||||
return client.getCollections();
|
return client.getCollections();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -94,27 +98,41 @@ public class DeltacloudRestClientModule extends RestClientModule<DeltacloudClien
|
||||||
*/
|
*/
|
||||||
@Provides
|
@Provides
|
||||||
@Images
|
@Images
|
||||||
protected URI provideImageCollection(Supplier<Map<DeltacloudCollection, URI>> collectionSupplier) {
|
protected URI provideImageCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
|
||||||
return collectionSupplier.get().get(DeltacloudCollection.IMAGES);
|
return findCollectionWithRel(collectionSupplier.get(), "images").getHref();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DeltacloudCollection findCollectionWithRel(Iterable<? extends DeltacloudCollection> iterable,
|
||||||
|
final String rel) {
|
||||||
|
try {
|
||||||
|
return Iterables.find(iterable, new Predicate<DeltacloudCollection>() {
|
||||||
|
|
||||||
|
@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<Set<? extends DeltacloudCollection>> 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
|
@Provides
|
||||||
@Instances
|
@Instances
|
||||||
protected URI provideInstanceCollection(Supplier<Map<DeltacloudCollection, URI>> collectionSupplier) {
|
protected URI provideInstanceCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
|
||||||
return collectionSupplier.get().get(DeltacloudCollection.INSTANCES);
|
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
|
@Provides
|
||||||
@Realms
|
@Realms
|
||||||
protected URI provideRealmCollection(Supplier<Map<DeltacloudCollection, URI>> collectionSupplier) {
|
protected URI provideRealmCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
|
||||||
return collectionSupplier.get().get(DeltacloudCollection.REALMS);
|
return findCollectionWithRel(collectionSupplier.get(), "realms").getHref();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<? extends Feature> features;
|
||||||
|
|
||||||
|
public DeltacloudCollection(URI href, String rel) {
|
||||||
|
this(href, rel, ImmutableSet.<Feature> of());
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeltacloudCollection(URI href, String rel, Set<? extends Feature> 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<? extends Feature> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,7 +7,7 @@
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* 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
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* 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.net.URI;
|
||||||
import java.util.Map;
|
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.http.functions.ParseSax;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.util.Utils;
|
||||||
import org.xml.sax.Attributes;
|
import org.xml.sax.Attributes;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class LinksHandler extends ParseSax.HandlerWithResult<Map<DeltacloudCollection, URI>> {
|
public class DeltacloudCollectionHandler extends ParseSax.HandlerWithResult<DeltacloudCollection> {
|
||||||
|
private URI href;
|
||||||
|
private String rel;
|
||||||
|
private Set<Feature> features = Sets.newLinkedHashSet();
|
||||||
|
|
||||||
private Map<DeltacloudCollection, URI> links = Maps.newLinkedHashMap();
|
private DeltacloudCollection realm;
|
||||||
|
|
||||||
public Map<DeltacloudCollection, URI> getResult() {
|
public DeltacloudCollection getResult() {
|
||||||
return links;
|
return realm;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
|
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
|
||||||
Map<String, String> attributes = Utils.cleanseAttributes(attrs);
|
Map<String, String> attributes = Utils.cleanseAttributes(attrs);
|
||||||
if (qName.equals("link")) {
|
if (qName.equalsIgnoreCase("link")) {
|
||||||
String rel = attributes.get("rel");
|
this.href = URI.create(attributes.get("href"));
|
||||||
if (rel != null) {
|
this.rel = attributes.get("rel");
|
||||||
DeltacloudCollection link = DeltacloudCollection.fromValue(rel);
|
} else if (qName.equalsIgnoreCase("feature")) {
|
||||||
links.put(link, URI.create(attributes.get("href")));
|
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();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* 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<Set<? extends DeltacloudCollection>> {
|
||||||
|
private StringBuilder currentText = new StringBuilder();
|
||||||
|
|
||||||
|
private Set<DeltacloudCollection> links = Sets.newLinkedHashSet();
|
||||||
|
private final DeltacloudCollectionHandler linkHandler;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public DeltacloudCollectionsHandler(DeltacloudCollectionHandler linkHandler) {
|
||||||
|
this.linkHandler = linkHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<? extends DeltacloudCollection> 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -24,17 +24,19 @@ import static org.testng.Assert.assertEquals;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.jclouds.deltacloud.collections.DeltacloudCollection;
|
|
||||||
import org.jclouds.deltacloud.config.DeltacloudRestClientModule;
|
import org.jclouds.deltacloud.config.DeltacloudRestClientModule;
|
||||||
|
import org.jclouds.deltacloud.domain.DeltacloudCollection;
|
||||||
import org.jclouds.deltacloud.options.CreateInstanceOptions;
|
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.ImageHandler;
|
||||||
import org.jclouds.deltacloud.xml.ImagesHandler;
|
import org.jclouds.deltacloud.xml.ImagesHandler;
|
||||||
import org.jclouds.deltacloud.xml.InstanceHandler;
|
import org.jclouds.deltacloud.xml.InstanceHandler;
|
||||||
import org.jclouds.deltacloud.xml.InstancesHandler;
|
import org.jclouds.deltacloud.xml.InstancesHandler;
|
||||||
import org.jclouds.deltacloud.xml.LinksHandler;
|
|
||||||
import org.jclouds.deltacloud.xml.RealmHandler;
|
import org.jclouds.deltacloud.xml.RealmHandler;
|
||||||
import org.jclouds.deltacloud.xml.RealmsHandler;
|
import org.jclouds.deltacloud.xml.RealmsHandler;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
|
@ -86,7 +88,7 @@ public class DeltacloudAsyncClientTest extends RestClientTest<DeltacloudAsyncCli
|
||||||
assertPayloadEquals(httpRequest, null, null, false);
|
assertPayloadEquals(httpRequest, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseSax.class);
|
assertResponseParserClassEquals(method, httpRequest, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, LinksHandler.class);
|
assertSaxResponseParserClassEquals(method, DeltacloudCollectionsHandler.class);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
checkFilters(httpRequest);
|
checkFilters(httpRequest);
|
||||||
|
@ -153,6 +155,36 @@ public class DeltacloudAsyncClientTest extends RestClientTest<DeltacloudAsyncCli
|
||||||
checkFilters(request);
|
checkFilters(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testListHardwareProfiles() throws IOException, SecurityException, NoSuchMethodException {
|
||||||
|
Method method = DeltacloudAsyncClient.class.getMethod("listHardwareProfiles");
|
||||||
|
HttpRequest request = processor.createRequest(method);
|
||||||
|
|
||||||
|
assertRequestLineEquals(request, "GET http://localhost:3001/api/profiles HTTP/1.1");
|
||||||
|
assertNonPayloadHeadersEqual(request, "Accept: application/xml\n");
|
||||||
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
|
assertSaxResponseParserClassEquals(method, HardwareProfilesHandler.class);
|
||||||
|
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||||
|
|
||||||
|
checkFilters(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetHardwareProfile() throws IOException, SecurityException, NoSuchMethodException {
|
||||||
|
Method method = DeltacloudAsyncClient.class.getMethod("getHardwareProfile", URI.class);
|
||||||
|
HttpRequest request = processor.createRequest(method, URI.create("https://delta/profile1"));
|
||||||
|
|
||||||
|
assertRequestLineEquals(request, "GET https://delta/profile1 HTTP/1.1");
|
||||||
|
assertNonPayloadHeadersEqual(request, "Accept: application/xml\n");
|
||||||
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
|
assertSaxResponseParserClassEquals(method, HardwareProfileHandler.class);
|
||||||
|
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||||
|
|
||||||
|
checkFilters(request);
|
||||||
|
}
|
||||||
|
|
||||||
public void testListInstances() throws IOException, SecurityException, NoSuchMethodException {
|
public void testListInstances() throws IOException, SecurityException, NoSuchMethodException {
|
||||||
Method method = DeltacloudAsyncClient.class.getMethod("listInstances");
|
Method method = DeltacloudAsyncClient.class.getMethod("listInstances");
|
||||||
HttpRequest request = processor.createRequest(method);
|
HttpRequest request = processor.createRequest(method);
|
||||||
|
@ -270,22 +302,27 @@ public class DeltacloudAsyncClientTest extends RestClientTest<DeltacloudAsyncCli
|
||||||
public static class DeltacloudRestClientModuleExtension extends DeltacloudRestClientModule {
|
public static class DeltacloudRestClientModuleExtension extends DeltacloudRestClientModule {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Supplier<Map<DeltacloudCollection, URI>> provideCollections(long seconds, DeltacloudClient client) {
|
protected Supplier<Set<? extends DeltacloudCollection>> provideCollections(long seconds, DeltacloudClient client) {
|
||||||
return Suppliers.ofInstance(null);
|
return Suppliers.ofInstance(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected URI provideImageCollection(Supplier<Map<DeltacloudCollection, URI>> collectionSupplier) {
|
protected URI provideImageCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
|
||||||
return URI.create("http://localhost:3001/api/images");
|
return URI.create("http://localhost:3001/api/images");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected URI provideInstanceCollection(Supplier<Map<DeltacloudCollection, URI>> collectionSupplier) {
|
protected URI provideHardwareProfileCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
|
||||||
|
return URI.create("http://localhost:3001/api/profiles");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected URI provideInstanceCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
|
||||||
return URI.create("http://localhost:3001/api/instances");
|
return URI.create("http://localhost:3001/api/instances");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected URI provideRealmCollection(Supplier<Map<DeltacloudCollection, URI>> collectionSupplier) {
|
protected URI provideRealmCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
|
||||||
return URI.create("http://localhost:3001/api/realms");
|
return URI.create("http://localhost:3001/api/realms");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,14 +25,14 @@ import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.jclouds.Constants;
|
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.Image;
|
||||||
import org.jclouds.deltacloud.domain.Instance;
|
import org.jclouds.deltacloud.domain.Instance;
|
||||||
import org.jclouds.deltacloud.domain.InstanceAction;
|
import org.jclouds.deltacloud.domain.InstanceAction;
|
||||||
|
@ -112,10 +112,8 @@ public class DeltacloudClientLiveTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetLinksContainsAll() throws Exception {
|
public void testGetLinksContainsAll() throws Exception {
|
||||||
Map<DeltacloudCollection, URI> links = client.getCollections();
|
Set<? extends DeltacloudCollection> links = client.getCollections();
|
||||||
assertNotNull(links);
|
assertNotNull(links);
|
||||||
for (DeltacloudCollection link : DeltacloudCollection.values())
|
|
||||||
assert (links.get(link) != null) : link;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testListAndGetRealms() throws Exception {
|
public void testListAndGetRealms() throws Exception {
|
||||||
|
@ -140,6 +138,17 @@ public class DeltacloudClientLiveTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testListAndGetHardwareProfiles() throws Exception {
|
||||||
|
Set<? extends HardwareProfile> 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 {
|
public void testListAndGetInstances() throws Exception {
|
||||||
Set<? extends Instance> response = client.listInstances();
|
Set<? extends Instance> response = client.listInstances();
|
||||||
assert null != response;
|
assert null != response;
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* 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<DeltacloudCollection> 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
|
||||||
|
.<Feature> 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);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,58 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
|
||||||
*
|
|
||||||
* ====================================================================
|
|
||||||
* 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<DeltacloudCollection, URI> 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);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,7 +1,23 @@
|
||||||
<api driver='ec2' version='1.0'>
|
<api driver='mock' version='0.1.0'>
|
||||||
<link href='http://fancycloudprovider.com/api/hardware_profiles' rel='hardware_profiles' />
|
<link href='http://localhost:3001/api/realms' rel='realms'>
|
||||||
<link href='http://fancycloudprovider.com/api/instance_states' rel='instance_states' />
|
</link>
|
||||||
<link href='http://fancycloudprovider.com/api/realms' rel='realms' />
|
<link href='http://localhost:3001/api/images' rel='images'>
|
||||||
<link href='http://fancycloudprovider.com/api/images' rel='images' />
|
</link>
|
||||||
<link href='http://fancycloudprovider.com/api/instances' rel='instances' />
|
<link href='http://localhost:3001/api/instance_states' rel='instance_states'>
|
||||||
|
</link>
|
||||||
|
<link href='http://localhost:3001/api/instances' rel='instances'>
|
||||||
|
<feature name='hardware_profiles'></feature>
|
||||||
|
<feature name='user_name'></feature>
|
||||||
|
<feature name='authentication_key'></feature>
|
||||||
|
</link>
|
||||||
|
<link href='http://localhost:3001/api/hardware_profiles' rel='hardware_profiles'>
|
||||||
|
</link>
|
||||||
|
<link href='http://localhost:3001/api/storage_snapshots' rel='storage_snapshots'>
|
||||||
|
</link>
|
||||||
|
<link href='http://localhost:3001/api/storage_volumes' rel='storage_volumes'>
|
||||||
|
</link>
|
||||||
|
<link href='http://localhost:3001/api/keys' rel='keys'>
|
||||||
|
</link>
|
||||||
|
<link href='http://localhost:3001/api/buckets' rel='buckets'>
|
||||||
|
</link>
|
||||||
</api>
|
</api>
|
Loading…
Reference in New Issue