formatting and imports

This commit is contained in:
Adrian Cole 2012-05-15 14:43:29 -07:00
parent c1d9a7c47c
commit c63f3119ca
35 changed files with 766 additions and 887 deletions

View File

@ -36,7 +36,7 @@ import com.google.inject.Module;
* @author Adrian Cole
*/
public class SDCApiMetadata extends BaseRestApiMetadata {
/** The serialVersionUID */
private static final long serialVersionUID = 6725672099385580694L;
@ -66,17 +66,12 @@ public class SDCApiMetadata extends BaseRestApiMetadata {
protected Builder() {
super(SDCClient.class, SDCAsyncClient.class);
id("joyent-sdc")
.name("Joyent SDC API")
.identityName("username")
.credentialName("password")
.documentation(URI.create("http://sdc.joyent.org/sdcapi.html"))
.version("~6.5")
.defaultEndpoint("https://api.joyentcloud.com")
.defaultProperties(SDCApiMetadata.defaultProperties())
.defaultModules(ImmutableSet.<Class<? extends Module>>of(SDCRestClientModule.class));
id("joyent-sdc").name("Joyent SDC API").identityName("username").credentialName("password")
.documentation(URI.create("http://sdc.joyent.org/sdcapi.html")).version("~6.5")
.defaultEndpoint("https://api.joyentcloud.com").defaultProperties(SDCApiMetadata.defaultProperties())
.defaultModules(ImmutableSet.<Class<? extends Module>> of(SDCRestClientModule.class));
}
@Override
public SDCApiMetadata build() {
return new SDCApiMetadata(this);

View File

@ -33,13 +33,13 @@ import org.jclouds.rest.annotations.Delegate;
* @author Adrian Cole
*/
public interface SDCAsyncClient {
/**
* Provides asynchronous access to Datacenter features.
*/
@Delegate
DatacenterAsyncClient getDatacenterClient();
/**
* Provides asynchronous access to Machine features.
*/
@ -51,7 +51,7 @@ public interface SDCAsyncClient {
*/
@Delegate
DatasetAsyncClient getDatasetClient();
/**
* Provides asynchronous access to Package features.
*/

View File

@ -43,7 +43,7 @@ public interface SDCClient {
*/
@Delegate
DatacenterClient getDatacenterClient();
/**
* Provides synchronous access to Machine features.
*/
@ -55,7 +55,7 @@ public interface SDCClient {
*/
@Delegate
DatasetClient getDatasetClient();
/**
* Provides synchronous access to Package features.
*/

View File

@ -38,8 +38,8 @@ public class SDCParserModule extends AbstractModule {
@Provides
@Singleton
public Map<Type, Object> provideCustomAdapterBindings() {
return ImmutableMap.<Type, Object> of(Machine.State.class, new SDCTypeAdapters.ServerStateAdapter(),
Type.class, new SDCTypeAdapters.SDCTypeAdapter());
return ImmutableMap.<Type, Object> of(Machine.State.class, new SDCTypeAdapters.ServerStateAdapter(), Type.class,
new SDCTypeAdapters.SDCTypeAdapter());
}
@Override

View File

@ -20,7 +20,7 @@ package org.jclouds.joyent.sdc.v6_5.config;
/**
* Configuration properties and constants used in joyent SDC connections.
*
*
* @author Adrian Cole
*/
public class SDCProperties {

View File

@ -50,11 +50,8 @@ import com.google.common.collect.ImmutableMap;
@ConfiguresRestClient
public class SDCRestClientModule extends RestClientModule<SDCClient, SDCAsyncClient> {
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()
.put(DatacenterClient.class, DatacenterAsyncClient.class)
.put(MachineClient.class, MachineAsyncClient.class)
.put(DatasetClient.class, DatasetAsyncClient.class)
.put(PackageClient.class, PackageAsyncClient.class)
.build();
.put(DatacenterClient.class, DatacenterAsyncClient.class).put(MachineClient.class, MachineAsyncClient.class)
.put(DatasetClient.class, DatasetAsyncClient.class).put(PackageClient.class, PackageAsyncClient.class).build();
public SDCRestClientModule() {
super(DELEGATE_MAP);

View File

@ -13,150 +13,144 @@ import com.google.gson.annotations.SerializedName;
*/
public class Dataset implements Comparable<Dataset> {
public static Builder builder() {
return new Builder();
}
public static Builder builder() {
return new Builder();
}
public static class Builder {
private String id;
private String name;
private Type type;
private String version;
private String urn;
private boolean defaultDataset;
private Date created;
public static class Builder {
private String id;
private String name;
private Type type;
private String version;
private String urn;
private boolean isDefault;
private Date created;
public Builder id(String id) {
this.id = id;
return this;
}
public Builder id(String id) {
this.id = id;
return this;
}
public Builder name(String name) {
this.name = name;
return this;
}
public Builder name(String name) {
this.name = name;
return this;
}
public Builder type(Type type) {
this.type = type;
return this;
}
public Builder type(Type type) {
this.type = type;
return this;
}
public Builder version(String version) {
this.version = version;
return this;
}
public Builder version(String version) {
this.version = version;
return this;
}
public Builder urn(String urn) {
this.urn = urn;
return this;
}
public Builder urn(String urn) {
this.urn = urn;
return this;
}
public Builder defaultDataset(boolean defaultDataset) {
this.defaultDataset = defaultDataset;
return this;
}
public Builder isDefault(boolean isDefault) {
this.isDefault = isDefault;
return this;
}
public Builder created(Date created) {
this.created = created;
return this;
}
public Builder created(Date created) {
this.created = created;
return this;
}
public Dataset build() {
return new Dataset(id, name, type, version, urn, defaultDataset, created);
}
public Dataset build() {
return new Dataset(id, name, type, version, urn, isDefault, created);
}
public Builder fromDataset(Dataset in) {
return id(in.getId()).name(in.getName()).type(in.getType()).version(
in.getVersion()).urn(in.getUrn()).defaultDataset(
in.isDefaultDataset()).created(
in.getCreated());
}
}
public Builder fromDataset(Dataset in) {
return id(in.getId()).name(in.getName()).type(in.getType()).version(in.getVersion()).urn(in.getUrn())
.isDefault(in.isDefault()).created(in.getCreated());
}
}
// The globally unique id for this dataset
protected final String id;
// The "friendly" name for this dataset
protected final String name;
// Whether this is a smartmachine or virtualmachine
protected final Type type;
// The version for this dataset
protected final String version;
// The full URN for this dataset
protected final String urn;
// Whether this is the default dataset in this datacenter
@SerializedName("default")
protected final boolean defaultDataset;
// Date (ISO8601) When this dataset was created
protected final Date created;
// The globally unique id for this dataset
protected final String id;
// The "friendly" name for this dataset
protected final String name;
// Whether this is a smartmachine or virtualmachine
protected final Type type;
// The version for this dataset
protected final String version;
// The full URN for this dataset
protected final String urn;
// Whether this is the default dataset in this datacenter
@SerializedName("default")
protected final boolean isDefault;
// Date (ISO8601) When this dataset was created
protected final Date created;
public Dataset(String id, String name, Type type, String version,
String urn, boolean defaultDataset, Date created) {
super();
this.id = id;
this.name = name;
this.type = type;
this.version = version;
this.urn = urn;
this.defaultDataset = defaultDataset;
this.created = created;
}
public Dataset(String id, String name, Type type, String version, String urn, boolean isDefault, Date created) {
super();
this.id = id;
this.name = name;
this.type = type;
this.version = version;
this.urn = urn;
this.isDefault = isDefault;
this.created = created;
}
public String getId() {
return id;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public String getName() {
return name;
}
public Type getType() {
return type;
}
public Type getType() {
return type;
}
public String getVersion() {
return version;
}
public String getVersion() {
return version;
}
public String getUrn() {
return urn;
}
public String getUrn() {
return urn;
}
public boolean isDefaultDataset() {
return defaultDataset;
}
public boolean isDefault() {
return isDefault;
}
public Date getCreated() {
return created;
}
public Date getCreated() {
return created;
}
@Override
public int compareTo(Dataset other) {
return id.compareTo(other.getId());
}
@Override
public int compareTo(Dataset other) {
return id.compareTo(other.getId());
}
@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object instanceof Machine) {
return Objects.equal(id, ((Machine) object).id);
} else {
return false;
}
}
@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object instanceof Machine) {
return Objects.equal(id, ((Machine) object).id);
} else {
return false;
}
}
@Override
public int hashCode() {
return Objects.hashCode(id);
}
@Override
public int hashCode() {
return Objects.hashCode(id);
}
@Override
public String toString() {
return String
.format(
"[id=%s, name=%s, type=%s, version=%s, urn=%s, default=%s, created=%s]",
id, name, type.name(), type.name(), version, urn,
defaultDataset, created);
}
@Override
public String toString() {
return String.format("[id=%s, name=%s, type=%s, version=%s, urn=%s, default=%s, created=%s]", id, name,
type.name(), type.name(), version, urn, isDefault, created);
}
}

View File

@ -38,234 +38,224 @@ import com.google.gson.annotations.SerializedName;
*/
public class Machine implements Comparable<Machine> {
public static enum State {
PUBLISHING, RUNNING, STOPPED, UNRECOGNIZED;
public static enum State {
PUBLISHING, RUNNING, STOPPED, UNRECOGNIZED;
public static State fromValue(String state) {
try {
return valueOf(CaseFormat.UPPER_CAMEL.to(
CaseFormat.UPPER_UNDERSCORE, checkNotNull(state,
"state")));
} catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
}
public static State fromValue(String state) {
try {
return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(state, "state")));
} catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
}
public String value() {
return (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL,
name()));
}
public String value() {
return (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name()));
}
@Override
public String toString() {
return value();
}
}
@Override
public String toString() {
return value();
}
}
public static Builder builder() {
return new Builder();
}
public static Builder builder() {
return new Builder();
}
public static class Builder {
private String id;
private String name;
private Type type;
private State state;
private String dataset;
private int memorySizeMb;
private int diskSizeGb;
private Set<String> ips;
private Date created;
private Date updated;
private Map<String, String> metadata = ImmutableMap.of();
public static class Builder {
private String id;
private String name;
private Type type;
private State state;
private String dataset;
private int memorySizeMb;
private int diskSizeGb;
private Set<String> ips;
private Date created;
private Date updated;
private Map<String, String> metadata = ImmutableMap.of();
public Builder id(String id) {
this.id = id;
return this;
}
public Builder id(String id) {
this.id = id;
return this;
}
public Builder name(String name) {
this.name = name;
return this;
}
public Builder name(String name) {
this.name = name;
return this;
}
public Builder type(Type type) {
this.type = type;
return this;
}
public Builder type(Type type) {
this.type = type;
return this;
}
public Builder state(State state) {
this.state = state;
return this;
}
public Builder state(State state) {
this.state = state;
return this;
}
public Builder dataset(String dataset) {
this.dataset = dataset;
return this;
}
public Builder dataset(String dataset) {
this.dataset = dataset;
return this;
}
public Builder memorySizeMb(int memorySizeMb) {
this.memorySizeMb = memorySizeMb;
return this;
}
public Builder memorySizeMb(int memorySizeMb) {
this.memorySizeMb = memorySizeMb;
return this;
}
public Builder diskSizeGb(int diskSizeGb) {
this.diskSizeGb = diskSizeGb;
return this;
}
public Builder diskSizeGb(int diskSizeGb) {
this.diskSizeGb = diskSizeGb;
return this;
}
public Builder ips(Set<String> ips) {
this.ips = ips;
return this;
}
public Builder ips(Set<String> ips) {
this.ips = ips;
return this;
}
public Builder created(Date created) {
this.created = created;
return this;
}
public Builder created(Date created) {
this.created = created;
return this;
}
public Builder updated(Date updated) {
this.updated = updated;
return this;
}
public Builder updated(Date updated) {
this.updated = updated;
return this;
}
/**
* @see Machine#getMetadata()
*/
public Builder metadata(Map<String, String> metadata) {
this.metadata = metadata;
return this;
}
/**
* @see Machine#getMetadata()
*/
public Builder metadata(Map<String, String> metadata) {
this.metadata = metadata;
return this;
}
public Machine build() {
return new Machine(id, name, type, state, dataset, memorySizeMb,
diskSizeGb, ips, created, updated, metadata);
}
public Machine build() {
return new Machine(id, name, type, state, dataset, memorySizeMb, diskSizeGb, ips, created, updated, metadata);
}
public Builder fromMachine(Machine in) {
return id(in.getId()).name(in.getName()).type(in.getType()).state(
in.getState()).dataset(in.getDataset()).memorySizeMb(
in.getMemorySizeMb()).diskSizeGb(in.getDiskSizeGb()).ips(
in.getIps()).metadata(in.getMetadata()).created(
in.getCreated()).updated(in.getUpdated());
}
}
public Builder fromMachine(Machine in) {
return id(in.getId()).name(in.getName()).type(in.getType()).state(in.getState()).dataset(in.getDataset())
.memorySizeMb(in.getMemorySizeMb()).diskSizeGb(in.getDiskSizeGb()).ips(in.getIps())
.metadata(in.getMetadata()).created(in.getCreated()).updated(in.getUpdated());
}
}
// The globally unique id for this machine
protected final String id;
// The "friendly" name for this machine
protected final String name;
// Whether this is a smartmachine or virtualmachine
protected final Type type;
// The current state of this machine
protected final State state;
// The dataset urn this machine was provisioned with
protected final String dataset;
// The amount of memory this machine has (Mb)
@SerializedName("memory")
protected final int memorySizeMb;
// The amount of disk this machine has (Gb)
@SerializedName("disk")
protected final int diskSizeGb;
// The IP addresses this machine has
protected final Set<String> ips;
// Date (ISO8601) When this machine was created
protected final Date created;
// Date (ISO8601) When this machine was updated
protected final Date updated;
// The globally unique id for this machine
protected final String id;
// The "friendly" name for this machine
protected final String name;
// Whether this is a smartmachine or virtualmachine
protected final Type type;
// The current state of this machine
protected final State state;
// The dataset urn this machine was provisioned with
protected final String dataset;
// The amount of memory this machine has (Mb)
@SerializedName("memory")
protected final int memorySizeMb;
// The amount of disk this machine has (Gb)
@SerializedName("disk")
protected final int diskSizeGb;
// The IP addresses this machine has
protected final Set<String> ips;
// Date (ISO8601) When this machine was created
protected final Date created;
// Date (ISO8601) When this machine was updated
protected final Date updated;
// metadata Object[String => String] Any "extra" metadata this machine has
private final Map<String, String> metadata;
// metadata Object[String => String] Any "extra" metadata this machine has
private final Map<String, String> metadata;
@Override
public int compareTo(Machine other) {
return id.compareTo(other.getId());
}
@Override
public int compareTo(Machine other) {
return id.compareTo(other.getId());
}
public Machine(String id, String name, Type type, State state,
String dataset, int memorySizeMb, int diskSizeGb, Set<String> ips,
Date created, Date updated, final Map<String, String> metadata) {
super();
this.id = id;
this.name = name;
this.type = type;
this.state = state;
this.dataset = dataset;
this.memorySizeMb = memorySizeMb;
this.diskSizeGb = diskSizeGb;
this.ips = ImmutableSet.<String> copyOf(ips);
this.created = created;
this.updated = updated;
this.metadata = metadata;
}
public Machine(String id, String name, Type type, State state, String dataset, int memorySizeMb, int diskSizeGb,
Set<String> ips, Date created, Date updated, final Map<String, String> metadata) {
super();
this.id = id;
this.name = name;
this.type = type;
this.state = state;
this.dataset = dataset;
this.memorySizeMb = memorySizeMb;
this.diskSizeGb = diskSizeGb;
this.ips = ImmutableSet.<String> copyOf(ips);
this.created = created;
this.updated = updated;
this.metadata = metadata;
}
public String getId() {
return id;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public String getName() {
return name;
}
public Type getType() {
return type;
}
public Type getType() {
return type;
}
public State getState() {
return state;
}
public State getState() {
return state;
}
public String getDataset() {
return dataset;
}
public String getDataset() {
return dataset;
}
public int getMemorySizeMb() {
return memorySizeMb;
}
public int getMemorySizeMb() {
return memorySizeMb;
}
public int getDiskSizeGb() {
return diskSizeGb;
}
public int getDiskSizeGb() {
return diskSizeGb;
}
public Set<String> getIps() {
return ips;
}
public Set<String> getIps() {
return ips;
}
public Date getCreated() {
return created;
}
public Date getCreated() {
return created;
}
public Date getUpdated() {
return updated;
}
public Date getUpdated() {
return updated;
}
public Map<String, String> getMetadata() {
return metadata;
}
public Map<String, String> getMetadata() {
return metadata;
}
@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object instanceof Machine) {
return Objects.equal(id, ((Machine) object).id);
} else {
return false;
}
}
@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object instanceof Machine) {
return Objects.equal(id, ((Machine) object).id);
} else {
return false;
}
}
@Override
public int hashCode() {
return Objects.hashCode(id);
}
@Override
public int hashCode() {
return Objects.hashCode(id);
}
@Override
public String toString() {
return String
.format(
"[id=%s, name=%s, type=%s, state=%s, memory=%s, disk=%s, ips=%s, created=%s, updated=%s]",
id, name, type.name(), state.name(), memorySizeMb,
diskSizeGb, ips, created, updated);
}
@Override
public String toString() {
return String.format("[id=%s, name=%s, type=%s, state=%s, memory=%s, disk=%s, ips=%s, created=%s, updated=%s]",
id, name, type.name(), state.name(), memorySizeMb, diskSizeGb, ips, created, updated);
}
}

View File

@ -29,128 +29,121 @@ import com.google.gson.annotations.SerializedName;
*/
public class Package implements Comparable<Package> {
public static Builder builder() {
return new Builder();
}
public static Builder builder() {
return new Builder();
}
public static class Builder {
private String name;
private int memorySizeMb;
private int diskSizeGb;
private int swapSizeMb;
private boolean isDefault;
public static class Builder {
private String name;
private int memorySizeMb;
private int diskSizeGb;
private int swapSizeMb;
private boolean defaultPackage;
public Builder name(String name) {
this.name = name;
return this;
}
public Builder name(String name) {
this.name = name;
return this;
}
public Builder memorySizeMb(int memorySizeMb) {
this.memorySizeMb = memorySizeMb;
return this;
}
public Builder memorySizeMb(int memorySizeMb) {
this.memorySizeMb = memorySizeMb;
return this;
}
public Builder diskSizeGb(int diskSizeGb) {
this.diskSizeGb = diskSizeGb;
return this;
}
public Builder diskSizeGb(int diskSizeGb) {
this.diskSizeGb = diskSizeGb;
return this;
}
public Builder swapSizeMb(int swapSizeMb) {
this.swapSizeMb = swapSizeMb;
return this;
}
public Builder swapSizeMb(int swapSizeMb) {
this.swapSizeMb = swapSizeMb;
return this;
}
public Builder isDefault(boolean isDefault) {
this.isDefault = isDefault;
return this;
}
public Builder isDefault(boolean defaultPackage) {
this.defaultPackage = defaultPackage;
return this;
}
public Package build() {
return new Package(name, memorySizeMb, diskSizeGb, swapSizeMb, isDefault);
}
public Builder fromPackage(Package in) {
return name(in.getName()).memorySizeMb(in.getMemorySizeMb()).diskSizeGb(in.getDiskSizeGb())
.swapSizeMb(in.getSwapSizeMb()).isDefault(in.isDefault());
}
}
public Package build() {
return new Package(name, memorySizeMb,
diskSizeGb, swapSizeMb, defaultPackage);
}
// The "friendly" name for this machine
protected final String name;
// The amount of memory this package has (Mb)
@SerializedName("memory")
protected final int memorySizeMb;
// The amount of disk this package has (Gb)
@SerializedName("disk")
protected final int diskSizeGb;
// The amount of swap this package has (Gb)
@SerializedName("swap")
protected final int swapSizeMb;
// Whether this is the default package in this datacenter
@SerializedName("default")
protected final boolean isDefault;
public Builder fromPackage(Package in) {
return name(in.getName()).memorySizeMb(
in.getMemorySizeMb()).diskSizeGb(in.getDiskSizeGb()).swapSizeMb(in.getSwapSizeMb()).isDefault(in.isDefault());
}
}
@Override
public int compareTo(Package other) {
return name.compareTo(other.getName());
}
// The "friendly" name for this machine
protected final String name;
// The amount of memory this package has (Mb)
@SerializedName("memory")
protected final int memorySizeMb;
// The amount of disk this package has (Gb)
@SerializedName("disk")
protected final int diskSizeGb;
// The amount of swap this package has (Gb)
@SerializedName("swap")
protected final int swapSizeMb;
// Whether this is the default package in this datacenter
@SerializedName("default")
protected final boolean defaultPackage;
public Package(String name, int memorySizeMb, int diskSizeGb, int swapSizeMb, boolean isDefault) {
super();
this.name = name;
this.memorySizeMb = memorySizeMb;
this.diskSizeGb = diskSizeGb;
this.swapSizeMb = swapSizeMb;
this.isDefault = isDefault;
}
@Override
public int compareTo(Package other) {
return name.compareTo(other.getName());
}
public String getName() {
return name;
}
public Package(String name, int memorySizeMb, int diskSizeGb,
int swapSizeMb, boolean defaultPackage) {
super();
this.name = name;
this.memorySizeMb = memorySizeMb;
this.diskSizeGb = diskSizeGb;
this.swapSizeMb = swapSizeMb;
this.defaultPackage = defaultPackage;
}
public int getMemorySizeMb() {
return memorySizeMb;
}
public String getName() {
return name;
}
public int getDiskSizeGb() {
return diskSizeGb;
}
public int getMemorySizeMb() {
return memorySizeMb;
}
public int getSwapSizeMb() {
return swapSizeMb;
}
public int getDiskSizeGb() {
return diskSizeGb;
}
public boolean isDefault() {
return isDefault;
}
public int getSwapSizeMb() {
return swapSizeMb;
}
@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object instanceof Package) {
return Objects.equal(name, ((Package) object).name);
} else {
return false;
}
}
public boolean isDefault() {
return defaultPackage;
}
@Override
public int hashCode() {
return Objects.hashCode(name);
}
@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object instanceof Package) {
return Objects.equal(name, ((Package) object).name);
} else {
return false;
}
}
@Override
public int hashCode() {
return Objects.hashCode(name);
}
@Override
public String toString() {
return String
.format(
"[name=%s, memory=%s, disk=%s, swap=%s, default=%s]",
name, memorySizeMb,
diskSizeGb, swapSizeMb, defaultPackage);
}
@Override
public String toString() {
return String.format("[name=%s, memory=%s, disk=%s, swap=%s, default=%s]", name, memorySizeMb, diskSizeGb,
swapSizeMb, isDefault);
}
}

View File

@ -5,25 +5,22 @@ import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.CaseFormat;
public enum Type {
VIRTUALMACHINE, SMARTMACHINE, UNRECOGNIZED;
VIRTUALMACHINE, SMARTMACHINE, UNRECOGNIZED;
public static Type fromValue(String type) {
try {
return valueOf(CaseFormat.UPPER_CAMEL
.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(type,
"type")));
} catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
}
public static Type fromValue(String type) {
try {
return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(type, "type")));
} catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
}
public String value() {
return (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL,
name()));
}
public String value() {
return (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name()));
}
@Override
public String toString() {
return value();
}
@Override
public String toString() {
return value();
}
}

View File

@ -42,11 +42,11 @@ import com.google.common.util.concurrent.ListenableFuture;
* @author Adrian Cole
* @see <a href="http://sdc.joyent.org/sdcapi.html">api doc</a>
*/
@SkipEncoding( { '/', '=' })
@Headers(keys="X-Api-Version", values="{jclouds.api-version}")
@SkipEncoding({ '/', '=' })
@Headers(keys = "X-Api-Version", values = "{jclouds.api-version}")
@RequestFilters(BasicAuthentication.class)
public interface DatacenterAsyncClient {
/**
* @see DatacenterClient#getDatacenters
*/

View File

@ -27,25 +27,25 @@ import com.google.common.util.concurrent.ListenableFuture;
* @see DatasetClient
* @see <a href="http://apidocs.joyent.com/sdcapidoc/cloudapi">api doc</a>
*/
@SkipEncoding( { '/', '=' })
@SkipEncoding({ '/', '=' })
@Headers(keys = "X-Api-Version", values = "{jclouds.api-version}")
@RequestFilters(BasicAuthentication.class)
public interface DatasetAsyncClient {
/**
* @see DatasetClient#listMachines
*/
@GET
@Path("/my/datasets")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<Dataset>> listDatasets();
/**
* @see DatasetClient#listMachines
*/
@GET
@Path("/my/datasets")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<Dataset>> listDatasets();
/**
* @see DatasetClient#getMachineDetails
*/
@GET
@Path("/my/datasets/{id}")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Dataset> getDataset(@PathParam("id") String id);
/**
* @see DatasetClient#getMachineDetails
*/
@GET
@Path("/my/datasets/{id}")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Dataset> getDataset(@PathParam("id") String id);
}

View File

@ -17,18 +17,19 @@ import org.jclouds.joyent.sdc.v6_5.domain.Dataset;
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
public interface DatasetClient {
/**
* Provides a list of datasets available in this datacenter.
* @return
*/
Set<Dataset> listDatasets();
/**
* Provides a list of datasets available in this datacenter.
*
* @return
*/
Set<Dataset> listDatasets();
/**
* Gets an individual dataset by id.
*
* @param id
* the id of the dataset
* @return
*/
Dataset getDataset(String id);
/**
* Gets an individual dataset by id.
*
* @param id
* the id of the dataset
* @return
*/
Dataset getDataset(String id);
}

View File

@ -45,27 +45,27 @@ import com.google.common.util.concurrent.ListenableFuture;
* @see MachineClient
* @see <a href="http://apidocs.joyent.com/sdcapidoc/cloudapi">api doc</a>
*/
@SkipEncoding( { '/', '=' })
@SkipEncoding({ '/', '=' })
@Headers(keys = "X-Api-Version", values = "{jclouds.api-version}")
@RequestFilters(BasicAuthentication.class)
public interface MachineAsyncClient {
/**
* @see MachineClient#listMachines
*/
@GET
@Path("/my/machines")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<Machine>> listMachines();
/**
* @see MachineClient#listMachines
*/
@GET
@Path("/my/machines")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<Machine>> listMachines();
/**
* @see MachineClient#getMachineDetails
*/
@GET
@Path("/my/machines/{id}")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Machine> getMachine(@PathParam("id") String id);
/**
* @see MachineClient#getMachineDetails
*/
@GET
@Path("/my/machines/{id}")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Machine> getMachine(@PathParam("id") String id);
}

View File

@ -24,7 +24,6 @@ import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.joyent.sdc.v6_5.domain.Machine;
/**
* Provides synchronous access to Machine.
* <p/>
@ -42,12 +41,12 @@ public interface MachineClient {
* @return an account's associated machine objects.
*/
Set<Machine> listMachines();
/**
* Gets the details for an individual machine.
*
* @param id the id of the machine
* @param id
* the id of the machine
* @return
*/
Machine getMachine(String id);

View File

@ -26,25 +26,25 @@ import com.google.common.util.concurrent.ListenableFuture;
* @see PackageClient
* @see <a href="http://apidocs.joyent.com/sdcapidoc/cloudapi">api doc</a>
*/
@SkipEncoding( { '/', '=' })
@SkipEncoding({ '/', '=' })
@Headers(keys = "X-Api-Version", values = "{jclouds.api-version}")
@RequestFilters(BasicAuthentication.class)
public interface PackageAsyncClient {
/**
* @see PackageClient#listPackages
*/
@GET
@Path("/my/packages")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<org.jclouds.joyent.sdc.v6_5.domain.Package>> listPackages();
/**
* @see PackageClient#listPackages
*/
@GET
@Path("/my/packages")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<org.jclouds.joyent.sdc.v6_5.domain.Package>> listPackages();
/**
* @see PackageClient#getPackageDetails
*/
@GET
@Path("/my/packages/{name}")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<org.jclouds.joyent.sdc.v6_5.domain.Package> getPackage(@PathParam("name") String name);
/**
* @see PackageClient#getPackageDetails
*/
@GET
@Path("/my/packages/{name}")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<org.jclouds.joyent.sdc.v6_5.domain.Package> getPackage(@PathParam("name") String name);
}

View File

@ -16,18 +16,19 @@ import org.jclouds.concurrent.Timeout;
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
public interface PackageClient {
/**
* Provides a list of packages available in this datacenter.
* @return
*/
Set<org.jclouds.joyent.sdc.v6_5.domain.Package> listPackages();
/**
* Provides a list of packages available in this datacenter.
*
* @return
*/
Set<org.jclouds.joyent.sdc.v6_5.domain.Package> listPackages();
/**
* Gets an individual package by id.
*
* @param name
* the name of the package
* @return
*/
org.jclouds.joyent.sdc.v6_5.domain.Package getPackage(String name);
/**
* Gets an individual package by id.
*
* @param name
* the name of the package
* @return
*/
org.jclouds.joyent.sdc.v6_5.domain.Package getPackage(String name);
}

View File

@ -44,21 +44,21 @@ public class SDCErrorHandler implements HttpErrorHandler {
String message = data != null ? new String(data) : null;
Exception exception = message != null ? new HttpResponseException(command, response, message)
: new HttpResponseException(command, response);
: new HttpResponseException(command, response);
message = message != null ? message : String.format("%s -> %s", command.getCurrentRequest().getRequestLine(),
response.getStatusLine());
response.getStatusLine());
switch (response.getStatusCode()) {
case 400:
break;
case 401:
case 403:
exception = new AuthorizationException(message, exception);
break;
case 404:
if (!command.getCurrentRequest().getMethod().equals("DELETE")) {
exception = new ResourceNotFoundException(message, exception);
}
break;
case 400:
break;
case 401:
case 403:
exception = new AuthorizationException(message, exception);
break;
case 404:
if (!command.getCurrentRequest().getMethod().equals("DELETE")) {
exception = new ResourceNotFoundException(message, exception);
}
break;
}
command.setException(exception);
}

View File

@ -36,25 +36,24 @@ import com.google.common.collect.ImmutableMultimap;
*/
@Test(groups = "unit", testName = "DatacenterClientExpectTest")
public class DatacenterClientExpectTest extends BaseSDCClientExpectTest {
HttpRequest getDatacenters = HttpRequest.builder()
.method("GET")
.endpoint(URI.create("https://api.joyentcloud.com/my/datacenters"))
.headers(ImmutableMultimap.<String, String> builder()
.put("X-Api-Version", "~6.5")
.put("Accept", "application/json")
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.build();
HttpRequest getDatacenters = HttpRequest
.builder()
.method("GET")
.endpoint(URI.create("https://api.joyentcloud.com/my/datacenters"))
.headers(
ImmutableMultimap.<String, String> builder().put("X-Api-Version", "~6.5")
.put("Accept", "application/json").put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==")
.build()).build();
public void testGetDatacentersWhenResponseIs2xx() {
HttpResponse getDatacentersResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResource("/datacenters.json")).build();
HttpResponse getDatacentersResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/datacenters.json")).build();
SDCClient clientWhenDatacentersExists = requestSendsResponse(getDatacenters, getDatacentersResponse);
assertEquals(clientWhenDatacentersExists.getDatacenterClient().getDatacenters(),
ImmutableMap.<String, URI> builder()
.put("us-east-1", URI.create("https://us-east-1.api.joyentcloud.com"))
assertEquals(
clientWhenDatacentersExists.getDatacenterClient().getDatacenters(),
ImmutableMap.<String, URI> builder().put("us-east-1", URI.create("https://us-east-1.api.joyentcloud.com"))
.put("us-west-1", URI.create("https://us-west-1.api.joyentcloud.com"))
.put("us-sw-1", URI.create("https://us-sw-1.api.joyentcloud.com"))
.put("eu-ams-1", URI.create("https://eu-ams-1.api.joyentcloud.com")).build());
@ -62,9 +61,9 @@ public class DatacenterClientExpectTest extends BaseSDCClientExpectTest {
public void testGetDatacentersWhenResponseIs404() {
HttpResponse getDatacentersResponse = HttpResponse.builder().statusCode(404).build();
SDCClient getDatacentersWhenNone = requestSendsResponse(getDatacenters, getDatacentersResponse);
assertEquals(getDatacentersWhenNone.getDatacenterClient().getDatacenters(), ImmutableMap.of());
}
}

View File

@ -33,7 +33,7 @@ import org.testng.annotations.Test;
@Test(groups = "live", testName = "DatacenterClientLiveTest")
public class DatacenterClientLiveTest extends BaseSDCClientLiveTest {
public void testGetDatacenters(){
public void testGetDatacenters() {
Map<String, URI> dcs = sdcContext.getApi().getDatacenterClient().getDatacenters();
assertNotNull(dcs);
assertTrue(dcs.size() > 0);

View File

@ -37,34 +37,30 @@ import com.google.common.collect.ImmutableSet;
*/
@Test(groups = "unit", testName = "DatasetClientExpectTest")
public class DatasetClientExpectTest extends BaseSDCClientExpectTest {
HttpRequest listDatasets = HttpRequest.builder().method("GET").endpoint(
URI.create("https://api.joyentcloud.com/my/datasets")).headers(
ImmutableMultimap.<String, String> builder().put("X-Api-Version",
"~6.5").put("Accept", "application/json").put(
"Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==")
.build()).build();
HttpRequest listDatasets = HttpRequest
.builder()
.method("GET")
.endpoint(URI.create("https://api.joyentcloud.com/my/datasets"))
.headers(
ImmutableMultimap.<String, String> builder().put("X-Api-Version", "~6.5")
.put("Accept", "application/json").put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==")
.build()).build();
public void testListDatasetsWhenResponseIs2xx() {
HttpResponse listDatasetsResponse = HttpResponse.builder()
.statusCode(200).payload(
payloadFromResource("/dataset_list.json")).build();
public void testListDatasetsWhenResponseIs2xx() {
HttpResponse listDatasetsResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/dataset_list.json")).build();
SDCClient clientWhenDatasetsExists = requestSendsResponse(listDatasets,
listDatasetsResponse);
SDCClient clientWhenDatasetsExists = requestSendsResponse(listDatasets, listDatasetsResponse);
assertEquals(
clientWhenDatasetsExists.getDatasetClient().listDatasets().toString(),
new ParseDatasetListTest().expected().toString());
}
assertEquals(clientWhenDatasetsExists.getDatasetClient().listDatasets().toString(), new ParseDatasetListTest()
.expected().toString());
}
public void testListDatasetsWhenResponseIs404() {
HttpResponse listDatasetsResponse = HttpResponse.builder().statusCode(
404).build();
public void testListDatasetsWhenResponseIs404() {
HttpResponse listDatasetsResponse = HttpResponse.builder().statusCode(404).build();
SDCClient listDatasetsWhenNone = requestSendsResponse(listDatasets,
listDatasetsResponse);
SDCClient listDatasetsWhenNone = requestSendsResponse(listDatasets, listDatasetsResponse);
assertEquals(listDatasetsWhenNone.getDatasetClient().listDatasets(),
ImmutableSet.of());
}
assertEquals(listDatasetsWhenNone.getDatasetClient().listDatasets(), ImmutableSet.of());
}
}

View File

@ -18,9 +18,9 @@
*/
package org.jclouds.joyent.sdc.v6_5.features;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import static org.testng.AssertJUnit.assertEquals;
import java.util.Set;
@ -34,17 +34,16 @@ import org.testng.annotations.Test;
@Test(groups = "live", testName = "DatasetClientLiveTest")
public class DatasetClientLiveTest extends BaseSDCClientLiveTest {
public void testListDatasets() {
Set<Dataset> datasets = sdcContext.getApi().getDatasetClient()
.listDatasets();
assertNotNull(datasets);
assertTrue(datasets.size() > 0);
}
public void testListDatasets() {
Set<Dataset> datasets = sdcContext.getApi().getDatasetClient().listDatasets();
assertNotNull(datasets);
assertTrue(datasets.size() > 0);
}
public void testGetDataset() {
final String id = "e4cd7b9e-4330-11e1-81cf-3bb50a972bda";
Dataset dataset = sdcContext.getApi().getDatasetClient().getDataset(id);
assertNotNull(dataset);
assertEquals(dataset.getId(), id);
}
public void testGetDataset() {
final String id = "e4cd7b9e-4330-11e1-81cf-3bb50a972bda";
Dataset dataset = sdcContext.getApi().getDatasetClient().getDataset(id);
assertNotNull(dataset);
assertEquals(dataset.getId(), id);
}
}

View File

@ -37,34 +37,29 @@ import com.google.common.collect.ImmutableSet;
*/
@Test(groups = "unit", testName = "MachineClientExpectTest")
public class MachineClientExpectTest extends BaseSDCClientExpectTest {
HttpRequest listMachines = HttpRequest.builder().method("GET").endpoint(
URI.create("https://api.joyentcloud.com/my/machines")).headers(
ImmutableMultimap.<String, String> builder().put("X-Api-Version",
"~6.5").put("Accept", "application/json").put(
"Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==")
.build()).build();
HttpRequest listMachines = HttpRequest
.builder()
.method("GET")
.endpoint(URI.create("https://api.joyentcloud.com/my/machines"))
.headers(
ImmutableMultimap.<String, String> builder().put("X-Api-Version", "~6.5")
.put("Accept", "application/json").put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==")
.build()).build();
public void testListMachinesWhenResponseIs2xx() {
HttpResponse listMachinesResponse = HttpResponse.builder()
.statusCode(200).payload(
payloadFromResource("/machine_list.json")).build();
public void testListMachinesWhenResponseIs2xx() {
HttpResponse listMachinesResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/machine_list.json")).build();
SDCClient clientWhenMachinesExists = requestSendsResponse(listMachines,
listMachinesResponse);
SDCClient clientWhenMachinesExists = requestSendsResponse(listMachines, listMachinesResponse);
assertEquals(
clientWhenMachinesExists.getMachineClient().listMachines(),
new ParseMachineListTest().expected());
}
assertEquals(clientWhenMachinesExists.getMachineClient().listMachines(), new ParseMachineListTest().expected());
}
public void testListMachinesWhenResponseIs404() {
HttpResponse listMachinesResponse = HttpResponse.builder().statusCode(
404).build();
public void testListMachinesWhenResponseIs404() {
HttpResponse listMachinesResponse = HttpResponse.builder().statusCode(404).build();
SDCClient listMachinesWhenNone = requestSendsResponse(listMachines,
listMachinesResponse);
SDCClient listMachinesWhenNone = requestSendsResponse(listMachines, listMachinesResponse);
assertEquals(listMachinesWhenNone.getMachineClient().listMachines(),
ImmutableSet.of());
}
assertEquals(listMachinesWhenNone.getMachineClient().listMachines(), ImmutableSet.of());
}
}

View File

@ -18,8 +18,8 @@
*/
package org.jclouds.joyent.sdc.v6_5.features;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import java.util.Set;
@ -34,17 +34,16 @@ import org.testng.annotations.Test;
@Test(groups = "live", testName = "MachineClientLiveTest")
public class MachineClientLiveTest extends BaseSDCClientLiveTest {
public void testListMachines() {
Set<Machine> machines = sdcContext.getApi().getMachineClient()
.listMachines();
assertNotNull(machines);
assertTrue(machines.size() > 0);
}
public void testListMachines() {
Set<Machine> machines = sdcContext.getApi().getMachineClient().listMachines();
assertNotNull(machines);
assertTrue(machines.size() > 0);
}
public void testGetMachine() {
final String id = "d73cb0b0-7d1f-44ef-8c40-e040eef0f726";
Machine machine = sdcContext.getApi().getMachineClient().getMachine(id);
assertNotNull(machine);
assertEquals(machine.getId(), id);
}
public void testGetMachine() {
final String id = "d73cb0b0-7d1f-44ef-8c40-e040eef0f726";
Machine machine = sdcContext.getApi().getMachineClient().getMachine(id);
assertNotNull(machine);
assertEquals(machine.getId(), id);
}
}

View File

@ -37,34 +37,29 @@ import com.google.common.collect.ImmutableSet;
*/
@Test(groups = "unit", testName = "PackageClientExpectTest")
public class PackageClientExpectTest extends BaseSDCClientExpectTest {
HttpRequest listPackages = HttpRequest.builder().method("GET").endpoint(
URI.create("https://api.joyentcloud.com/my/packages")).headers(
ImmutableMultimap.<String, String> builder().put("X-Api-Version",
"~6.5").put("Accept", "application/json").put(
"Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==")
.build()).build();
HttpRequest listPackages = HttpRequest
.builder()
.method("GET")
.endpoint(URI.create("https://api.joyentcloud.com/my/packages"))
.headers(
ImmutableMultimap.<String, String> builder().put("X-Api-Version", "~6.5")
.put("Accept", "application/json").put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==")
.build()).build();
public void testListPackagesWhenResponseIs2xx() {
HttpResponse listPackagesResponse = HttpResponse.builder()
.statusCode(200).payload(
payloadFromResource("/package_list.json")).build();
public void testListPackagesWhenResponseIs2xx() {
HttpResponse listPackagesResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/package_list.json")).build();
SDCClient clientWhenPackagesExists = requestSendsResponse(listPackages,
listPackagesResponse);
SDCClient clientWhenPackagesExists = requestSendsResponse(listPackages, listPackagesResponse);
assertEquals(
clientWhenPackagesExists.getPackageClient().listPackages(),
new ParsePackageListTest().expected());
}
assertEquals(clientWhenPackagesExists.getPackageClient().listPackages(), new ParsePackageListTest().expected());
}
public void testListPackagesWhenResponseIs404() {
HttpResponse listPackagesResponse = HttpResponse.builder().statusCode(
404).build();
public void testListPackagesWhenResponseIs404() {
HttpResponse listPackagesResponse = HttpResponse.builder().statusCode(404).build();
SDCClient listPackagesWhenNone = requestSendsResponse(listPackages,
listPackagesResponse);
SDCClient listPackagesWhenNone = requestSendsResponse(listPackages, listPackagesResponse);
assertEquals(listPackagesWhenNone.getPackageClient().listPackages(),
ImmutableSet.of());
}
assertEquals(listPackagesWhenNone.getPackageClient().listPackages(), ImmutableSet.of());
}
}

View File

@ -18,9 +18,9 @@
*/
package org.jclouds.joyent.sdc.v6_5.features;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import static org.testng.AssertJUnit.assertEquals;
import java.util.Set;
@ -33,17 +33,16 @@ import org.testng.annotations.Test;
@Test(groups = "live", testName = "PackageClientLiveTest")
public class PackageClientLiveTest extends BaseSDCClientLiveTest {
public void testListPackages() {
Set<org.jclouds.joyent.sdc.v6_5.domain.Package> packages = sdcContext.getApi().getPackageClient()
.listPackages();
assertNotNull(packages);
assertTrue(packages.size() > 0);
}
public void testListPackages() {
Set<org.jclouds.joyent.sdc.v6_5.domain.Package> packages = sdcContext.getApi().getPackageClient().listPackages();
assertNotNull(packages);
assertTrue(packages.size() > 0);
}
public void testGetPackage() {
final String name = "Small 1GB";
org.jclouds.joyent.sdc.v6_5.domain.Package packageSDC = sdcContext.getApi().getPackageClient().getPackage(name);
assertNotNull(packageSDC);
assertEquals(packageSDC.getName(), name);
}
public void testGetPackage() {
final String name = "Small 1GB";
org.jclouds.joyent.sdc.v6_5.domain.Package packageSDC = sdcContext.getApi().getPackageClient().getPackage(name);
assertNotNull(packageSDC);
assertEquals(packageSDC.getName(), name);
}
}

View File

@ -41,21 +41,20 @@ import org.testng.annotations.Test;
@Test(groups = "unit", testName = "SDCErrorHandlerTest")
public class SDCErrorHandlerTest {
private void assertCodeMakes(String method, URI uri, int statusCode, String message, String content,
Class<? extends Exception> expected) {
Class<? extends Exception> expected) {
assertCodeMakes(method, uri, statusCode, message, "text/plain", content, expected);
}
private void assertCodeMakes(String method, URI uri, int statusCode, String message, String contentType,
String content, Class<? extends Exception> expected) {
String content, Class<? extends Exception> expected) {
SDCErrorHandler function = new SDCErrorHandler();
HttpCommand command = createMockBuilder(HttpCommand.class).createMock();
HttpRequest request = new HttpRequest(method, uri);
HttpResponse response = new HttpResponse(statusCode, message, Payloads.newInputStreamPayload(Strings2
.toInputStream(content)));
.toInputStream(content)));
response.getPayload().getContentMetadata().setContentType(contentType);
expect(command.getCurrentRequest()).andReturn(request).atLeastOnce();
@ -87,5 +86,4 @@ public class SDCErrorHandlerTest {
return null;
}
}

View File

@ -49,7 +49,7 @@ public class BaseSDCClientLiveTest extends BaseContextLiveTest<RestContext<SDCCl
super.setupContext();
sdcContext = context;
}
@AfterGroups(groups = "live")
protected void tearDown() {
if (sdcContext != null)

View File

@ -26,7 +26,7 @@ import org.jclouds.rest.internal.BaseRestClientExpectTest;
* @author Adrian Cole
*/
public class BaseSDCExpectTest<T> extends BaseRestClientExpectTest<T> {
public BaseSDCExpectTest() {
provider = "joyent-sdc";
}

View File

@ -41,50 +41,37 @@ import com.google.inject.Injector;
@Test(groups = "unit", testName = "ParseDatasetListTest")
public class ParseDatasetListTest extends BaseSetParserTest<Dataset> {
@Override
public String resource() {
return "/dataset_list.json";
}
@Override
public String resource() {
return "/dataset_list.json";
}
@Override
@Consumes(MediaType.APPLICATION_JSON)
public Set<Dataset> expected() {
return ImmutableSet
.of(
Dataset
.builder()
.id("e4cd7b9e-4330-11e1-81cf-3bb50a972bda")
.name("centos-6")
.urn("sdc:sdc:centos-6:1.0.1")
.type(Type.VIRTUALMACHINE)
.version("1.0.1")
.defaultDataset(false)
.created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2012-02-13T06:30:33+00:00"))
.build(),
Dataset
.builder()
.id("e62c30b4-cdda-11e0-9dd4-af4d032032e3")
.name("nodejs")
.urn("sdc:sdc:nodejs:1.2.3")
.type(Type.SMARTMACHINE)
.version("1.2.3")
.defaultDataset(false)
.created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-09-15T08:15:29+00:00"))
.build()
@Override
@Consumes(MediaType.APPLICATION_JSON)
public Set<Dataset> expected() {
return ImmutableSet.of(
Dataset.builder().id("e4cd7b9e-4330-11e1-81cf-3bb50a972bda").name("centos-6").urn("sdc:sdc:centos-6:1.0.1")
.type(Type.VIRTUALMACHINE).version("1.0.1").isDefault(false)
.created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2012-02-13T06:30:33+00:00"))
.build(),
);
}
Dataset.builder().id("e62c30b4-cdda-11e0-9dd4-af4d032032e3").name("nodejs").urn("sdc:sdc:nodejs:1.2.3")
.type(Type.SMARTMACHINE).version("1.2.3").isDefault(false)
.created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-09-15T08:15:29+00:00"))
.build()
protected Injector injector() {
return Guice.createInjector(new SDCParserModule(), new GsonModule() {
);
}
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
protected Injector injector() {
return Guice.createInjector(new SDCParserModule(), new GsonModule() {
});
}
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
});
}
}

View File

@ -43,31 +43,23 @@ public class ParseDatasetTest extends BaseItemParserTest<Dataset> {
return "/dataset.json";
}
@Override
@Consumes(MediaType.APPLICATION_JSON)
public Dataset expected() {
return Dataset
.builder()
.id("e4cd7b9e-4330-11e1-81cf-3bb50a972bda")
.name("centos-6")
.urn("sdc:sdc:centos-6:1.0.1")
.type(Type.VIRTUALMACHINE)
.version("1.0.1")
.defaultDataset(false)
.created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2012-02-13T06:30:33+00:00"))
.build();
return Dataset.builder().id("e4cd7b9e-4330-11e1-81cf-3bb50a972bda").name("centos-6")
.urn("sdc:sdc:centos-6:1.0.1").type(Type.VIRTUALMACHINE).version("1.0.1").isDefault(false)
.created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2012-02-13T06:30:33+00:00")).build();
}
protected Injector injector() {
return Guice.createInjector(new SDCParserModule(), new GsonModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
});
});
}
}

View File

@ -42,79 +42,52 @@ import com.google.inject.Injector;
@Test(groups = "unit", testName = "ParseMachineListTest")
public class ParseMachineListTest extends BaseSetParserTest<Machine> {
@Override
public String resource() {
return "/machine_list.json";
}
@Override
public String resource() {
return "/machine_list.json";
}
@Override
@Consumes(MediaType.APPLICATION_JSON)
public Set<Machine> expected() {
return ImmutableSet
.of(
Machine
.builder()
.id("94eba336-ecb7-49f5-8a27-52f5e4dd57a1")
.name("testJClouds")
.type(Type.VIRTUALMACHINE)
.state(Machine.State.RUNNING)
.dataset("sdc:sdc:centos-5.7:1.2.1")
.ips(
ImmutableSet.<String> builder().add(
"37.153.96.62").add(
"10.224.0.63").build())
.memorySizeMb(1024)
.diskSizeGb(61440)
.metadata(
ImmutableMap
.<String, String> builder()
.put("root_authorized_keys",
"ssh-rsa XXXXXX== test@xxxx.ovh.net\n")
.build())
.created(
new SimpleDateFormatDateService()
.iso8601SecondsDateParse("2012-05-09T13:32:46+00:00"))
.updated(
new SimpleDateFormatDateService()
.iso8601SecondsDateParse("2012-05-11T09:00:33+00:00"))
.build(),
Machine
.builder()
.id("d73cb0b0-7d1f-44ef-8c40-e040eef0f726")
.name("testJClouds2")
.type(Type.SMARTMACHINE)
.state(Machine.State.RUNNING)
.dataset("sdc:sdc:smartosplus:3.1.0")
.ips(
ImmutableSet.<String> builder().add(
"37.153.96.56").add(
"10.224.0.57").build())
.memorySizeMb(1024)
.diskSizeGb(61440)
.metadata(
ImmutableMap
.<String, String> of())
.created(
new SimpleDateFormatDateService()
.iso8601SecondsDateParse("2012-05-09T13:39:43+00:00"))
.updated(
new SimpleDateFormatDateService()
.iso8601SecondsDateParse("2012-05-09T13:43:45+00:00"))
.build()
@Override
@Consumes(MediaType.APPLICATION_JSON)
public Set<Machine> expected() {
return ImmutableSet.of(
Machine
.builder()
.id("94eba336-ecb7-49f5-8a27-52f5e4dd57a1")
.name("testJClouds")
.type(Type.VIRTUALMACHINE)
.state(Machine.State.RUNNING)
.dataset("sdc:sdc:centos-5.7:1.2.1")
.ips(ImmutableSet.<String> builder().add("37.153.96.62").add("10.224.0.63").build())
.memorySizeMb(1024)
.diskSizeGb(61440)
.metadata(
ImmutableMap.<String, String> builder()
.put("root_authorized_keys", "ssh-rsa XXXXXX== test@xxxx.ovh.net\n").build())
.created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2012-05-09T13:32:46+00:00"))
.updated(new SimpleDateFormatDateService().iso8601SecondsDateParse("2012-05-11T09:00:33+00:00"))
.build(),
);
}
Machine.builder().id("d73cb0b0-7d1f-44ef-8c40-e040eef0f726").name("testJClouds2").type(Type.SMARTMACHINE)
.state(Machine.State.RUNNING).dataset("sdc:sdc:smartosplus:3.1.0")
.ips(ImmutableSet.<String> builder().add("37.153.96.56").add("10.224.0.57").build())
.memorySizeMb(1024).diskSizeGb(61440).metadata(ImmutableMap.<String, String> of())
.created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2012-05-09T13:39:43+00:00"))
.updated(new SimpleDateFormatDateService().iso8601SecondsDateParse("2012-05-09T13:43:45+00:00"))
.build()
protected Injector injector() {
return Guice.createInjector(new SDCParserModule(), new GsonModule() {
);
}
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
protected Injector injector() {
return Guice.createInjector(new SDCParserModule(), new GsonModule() {
});
}
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
});
}
}

View File

@ -55,24 +55,25 @@ public class ParseMachineTest extends BaseItemParserTest<Machine> {
.type(Type.VIRTUALMACHINE)
.state(Machine.State.STOPPED)
.dataset("sdc:sdc:centos-5.7:1.2.1")
.ips(ImmutableSet. <String>builder().add("37.153.96.62").add("10.224.0.63").build())
.ips(ImmutableSet.<String> builder().add("37.153.96.62").add("10.224.0.63").build())
.memorySizeMb(1024)
.diskSizeGb(61440)
.metadata(ImmutableMap. <String,String>builder().put("root_authorized_keys","ssh-rsa XXXXXX== test@xxxx.ovh.net\n").build())
.metadata(
ImmutableMap.<String, String> builder()
.put("root_authorized_keys", "ssh-rsa XXXXXX== test@xxxx.ovh.net\n").build())
.created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2012-05-09T13:32:46+00:00"))
.updated(new SimpleDateFormatDateService().iso8601SecondsDateParse("2012-05-11T08:44:53+00:00"))
.build();
.updated(new SimpleDateFormatDateService().iso8601SecondsDateParse("2012-05-11T08:44:53+00:00")).build();
}
protected Injector injector() {
return Guice.createInjector(new SDCParserModule(), new GsonModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
});
});
}
}

View File

@ -39,46 +39,32 @@ import com.google.inject.Injector;
@Test(groups = "unit", testName = "ParsePackageListTest")
public class ParsePackageListTest extends BaseSetParserTest<Package> {
@Override
public String resource() {
return "/package_list.json";
}
@Override
public String resource() {
return "/package_list.json";
}
@Override
@Consumes(MediaType.APPLICATION_JSON)
public Set<Package> expected() {
return ImmutableSet
.of(
org.jclouds.joyent.sdc.v6_5.domain.Package
.builder()
.name("Small 1GB")
.memorySizeMb(1024)
.diskSizeGb(30720)
.swapSizeMb(2048)
.isDefault(true)
.build(),
org.jclouds.joyent.sdc.v6_5.domain.Package
.builder()
.name("Medium 2GB")
.memorySizeMb(2048)
.diskSizeGb(61440)
.swapSizeMb(4096)
.isDefault(false)
.build()
@Override
@Consumes(MediaType.APPLICATION_JSON)
public Set<Package> expected() {
return ImmutableSet.of(org.jclouds.joyent.sdc.v6_5.domain.Package.builder().name("Small 1GB").memorySizeMb(1024)
.diskSizeGb(30720).swapSizeMb(2048).isDefault(true).build(),
);
}
org.jclouds.joyent.sdc.v6_5.domain.Package.builder().name("Medium 2GB").memorySizeMb(2048).diskSizeGb(61440)
.swapSizeMb(4096).isDefault(false).build()
protected Injector injector() {
return Guice.createInjector(new SDCParserModule(), new GsonModule() {
);
}
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
protected Injector injector() {
return Guice.createInjector(new SDCParserModule(), new GsonModule() {
});
}
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
});
}
}

View File

@ -40,29 +40,22 @@ public class ParsePackageTest extends BaseItemParserTest<org.jclouds.joyent.sdc.
return "/package.json";
}
@Override
@Consumes(MediaType.APPLICATION_JSON)
public org.jclouds.joyent.sdc.v6_5.domain.Package expected() {
return org.jclouds.joyent.sdc.v6_5.domain.Package
.builder()
.name("Small 1GB")
.memorySizeMb(1024)
.diskSizeGb(30720)
.swapSizeMb(2048)
.isDefault(true)
.build();
return org.jclouds.joyent.sdc.v6_5.domain.Package.builder().name("Small 1GB").memorySizeMb(1024)
.diskSizeGb(30720).swapSizeMb(2048).isDefault(true).build();
}
protected Injector injector() {
return Guice.createInjector(new SDCParserModule(), new GsonModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
});
});
}
}