From 602002660abb287d684e6a68d0ea5f908279e13a Mon Sep 17 00:00:00 2001 From: Adam Lowe Date: Mon, 9 Jan 2012 13:01:24 +0000 Subject: [PATCH 1/6] Improving javadocs for Archive, Domain, Email and Server GleSYS clients --- .../org/jclouds/glesys/domain/Archive.java | 5 +- .../org/jclouds/glesys/domain/Domain.java | 4 + .../jclouds/glesys/domain/DomainRecord.java | 19 +++++ .../java/org/jclouds/glesys/domain/Email.java | 9 ++ .../jclouds/glesys/domain/EmailOverview.java | 4 + .../glesys/domain/EmailOverviewDomain.java | 5 ++ .../glesys/domain/EmailOverviewSummary.java | 6 ++ .../jclouds/glesys/domain/ServerCreated.java | 19 +++-- .../jclouds/glesys/domain/ServerUptime.java | 3 + .../glesys/features/DomainAsyncClient.java | 23 ++++- .../jclouds/glesys/features/DomainClient.java | 9 +- .../glesys/features/EmailAsyncClient.java | 2 +- .../jclouds/glesys/features/EmailClient.java | 39 ++++++++- .../jclouds/glesys/features/ServerClient.java | 4 +- .../glesys/options/DomainAddOptions.java | 75 +++++++++++++++++ .../jclouds/glesys/options/DomainOptions.java | 51 ++++++++--- .../options/DomainRecordAddOptions.java | 13 ++- .../options/DomainRecordEditOptions.java | 63 ++++++++++++++ .../options/DomainRecordModifyOptions.java | 83 ------------------ .../glesys/options/EmailCreateOptions.java | 11 ++- .../glesys/options/EmailEditOptions.java | 23 ++++- .../glesys/options/ServerCloneOptions.java | 24 +++--- .../glesys/options/ServerEditOptions.java | 6 ++ .../features/DomainAsyncClientTest.java | 4 +- .../glesys/features/DomainClientLiveTest.java | 51 +++++++++++ .../glesys/features/EmailClientLiveTest.java | 84 ++++++++----------- .../glesys/features/ServerClientLiveTest.java | 17 ++-- 27 files changed, 452 insertions(+), 204 deletions(-) create mode 100644 sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/DomainAddOptions.java create mode 100644 sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/DomainRecordEditOptions.java delete mode 100644 sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/DomainRecordModifyOptions.java diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Archive.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Archive.java index 1d87820fb8..cfbb059b87 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Archive.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Archive.java @@ -74,18 +74,22 @@ public class Archive implements Comparable { private final String freeSize; private final boolean locked; + /** @return the name (username) of the archive */ public String getUsername() { return username; } + /** @return the total size of the archive, ex. "10 GB" */ public String getTotalSize() { return totalSize; } + /** @return the free space left of the archive */ public String getFreeSize() { return freeSize; } + /** @return true if the archive is locked */ public boolean isLocked() { return locked; } @@ -97,7 +101,6 @@ public class Archive implements Comparable { this.locked = locked; } - @Override public int hashCode() { return Objects.hashCode(username); diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Domain.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Domain.java index bdee0df871..5aa645dfed 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Domain.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Domain.java @@ -84,18 +84,22 @@ public class Domain implements Comparable { this.glesysNameServer = glesysNameServer; } + /** @return the domain name, ex. "jclouds.org" */ public String getDomain() { return domain; } + /** @return the date the domain was registered with GleSYS */ public Date getCreateTime() { return createTime; } + /** @return the number of DNS records for this domain */ public int getRecordCount() { return recordCount; } + /** @return true if a GleSYS nameserver holds the records */ public boolean getGlesysNameServer() { return glesysNameServer; } diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/DomainRecord.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/DomainRecord.java index 86b4fe6487..3ea489648b 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/DomainRecord.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/DomainRecord.java @@ -95,26 +95,45 @@ public class DomainRecord implements Comparable { this.ttl = ttl; } + /** + * @return the id of the record used to modify it via the API + * @see org.jclouds.glesys.features.DomainClient + */ public String getId() { return id; } + /** + * @return the zone content of the record + */ public String getZone() { return zone; } + /** + * @return the host content of the record + */ public String getHost() { return host; } + /** + * @return the type of the record, ex. "A" + */ public String getType() { return type; } + /** + * @return the data content of the record + */ public String getData() { return data; } + /** + * @return the TTL/Time-to-live for the record + */ public int getTtl() { return ttl; } diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Email.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Email.java index 3846c4e197..af6accd5da 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Email.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Email.java @@ -139,26 +139,32 @@ public class Email implements Comparable { this.modified = modified; } + /** @return the e-mail address for this e-mail account */ public String getAccount() { return account; } + /** @return the quota for this e-mail account */ public String getQuota() { return quota; } + /** @return the amount of quota currently in use */ public String getUsedQuota() { return usedQuota; } + /** @return the antispam level of the e-mail account */ public int getAntispamLevel() { return antispamLevel; } + /** @return true if antivirus is enabled for this e-mail account */ public boolean getAntiVirus() { return antiVirus; } + /** @return true if auto-respond is enabled for this e-mail account */ public boolean getAutoRespond() { return autoRespond; } @@ -167,14 +173,17 @@ public class Email implements Comparable { return autoRespondMessage; } + /** @return true if saving is enabled for auto-respond e-mails */ public boolean getAutoRespondSaveEmail() { return autoRespondSaveEmail; } + /** @return when this account was created */ public Date getCreated() { return created; } + /** @return when this account was last modified */ public Date getModified() { return modified; } diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverview.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverview.java index 708dcc1a62..f37ee3db56 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverview.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverview.java @@ -25,6 +25,8 @@ import com.google.common.collect.ImmutableSet; import java.util.Set; /** + * Structure containing all information about e-mail addresses for a GleSYS account + * * @author Adam Lowe * @see */ @@ -68,10 +70,12 @@ public class EmailOverview { this.domains = domains; } + /** @return summary information about the account */ public EmailOverviewSummary getSummary() { return summary; } + /** @return the set of detailed information about the e-mail addresses and aliases for each domain */ public Set getDomains() { return domains == null ? ImmutableSet.of() : domains; } diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverviewDomain.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverviewDomain.java index 0836645591..6475bf46b4 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverviewDomain.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverviewDomain.java @@ -21,6 +21,8 @@ package org.jclouds.glesys.domain; import com.google.common.base.Objects; /** + * Detailed information about e-mail settings for a single domain + * * @author Adam Lowe * @see */ @@ -68,14 +70,17 @@ public class EmailOverviewDomain { this.aliases = aliases; } + /** @return the domain name */ public String getDomain() { return domain; } + /** @return the number of e-mail accounts in the domain */ public int getAccounts() { return accounts; } + /** @return the number of e-mail aliases in the domain */ public int getAliases() { return aliases; } diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverviewSummary.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverviewSummary.java index 06bf11419f..d8553bd0d8 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverviewSummary.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverviewSummary.java @@ -22,6 +22,8 @@ import com.google.common.base.Objects; import com.google.gson.annotations.SerializedName; /** + * Summary information of e-mail settings and limits for a GleSYS account + * * @author Adam Lowe * @see */ @@ -79,18 +81,22 @@ public class EmailOverviewSummary { this.maxAliases = maxAliases; } + /** @return the number of e-mail accounts */ public int getAccounts() { return accounts; } + /** @return the maximum number of e-mail accounts */ public int getMaxAccounts() { return maxAccounts; } + /** @return the number of e-mail aliases */ public int getAliases() { return aliases; } + /** @return the maximum number of e-mail aliases */ public int getMaxAliases() { return maxAliases; } diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerCreated.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerCreated.java index 07aa87b352..7f02659c96 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerCreated.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerCreated.java @@ -30,8 +30,8 @@ import com.google.common.collect.ImmutableList; import com.google.gson.annotations.SerializedName; /** - * Connection information to connect to a server with VNC. - * + * Information about a new server + * * @author Adam Lowe * @see */ @@ -44,11 +44,12 @@ public class ServerCreated { private String id; private String hostname; private List ips; - + public Builder id(String id) { this.id = id; return this; } + public Builder ips(List ips) { this.ips = ips; return this; @@ -57,16 +58,16 @@ public class ServerCreated { public Builder ips(ServerCreatedIp... ips) { return ips(Arrays.asList(ips)); } - + public Builder hostname(String hostname) { this.hostname = hostname; return this; } - + public ServerCreated build() { return new ServerCreated(id, hostname, ips); } - + public Builder fromServerCreated(ServerCreated in) { return id(in.getId()).hostname(in.getHostname()).ips(in.getIps()); } @@ -85,14 +86,20 @@ public class ServerCreated { this.ips = ips; } + /** + * @return the id of the server (used for other calls to identify the server. + * @see org.jclouds.glesys.features.ServerClient + */ public String getId() { return id; } + /** @return the hostname of the server */ public String getHostname() { return hostname; } + /** @return the IP addresses assigned to the server */ public List getIps() { return ips == null ? ImmutableList.of() : ips; } diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerUptime.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerUptime.java index 24ab2a9792..7eefe11bf9 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerUptime.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerUptime.java @@ -81,6 +81,9 @@ public class ServerUptime { return new ServerUptime(time); } + /** + * @return the number of seconds the server has been up + */ public long getTime() { return time; } diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/DomainAsyncClient.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/DomainAsyncClient.java index c0ba9e5e32..d719a24c7f 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/DomainAsyncClient.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/DomainAsyncClient.java @@ -21,9 +21,10 @@ package org.jclouds.glesys.features; import com.google.common.util.concurrent.ListenableFuture; import org.jclouds.glesys.domain.Domain; import org.jclouds.glesys.domain.DomainRecord; +import org.jclouds.glesys.options.DomainAddOptions; import org.jclouds.glesys.options.DomainOptions; import org.jclouds.glesys.options.DomainRecordAddOptions; -import org.jclouds.glesys.options.DomainRecordModifyOptions; +import org.jclouds.glesys.options.DomainRecordEditOptions; import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.RequestFilters; @@ -63,7 +64,7 @@ public interface DomainAsyncClient { */ @POST @Path("/domain/add/format/json") - ListenableFuture addDomain(@FormParam("name") String name, DomainOptions... options); + ListenableFuture addDomain(@FormParam("name") String name, DomainAddOptions... options); /** * @see DomainClient#editDomain @@ -72,26 +73,42 @@ public interface DomainAsyncClient { @Path("/domain/edit/format/json") ListenableFuture editDomain(@FormParam("domain") String domain, DomainOptions... options); + + /** + * @see DomainClient#deleteDomain + */ @POST @Path("/domain/delete/format/json") ListenableFuture deleteDomain(@FormParam("domain") String domain); + /** + * @see DomainClient#listRecords + */ @POST @Path("/domain/list_records/format/json") @SelectJson("records") @Consumes(MediaType.APPLICATION_JSON) ListenableFuture> listRecords(@FormParam("domain") String domain); + /** + * @see DomainClient#addRecord + */ @POST @Path("/domain/add_record/format/json") ListenableFuture addRecord(@FormParam("domain") String domain, @FormParam("host") String host, @FormParam("type") String type, @FormParam("data") String data, DomainRecordAddOptions... options); + /** + * @see DomainClient#editRecord + */ @POST @Path("/domain/update_record/format/json") - ListenableFuture editRecord(@FormParam("record_id") String record_id, DomainRecordModifyOptions... options); + ListenableFuture editRecord(@FormParam("record_id") String record_id, DomainRecordEditOptions... options); + /** + * @see DomainClient#deleteRecord + */ @POST @Path("/domain/delete_record/format/json") ListenableFuture deleteRecord(@FormParam("record_id") String recordId); diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/DomainClient.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/DomainClient.java index 80d0b3e90e..f02a776ad7 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/DomainClient.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/DomainClient.java @@ -21,15 +21,16 @@ package org.jclouds.glesys.features; import org.jclouds.concurrent.Timeout; import org.jclouds.glesys.domain.Domain; import org.jclouds.glesys.domain.DomainRecord; +import org.jclouds.glesys.options.DomainAddOptions; import org.jclouds.glesys.options.DomainOptions; import org.jclouds.glesys.options.DomainRecordAddOptions; -import org.jclouds.glesys.options.DomainRecordModifyOptions; +import org.jclouds.glesys.options.DomainRecordEditOptions; import java.util.Set; import java.util.concurrent.TimeUnit; /** - * Provides synchronous access to Invoice requests. + * Provides synchronous access to Domain requests. *

* * @author Adam Lowe @@ -52,7 +53,7 @@ public interface DomainClient { * @param domain the name of the domain to add. * @param options optional parameters */ - void addDomain(String domain, DomainOptions... options); + void addDomain(String domain, DomainAddOptions... options); /** * Add a domain to the Glesys dns-system @@ -94,7 +95,7 @@ public interface DomainClient { * @param options the settings to change * @see #listRecords to retrieve the necessary ids */ - void editRecord(String recordId, DomainRecordModifyOptions... options); + void editRecord(String recordId, DomainRecordEditOptions... options); /** * Delete a DNS record diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/EmailAsyncClient.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/EmailAsyncClient.java index 7d88a81c32..cd940087bd 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/EmailAsyncClient.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/EmailAsyncClient.java @@ -50,7 +50,7 @@ import com.google.common.util.concurrent.ListenableFuture; public interface EmailAsyncClient { /** - * @see org.jclouds.glesys.features.EmailClient#emailOverview + * @see org.jclouds.glesys.features.EmailClient#getEmailOverview */ @POST @Path("/email/overview/format/json") diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/EmailClient.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/EmailClient.java index b2304e4a8a..f224bbcff5 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/EmailClient.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/EmailClient.java @@ -46,19 +46,52 @@ public interface EmailClient { EmailOverview getEmailOverview(); /** - * - * @return + * Get the set of detailed information about e-mail accounts + * + * @return the relevant set of details */ Set listAccounts(String domain); + /** + * Create a new e-mail account + * + * @param accountAddress the e-mail address to use (the domain should already exist) + * @param password the password to use for the mailbox + * @param options optional parameters + * @see DomainClient#addDomain + */ void createAccount(String accountAddress, String password, EmailCreateOptions... options); + /** + * Create an e-mail alias for an e-mail account + * + * @param aliasAddress the address to use for the alias (the domain should already exist) + * @param toEmailAddress the existing e-mail account address the alias should forward to + * @see DomainClient#addDomain + */ void createAlias(String aliasAddress, String toEmailAddress); + /** + * Adjust an e-mail account's settings + * + * @param accountAddress the existing e-mail account address + * @param options optional parameters + */ void editAccount(String accountAddress, EmailEditOptions... options); - + + /** + * Adjust (re-target) an e-mail alias + * + * @param aliasAddress the existing alias e-mail address + * @param toEmailAddress the existing e-mail account address the alias should forward to + */ void editAlias(String aliasAddress, String toEmailAddress); + /** + * Delete an e-mail account or alias + * + * @param accountAddress the existing alias e-mail account or alias address + */ void delete(String accountAddress); } \ No newline at end of file diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ServerClient.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ServerClient.java index 8d0b96602a..251d1a32ed 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ServerClient.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ServerClient.java @@ -100,9 +100,9 @@ public interface ServerClient { /** * Get information about the OS templates available * - * @return a map of templates, keyed on platform + * @return the set of information about each template */ - Map> getTemplates(); + Set getTemplates(); /** * Get information about valid arguments to #createServer for each platform diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/DomainAddOptions.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/DomainAddOptions.java new file mode 100644 index 0000000000..cba2b0b0c3 --- /dev/null +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/DomainAddOptions.java @@ -0,0 +1,75 @@ +package org.jclouds.glesys.options; + +import org.jclouds.http.options.BaseHttpRequestOptions; + +/** + * @author Adam Lowe + */ +public class DomainAddOptions extends DomainOptions { + public static class Builder { + /** + * @see DomainAddOptions#primaryNameServer + */ + public static DomainAddOptions primaryNameServer(String primaryNameServer) { + return DomainAddOptions.class.cast(new DomainAddOptions().primaryNameServer(primaryNameServer)); + } + + /** + * @see DomainAddOptions#responsiblePerson + */ + public static DomainAddOptions responsiblePerson(String responsiblePerson) { + return DomainAddOptions.class.cast(new DomainAddOptions().responsiblePerson(responsiblePerson)); + } + + /** + * @see DomainAddOptions#ttl + */ + public static DomainAddOptions ttl(int ttl) { + return DomainAddOptions.class.cast(new DomainAddOptions().ttl(ttl)); + } + + /** + * @see DomainAddOptions#refresh + */ + public static DomainAddOptions refresh(int refresh) { + return DomainAddOptions.class.cast(new DomainAddOptions().refresh(refresh)); + } + + /** + * @see DomainAddOptions#retry + */ + public static DomainAddOptions retry(int retry) { + return DomainAddOptions.class.cast(new DomainAddOptions().retry(retry)); + } + + /** + * @see DomainAddOptions#expire + */ + public static DomainAddOptions expire(int expire) { + return DomainAddOptions.class.cast(new DomainAddOptions().expire(expire)); + } + + /** + * @see DomainAddOptions#minimum + */ + public static DomainAddOptions minimum(int minimum) { + return DomainAddOptions.class.cast(new DomainAddOptions().minimum(minimum)); + } + + /** + * @see DomainAddOptions#minimalRecords + */ + public static DomainAddOptions minimalRecords() { + return DomainAddOptions.class.cast(new DomainAddOptions().minimalRecords()); + } + } + + /** + * Ensure only NS and SOA records will be created by default, when this option is not used a number of default records will be created on the domain. + */ + public DomainOptions minimalRecords() { + formParameters.put("create_records", "0"); + return this; + } + +} \ No newline at end of file diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/DomainOptions.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/DomainOptions.java index 6bc47aa8bf..0a322890f5 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/DomainOptions.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/DomainOptions.java @@ -52,7 +52,7 @@ public class DomainOptions extends BaseHttpRequestOptions { /** * @see DomainOptions#refresh */ - public static DomainOptions refresh(String refresh) { + public static DomainOptions refresh(int refresh) { DomainOptions options = new DomainOptions(); return options.refresh(refresh); } @@ -60,7 +60,7 @@ public class DomainOptions extends BaseHttpRequestOptions { /** * @see DomainOptions#retry */ - public static DomainOptions retry(String retry) { + public static DomainOptions retry(int retry) { DomainOptions options = new DomainOptions(); return options.retry(retry); } @@ -68,7 +68,7 @@ public class DomainOptions extends BaseHttpRequestOptions { /** * @see DomainOptions#expire */ - public static DomainOptions expire(String expire) { + public static DomainOptions expire(int expire) { DomainOptions options = new DomainOptions(); return options.expire(expire); } @@ -76,44 +76,71 @@ public class DomainOptions extends BaseHttpRequestOptions { /** * @see DomainOptions#minimum */ - public static DomainOptions minimum(String minimum) { + public static DomainOptions minimum(int minimum) { DomainOptions options = new DomainOptions(); return options.minimum(minimum); } } + /** + * Configure the primary DNS server for this domain. + */ public DomainOptions primaryNameServer(String primaryNameServer) { formParameters.put("primary_ns", primaryNameServer); return this; } + /** + * Configure the E-mail address of the person responsible for this domain (usually attached to MX records). + */ public DomainOptions responsiblePerson(String responsiblePerson) { + responsiblePerson = responsiblePerson.replaceAll("@", "."); + if (!responsiblePerson.endsWith(".")) { + responsiblePerson = responsiblePerson + "."; + } formParameters.put("resp_person", responsiblePerson); return this; } + /** + * TTL (time to live). The number of seconds a domain name is cached locally before expiration and return to authoritative nameservers for updates + */ public DomainOptions ttl(int ttl) { formParameters.put("ttl", Integer.toString(ttl)); return this; } - public DomainOptions refresh(String refresh) { - formParameters.put("refresh", refresh); + /** + * Configure the number of seconds between update requests from secondary and slave name servers + */ + public DomainOptions refresh(int refresh) { + formParameters.put("refresh", Integer.toString(refresh)); return this; } - public DomainOptions retry(String retry) { - formParameters.put("retry", retry); + /** + * Configure the number of seconds the secondary/slave will wait before retrying when the last attempt failed + */ + public DomainOptions retry(int retry) { + formParameters.put("retry", Integer.toString(retry)); return this; } - public DomainOptions expire(String expire) { - formParameters.put("primary_ns", expire); + /** + * Configure the number of seconds a master or slave will wait before considering the data stale if it cannot reach the primary name server + */ + public DomainOptions expire(int expire) { + formParameters.put("primary_ns", Integer.toString(expire)); return this; } - public DomainOptions minimum(String minimum) { - formParameters.put("minimum", minimum); + /** + * Configure the minimum/default TTL if the domain does not specify ttl + * + * @see #ttl + */ + public DomainOptions minimum(int minimum) { + formParameters.put("minimum", Integer.toString(minimum)); return this; } } \ No newline at end of file diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/DomainRecordAddOptions.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/DomainRecordAddOptions.java index fc304b841e..281cfbdf48 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/DomainRecordAddOptions.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/DomainRecordAddOptions.java @@ -37,24 +37,21 @@ public class DomainRecordAddOptions extends BaseHttpRequestOptions { /** * @see DomainRecordAddOptions#mxPriority */ - public static DomainRecordAddOptions mxPriority(String mxPriority) { + public static DomainRecordAddOptions mxPriority(int mxPriority) { DomainRecordAddOptions options = new DomainRecordAddOptions(); return options.mxPriority(mxPriority); } } - public DomainRecordAddOptions host(String host) { - formParameters.put("host", host); - return this; - } - + /** Configure TTL/Time-to-live for record */ public DomainRecordAddOptions ttl(int ttl) { formParameters.put("ttl", Integer.toString(ttl)); return this; } - public DomainRecordAddOptions mxPriority(String mxPriority) { - formParameters.put("mx_priority", mxPriority); + /** Configure the priority of an MX record */ + public DomainRecordAddOptions mxPriority(int mxPriority) { + formParameters.put("mx_priority", Integer.toString(mxPriority)); return this; } diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/DomainRecordEditOptions.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/DomainRecordEditOptions.java new file mode 100644 index 0000000000..f375375320 --- /dev/null +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/DomainRecordEditOptions.java @@ -0,0 +1,63 @@ +package org.jclouds.glesys.options; + +/** + * @author Adam Lowe + */ +public class DomainRecordEditOptions extends DomainRecordAddOptions { + + public static class Builder { + /** + * @see DomainRecordEditOptions#host + */ + public static DomainRecordEditOptions host(String host) { + return new DomainRecordEditOptions().host(host); + } + + /** + * @see DomainRecordEditOptions#type + */ + public static DomainRecordEditOptions type(String type) { + return new DomainRecordEditOptions().type(type); + } + + /** + * @see DomainRecordEditOptions#data + */ + public static DomainRecordEditOptions data(String data) { + return new DomainRecordEditOptions().data(data); + } + + /** + * @see DomainRecordEditOptions#ttl + */ + public static DomainRecordEditOptions ttl(int ttl) { + return DomainRecordEditOptions.class.cast(new DomainRecordEditOptions().ttl(ttl)); + } + + /** + * @see DomainRecordEditOptions#mxPriority + */ + public static DomainRecordEditOptions mxPriority(int mxPriority) { + return DomainRecordEditOptions.class.cast(new DomainRecordEditOptions().mxPriority(mxPriority)); + } + } + + + /** Configure the hostname attached to this record */ + public DomainRecordEditOptions host(String host) { + formParameters.put("host", host); + return this; + } + + /** Configure the type of record, ex. "A", "CNAME" or "MX" */ + public DomainRecordEditOptions type(String type) { + formParameters.put("type", type); + return this; + } + + /** Set the content of this record (depending on type, for an "A" record this would be an ip address) */ + public DomainRecordEditOptions data(String data) { + formParameters.put("data", data); + return this; + } +} \ No newline at end of file diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/DomainRecordModifyOptions.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/DomainRecordModifyOptions.java deleted file mode 100644 index 50e46d9de9..0000000000 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/DomainRecordModifyOptions.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.glesys.options; - -/** - * @author Adam Lowe - */ -public class DomainRecordModifyOptions extends DomainRecordAddOptions { - - public static class Builder { - /** - * @see org.jclouds.glesys.options.DomainRecordAddOptions#host - */ - public static DomainRecordModifyOptions host(String host) { - DomainRecordModifyOptions options = new DomainRecordModifyOptions(); - return options.host(host); - } - - /** - * @see org.jclouds.glesys.options.DomainRecordModifyOptions#type - */ - public static DomainRecordModifyOptions type(String type) { - DomainRecordModifyOptions options = new DomainRecordModifyOptions(); - return options.type(type); - } - - /** - * @see org.jclouds.glesys.options.DomainRecordModifyOptions#data - */ - public static DomainRecordModifyOptions data(String data) { - DomainRecordModifyOptions options = new DomainRecordModifyOptions(); - return options.data(data); - } - - /** - * @see org.jclouds.glesys.options.DomainRecordModifyOptions#ttl - */ - public static DomainRecordModifyOptions ttl(int ttl) { - DomainRecordModifyOptions options = new DomainRecordModifyOptions(); - return DomainRecordModifyOptions.class.cast(options.ttl(ttl)); - } - - /** - * @see org.jclouds.glesys.options.DomainRecordModifyOptions#mxPriority - */ - public static DomainRecordModifyOptions mxPriority(String mxPriority) { - DomainRecordModifyOptions options = new DomainRecordModifyOptions(); - return DomainRecordModifyOptions.class.cast(options.mxPriority(mxPriority)); - } - } - - public DomainRecordModifyOptions host(String host) { - formParameters.put("host", host); - return this; - } - - - public DomainRecordModifyOptions type(String type) { - formParameters.put("type", type); - return this; - } - - public DomainRecordModifyOptions data(String data) { - formParameters.put("data", data); - return this; - } -} \ No newline at end of file diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/EmailCreateOptions.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/EmailCreateOptions.java index b253f6ca76..a3c74ca975 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/EmailCreateOptions.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/EmailCreateOptions.java @@ -57,33 +57,38 @@ public class EmailCreateOptions extends BaseHttpRequestOptions { /** * @see EmailCreateOptions#autorespondMessage */ - public static EmailCreateOptions autorespondMessage(boolean autorespondMessage) { + public static EmailCreateOptions autorespondMessage(String autorespondMessage) { return new EmailCreateOptions().autorespondMessage(autorespondMessage); } } + /** Configure the antispam level of the account */ public EmailCreateOptions antispamLevel(int antispamLevel) { formParameters.put("antispamlevel", Integer.toString(antispamLevel)); return this; } + /** Enable or disable virus checking */ public EmailCreateOptions antiVirus(boolean antiVirus) { formParameters.put("antivirus", Integer.toString(antiVirus ? 1 : 0)); return this; } + /** Enable or disable auto-respond */ public EmailCreateOptions autorespond(boolean autorespond) { formParameters.put("autorespond", Integer.toString(autorespond ? 1 : 0)); return this; } + /** Enable or disable saving of auto-respond e-mails */ public EmailCreateOptions autorespondSaveEmail(boolean autorespondSaveEmail) { formParameters.put("autorespondsaveemail", Integer.toString(autorespondSaveEmail ? 1 : 0)); return this; } - public EmailCreateOptions autorespondMessage(boolean autorespondMessage) { - formParameters.put("autorespondmessage", Integer.toString(autorespondMessage ? 1 : 0)); + /** Configure the auto-respond message */ + public EmailCreateOptions autorespondMessage(String autorespondMessage) { + formParameters.put("autorespondmessage", autorespondMessage); return this; } } diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/EmailEditOptions.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/EmailEditOptions.java index 97f0e90c5d..7e07600067 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/EmailEditOptions.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/EmailEditOptions.java @@ -26,31 +26,50 @@ package org.jclouds.glesys.options; public class EmailEditOptions extends EmailCreateOptions { public static class Builder { + /** + * @see org.jclouds.glesys.options.EmailEditOptions#antispamLevel + */ public static EmailEditOptions antispamLevel(int antispamLevel) { return EmailEditOptions.class.cast(new EmailEditOptions().antispamLevel(antispamLevel)); } + /** + * @see org.jclouds.glesys.options.EmailEditOptions#antiVirus + */ public static EmailEditOptions antiVirus(boolean antiVirus) { return EmailEditOptions.class.cast(new EmailEditOptions().antiVirus(antiVirus)); } + /** + * @see org.jclouds.glesys.options.EmailEditOptions#autorespond + */ public static EmailEditOptions autorespond(boolean autorespond) { return EmailEditOptions.class.cast(new EmailEditOptions().autorespond(autorespond)); } + /** + * @see org.jclouds.glesys.options.EmailEditOptions#autorespondSaveEmail + */ public static EmailEditOptions autorespondSaveEmail(boolean autorespondSaveEmail) { return EmailEditOptions.class.cast(new EmailEditOptions().autorespondSaveEmail(autorespondSaveEmail)); } - public static EmailEditOptions autorespondMessage(boolean autorespondMessage) { + /** + * @see org.jclouds.glesys.options.EmailEditOptions#autorespondMessage + */ + public static EmailEditOptions autorespondMessage(String autorespondMessage) { return EmailEditOptions.class.cast(new EmailEditOptions().autorespondMessage(autorespondMessage)); } - public static EmailEditOptions autorespondMessage(String password) { + /** + * @see org.jclouds.glesys.options.EmailEditOptions#password + */ + public static EmailEditOptions password(String password) { return new EmailEditOptions().password(password); } } + /** Reset the password for this account */ public EmailEditOptions password(String password) { formParameters.put("password", password); return this; diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerCloneOptions.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerCloneOptions.java index 388a49d632..6ae8aaf54d 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerCloneOptions.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerCloneOptions.java @@ -27,59 +27,55 @@ public class ServerCloneOptions extends ServerEditOptions { * @see org.jclouds.glesys.options.ServerCloneOptions#disksize */ public static ServerCloneOptions disksize(int disksize) { - ServerCloneOptions options = new ServerCloneOptions(); - return ServerCloneOptions.class.cast(options.disksize(disksize)); + return ServerCloneOptions.class.cast(new ServerCloneOptions().disksize(disksize)); } /** * @see org.jclouds.glesys.options.ServerCloneOptions#memorysize */ public static ServerCloneOptions memorysize(int memorysize) { - ServerCloneOptions options = new ServerCloneOptions(); - return ServerCloneOptions.class.cast(options.memorysize(memorysize)); + return ServerCloneOptions.class.cast(new ServerCloneOptions().memorysize(memorysize)); } /** * @see org.jclouds.glesys.options.ServerCloneOptions#cpucores */ public static ServerCloneOptions cpucores(int cpucores) { - ServerCloneOptions options = new ServerCloneOptions(); - return ServerCloneOptions.class.cast(options.cpucores(cpucores)); + return ServerCloneOptions.class.cast(new ServerCloneOptions().cpucores(cpucores)); } /** * @see org.jclouds.glesys.options.ServerCloneOptions#cpucores */ public static ServerCloneOptions transfer(int transfer) { - ServerCloneOptions options = new ServerCloneOptions(); - return ServerCloneOptions.class.cast(options.transfer(transfer)); + return ServerCloneOptions.class.cast(new ServerCloneOptions().transfer(transfer)); } /** * @see org.jclouds.glesys.options.ServerCloneOptions#hostname */ public static ServerCloneOptions hostname(String hostname) { - ServerCloneOptions options = new ServerCloneOptions(); - return ServerCloneOptions.class.cast(options.hostname(hostname)); + return ServerCloneOptions.class.cast(new ServerCloneOptions().hostname(hostname)); } /** * @see org.jclouds.glesys.options.ServerEditOptions#description */ public static ServerCloneOptions description(String description) { - ServerCloneOptions options = new ServerCloneOptions(); - return ServerCloneOptions.class.cast(options.description(description)); + return ServerCloneOptions.class.cast(new ServerCloneOptions().description(description)); } /** * @see org.jclouds.glesys.options.ServerCloneOptions#dataCenter */ public static ServerCloneOptions dataCenter(String dataCenter) { - ServerCloneOptions options = new ServerCloneOptions(); - return options.dataCenter(dataCenter); + return new ServerCloneOptions().dataCenter(dataCenter); } } + /** + * Configure which datacenter to create the clone in + */ public ServerCloneOptions dataCenter(String dataCenter) { formParameters.put("datacenter", dataCenter); return this; diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerEditOptions.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerEditOptions.java index b45070b9d7..ba8a0ffe36 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerEditOptions.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerEditOptions.java @@ -76,31 +76,37 @@ public class ServerEditOptions extends BaseHttpRequestOptions { } } + /** Configure the size of the disk, in GB, of the server */ public ServerEditOptions disksize(int disksize) { formParameters.put("disksize", Integer.toString(disksize)); return this; } + /** Configure the amount of RAM, in MB, allocated to the server */ public ServerEditOptions memorysize(int memorysize) { formParameters.put("memorysize", Integer.toString(memorysize)); return this; } + /** Configure the number of CPU cores allocated to the server */ public ServerEditOptions cpucores(int cpucores) { formParameters.put("cpucores", Integer.toString(cpucores)); return this; } + /** Configure the transfer setting for the server */ public ServerEditOptions transfer(int transfer) { formParameters.put("cpucores", Integer.toString(transfer)); return this; } + /** Configure the host name of the server (must be unique within the GleSYS account) */ public ServerEditOptions hostname(String hostname) { formParameters.put("hostname", hostname); return this; } + /** Configure the description of the server */ public ServerEditOptions description(String description) { formParameters.put("description", description); return this; diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/DomainAsyncClientTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/DomainAsyncClientTest.java index e945854a6c..78dcafa6bc 100644 --- a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/DomainAsyncClientTest.java +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/DomainAsyncClientTest.java @@ -48,8 +48,8 @@ public class DomainAsyncClientTest extends BaseGleSYSAsyncClientTest domainCounter; private RetryablePredicate recordCounter; + @Test + public void testEditDomain() throws Exception { + client.editDomain(testDomain, DomainOptions.Builder.responsiblePerson("tester.jclouds.org")); + assertTrue(client.listDomains().contains(Domain.builder().domain(testDomain).build())); + } + @Test public void testCreateRecord() throws Exception { int before = client.listRecords(testDomain).size(); @@ -86,6 +97,46 @@ public class DomainClientLiveTest extends BaseGleSYSClientLiveTest { client.addRecord(testDomain, "test", "A", "127.0.0.1"); assertTrue(recordCounter.apply(before + 1)); + + for(DomainRecord record : client.listRecords(testDomain)) { + if ("test".equals(record.getHost())) { + assertEquals(record.getType(), "A"); + assertEquals(record.getData(), "127.0.0.1"); + } + } + } + + @Test + public void testEditRecord() throws Exception { + int before = client.listRecords(testDomain).size(); + + client.addRecord(testDomain, "testeditbefore", "A", "127.0.0.1"); + + assertTrue(recordCounter.apply(before + 1)); + + String recordId = null; + for(DomainRecord record : client.listRecords(testDomain)) { + if ("testeditbefore".equals(record.getHost())) { + assertEquals(record.getType(), "A"); + assertEquals(record.getData(), "127.0.0.1"); + recordId = record.getId(); + } + } + + assertNotNull(recordId); + + client.editRecord(recordId, DomainRecordEditOptions.Builder.host("testeditafter")); + + boolean found = false; + for(DomainRecord record : client.listRecords(testDomain)) { + if (recordId.equals(record.getId())) { + assertEquals(record.getHost(), "testeditafter"); + assertEquals(record.getType(), "A"); + assertEquals(record.getData(), "127.0.0.1"); + found = true; + } + } + assertTrue(found); } @Test diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/EmailClientLiveTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/EmailClientLiveTest.java index 845d17396e..108c608b1c 100644 --- a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/EmailClientLiveTest.java +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/EmailClientLiveTest.java @@ -16,24 +16,6 @@ * specific language governing permissions and limitations * under the License. */ -/** -* Licensed to jclouds, Inc. (jclouds) under one or more -* contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. jclouds licenses this file -* to you under the Apache License, Version 2.0 (the -* "License"); you may not use this file except in compliance -* with the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, -* software distributed under the License is distributed on an -* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -* KIND, either express or implied. See the License for the -* specific language governing permissions and limitations -* under the License. -*/ package org.jclouds.glesys.features; import com.google.common.base.Predicate; @@ -52,10 +34,10 @@ import java.util.concurrent.TimeUnit; import static org.testng.Assert.*; /** -* Tests behavior of {@code EmailClient} -* -* @author Adam Lowe -*/ + * Tests behavior of {@code EmailClient} + * + * @author Adam Lowe + */ @Test(groups = "live", testName = "EmailClientLiveTest", singleThreaded = true) public class EmailClientLiveTest extends BaseGleSYSClientLiveTest { @@ -64,15 +46,8 @@ public class EmailClientLiveTest extends BaseGleSYSClientLiveTest { super.setupClient(); client = context.getApi().getEmailClient(); - try { - client.delete("test@" + testDomain); - client.delete("test2@" + testDomain); - context.getApi().getDomainClient().deleteDomain(testDomain); - } catch(Exception e) { - } - serverId = createServer("test-email-jclouds").getServerId(); - + createDomain(testDomain); emailAccountCounter = new RetryablePredicate( @@ -80,42 +55,55 @@ public class EmailClientLiveTest extends BaseGleSYSClientLiveTest { public boolean apply(Integer value) { return client.listAccounts(testDomain).size() == value; } - }, 30, 1, TimeUnit.SECONDS); - + }, 90, 5, TimeUnit.SECONDS); + + assertTrue(emailAccountCounter.apply(0)); } - @AfterGroups(groups = {"live"}) public void tearDown() { client.delete("test@" + testDomain); + client.delete("test1@" + testDomain); assertTrue(emailAccountCounter.apply(0)); context.getApi().getDomainClient().deleteDomain(testDomain); context.getApi().getServerClient().destroyServer(serverId, ServerDestroyOptions.Builder.discardIp()); super.tearDown(); } - + private EmailClient client; private String serverId; private final String testDomain = "email-test.jclouds.org"; private RetryablePredicate emailAccountCounter; - + @Test - public void createEmail() { - client.createAccount("test@" + testDomain, "password", EmailCreateOptions.Builder.antiVirus(true)); + public void testCreateEmail() { + client.createAccount("test@" + testDomain, "password", + EmailCreateOptions.Builder.antiVirus(true).autorespond(true).autorespondMessage("out of office")); + assertTrue(emailAccountCounter.apply(1)); + + client.createAccount("test1@" + testDomain, "password"); + + assertTrue(emailAccountCounter.apply(2)); } - @Test(dependsOnMethods = "createEmail") - public void createAlias() { + @Test(dependsOnMethods = "testCreateEmail") + public void testAliases() { client.createAlias("test2@" + testDomain, "test@" + testDomain); EmailOverview overview = client.getEmailOverview(); assertTrue(overview.getSummary().getAliases() == 1); + + // TODO verify the result of editing the alias + client.editAlias("test2@" + testDomain, "test1@" + testDomain); + overview = client.getEmailOverview(); + assertTrue(overview.getSummary().getAliases() == 1); + client.delete("test2@" + testDomain); overview = client.getEmailOverview(); assertTrue(overview.getSummary().getAliases() == 0); } - - @Test(dependsOnMethods = "createEmail") + + @Test(dependsOnMethods = "testCreateEmail") public void testOverview() throws Exception { EmailOverview overview = client.getEmailOverview(); assertNotNull(overview.getSummary()); @@ -125,30 +113,30 @@ public class EmailClientLiveTest extends BaseGleSYSClientLiveTest { assertTrue(overview.getSummary().getMaxAliases() > 0); assertNotNull(overview.getDomains()); assertFalse(overview.getDomains().isEmpty()); - + EmailOverviewDomain domain = EmailOverviewDomain.builder().domain(testDomain).accounts(1).build(); assertTrue(overview.getDomains().contains(domain)); } - @Test(dependsOnMethods = "createEmail") + @Test(dependsOnMethods = "testCreateEmail") public void testListAccounts() throws Exception { Set accounts = client.listAccounts(testDomain); assertTrue(accounts.size() >= 1); } - @Test(dependsOnMethods = "createEmail") + @Test(dependsOnMethods = "testCreateEmail") public void testEditAccount() throws Exception { Set accounts = client.listAccounts(testDomain); - for(Email account : accounts) { + for (Email account : accounts) { if (account.getAccount().equals("test@" + testDomain)) { assertTrue(account.getAntiVirus()); } } - + client.editAccount("test@" + testDomain, EmailEditOptions.Builder.antiVirus(false)); - + accounts = client.listAccounts(testDomain); - for(Email account : accounts) { + for (Email account : accounts) { if (account.getAccount().equals("test@" + testDomain)) { assertFalse(account.getAntiVirus()); } diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerClientLiveTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerClientLiveTest.java index ee0230ebdf..6f28007fdf 100644 --- a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerClientLiveTest.java +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerClientLiveTest.java @@ -98,26 +98,19 @@ public class ServerClientLiveTest extends BaseGleSYSClientLiveTest { @Test public void testListTemplates() throws Exception { - Map> templates = client.getTemplates(); + Set templates = client.getTemplates(); - assertTrue(templates.containsKey("OpenVZ")); - assertTrue(templates.containsKey("Xen")); - - for(ServerTemplate template : templates.get("OpenVZ")) { - checkTemplate(template, "OpenVZ"); - } - - for(ServerTemplate template : templates.get("Xen")) { - checkTemplate(template, "Xen"); + for(ServerTemplate template : templates) { + checkTemplate(template); } } - private void checkTemplate(ServerTemplate t, String platform) { + private void checkTemplate(ServerTemplate t) { assertNotNull(t); assertNotNull(t.getName()); assertNotNull(t.getOs()); - assertEquals(t.getPlatform(), platform); + assertNotNull(t.getPlatform()); assert t.getMinDiskSize() > 0 : t; assert t.getMinMemSize() > 0 : t; } From bb47f6bba10671eb8c91f0045a19fe1765df2b36 Mon Sep 17 00:00:00 2001 From: Adam Lowe Date: Tue, 10 Jan 2012 10:54:03 +0000 Subject: [PATCH 2/6] Switching from AsyncClientTests to ClientExpectTests for Archive, Domain, Email and Server clients --- .../glesys/compute/GleSYSComputeService.java | 11 ++ .../GleSYSComputeServiceContextModule.java | 11 ++ .../jclouds/glesys/domain/ServerDetails.java | 2 +- .../glesys/features/ArchiveAsyncClient.java | 2 +- .../glesys/features/EmailAsyncClient.java | 3 +- .../jclouds/glesys/features/EmailClient.java | 2 +- .../glesys/options/ServerCloneOptions.java | 7 - .../features/ArchiveAsyncClientTest.java | 81 --------- .../features/ArchiveClientExpectTest.java | 107 ++++++++++++ .../features/BaseGleSYSAsyncClientTest.java | 81 --------- .../features/BaseGleSYSClientExpectTest.java | 115 +++++++++++++ .../features/DomainAsyncClientTest.java | 69 -------- .../features/DomainClientExpectTest.java | 84 ++++++++++ .../glesys/features/EmailAsyncClientTest.java | 68 -------- .../features/EmailClientExpectTest.java | 116 +++++++++++++ .../features/ServerAsyncClientTest.java | 136 --------------- .../features/ServerClientExpectTest.java | 158 ++++++++++++++++++ .../ParseServerAllowedArgumentsTest.java | 55 +++--- .../glesys/parse/ParseServerDetailsTest.java | 65 +++++++ .../src/test/resources/server_details.json | 1 + .../src/test/resources/server_limits.json | 1 + 21 files changed, 703 insertions(+), 472 deletions(-) create mode 100644 sandbox-providers/glesys/src/main/java/org/jclouds/glesys/compute/GleSYSComputeService.java create mode 100644 sandbox-providers/glesys/src/main/java/org/jclouds/glesys/compute/config/GleSYSComputeServiceContextModule.java delete mode 100644 sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ArchiveAsyncClientTest.java create mode 100644 sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ArchiveClientExpectTest.java create mode 100644 sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/BaseGleSYSClientExpectTest.java delete mode 100644 sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/DomainAsyncClientTest.java create mode 100644 sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/DomainClientExpectTest.java delete mode 100644 sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/EmailAsyncClientTest.java create mode 100644 sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/EmailClientExpectTest.java delete mode 100644 sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerAsyncClientTest.java create mode 100644 sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerClientExpectTest.java create mode 100644 sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseServerDetailsTest.java create mode 100644 sandbox-providers/glesys/src/test/resources/server_details.json create mode 100644 sandbox-providers/glesys/src/test/resources/server_limits.json diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/compute/GleSYSComputeService.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/compute/GleSYSComputeService.java new file mode 100644 index 0000000000..48266e0679 --- /dev/null +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/compute/GleSYSComputeService.java @@ -0,0 +1,11 @@ +package org.jclouds.glesys.compute; + +/** + * Created by IntelliJ IDEA. + * User: aplowe + * Date: 09/01/2012 + * Time: 13:03 + * To change this template use File | Settings | File Templates. + */ +public class GleSYSComputeService { +} diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/compute/config/GleSYSComputeServiceContextModule.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/compute/config/GleSYSComputeServiceContextModule.java new file mode 100644 index 0000000000..94b33686bd --- /dev/null +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/compute/config/GleSYSComputeServiceContextModule.java @@ -0,0 +1,11 @@ +package org.jclouds.glesys.compute.config; + +/** + * Created by IntelliJ IDEA. + * User: aplowe + * Date: 09/01/2012 + * Time: 13:05 + * To change this template use File | Settings | File Templates. + */ +public class GleSYSComputeServiceContextModule { +} diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerDetails.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerDetails.java index e8347bf444..4622233ac1 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerDetails.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerDetails.java @@ -111,7 +111,7 @@ public class ServerDetails extends Server { public ServerDetails(String id, String hostname, String datacenter, String platform, String description, int cpuCores, int memory, int disk, Cost cost) { super(id, hostname, datacenter, platform); - this.description = checkNotNull(description, "description"); + this.description = description; this.cpuCores = cpuCores; this.memory = memory; this.disk = disk; diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ArchiveAsyncClient.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ArchiveAsyncClient.java index 4098ebeade..f79a77f383 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ArchiveAsyncClient.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ArchiveAsyncClient.java @@ -99,7 +99,7 @@ public interface ArchiveAsyncClient { @Path("/archive/allowedarguments/format/json") @SelectJson("argumentslist") @Consumes(MediaType.APPLICATION_JSON) - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture getArchiveAllowedArguments(); } diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/EmailAsyncClient.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/EmailAsyncClient.java index cd940087bd..ed303905bf 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/EmailAsyncClient.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/EmailAsyncClient.java @@ -37,6 +37,7 @@ import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import com.google.common.util.concurrent.ListenableFuture; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; /** * Provides asynchronous access to E-Mail data via the Glesys REST API. @@ -56,7 +57,7 @@ public interface EmailAsyncClient { @Path("/email/overview/format/json") @SelectJson("response") @Consumes(MediaType.APPLICATION_JSON) - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture getEmailOverview(); /** diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/EmailClient.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/EmailClient.java index f224bbcff5..f7d75b3b32 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/EmailClient.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/EmailClient.java @@ -32,7 +32,7 @@ import org.jclouds.glesys.options.EmailEditOptions; *

* * @author Adam Lowe - * @see org.jclouds.glesys.features.DomainAsyncClient + * @see org.jclouds.glesys.features.EmailAsyncClient * @see */ @Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerCloneOptions.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerCloneOptions.java index 6ae8aaf54d..99997e0f91 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerCloneOptions.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerCloneOptions.java @@ -51,13 +51,6 @@ public class ServerCloneOptions extends ServerEditOptions { return ServerCloneOptions.class.cast(new ServerCloneOptions().transfer(transfer)); } - /** - * @see org.jclouds.glesys.options.ServerCloneOptions#hostname - */ - public static ServerCloneOptions hostname(String hostname) { - return ServerCloneOptions.class.cast(new ServerCloneOptions().hostname(hostname)); - } - /** * @see org.jclouds.glesys.options.ServerEditOptions#description */ diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ArchiveAsyncClientTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ArchiveAsyncClientTest.java deleted file mode 100644 index 124f4ec4f2..0000000000 --- a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ArchiveAsyncClientTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.glesys.features; - -import java.util.Map; - -import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; -import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; -import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; -import org.jclouds.rest.internal.RestAnnotationProcessor; -import org.testng.annotations.Test; - -import com.google.inject.TypeLiteral; - -/** - * Tests annotation parsing of {@code ArchiveAsyncClient} - * - * @author Adam Lowe - */ -@Test(groups = "unit", testName = "ArchiveAsyncClientTest") -public class ArchiveAsyncClientTest extends BaseGleSYSAsyncClientTest { - public ArchiveAsyncClientTest() { - asyncClientClass = ArchiveAsyncClient.class; - remoteServicePrefix = "archive"; - } - - private Map.Entry userName = newEntry("username", "x"); - - public void testListArchives() throws Exception { - testMethod("listArchives", "list", "POST", true, ReturnEmptySetOnNotFoundOr404.class); - } - - public void testArchiveDetails() throws Exception { - testMethod("getArchiveDetails", "details", "POST", true, ReturnNullOnNotFoundOr404.class, userName); - } - - public void testCreateArchive() throws Exception { - testMethod("createArchive", "create", "POST", false, MapHttp4xxCodesToExceptions.class, userName, - newEntry("password", "somepass"), newEntry("size", 5)); - } - - public void testDeleteArchive() throws Exception { - testMethod("deleteArchive", "delete", "POST", false, MapHttp4xxCodesToExceptions.class, userName); - } - - public void testResizeArchive() throws Exception { - testMethod("resizeArchive", "resize", "POST", false, MapHttp4xxCodesToExceptions.class, userName, - newEntry("size", "5 GB")); - } - - public void testChangeArchivePassword() throws Exception { - testMethod("changeArchivePassword", "changepassword", "POST", false, MapHttp4xxCodesToExceptions.class, userName, - newEntry("password", "newpass")); - } - - public void testGetArchiveAllowedArguments() throws Exception { - testMethod("getArchiveAllowedArguments", "allowedarguments", "GET", true, ReturnEmptySetOnNotFoundOr404.class); - } - - @Override - protected TypeLiteral> createTypeLiteral() { - return new TypeLiteral>() { - }; - } -} diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ArchiveClientExpectTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ArchiveClientExpectTest.java new file mode 100644 index 0000000000..524c8b7470 --- /dev/null +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ArchiveClientExpectTest.java @@ -0,0 +1,107 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.glesys.features; + +import com.google.common.collect.ImmutableList; +import org.jclouds.glesys.GleSYSClient; +import org.jclouds.glesys.domain.Archive; +import org.jclouds.glesys.domain.ArchiveAllowedArguments; +import org.jclouds.glesys.domain.ArchiveDetails; +import org.jclouds.rest.ResourceNotFoundException; +import org.testng.annotations.Test; + +import java.util.Map; + +import static org.testng.Assert.*; + +/** + * Tests annotation parsing of {@code ArchiveAsyncClient} + * + * @author Adam Lowe + */ +@Test(groups = "unit", testName = "ArchiveAsyncClientTest") +public class ArchiveClientExpectTest extends BaseGleSYSClientExpectTest { + public ArchiveClientExpectTest() { + remoteServicePrefix = "archive"; + } + + private Map.Entry userName = entry("username", "xxxxxx_test1"); + + public void testListArchives() throws Exception { + ArchiveClient client = createMock("list", "POST", 200, "/archive_list.json"); + assertEquals(client.listArchives(), + ImmutableList.of(Archive.builder().username("xxxxx_test1").freeSize("20 GB").totalSize("20 GB").locked(false).build())); + + // check not found response + client = createMock("list", "POST", 404, "Something not found"); + assertTrue(client.listArchives().isEmpty()); + } + + public void testArchiveDetails() throws Exception { + assertEquals(createMock("details", "POST", 200, "/archive_details.json", userName).getArchiveDetails("xxxxxx_test1"), + ArchiveDetails.builder().username("xxxxxx_test1").freeSize("30 GB").totalSize("30 GB").locked(false).build()); + assertNull(createMock("details", "POST", 404, "/archive_details.json", userName).getArchiveDetails("xxxxxx_test1")); + } + + public void testCreateArchive() throws Exception { + createMock("create", "POST", 200, null, userName, entry("size", 5), + entry("password", "somepass")).createArchive(userName.getValue(), "somepass", 5); + } + + public void testDeleteArchive() throws Exception { + createMock("delete", "POST", 200, null, userName).deleteArchive(userName.getValue()); + } + + @Test(expectedExceptions = {ResourceNotFoundException.class}) + public void testDeleteArchiveNotFound() throws Exception { + createMock("delete", "POST", 404, null, userName).deleteArchive(userName.getValue()); + } + + public void testResizeArchive() throws Exception { + createMock("resize", "POST", 200, null, entry("username", "username"), + entry("size", "5")).resizeArchive("username", 5); + } + + @Test(expectedExceptions = {ResourceNotFoundException.class}) + public void testResizeArchiveNotFound() throws Exception { + createMock("resize", "POST", 404, null, entry("username", "username"), entry("size", "5")).resizeArchive("username", 5); + } + + public void testChangeArchivePassword() throws Exception { + createMock("changepassword", "POST", 200, null, userName, + entry("password", "newpass")).changeArchivePassword(userName.getValue(), "newpass"); + } + + @Test(expectedExceptions = {ResourceNotFoundException.class}) + public void testChangeArchivePasswordNotFound() throws Exception { + createMock("changepassword", "POST", 404, null, userName, + entry("password", "newpass")).changeArchivePassword(userName.getValue(), "newpass"); + } + + public void testGetArchiveAllowedArguments() throws Exception { + assertEquals(createMock("allowedarguments", "GET", 200, "/archive_allowed_arguments.json").getArchiveAllowedArguments(), + ArchiveAllowedArguments.builder().archiveSizes(10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 125, 150, 175, 200, 225, 250, 275, 300, 325, 350, 375, 400, 425, 450, 475, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000).build()); + assertNull(createMock("allowedarguments", "GET", 404, "/archive_allowed_arguments.json").getArchiveAllowedArguments()); + } + + @Override + protected ArchiveClient getClient(GleSYSClient gleSYSClient) { + return gleSYSClient.getArchiveClient(); + } +} diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/BaseGleSYSAsyncClientTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/BaseGleSYSAsyncClientTest.java index 26e799aac4..43d645325a 100644 --- a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/BaseGleSYSAsyncClientTest.java +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/BaseGleSYSAsyncClientTest.java @@ -48,8 +48,6 @@ import com.google.common.collect.Maps; * @author Adam Lowe */ public abstract class BaseGleSYSAsyncClientTest extends RestClientTest { - protected Class asyncClientClass; - protected String remoteServicePrefix; @Override protected void checkFilters(HttpRequest request) { @@ -62,83 +60,4 @@ public abstract class BaseGleSYSAsyncClientTest extends RestClientTest { Properties props = new Properties(); return new RestContextFactory().createContextSpec("glesys", "username", "apiKey", props); } - - @Deprecated - protected Map.Entry newEntry(String key, Object value) { - return Maps.immutableEntry(key, value.toString()); - } - - /** - * Test that a method call is annotated correctly. - *

- * @param localMethod the method to call in asyncClientClass - * @param remoteCall the name of the expected call on the remote server - * @param httpMethod "GET" or "POST" - * @param expectResponse if true check Accept header and response parsers - * @param exceptionParser the class of exception handler expected - * @param args either Map.Entry or BaseHttpRequestOptions that make up the arguments to the method - */ - //TODO: kill this and related logic and transition to BaseRestClientExpectTest - @Deprecated - protected void testMethod(String localMethod, String remoteCall, String httpMethod, boolean expectResponse, - Class exceptionParser, Object... args) throws Exception { - testMethod(localMethod, remoteCall, httpMethod, expectResponse, ParseFirstJsonValueNamed.class, exceptionParser, - args); - } - - @Deprecated - @SuppressWarnings("unchecked") - protected void testMethod(String localMethod, String remoteCall, String httpMethod, boolean expectResponse, Class responseParser, Class exceptionParser, Object... args) throws Exception { - List argStrings = new ArrayList(); - List argValues = new ArrayList(); - - for (Object arg : args) { - if (arg instanceof BaseHttpRequestOptions) { - for (Map.Entry httpEntry : ((BaseHttpRequestOptions) arg).buildFormParameters().entries()) { - argStrings.add(httpEntry.getKey() + "=" + httpEntry.getValue()); - } - argValues.add(arg); - } else { - Map.Entry entry = (Map.Entry) arg; - argStrings.add(entry.getKey() + "=" + Strings2.urlEncode(entry.getValue())); - argValues.add(entry.getValue()); - } - } - - Method method = null; - for (Method m : asyncClientClass.getMethods()) { - if (m.getName().equals(localMethod)) { - assertNull(method, "More than one method called " + localMethod + " in class " + asyncClientClass); - method = m; - } - } - - assertNotNull(method, "Failed to locate method " + localMethod + " in class " + asyncClientClass); - - HttpRequest httpRequest = processor.createRequest(method, argValues.toArray()); - - assertRequestLineEquals(httpRequest, httpMethod + " https://api.glesys.com/" + remoteServicePrefix + "/" + remoteCall + "/format/json HTTP/1.1"); - - if (expectResponse) { - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); - assertResponseParserClassEquals(method, httpRequest, responseParser); - } - - if (argStrings.isEmpty()) { - assertPayloadEquals(httpRequest, null, null, false); - } else { - assertNotNull(httpRequest.getPayload()); - String payload = (String) httpRequest.getPayload().getRawContent(); - Iterable in = Splitter.on("&").split(payload); - assertContentHeadersEqual(httpRequest, "application/x-www-form-urlencoded", null, null, null, 0L + payload.length(), null); - assertEquals(ImmutableSortedSet.copyOf(in), ImmutableSortedSet.copyOf(argStrings)); - - } - - assertSaxResponseParserClassEquals(method, null); - assertExceptionParserClassEquals(method, exceptionParser); - - checkFilters(httpRequest); - } - } diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/BaseGleSYSClientExpectTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/BaseGleSYSClientExpectTest.java new file mode 100644 index 0000000000..5e7f0e02ca --- /dev/null +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/BaseGleSYSClientExpectTest.java @@ -0,0 +1,115 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.glesys.features; + +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.LinkedHashMultimap; +import com.google.common.collect.Maps; +import com.google.common.collect.Multimap; +import org.jclouds.glesys.GleSYSClient; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.options.BaseHttpRequestOptions; +import org.jclouds.io.payloads.StringPayload; +import org.jclouds.rest.BaseRestClientExpectTest; + +import java.net.URI; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import static org.jclouds.io.Payloads.newUrlEncodedFormPayload; + +/** + * Support for short-hand generation of ClientExpectTests for the GleSYS clients + * + * @author Adam Lowe + */ +public abstract class BaseGleSYSClientExpectTest extends BaseRestClientExpectTest { + protected String remoteServicePrefix; + + public BaseGleSYSClientExpectTest() { + provider = "glesys"; + } + + protected abstract T getClient(GleSYSClient gleSYSClient); + + protected Map.Entry entry(String key, Object value) { + return Maps.immutableEntry(key, value.toString()); + } + + /** + * Build a mock of a GleSYS client that responds as instructed + * + * @param remoteCall the name of the expected call on the remote server + * @param httpMethod "GET" or "POST" + * @param returnCode the http status code expected (ordinarily 200) + * @param expectedResponse ensure this is not-null for calls that expect a response - for OK responses this should be + * the classpath location of a file with a valid server response, for errors any String + * @param args either Map.Entry or BaseHttpRequestOption objects that make up the arguments to the method + * @return the appropriate client for test to invoke methods on (by calling getClient() in the appropriate subclass) + */ + @SuppressWarnings("unchecked") + protected T createMock(String remoteCall, String httpMethod, int returnCode, String expectedResponse, Object... args) throws Exception { + List argValues = new ArrayList(); + + Multimap map = LinkedHashMultimap.create(); + + for (Object arg : args) { + if (arg instanceof BaseHttpRequestOptions) { + for (Map.Entry httpEntry : ((BaseHttpRequestOptions) arg).buildFormParameters().entries()) { + map.put(httpEntry.getKey(), httpEntry.getValue()); + } + argValues.add(arg); + } else { + Map.Entry entry = (Map.Entry) arg; + map.put(entry.getKey(), entry.getValue()); + argValues.add(entry.getValue()); + } + } + + HttpRequest.Builder httpRequestBuilder = HttpRequest.builder().method(httpMethod).endpoint( + URI.create("https://api.glesys.com/" + remoteServicePrefix + "/" + remoteCall + "/format/json")); + + if (expectedResponse == null) { + httpRequestBuilder.headers(ImmutableMultimap.builder() + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()); + } else { + httpRequestBuilder.headers(ImmutableMultimap.builder() + .put("Accept", "application/json").put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()); + } + + if (!map.isEmpty()) { + httpRequestBuilder.payload(newUrlEncodedFormPayload( + ImmutableMultimap.builder().putAll(map).build())); + } + + HttpResponse.Builder responseBuilder = HttpResponse.builder().statusCode(returnCode); + + if (expectedResponse != null) { + if (returnCode < 300) { + responseBuilder.payload(payloadFromResource(expectedResponse)); + } else { + responseBuilder.payload(new StringPayload(expectedResponse)); + } + } + + return getClient(requestSendsResponse(httpRequestBuilder.build(), responseBuilder.build())); + } +} diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/DomainAsyncClientTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/DomainAsyncClientTest.java deleted file mode 100644 index 78dcafa6bc..0000000000 --- a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/DomainAsyncClientTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.glesys.features; - -import java.util.Map; - -import org.jclouds.glesys.options.DomainOptions; -import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; -import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; -import org.jclouds.rest.internal.RestAnnotationProcessor; -import org.testng.annotations.Test; - -import com.google.inject.TypeLiteral; - -/** - * Tests annotation parsing of {@code DomainAsyncClient} - * - * @author Adam Lowe - */ -@Test(groups = "unit", testName = "DomainAsyncClientTest") -public class DomainAsyncClientTest extends BaseGleSYSAsyncClientTest { - public DomainAsyncClientTest() { - asyncClientClass = DomainAsyncClient.class; - remoteServicePrefix = "domain"; - } - - private Map.Entry domainName = newEntry("domain", "cl666666someuser"); - - public void testListDomains() throws Exception { - testMethod("listDomains", "list", "POST", true, ReturnEmptySetOnNotFoundOr404.class); - } - - public void testAddDomain() throws Exception { - testMethod("addDomain", "add", "POST", false, MapHttp4xxCodesToExceptions.class, newEntry("name", "cl66666_x"), - DomainOptions.Builder.primaryNameServer("ns1.somewhere.x").expire(1).minimum(1).refresh(1). - responsiblePerson("Tester").retry(1).ttl(1)); - testMethod("addDomain", "add", "POST", false, MapHttp4xxCodesToExceptions.class, newEntry("name", "cl66666_x")); - } - - public void testEditDomain() throws Exception { - testMethod("editDomain", "edit", "POST", false, MapHttp4xxCodesToExceptions.class, newEntry("domain", "x")); - } - - public void testDeleteDomain() throws Exception { - testMethod("deleteDomain", "delete", "POST", false, MapHttp4xxCodesToExceptions.class, domainName); - } - - @Override - protected TypeLiteral> createTypeLiteral() { - return new TypeLiteral>() { - }; - } -} diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/DomainClientExpectTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/DomainClientExpectTest.java new file mode 100644 index 0000000000..446413102a --- /dev/null +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/DomainClientExpectTest.java @@ -0,0 +1,84 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.glesys.features; + +import com.google.common.collect.ImmutableSet; +import org.jclouds.glesys.GleSYSClient; +import org.jclouds.glesys.domain.Domain; +import org.jclouds.glesys.options.DomainAddOptions; +import org.jclouds.rest.ResourceNotFoundException; +import org.testng.annotations.Test; + +import java.text.SimpleDateFormat; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +/** + * Tests annotation parsing of {@code DomainAsyncClient} + * + * @author Adam Lowe + */ +@Test(groups = "unit", testName = "DomainAsyncClientTest") +public class DomainClientExpectTest extends BaseGleSYSClientExpectTest { + public DomainClientExpectTest() { + remoteServicePrefix = "domain"; + } + + public void testListDomains() throws Exception { + DomainClient client = createMock("list", "POST", 200, "/domain_list.json"); + assertEquals(client.listDomains(), ImmutableSet.of( + Domain.builder().domain("adamlowe.net").createTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2011-12-20 10:58:51")).build() + )); + + // check not found response + client = createMock("list", "POST", 404, "/domain_list.json"); + assertTrue(client.listDomains().isEmpty()); + } + + public void testAddDomain() throws Exception { + createMock("add", "POST", 200, null, entry("name", "cl66666_x")).addDomain("cl66666_x"); + DomainAddOptions options = (DomainAddOptions) DomainAddOptions.Builder.primaryNameServer("ns1.somewhere.x").expire(1).minimum(1).refresh(1). + responsiblePerson("Tester").retry(1).ttl(1); createMock("add", "POST", 200, null, entry("name", "cl66666_x")); + createMock("add", "POST", 200, null, entry("name", "cl66666_x"), options).addDomain("cl66666_x", options); + } + + public void testEditDomain() throws Exception { + createMock("edit", "POST", 200, null, entry("domain", "x")).editDomain("x"); + } + + @Test(expectedExceptions = {ResourceNotFoundException.class}) + public void testEditDomainNotFound() throws Exception { + createMock("edit", "POST", 404, null, entry("domain", "x")).editDomain("x"); + } + + public void testDeleteDomain() throws Exception { + createMock("delete", "POST", 200, null, entry("domain", "cl666666someuser")).deleteDomain("cl666666someuser"); + } + + @Test(expectedExceptions = {ResourceNotFoundException.class}) + public void testDeleteDomainNotFound() throws Exception { + createMock("delete", "POST", 404, null, entry("domain", "cl666666someuser")).deleteDomain("cl666666someuser"); + } + + @Override + protected DomainClient getClient(GleSYSClient gleSYSClient) { + return gleSYSClient.getDomainClient(); + } +} diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/EmailAsyncClientTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/EmailAsyncClientTest.java deleted file mode 100644 index 84fb0cae0d..0000000000 --- a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/EmailAsyncClientTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.glesys.features; - -import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; -import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; -import org.jclouds.rest.internal.RestAnnotationProcessor; -import org.testng.annotations.Test; - -import com.google.inject.TypeLiteral; - -/** - * Tests annotation parsing of {@code ArchiveAsyncClient} - * - * @author Adam Lowe - */ -@Test(groups = "unit", testName = "EmailAsyncClientTest") -public class EmailAsyncClientTest extends BaseGleSYSAsyncClientTest { - public EmailAsyncClientTest() { - asyncClientClass = EmailAsyncClient.class; - remoteServicePrefix = "email"; - } - - public void testList() throws Exception { - testMethod("listAccounts", "list", "POST", true, ReturnEmptySetOnNotFoundOr404.class, newEntry("domain","test")); - } - - public void testOverview() throws Exception { - testMethod("getEmailOverview", "overview", "POST", true, ReturnEmptySetOnNotFoundOr404.class); - } - - public void testCreateAccount() throws Exception { - testMethod("createAccount", "createaccount", "POST", false, MapHttp4xxCodesToExceptions.class, - newEntry("emailaccount", "jclouds.org"), newEntry("password", "test@jclouds.org")); - } - - public void testCreateAlias() throws Exception { - testMethod("createAlias", "createalias", "POST", false, MapHttp4xxCodesToExceptions.class, - newEntry("emailalias", "test2@jclouds.org"), newEntry("goto", "test@jclouds.org")); - } - - public void testEditAlias() throws Exception { - testMethod("editAlias", "editalias", "POST", false, MapHttp4xxCodesToExceptions.class, - newEntry("emailalias", "test2@jclouds.org"), newEntry("goto", "test1@jclouds.org")); - } - - @Override - protected TypeLiteral> createTypeLiteral() { - return new TypeLiteral>() { - }; - } -} diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/EmailClientExpectTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/EmailClientExpectTest.java new file mode 100644 index 0000000000..57de0677f0 --- /dev/null +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/EmailClientExpectTest.java @@ -0,0 +1,116 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.glesys.features; + +import com.google.common.collect.ImmutableSet; +import org.jclouds.glesys.GleSYSClient; +import org.jclouds.glesys.domain.Email; +import org.jclouds.glesys.domain.EmailOverview; +import org.jclouds.glesys.domain.EmailOverviewDomain; +import org.jclouds.glesys.domain.EmailOverviewSummary; +import org.jclouds.rest.ResourceNotFoundException; +import org.testng.annotations.Test; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Set; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +/** + * Tests annotation parsing of {@code ArchiveAsyncClient} + * + * @author Adam Lowe + */ +@Test(groups = "unit", testName = "EmailAsyncClientTest") +public class EmailClientExpectTest extends BaseGleSYSClientExpectTest { + public EmailClientExpectTest() { + remoteServicePrefix = "email"; + } + + public void testList() throws Exception { + EmailClient client = createMock("list", "POST", 200, "/email_list.json", entry("domain", "test")); + + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); + Email.Builder builder = Email.builder().quota("200 MB").usedQuota("0 MB").antispamLevel(3).antiVirus(true).autoRespond(false).autoRespondSaveEmail(true).autoRespondMessage("false"); + Set expected = + ImmutableSet.of( + builder.account("test@adamlowe.net").created(dateFormat.parse("2011-12-22T12:13:14")).modified(dateFormat.parse("2011-12-22T12:13:35")).build(), + builder.account("test2@adamlowe.net").created(dateFormat.parse("2011-12-22T12:14:29")).modified(dateFormat.parse("2011-12-22T12:14:31")).build() + ); + assertEquals(client.listAccounts("test"), expected); + + // check not found response + client = createMock("list", "POST", 404, "Domain not found", entry("domain", "test")); + assertTrue(client.listAccounts("test").isEmpty()); + } + + public void testOverview() throws Exception { + EmailClient client = createMock("overview", "POST", 200, "/email_overview.json"); + + EmailOverviewSummary summary = EmailOverviewSummary.builder().accounts(2).maxAccounts(50).aliases(0).maxAliases(1000).build(); + EmailOverviewDomain domain = EmailOverviewDomain.builder().domain("adamlowe.net").accounts(2).aliases(0).build(); + EmailOverview expected = EmailOverview.builder().summary(summary).domains(domain).build(); + + assertEquals(client.getEmailOverview(), expected); + + assertNull(createMock("overview", "POST", 404, "Not found").getEmailOverview()); + } + + public void testCreateAccount() throws Exception { + createMock("createaccount", "POST", 200, null, + entry("emailaccount", "test@jclouds.org"), entry("password", "newpass")).createAccount("test@jclouds.org", "newpass"); + } + + @Test(expectedExceptions = {ResourceNotFoundException.class}) + public void testCreateAccountDomainNotFound() throws Exception { + createMock("createaccount", "POST", 404, null, + entry("emailaccount", "test@jclouds.org"), entry("password", "newpass")).createAccount("test@jclouds.org", "newpass"); + } + + + public void testCreateAlias() throws Exception { + createMock("createalias", "POST", 200, null, + entry("emailalias", "test2@jclouds.org"), entry("goto", "test@jclouds.org")).createAlias("test2@jclouds.org", "test@jclouds.org"); + } + + @Test(expectedExceptions = {ResourceNotFoundException.class}) + public void testCreateAliasNotFound() throws Exception { + createMock("createalias", "POST", 404, null, + entry("emailalias", "test2@jclouds.org"), entry("goto", "test@jclouds.org")).createAlias("test2@jclouds.org", "test@jclouds.org"); + } + + public void testEditAlias() throws Exception { + createMock("editalias", "POST", 200, null, + entry("emailalias", "test2@jclouds.org"), entry("goto", "test1@jclouds.org")).editAlias("test2@jclouds.org", "test1@jclouds.org"); + } + + @Test(expectedExceptions = {ResourceNotFoundException.class}) + public void testEditAliasNotFound() throws Exception { + createMock("editalias", "POST", 404, null, + entry("emailalias", "test2@jclouds.org"), entry("goto", "test1@jclouds.org")).editAlias("test2@jclouds.org", "test1@jclouds.org"); + } + + @Override + protected EmailClient getClient(GleSYSClient gleSYSClient) { + return gleSYSClient.getEmailClient(); + } +} diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerAsyncClientTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerAsyncClientTest.java deleted file mode 100644 index 283c622c6e..0000000000 --- a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerAsyncClientTest.java +++ /dev/null @@ -1,136 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.glesys.features; - -import java.util.Map; - -import org.jclouds.glesys.functions.ParseServerTemplatesFromHttpResponse; -import org.jclouds.glesys.options.ServerCloneOptions; -import org.jclouds.glesys.options.ServerCreateOptions; -import org.jclouds.glesys.options.ServerDestroyOptions; -import org.jclouds.glesys.options.ServerEditOptions; -import org.jclouds.glesys.options.ServerStatusOptions; -import org.jclouds.glesys.options.ServerStopOptions; -import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; -import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; -import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; -import org.jclouds.rest.internal.RestAnnotationProcessor; -import org.testng.annotations.Test; - -import com.google.inject.TypeLiteral; - -/** - * Tests annotation parsing of {@code ServerAsyncClient} - * - * @author Adrian Cole - * @author Adam Lowe - */ -@Test(groups = "unit", testName = "ServerAsyncClientTest") -public class ServerAsyncClientTest extends BaseGleSYSAsyncClientTest { - - public ServerAsyncClientTest() { - asyncClientClass = ServerAsyncClient.class; - remoteServicePrefix = "server"; - } - - private Map.Entry serverIdOnly = newEntry("serverid", "abcd"); - - public void testListServers() throws Exception { - testMethod("listServers", "list", "POST", true, ReturnEmptySetOnNotFoundOr404.class); - } - - public void testGetAllowedArguments() throws Exception { - testMethod("getServerAllowedArguments", "allowedarguments", "GET", true, MapHttp4xxCodesToExceptions.class); - } - - public void testGetTemplates() throws Exception { - testMethod("getTemplates", "templates", "GET", true, ParseServerTemplatesFromHttpResponse.class, - MapHttp4xxCodesToExceptions.class); - } - - public void testGetServer() throws Exception { - testMethod("getServerDetails", "details", "POST", true, ReturnNullOnNotFoundOr404.class, serverIdOnly); - } - - @Test - public void testCreateServer() throws Exception { - testMethod("createServer", "create", "POST", true, MapHttp4xxCodesToExceptions.class, - newEntry("datacenter", "Falkenberg"), newEntry("platform", "OpenVZ"), - newEntry("hostname", "jclouds-test"), newEntry("template", "Ubuntu%2032-bit"), - newEntry("disksize", 5), newEntry("memorysize", 512), newEntry("cpucores", 1), - newEntry("rootpw", "password"), newEntry("transfer", 50)); - testMethod("createServer", "create", "POST", true, MapHttp4xxCodesToExceptions.class, - newEntry("datacenter", "Falkenberg"), newEntry("platform", "OpenVZ"), - newEntry("hostname", "jclouds-test"), newEntry("template", "Ubuntu%2032-bit"), - newEntry("disksize", 5), newEntry("memorysize", 512), newEntry("cpucores", 1), - newEntry("rootpw", "password"), newEntry("transfer", 50), - ServerCreateOptions.Builder.description("Description-of-server").ip("10.0.0.1")); - } - - @Test - public void testEditServer() throws Exception { - testMethod("editServer", "edit", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly); - testMethod("editServer", "edit", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly, - ServerEditOptions.Builder.description("Description-of-server").disksize(1).memorysize(512).cpucores(1).hostname("jclouds-test")); - } - - @Test - public void testCloneServer() throws Exception { - testMethod("cloneServer", "clone", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly, newEntry("hostname", "somename")); - testMethod("cloneServer", "clone", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly, newEntry("hostname", "somename"), - ServerCloneOptions.Builder.description("Description-of-server").disksize(1).memorysize(512).cpucores(1).hostname("jclouds-test")); - } - - public void testGetServerStatus() throws Exception { - testMethod("getServerStatus", "status", "POST", true, ReturnNullOnNotFoundOr404.class, serverIdOnly); - testMethod("getServerStatus", "status", "POST", true, ReturnNullOnNotFoundOr404.class, serverIdOnly, ServerStatusOptions.Builder.state()); - } - - public void testGetServerLimits() throws Exception { - testMethod("getServerLimits", "limits", "POST", true, ReturnNullOnNotFoundOr404.class, serverIdOnly); - } - - public void testGetServerConsole() throws Exception { - testMethod("getServerConsole", "console", "POST", true, ReturnNullOnNotFoundOr404.class, serverIdOnly); - } - - public void testStartServer() throws Exception { - testMethod("startServer", "start", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly); - } - - public void testStopServer() throws Exception { - testMethod("stopServer", "stop", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly); - testMethod("stopServer", "stop", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly, ServerStopOptions.Builder.hard()); - } - - public void testRebootServer() throws Exception { - testMethod("rebootServer", "reboot", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly); - } - - public void testDestroyServer() throws Exception { - testMethod("destroyServer", "destroy", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly, ServerDestroyOptions.Builder.keepIp()); - testMethod("destroyServer", "destroy", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly, ServerDestroyOptions.Builder.discardIp()); - } - - @Override - protected TypeLiteral> createTypeLiteral() { - return new TypeLiteral>() { - }; - } -} diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerClientExpectTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerClientExpectTest.java new file mode 100644 index 0000000000..8e00e2ca04 --- /dev/null +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerClientExpectTest.java @@ -0,0 +1,158 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.glesys.features; + +import java.util.Map; + +import com.google.common.collect.ImmutableSet; +import org.jclouds.glesys.GleSYSClient; +import org.jclouds.glesys.domain.*; +import org.jclouds.glesys.options.ServerCloneOptions; +import org.jclouds.glesys.options.ServerCreateOptions; +import org.jclouds.glesys.options.ServerDestroyOptions; +import org.jclouds.glesys.options.ServerEditOptions; +import org.jclouds.glesys.options.ServerStatusOptions; +import org.jclouds.glesys.options.ServerStopOptions; +import org.jclouds.glesys.parse.ParseServerAllowedArgumentsTest; +import org.jclouds.glesys.parse.ParseServerDetailsTest; +import org.testng.annotations.Test; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +/** + * Tests annotation parsing of {@code ServerAsyncClient} + * + * @author Adrian Cole + * @author Adam Lowe + */ +@Test(groups = "unit", testName = "ServerAsyncClientTest") +public class ServerClientExpectTest extends BaseGleSYSClientExpectTest { + + public ServerClientExpectTest() { + remoteServicePrefix = "server"; + } + + private final String serverId = "abcd"; + private final Map.Entry serverIdOnly = entry("serverid", serverId); + + public void testListServers() throws Exception { + ServerClient client = createMock("list", "POST", 200, "/server_list.json"); + Server expected = Server.builder().id("vz1541880").hostname("mammamia").datacenter("Falkenberg").platform("OpenVZ").build(); + assertEquals(client.listServers(), ImmutableSet.of(expected)); + + // check we get empty set, if not-found + assertTrue(createMock("list", "POST", 404, "Not found").listServers().isEmpty()); + } + + public void testGetAllowedArguments() throws Exception { + ServerClient client = createMock("allowedarguments", "GET", 200, "/server_allowed_arguments.json"); + assertEquals(client.getServerAllowedArguments(), ParseServerAllowedArgumentsTest.getData()); + } + + public void testGetTemplates() throws Exception { + createMock("templates", "GET", 200, "/server_templates.json"); + } + + public void testGetServer() throws Exception { + ServerClient client = createMock("details", "POST", 200, "/server_details.json", serverIdOnly); + + ServerDetails actual = client.getServerDetails(serverId); + assertEquals(actual, ParseServerDetailsTest.getData()); + assertEquals(actual.toString(), ParseServerDetailsTest.getData().toString()); + } + + @Test + public void testCreateServer() throws Exception { + ServerCreated expected = ServerCreated.builder().hostname("jclouds-test").id("xm3630641").ips(ServerCreatedIp.builder().ip("109.74.10.27").build()).build(); + ServerClient client = createMock("create", "POST", 200, "/server_created.json", + entry("cpucores", 1), entry("memorysize", 512), + entry("datacenter", "Falkenberg"), entry("transfer", 50), + entry("rootpw", "password"), entry("hostname", "jclouds-test"), entry("platform", "OpenVZ"), + entry("template", "Ubuntu 32-bit"), + entry("disksize", 5)); + assertEquals(client.createServer("Falkenberg", "OpenVZ", "jclouds-test", "Ubuntu 32-bit", 5, 512, 1, "password", 50), expected); + + ServerCreateOptions options = ServerCreateOptions.Builder.description("Description-of-server").ip("10.0.0.1"); + client = createMock("create", "POST", 200, "/server_created.json", + entry("cpucores", 1), entry("memorysize", 512), + entry("datacenter", "Falkenberg"), entry("transfer", 50), + entry("rootpw", "password"), entry("hostname", "jclouds-test"), entry("platform", "OpenVZ"), + entry("template", "Ubuntu 32-bit"), + entry("disksize", 5), options); + assertEquals(client.createServer("Falkenberg", "OpenVZ", "jclouds-test", "Ubuntu 32-bit", 5, 512, 1, "password", 50, options), expected); + } + + @Test + public void testEditServer() throws Exception { + createMock("edit", "POST", 200, null, serverIdOnly).editServer(serverId); + ServerEditOptions options = + ServerEditOptions.Builder.description("Description-of-server").disksize(1).memorysize(512).cpucores(1).hostname("jclouds-test"); + createMock("edit", "POST", 200, null, serverIdOnly, options).editServer(serverId, options); + } + + @Test + public void testCloneServer() throws Exception { + createMock("clone", "POST", 200, "/server_created.json", serverIdOnly, entry("hostname", "somename")).cloneServer(serverId, "somename"); + ServerCloneOptions options = (ServerCloneOptions) ServerCloneOptions.Builder.description("Description-of-server").disksize(1).memorysize(512).cpucores(1); + createMock("clone", "POST", 200, "/server_created.json", serverIdOnly, entry("hostname", "somename"), options).cloneServer(serverId, "somename", options); + } + + public void testGetServerStatus() throws Exception { + createMock("status", "POST", 200, "/server_status.json", serverIdOnly).getServerStatus(serverId); + createMock("status", "POST", 200, "/server_status.json", serverIdOnly, ServerStatusOptions.Builder.state()). + getServerStatus(serverId, ServerStatusOptions.Builder.state()); + createMock("status", "POST", 404, "Not found", serverIdOnly).getServerStatus(serverId); + } + + public void testGetServerLimits() throws Exception { + createMock("limits", "POST", 200, "/server_limits.json", serverIdOnly).getServerLimits(serverId); + assertNull(createMock("limits", "POST", 404, "Not found", serverIdOnly).getServerLimits(serverId)); + } + + public void testGetServerConsole() throws Exception { + createMock("console", "POST", 200, "/server_console.json", serverIdOnly).getServerConsole(serverId); + assertNull(createMock("console", "POST", 404, "Not found", serverIdOnly).getServerConsole(serverId)); + } + + public void testStartServer() throws Exception { + createMock("start", "POST", 200, null, serverIdOnly).startServer(serverId); + } + + public void testStopServer() throws Exception { + createMock("stop", "POST", 200, null, serverIdOnly).stopServer(serverId); + createMock("stop", "POST", 200, null, serverIdOnly, ServerStopOptions.Builder.hard()).stopServer(serverId, ServerStopOptions.Builder.hard()); + } + + public void testRebootServer() throws Exception { + createMock("reboot", "POST", 200, null, serverIdOnly).rebootServer(serverId); + } + + public void testDestroyServer() throws Exception { + createMock("destroy", "POST", 200, null, serverIdOnly, ServerDestroyOptions.Builder.keepIp()).destroyServer(serverId, ServerDestroyOptions.Builder.keepIp()); + createMock("destroy", "POST", 200, null, serverIdOnly, ServerDestroyOptions.Builder.discardIp()).destroyServer(serverId, ServerDestroyOptions.Builder.discardIp()); + } + + @Override + protected ServerClient getClient(GleSYSClient gleSYSClient) { + return gleSYSClient.getServerClient(); + } + +} diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseServerAllowedArgumentsTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseServerAllowedArgumentsTest.java index cebde48f22..ca7cee8fec 100644 --- a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseServerAllowedArgumentsTest.java +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseServerAllowedArgumentsTest.java @@ -47,34 +47,37 @@ public class ParseServerAllowedArgumentsTest extends BaseItemParserTest expected() { - Map result = new LinkedHashMap(); - ServerAllowedArguments openvz = ServerAllowedArguments.builder() - .dataCenters("Amsterdam", "Falkenberg", "New York City", "Stockholm") - .memorySizes(128, 256, 512, 768, 1024, 1536, 2048, 2560, 3072, 3584, 4096, 5120, 6144, 7168, 8192, 9216, 10240, 11264, 12288) - .diskSizes(5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 120, 140, 150) - .cpuCores(1, 2, 3, 4, 5, 6, 7, 8) - .templates("Centos 5", "Centos 5 64-bit", "Centos 6 32-bit", "Centos 6 64-bit", "Debian 5.0 32-bit", - "Debian 5.0 64-bit", "Debian 6.0 32-bit", "Debian 6.0 64-bit", "Fedora Core 11", "Fedora Core 11 64-bit", - "Gentoo", "Gentoo 64-bit", "Scientific Linux 6", "Scientific Linux 6 64-bit", "Slackware 12", - "Ubuntu 10.04 LTS 32-bit", "Ubuntu 10.04 LTS 64-bit", "Ubuntu 11.04 64-bit") - .transfers(50, 100, 250, 500, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000) - .build(); - ServerAllowedArguments xen = ServerAllowedArguments.builder() - .memorySizes(512, 768, 1024, 1536, 2048, 2560, 3072, 3584, 4096, 5120, 6144, 7168, 8192, 9216, 10240, 11264, 12288, 14336, 16384) - .diskSizes(5, 10, 20, 30, 40, 50, 80, 100, 120, 140, 150, 160, 160, 200, 250, 300) - .cpuCores(1, 2, 3, 4, 5, 6, 7, 8) - .templates("CentOS 5.5 x64", "CentOS 5.5 x86", "Centos 6 x64", "Centos 6 x86", "Debian-6 x64", - "Debian 5.0.1 x64", "FreeBSD 8.2", "Gentoo 10.1 x64", "Ubuntu 8.04 x64", "Ubuntu 10.04 LTS 64-bit", - "Ubuntu 10.10 x64", "Ubuntu 11.04 x64", "Windows Server 2008 R2 x64 std", - "Windows Server 2008 R2 x64 web", "Windows Server 2008 x64 web", "Windows Server 2008 x86 web") - .transfers(50, 100, 250, 500, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000) - .dataCenters("Falkenberg") - .build(); - result.put("Xen", xen); - result.put("OpenVZ", openvz); - return result; + return getData(); } + public static Map getData() { + Map result = new LinkedHashMap(); + ServerAllowedArguments openvz = ServerAllowedArguments.builder() + .dataCenters("Amsterdam", "Falkenberg", "New York City", "Stockholm") + .memorySizes(128, 256, 512, 768, 1024, 1536, 2048, 2560, 3072, 3584, 4096, 5120, 6144, 7168, 8192, 9216, 10240, 11264, 12288) + .diskSizes(5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 120, 140, 150) + .cpuCores(1, 2, 3, 4, 5, 6, 7, 8) + .templates("Centos 5", "Centos 5 64-bit", "Centos 6 32-bit", "Centos 6 64-bit", "Debian 5.0 32-bit", + "Debian 5.0 64-bit", "Debian 6.0 32-bit", "Debian 6.0 64-bit", "Fedora Core 11", "Fedora Core 11 64-bit", + "Gentoo", "Gentoo 64-bit", "Scientific Linux 6", "Scientific Linux 6 64-bit", "Slackware 12", + "Ubuntu 10.04 LTS 32-bit", "Ubuntu 10.04 LTS 64-bit", "Ubuntu 11.04 64-bit") + .transfers(50, 100, 250, 500, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000) + .build(); + ServerAllowedArguments xen = ServerAllowedArguments.builder() + .memorySizes(512, 768, 1024, 1536, 2048, 2560, 3072, 3584, 4096, 5120, 6144, 7168, 8192, 9216, 10240, 11264, 12288, 14336, 16384) + .diskSizes(5, 10, 20, 30, 40, 50, 80, 100, 120, 140, 150, 160, 160, 200, 250, 300) + .cpuCores(1, 2, 3, 4, 5, 6, 7, 8) + .templates("CentOS 5.5 x64", "CentOS 5.5 x86", "Centos 6 x64", "Centos 6 x86", "Debian-6 x64", + "Debian 5.0.1 x64", "FreeBSD 8.2", "Gentoo 10.1 x64", "Ubuntu 8.04 x64", "Ubuntu 10.04 LTS 64-bit", + "Ubuntu 10.10 x64", "Ubuntu 11.04 x64", "Windows Server 2008 R2 x64 std", + "Windows Server 2008 R2 x64 web", "Windows Server 2008 x64 web", "Windows Server 2008 x86 web") + .transfers(50, 100, 250, 500, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000) + .dataCenters("Falkenberg") + .build(); + result.put("Xen", xen); + result.put("OpenVZ", openvz); + return result; + } protected Injector injector() { return Guice.createInjector(new GleSYSParserModule(), new GsonModule()); diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseServerDetailsTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseServerDetailsTest.java new file mode 100644 index 0000000000..80e19c035b --- /dev/null +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseServerDetailsTest.java @@ -0,0 +1,65 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.glesys.parse; + + +import com.google.inject.Guice; +import com.google.inject.Injector; +import org.jclouds.glesys.config.GleSYSParserModule; +import org.jclouds.glesys.domain.Cost; +import org.jclouds.glesys.domain.ServerCreated; +import org.jclouds.glesys.domain.ServerCreatedIp; +import org.jclouds.glesys.domain.ServerDetails; +import org.jclouds.json.BaseItemParserTest; +import org.jclouds.json.config.GsonModule; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +/** + * @author Adam Lowe + */ +@Test(groups = "unit", testName = "ParseServerDetailsTest") +public class ParseServerDetailsTest extends BaseItemParserTest { + + @Override + public String resource() { + return "/server_details.json"; + } + + @Override + @SelectJson("server") + @Consumes(MediaType.APPLICATION_JSON) + public ServerDetails expected() { + return getData(); + } + + public static ServerDetails getData() { + Cost cost = Cost.builder().amount(6.38).currency("EUR").timePeriod("month").build(); + return ServerDetails.builder().id("vz1908384").hostname("jclouds-unit").cpuCores(1). + memory(128).disk(5). + description("unit test server").datacenter("Falkenberg").platform("OpenVZ").cost(cost).build(); + } + + protected Injector injector() { + return Guice.createInjector(new GleSYSParserModule(), new GsonModule()); + } +} diff --git a/sandbox-providers/glesys/src/test/resources/server_details.json b/sandbox-providers/glesys/src/test/resources/server_details.json new file mode 100644 index 0000000000..55ae23ac82 --- /dev/null +++ b/sandbox-providers/glesys/src/test/resources/server_details.json @@ -0,0 +1 @@ +{"response":{"status":{"code":"200","text":"OK"},"server":{"serverid":"vz1908384","hostname":"jclouds-unit","description":"unit test server","cpucores":"1","memory":"128","disk":"5","transfer":"50","template":"Debian 6.0 64-bit","datacenter":"Falkenberg","managedhosting":"no","platform":"OpenVZ","cost":{"amount":6.38,"currency":"EUR","timeperiod":"month"},"iplist":[]},"debug":{"input":{"serverid":"vz1908384"}}}} \ No newline at end of file diff --git a/sandbox-providers/glesys/src/test/resources/server_limits.json b/sandbox-providers/glesys/src/test/resources/server_limits.json new file mode 100644 index 0000000000..6939127b7b --- /dev/null +++ b/sandbox-providers/glesys/src/test/resources/server_limits.json @@ -0,0 +1 @@ +{"response":{"status":{"code":"200","text":"OK"},"limits":{"numiptent":{"held":"24","maxheld":"24","barrier":"800","limit":"800","failcnt":0},"numfile":{"held":"91","maxheld":"140","barrier":"4000","limit":"4000","failcnt":0},"dcachesize":{"held":"695143","maxheld":"724260","barrier":"3500000","limit":"4375000","failcnt":0},"numothersock":{"held":"63","maxheld":"66","barrier":"6000","limit":"6000","failcnt":0},"dgramrcvbuf":{"held":"0","maxheld":"0","barrier":"209715200","limit":"262144000","failcnt":0},"othersockbuf":{"held":"4624","maxheld":"13080","barrier":"209715200","limit":"262144000","failcnt":0},"tcprcvbuf":{"held":"32768","maxheld":"32768","barrier":"209715200","limit":"262144000","failcnt":0},"tcpsndbuf":{"held":"34880","maxheld":"34880","barrier":"209715200","limit":"262144000","failcnt":0},"numsiginfo":{"held":"0","maxheld":"15","barrier":"256","limit":"256","failcnt":0},"numpty":{"held":"0","maxheld":"0","barrier":"32","limit":"32","failcnt":0},"numflock":{"held":"1","maxheld":"2","barrier":"376","limit":"412","failcnt":0},"numtcpsock":{"held":"2","maxheld":"2","barrier":"6000","limit":"6000","failcnt":0},"oomguarpages":{"held":"362","maxheld":"464","barrier":"32768","limit":"32768","failcnt":0},"vmguarpages":{"held":"0","maxheld":"0","barrier":"32768","limit":"32768","failcnt":0},"physpages":{"held":"2056","maxheld":"5194","barrier":"0","limit":"9223372036854775807","failcnt":0},"numproc":{"held":"21","maxheld":"33","barrier":"2000","limit":"2000","failcnt":0},"shmpages":{"held":"0","maxheld":"0","barrier":"512000","limit":"512000","failcnt":0},"privvmpages":{"held":"650","maxheld":"1718","barrier":"32768","limit":"32768","failcnt":0},"lockedpages":{"held":"0","maxheld":"0","barrier":"256","limit":"256","failcnt":0},"kmemsize":{"held":"1964946","maxheld":"2932736","barrier":"7680000","limit":"11520000","failcnt":0}},"debug":{"input":{"serverid":"vz1908384"}}}} \ No newline at end of file From f1a8649c3f7e5fda060e1ba2d72733984148da2f Mon Sep 17 00:00:00 2001 From: Adam Lowe Date: Tue, 10 Jan 2012 10:57:23 +0000 Subject: [PATCH 3/6] Removing erroneously committed files --- .../jclouds/glesys/compute/GleSYSComputeService.java | 11 ----------- .../config/GleSYSComputeServiceContextModule.java | 11 ----------- 2 files changed, 22 deletions(-) delete mode 100644 sandbox-providers/glesys/src/main/java/org/jclouds/glesys/compute/GleSYSComputeService.java delete mode 100644 sandbox-providers/glesys/src/main/java/org/jclouds/glesys/compute/config/GleSYSComputeServiceContextModule.java diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/compute/GleSYSComputeService.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/compute/GleSYSComputeService.java deleted file mode 100644 index 48266e0679..0000000000 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/compute/GleSYSComputeService.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.jclouds.glesys.compute; - -/** - * Created by IntelliJ IDEA. - * User: aplowe - * Date: 09/01/2012 - * Time: 13:03 - * To change this template use File | Settings | File Templates. - */ -public class GleSYSComputeService { -} diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/compute/config/GleSYSComputeServiceContextModule.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/compute/config/GleSYSComputeServiceContextModule.java deleted file mode 100644 index 94b33686bd..0000000000 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/compute/config/GleSYSComputeServiceContextModule.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.jclouds.glesys.compute.config; - -/** - * Created by IntelliJ IDEA. - * User: aplowe - * Date: 09/01/2012 - * Time: 13:05 - * To change this template use File | Settings | File Templates. - */ -public class GleSYSComputeServiceContextModule { -} From 41dedd049895a816ddaca2b3fe3a03e28c8c38b6 Mon Sep 17 00:00:00 2001 From: Adam Lowe Date: Wed, 11 Jan 2012 01:05:56 +0000 Subject: [PATCH 4/6] Re-writing ClientExpectTest in the required format --- .../features/ArchiveClientExpectTest.java | 209 ++++++-- .../features/BaseGleSYSAsyncClientTest.java | 1 - .../features/BaseGleSYSClientExpectTest.java | 115 ----- .../features/DomainClientExpectTest.java | 138 ++++-- .../features/EmailClientExpectTest.java | 179 +++++-- .../features/ServerClientExpectTest.java | 464 ++++++++++++++---- .../ParseServerAllowedArgumentsTest.java | 56 +-- .../glesys/parse/ParseServerDetailsTest.java | 4 - 8 files changed, 814 insertions(+), 352 deletions(-) delete mode 100644 sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/BaseGleSYSClientExpectTest.java diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ArchiveClientExpectTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ArchiveClientExpectTest.java index 524c8b7470..c0e48753c6 100644 --- a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ArchiveClientExpectTest.java +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ArchiveClientExpectTest.java @@ -19,89 +19,206 @@ package org.jclouds.glesys.features; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMultimap; import org.jclouds.glesys.GleSYSClient; import org.jclouds.glesys.domain.Archive; import org.jclouds.glesys.domain.ArchiveAllowedArguments; import org.jclouds.glesys.domain.ArchiveDetails; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.HttpResponseException; +import org.jclouds.rest.BaseRestClientExpectTest; import org.jclouds.rest.ResourceNotFoundException; import org.testng.annotations.Test; -import java.util.Map; +import java.net.URI; +import java.util.List; +import static org.jclouds.io.Payloads.newUrlEncodedFormPayload; import static org.testng.Assert.*; /** - * Tests annotation parsing of {@code ArchiveAsyncClient} + * Tests parsing of {@code ArchiveAsyncClient} * * @author Adam Lowe */ -@Test(groups = "unit", testName = "ArchiveAsyncClientTest") -public class ArchiveClientExpectTest extends BaseGleSYSClientExpectTest { +@Test(groups = "unit", testName = "ArchiveClientExpectTest") +public class ArchiveClientExpectTest extends BaseRestClientExpectTest { public ArchiveClientExpectTest() { - remoteServicePrefix = "archive"; + provider = "glesys"; } - private Map.Entry userName = entry("username", "xxxxxx_test1"); + public void testListArchivesWhenReponseIs2xx() throws Exception { + ArchiveClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/archive/list/format/json")) + .headers(ImmutableMultimap.builder() + .put("Accept", "application/json") + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .build(), + HttpResponse.builder().statusCode(200).payload(payloadFromResource("/archive_list.json")).build()) + .getArchiveClient(); - public void testListArchives() throws Exception { - ArchiveClient client = createMock("list", "POST", 200, "/archive_list.json"); - assertEquals(client.listArchives(), - ImmutableList.of(Archive.builder().username("xxxxx_test1").freeSize("20 GB").totalSize("20 GB").locked(false).build())); + List expected = ImmutableList.of( + Archive.builder().username("xxxxx_test1").freeSize("20 GB").totalSize("20 GB").locked(false).build()); + + assertEquals(client.listArchives(), expected); + } + + public void testListArchivesWhenResponseIs4xxReturnsEmpty() { + ArchiveClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/archive/list/format/json")) + .headers(ImmutableMultimap.builder() + .put("Accept", "application/json") + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()).build(), + HttpResponse.builder().statusCode(404).build()).getArchiveClient(); - // check not found response - client = createMock("list", "POST", 404, "Something not found"); assertTrue(client.listArchives().isEmpty()); } - public void testArchiveDetails() throws Exception { - assertEquals(createMock("details", "POST", 200, "/archive_details.json", userName).getArchiveDetails("xxxxxx_test1"), - ArchiveDetails.builder().username("xxxxxx_test1").freeSize("30 GB").totalSize("30 GB").locked(false).build()); - assertNull(createMock("details", "POST", 404, "/archive_details.json", userName).getArchiveDetails("xxxxxx_test1")); + public void testArchiveDetailsWhenResponseIs2xx() throws Exception { + ArchiveClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/archive/details/format/json")) + .headers(ImmutableMultimap.builder() + .put("Accept", "application/json") + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload( + ImmutableMultimap.builder().put("username", "xxxxxx_test1").build())).build(), + HttpResponse.builder().statusCode(200).payload(payloadFromResource("/archive_details.json")).build()) + .getArchiveClient(); + ArchiveDetails expected = ArchiveDetails.builder().username("xxxxxx_test1").freeSize("30 GB").totalSize("30 GB").locked(false).build(); + + assertEquals(client.getArchiveDetails("xxxxxx_test1"), expected); } - public void testCreateArchive() throws Exception { - createMock("create", "POST", 200, null, userName, entry("size", 5), - entry("password", "somepass")).createArchive(userName.getValue(), "somepass", 5); + public void testArchiveDetailsWhenResponseIs4xxReturnsNull() { + ArchiveClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/archive/details/format/json")) + .headers(ImmutableMultimap.builder() + .put("Accept", "application/json") + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload( + ImmutableMultimap.builder().put("username", "xxxxxx_test1").build())).build(), + HttpResponse.builder().statusCode(404).build()) + .getArchiveClient(); + assertNull(client.getArchiveDetails("xxxxxx_test1")); } - public void testDeleteArchive() throws Exception { - createMock("delete", "POST", 200, null, userName).deleteArchive(userName.getValue()); + public void testCreateArchiveWhenResponseIs2xx() throws Exception { + ArchiveClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/archive/create/format/json")) + .headers(ImmutableMultimap.builder().put( + "Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("username", "xxxxxx_test1") + .put("size", "5") + .put("password", "somepass").build())).build(), + HttpResponse.builder().statusCode(200).build()).getArchiveClient(); + client.createArchive("xxxxxx_test1", "somepass", 5); + } + + public void testDeleteArchiveWhenResponseIs2xx() throws Exception { + ArchiveClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/archive/delete/format/json")) + .headers(ImmutableMultimap.builder().put( + "Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("username", "xxxxxx_test1").build())).build(), + HttpResponse.builder().statusCode(200).build()).getArchiveClient(); + + client.deleteArchive("xxxxxx_test1"); + } + + @Test(expectedExceptions = {HttpResponseException.class}) + public void testDeleteArchiveWhenResponseIs4xxThrows() throws Exception { + ArchiveClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/archive/delete/format/json")) + .headers(ImmutableMultimap.builder().put( + "Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("username", "xxxxxx_test1").build())).build(), + HttpResponse.builder().statusCode(402).build()).getArchiveClient(); + client.deleteArchive("xxxxxx_test1"); + } + + public void testResizeArchiveWhenResponseIs2xx() throws Exception { + ArchiveClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/archive/resize/format/json")) + .headers(ImmutableMultimap.builder().put( + "Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("username", "username1") + .put("size", "5").build())).build(), + HttpResponse.builder().statusCode(200).build()).getArchiveClient(); + + client.resizeArchive("username1", 5); } @Test(expectedExceptions = {ResourceNotFoundException.class}) - public void testDeleteArchiveNotFound() throws Exception { - createMock("delete", "POST", 404, null, userName).deleteArchive(userName.getValue()); + public void testResizeArchiveWhenResponseIs4xxThrows() throws Exception { + ArchiveClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/archive/resize/format/json")) + .headers(ImmutableMultimap.builder().put( + "Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("username", "username1") + .put("size", "5").build())).build(), + HttpResponse.builder().statusCode(404).build()).getArchiveClient(); + + client.resizeArchive("username1", 5); } - public void testResizeArchive() throws Exception { - createMock("resize", "POST", 200, null, entry("username", "username"), - entry("size", "5")).resizeArchive("username", 5); + public void testChangeArchivePasswordWhenResponseIs2xx() throws Exception { + ArchiveClient client = requestSendsResponse( + HttpRequest.builder().method("POST") + .endpoint(URI.create("https://api.glesys.com/archive/changepassword/format/json")) + .headers(ImmutableMultimap.builder().put( + "Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("username", "username") + .put("password", "newpass").build())).build(), + HttpResponse.builder().statusCode(200).build()).getArchiveClient(); + + client.changeArchivePassword("username", "newpass"); } @Test(expectedExceptions = {ResourceNotFoundException.class}) - public void testResizeArchiveNotFound() throws Exception { - createMock("resize", "POST", 404, null, entry("username", "username"), entry("size", "5")).resizeArchive("username", 5); - } - - public void testChangeArchivePassword() throws Exception { - createMock("changepassword", "POST", 200, null, userName, - entry("password", "newpass")).changeArchivePassword(userName.getValue(), "newpass"); + public void testChangeArchivePasswordWhenResponseIs4xxThrows() throws Exception { + ArchiveClient client = requestSendsResponse( + HttpRequest.builder().method("POST") + .endpoint(URI.create("https://api.glesys.com/archive/changepassword/format/json")) + .headers(ImmutableMultimap.builder().put( + "Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("username", "username") + .put("password", "newpass").build())).build(), + HttpResponse.builder().statusCode(404).build()).getArchiveClient(); + + client.changeArchivePassword("username", "newpass"); } - @Test(expectedExceptions = {ResourceNotFoundException.class}) - public void testChangeArchivePasswordNotFound() throws Exception { - createMock("changepassword", "POST", 404, null, userName, - entry("password", "newpass")).changeArchivePassword(userName.getValue(), "newpass"); - } - - public void testGetArchiveAllowedArguments() throws Exception { - assertEquals(createMock("allowedarguments", "GET", 200, "/archive_allowed_arguments.json").getArchiveAllowedArguments(), - ArchiveAllowedArguments.builder().archiveSizes(10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 125, 150, 175, 200, 225, 250, 275, 300, 325, 350, 375, 400, 425, 450, 475, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000).build()); - assertNull(createMock("allowedarguments", "GET", 404, "/archive_allowed_arguments.json").getArchiveAllowedArguments()); + public void testGetArchiveAllowedArgumentsWhenResponseIs2xx() throws Exception { + ArchiveClient client = requestSendsResponse( + HttpRequest.builder().method("GET") + .endpoint(URI.create("https://api.glesys.com/archive/allowedarguments/format/json")) + .headers(ImmutableMultimap.builder() + .put("Accept", "application/json") + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==") + .build()).build(), + HttpResponse.builder().statusCode(200).payload(payloadFromResource("/archive_allowed_arguments.json")).build()).getArchiveClient(); + ArchiveAllowedArguments expected = ArchiveAllowedArguments.builder().archiveSizes(10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 125, 150, 175, 200, 225, 250, 275, 300, 325, 350, 375, 400, 425, 450, 475, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000).build(); + + assertEquals(client.getArchiveAllowedArguments(), expected); } - @Override - protected ArchiveClient getClient(GleSYSClient gleSYSClient) { - return gleSYSClient.getArchiveClient(); + public void testGetArchiveAllowedArguments4xxWhenResponseIs2xx() throws Exception { + ArchiveClient client = requestSendsResponse( + HttpRequest.builder().method("GET") + .endpoint(URI.create("https://api.glesys.com/archive/allowedarguments/format/json")) + .headers(ImmutableMultimap.builder() + .put("Accept", "application/json") + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()).build(), + HttpResponse.builder().statusCode(404).build()).getArchiveClient(); + + assertNull(client.getArchiveAllowedArguments()); } } diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/BaseGleSYSAsyncClientTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/BaseGleSYSAsyncClientTest.java index 43d645325a..e52ef601a7 100644 --- a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/BaseGleSYSAsyncClientTest.java +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/BaseGleSYSAsyncClientTest.java @@ -45,7 +45,6 @@ import com.google.common.collect.Maps; /** * @author Adrian Cole - * @author Adam Lowe */ public abstract class BaseGleSYSAsyncClientTest extends RestClientTest { diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/BaseGleSYSClientExpectTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/BaseGleSYSClientExpectTest.java deleted file mode 100644 index 5e7f0e02ca..0000000000 --- a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/BaseGleSYSClientExpectTest.java +++ /dev/null @@ -1,115 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.glesys.features; - -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.LinkedHashMultimap; -import com.google.common.collect.Maps; -import com.google.common.collect.Multimap; -import org.jclouds.glesys.GleSYSClient; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; -import org.jclouds.http.options.BaseHttpRequestOptions; -import org.jclouds.io.payloads.StringPayload; -import org.jclouds.rest.BaseRestClientExpectTest; - -import java.net.URI; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import static org.jclouds.io.Payloads.newUrlEncodedFormPayload; - -/** - * Support for short-hand generation of ClientExpectTests for the GleSYS clients - * - * @author Adam Lowe - */ -public abstract class BaseGleSYSClientExpectTest extends BaseRestClientExpectTest { - protected String remoteServicePrefix; - - public BaseGleSYSClientExpectTest() { - provider = "glesys"; - } - - protected abstract T getClient(GleSYSClient gleSYSClient); - - protected Map.Entry entry(String key, Object value) { - return Maps.immutableEntry(key, value.toString()); - } - - /** - * Build a mock of a GleSYS client that responds as instructed - * - * @param remoteCall the name of the expected call on the remote server - * @param httpMethod "GET" or "POST" - * @param returnCode the http status code expected (ordinarily 200) - * @param expectedResponse ensure this is not-null for calls that expect a response - for OK responses this should be - * the classpath location of a file with a valid server response, for errors any String - * @param args either Map.Entry or BaseHttpRequestOption objects that make up the arguments to the method - * @return the appropriate client for test to invoke methods on (by calling getClient() in the appropriate subclass) - */ - @SuppressWarnings("unchecked") - protected T createMock(String remoteCall, String httpMethod, int returnCode, String expectedResponse, Object... args) throws Exception { - List argValues = new ArrayList(); - - Multimap map = LinkedHashMultimap.create(); - - for (Object arg : args) { - if (arg instanceof BaseHttpRequestOptions) { - for (Map.Entry httpEntry : ((BaseHttpRequestOptions) arg).buildFormParameters().entries()) { - map.put(httpEntry.getKey(), httpEntry.getValue()); - } - argValues.add(arg); - } else { - Map.Entry entry = (Map.Entry) arg; - map.put(entry.getKey(), entry.getValue()); - argValues.add(entry.getValue()); - } - } - - HttpRequest.Builder httpRequestBuilder = HttpRequest.builder().method(httpMethod).endpoint( - URI.create("https://api.glesys.com/" + remoteServicePrefix + "/" + remoteCall + "/format/json")); - - if (expectedResponse == null) { - httpRequestBuilder.headers(ImmutableMultimap.builder() - .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()); - } else { - httpRequestBuilder.headers(ImmutableMultimap.builder() - .put("Accept", "application/json").put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()); - } - - if (!map.isEmpty()) { - httpRequestBuilder.payload(newUrlEncodedFormPayload( - ImmutableMultimap.builder().putAll(map).build())); - } - - HttpResponse.Builder responseBuilder = HttpResponse.builder().statusCode(returnCode); - - if (expectedResponse != null) { - if (returnCode < 300) { - responseBuilder.payload(payloadFromResource(expectedResponse)); - } else { - responseBuilder.payload(new StringPayload(expectedResponse)); - } - } - - return getClient(requestSendsResponse(httpRequestBuilder.build(), responseBuilder.build())); - } -} diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/DomainClientExpectTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/DomainClientExpectTest.java index 446413102a..b51208b08b 100644 --- a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/DomainClientExpectTest.java +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/DomainClientExpectTest.java @@ -18,15 +18,22 @@ */ package org.jclouds.glesys.features; +import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableSet; import org.jclouds.glesys.GleSYSClient; import org.jclouds.glesys.domain.Domain; import org.jclouds.glesys.options.DomainAddOptions; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.rest.BaseRestClientExpectTest; import org.jclouds.rest.ResourceNotFoundException; import org.testng.annotations.Test; +import java.net.URI; import java.text.SimpleDateFormat; +import java.util.Set; +import static org.jclouds.io.Payloads.newUrlEncodedFormPayload; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; @@ -35,50 +42,123 @@ import static org.testng.Assert.assertTrue; * * @author Adam Lowe */ -@Test(groups = "unit", testName = "DomainAsyncClientTest") -public class DomainClientExpectTest extends BaseGleSYSClientExpectTest { +@Test(groups = "unit", testName = "DomainClientExpectTest") +public class DomainClientExpectTest extends BaseRestClientExpectTest { public DomainClientExpectTest() { - remoteServicePrefix = "domain"; + provider = "glesys"; } - public void testListDomains() throws Exception { - DomainClient client = createMock("list", "POST", 200, "/domain_list.json"); - assertEquals(client.listDomains(), ImmutableSet.of( - Domain.builder().domain("adamlowe.net").createTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2011-12-20 10:58:51")).build() - )); + public void testListDomainsWhenResponseIs2xx() throws Exception { + //DomainClient client = createMock("list", "POST", 200, "/domain_list.json"); + + DomainClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/domain/list/format/json")) + .headers(ImmutableMultimap.builder() + .put("Accept", "application/json") + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .build(), + HttpResponse.builder().statusCode(200).payload(payloadFromResource("/domain_list.json")).build()).getDomainClient(); + + Set expected = ImmutableSet.of( + Domain.builder().domain("adamlowe.net").createTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2011-12-20 10:58:51")).build()); + + assertEquals(client.listDomains(), expected); + } + + public void testListDomainsWhenResponseIs4xxReturnsEmpty() throws Exception { + DomainClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/domain/list/format/json")) + .headers(ImmutableMultimap.builder() + .put("Accept", "application/json") + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .build(), + HttpResponse.builder().statusCode(404).build()).getDomainClient(); - // check not found response - client = createMock("list", "POST", 404, "/domain_list.json"); assertTrue(client.listDomains().isEmpty()); } - public void testAddDomain() throws Exception { - createMock("add", "POST", 200, null, entry("name", "cl66666_x")).addDomain("cl66666_x"); - DomainAddOptions options = (DomainAddOptions) DomainAddOptions.Builder.primaryNameServer("ns1.somewhere.x").expire(1).minimum(1).refresh(1). - responsiblePerson("Tester").retry(1).ttl(1); createMock("add", "POST", 200, null, entry("name", "cl66666_x")); - createMock("add", "POST", 200, null, entry("name", "cl66666_x"), options).addDomain("cl66666_x", options); + public void testAddDomainWhenResponseIs2xx() throws Exception { + DomainClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/domain/add/format/json")) + .headers(ImmutableMultimap.builder().put( + "Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("name", "cl66666_x").build())).build(), + HttpResponse.builder().statusCode(200).build()).getDomainClient(); + + client.addDomain("cl66666_x"); } - public void testEditDomain() throws Exception { - createMock("edit", "POST", 200, null, entry("domain", "x")).editDomain("x"); + + public void testAddDomainWithOptsWhenResponseIs2xx() throws Exception { + DomainClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/domain/add/format/json")) + .headers(ImmutableMultimap.builder().put( + "Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("name", "cl66666_x") + .put("primary_ns", "ns1.somewhere.x") + .put("expire", "1") + .put("minimum", "1") + .put("refresh", "1") + .put("resp_person", "Tester.") + .put("retry", "1") + .put("ttl", "1") + .build())).build(), + HttpResponse.builder().statusCode(200).build()).getDomainClient(); + DomainAddOptions options = (DomainAddOptions) DomainAddOptions.Builder.primaryNameServer("ns1.somewhere.x") + .expire(1).minimum(1).refresh(1).responsiblePerson("Tester").retry(1).ttl(1); + + client.addDomain("cl66666_x", options); + } + + public void testEditDomainWhenResponseIs2xx() throws Exception { + DomainClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/domain/edit/format/json")) + .headers(ImmutableMultimap.builder().put( + "Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("domain", "x").build())).build(), + HttpResponse.builder().statusCode(200).build()).getDomainClient(); + + client.editDomain("x"); } @Test(expectedExceptions = {ResourceNotFoundException.class}) - public void testEditDomainNotFound() throws Exception { - createMock("edit", "POST", 404, null, entry("domain", "x")).editDomain("x"); + public void testEditDomainWhenResponseIs4xxThrows() throws Exception { + DomainClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/domain/edit/format/json")) + .headers(ImmutableMultimap.builder().put( + "Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("domain", "x").build())).build(), + HttpResponse.builder().statusCode(404).build()).getDomainClient(); + + client.editDomain("x"); } - - public void testDeleteDomain() throws Exception { - createMock("delete", "POST", 200, null, entry("domain", "cl666666someuser")).deleteDomain("cl666666someuser"); + + public void testDeleteDomainWhenResponseIs2xx() throws Exception { + DomainClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/domain/delete/format/json")) + .headers(ImmutableMultimap.builder().put( + "Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("domain", "x").build())).build(), + HttpResponse.builder().statusCode(200).build()).getDomainClient(); + + client.deleteDomain("x"); } @Test(expectedExceptions = {ResourceNotFoundException.class}) - public void testDeleteDomainNotFound() throws Exception { - createMock("delete", "POST", 404, null, entry("domain", "cl666666someuser")).deleteDomain("cl666666someuser"); - } - - @Override - protected DomainClient getClient(GleSYSClient gleSYSClient) { - return gleSYSClient.getDomainClient(); + public void testDeleteDomainWhenResponseIs4xxThrows() throws Exception { + DomainClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/domain/delete/format/json")) + .headers(ImmutableMultimap.builder().put( + "Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("domain", "x").build())).build(), + HttpResponse.builder().statusCode(404).build()).getDomainClient(); + + client.deleteDomain("x"); } } diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/EmailClientExpectTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/EmailClientExpectTest.java index 57de0677f0..ac95aae1d3 100644 --- a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/EmailClientExpectTest.java +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/EmailClientExpectTest.java @@ -18,36 +18,51 @@ */ package org.jclouds.glesys.features; +import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableSet; import org.jclouds.glesys.GleSYSClient; import org.jclouds.glesys.domain.Email; import org.jclouds.glesys.domain.EmailOverview; import org.jclouds.glesys.domain.EmailOverviewDomain; import org.jclouds.glesys.domain.EmailOverviewSummary; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.HttpResponseException; +import org.jclouds.rest.AuthorizationException; +import org.jclouds.rest.BaseRestClientExpectTest; import org.jclouds.rest.ResourceNotFoundException; import org.testng.annotations.Test; +import java.net.URI; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Set; +import static org.jclouds.io.Payloads.newUrlEncodedFormPayload; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; /** - * Tests annotation parsing of {@code ArchiveAsyncClient} - * + * Tests annotation parsing of {@code EmailClient} + * * @author Adam Lowe */ @Test(groups = "unit", testName = "EmailAsyncClientTest") -public class EmailClientExpectTest extends BaseGleSYSClientExpectTest { +public class EmailClientExpectTest extends BaseRestClientExpectTest { public EmailClientExpectTest() { - remoteServicePrefix = "email"; + provider = "glesys"; } - public void testList() throws Exception { - EmailClient client = createMock("list", "POST", 200, "/email_list.json", entry("domain", "test")); + public void testListWhenResponseIs2xx() throws Exception { + EmailClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/email/list/format/json")) + .headers(ImmutableMultimap.builder() + .put("Accept", "application/json") + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload( + ImmutableMultimap.builder().put("domain", "test").build())).build(), + HttpResponse.builder().statusCode(200).payload(payloadFromResource("/email_list.json")).build()).getEmailClient(); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); Email.Builder builder = Email.builder().quota("200 MB").usedQuota("0 MB").antispamLevel(3).antiVirus(true).autoRespond(false).autoRespondSaveEmail(true).autoRespondMessage("false"); @@ -56,61 +71,141 @@ public class EmailClientExpectTest extends BaseGleSYSClientExpectTestbuilder() + .put("Accept", "application/json") + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload( + ImmutableMultimap.builder().put("domain", "test").build())).build(), + HttpResponse.builder().statusCode(404).build()).getEmailClient(); + assertTrue(client.listAccounts("test").isEmpty()); } - public void testOverview() throws Exception { - EmailClient client = createMock("overview", "POST", 200, "/email_overview.json"); + public void testOverviewWhenResponseIs2xx() throws Exception { + EmailClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/email/overview/format/json")) + .headers(ImmutableMultimap.builder() + .put("Accept", "application/json") + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .build(), + HttpResponse.builder().statusCode(200).payload(payloadFromResource("/email_overview.json")).build()).getEmailClient(); EmailOverviewSummary summary = EmailOverviewSummary.builder().accounts(2).maxAccounts(50).aliases(0).maxAliases(1000).build(); EmailOverviewDomain domain = EmailOverviewDomain.builder().domain("adamlowe.net").accounts(2).aliases(0).build(); EmailOverview expected = EmailOverview.builder().summary(summary).domains(domain).build(); - + assertEquals(client.getEmailOverview(), expected); - - assertNull(createMock("overview", "POST", 404, "Not found").getEmailOverview()); } - public void testCreateAccount() throws Exception { - createMock("createaccount", "POST", 200, null, - entry("emailaccount", "test@jclouds.org"), entry("password", "newpass")).createAccount("test@jclouds.org", "newpass"); + public void testOverviewWhenResponseIs404ReturnsNull() throws Exception { + EmailClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/email/overview/format/json")) + .headers(ImmutableMultimap.builder() + .put("Accept", "application/json") + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .build(), + HttpResponse.builder().statusCode(404).build()).getEmailClient(); + + assertNull(client.getEmailOverview()); + } + + public void testCreateAccountWhenResponseIs2xx() throws Exception { + EmailClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/email/createaccount/format/json")) + .headers(ImmutableMultimap.builder() + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("emailaccount", "test@jclouds.org") + .put("password", "newpass") + .build())) + .build(), + HttpResponse.builder().statusCode(200).build()).getEmailClient(); + + client.createAccount("test@jclouds.org", "newpass"); } @Test(expectedExceptions = {ResourceNotFoundException.class}) - public void testCreateAccountDomainNotFound() throws Exception { - createMock("createaccount", "POST", 404, null, - entry("emailaccount", "test@jclouds.org"), entry("password", "newpass")).createAccount("test@jclouds.org", "newpass"); + public void testCreateAccountWhenResponseIs4xxThrows() throws Exception { + EmailClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/email/createaccount/format/json")) + .headers(ImmutableMultimap.builder() + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("emailaccount", "test@jclouds.org") + .put("password", "newpass") + .build())) + .build(), + HttpResponse.builder().statusCode(404).build()).getEmailClient(); + + client.createAccount("test@jclouds.org", "newpass"); } - - public void testCreateAlias() throws Exception { - createMock("createalias", "POST", 200, null, - entry("emailalias", "test2@jclouds.org"), entry("goto", "test@jclouds.org")).createAlias("test2@jclouds.org", "test@jclouds.org"); + public void testCreateAliasWhenResponseIs2xx() throws Exception { + EmailClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/email/createalias/format/json")) + .headers(ImmutableMultimap.builder() + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("emailalias", "test2@jclouds.org") + .put("goto", "test@jclouds.org") + .build())) + .build(), + HttpResponse.builder().statusCode(200).build()).getEmailClient(); + + client.createAlias("test2@jclouds.org", "test@jclouds.org"); + } + + @Test(expectedExceptions = {AuthorizationException.class}) + public void testCreateAliasWhenResponseIs4xxThrows() throws Exception { + EmailClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/email/createalias/format/json")) + .headers(ImmutableMultimap.builder() + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("emailalias", "test2@jclouds.org") + .put("goto", "test@jclouds.org") + .build())) + .build(), + HttpResponse.builder().statusCode(401).build()).getEmailClient(); + + client.createAlias("test2@jclouds.org", "test@jclouds.org"); + } + + public void testEditAliasWhenResponseIs2xx() throws Exception { + EmailClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/email/editalias/format/json")) + .headers(ImmutableMultimap.builder() + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("emailalias", "test2@jclouds.org") + .put("goto", "test@jclouds.org") + .build())) + .build(), + HttpResponse.builder().statusCode(200).build()).getEmailClient(); + + client.editAlias("test2@jclouds.org", "test@jclouds.org"); } @Test(expectedExceptions = {ResourceNotFoundException.class}) - public void testCreateAliasNotFound() throws Exception { - createMock("createalias", "POST", 404, null, - entry("emailalias", "test2@jclouds.org"), entry("goto", "test@jclouds.org")).createAlias("test2@jclouds.org", "test@jclouds.org"); - } + public void testEditAliasWhenResponseIs4xxThrows() throws Exception { + EmailClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/email/editalias/format/json")) + .headers(ImmutableMultimap.builder() + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("emailalias", "test2@jclouds.org") + .put("goto", "test@jclouds.org") + .build())) + .build(), + HttpResponse.builder().statusCode(404).build()).getEmailClient(); - public void testEditAlias() throws Exception { - createMock("editalias", "POST", 200, null, - entry("emailalias", "test2@jclouds.org"), entry("goto", "test1@jclouds.org")).editAlias("test2@jclouds.org", "test1@jclouds.org"); - } - - @Test(expectedExceptions = {ResourceNotFoundException.class}) - public void testEditAliasNotFound() throws Exception { - createMock("editalias", "POST", 404, null, - entry("emailalias", "test2@jclouds.org"), entry("goto", "test1@jclouds.org")).editAlias("test2@jclouds.org", "test1@jclouds.org"); - } - - @Override - protected EmailClient getClient(GleSYSClient gleSYSClient) { - return gleSYSClient.getEmailClient(); + client.editAlias("test2@jclouds.org", "test@jclouds.org"); } } diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerClientExpectTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerClientExpectTest.java index 8e00e2ca04..4826b52684 100644 --- a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerClientExpectTest.java +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerClientExpectTest.java @@ -18,24 +18,26 @@ */ package org.jclouds.glesys.features; -import java.util.Map; - +import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableSet; import org.jclouds.glesys.GleSYSClient; -import org.jclouds.glesys.domain.*; -import org.jclouds.glesys.options.ServerCloneOptions; -import org.jclouds.glesys.options.ServerCreateOptions; -import org.jclouds.glesys.options.ServerDestroyOptions; -import org.jclouds.glesys.options.ServerEditOptions; -import org.jclouds.glesys.options.ServerStatusOptions; -import org.jclouds.glesys.options.ServerStopOptions; -import org.jclouds.glesys.parse.ParseServerAllowedArgumentsTest; -import org.jclouds.glesys.parse.ParseServerDetailsTest; +import org.jclouds.glesys.domain.Server; +import org.jclouds.glesys.domain.ServerCreated; +import org.jclouds.glesys.domain.ServerCreatedIp; +import org.jclouds.glesys.domain.ServerDetails; +import org.jclouds.glesys.options.*; +import org.jclouds.glesys.parse.*; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.rest.AuthorizationException; +import org.jclouds.rest.BaseRestClientExpectTest; +import org.jclouds.rest.ResourceNotFoundException; import org.testng.annotations.Test; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; +import java.net.URI; + +import static org.jclouds.io.Payloads.newUrlEncodedFormPayload; +import static org.testng.Assert.*; /** * Tests annotation parsing of {@code ServerAsyncClient} @@ -44,115 +46,407 @@ import static org.testng.Assert.assertTrue; * @author Adam Lowe */ @Test(groups = "unit", testName = "ServerAsyncClientTest") -public class ServerClientExpectTest extends BaseGleSYSClientExpectTest { +public class ServerClientExpectTest extends BaseRestClientExpectTest { public ServerClientExpectTest() { - remoteServicePrefix = "server"; + provider = "glesys"; } - private final String serverId = "abcd"; - private final Map.Entry serverIdOnly = entry("serverid", serverId); - - public void testListServers() throws Exception { - ServerClient client = createMock("list", "POST", 200, "/server_list.json"); + public void testListServersWhenResponseIs2xx() throws Exception { + ServerClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/list/format/json")) + .headers(ImmutableMultimap.builder() + .put("Accept", "application/json") + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()).build(), + HttpResponse.builder().statusCode(204).payload(payloadFromResource("/server_list.json")).build()).getServerClient(); Server expected = Server.builder().id("vz1541880").hostname("mammamia").datacenter("Falkenberg").platform("OpenVZ").build(); + assertEquals(client.listServers(), ImmutableSet.of(expected)); - - // check we get empty set, if not-found - assertTrue(createMock("list", "POST", 404, "Not found").listServers().isEmpty()); - } - - public void testGetAllowedArguments() throws Exception { - ServerClient client = createMock("allowedarguments", "GET", 200, "/server_allowed_arguments.json"); - assertEquals(client.getServerAllowedArguments(), ParseServerAllowedArgumentsTest.getData()); } - public void testGetTemplates() throws Exception { - createMock("templates", "GET", 200, "/server_templates.json"); + public void testListServersWhenReponseIs404IsEmpty() { + ServerClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/list/format/json")) + .headers(ImmutableMultimap.builder() + .put("Accept", "application/json") + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()).build(), + HttpResponse.builder().statusCode(404).build()).getServerClient(); + + assertTrue(client.listServers().isEmpty()); } - public void testGetServer() throws Exception { - ServerClient client = createMock("details", "POST", 200, "/server_details.json", serverIdOnly); + public void testGetAllowedArgumentsWhenResponseIs2xx() throws Exception { + ServerClient client = requestSendsResponse( + HttpRequest.builder().method("GET").endpoint(URI.create("https://api.glesys.com/server/allowedarguments/format/json")) + .headers(ImmutableMultimap.builder() + .put("Accept", "application/json") + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()).build(), + HttpResponse.builder().statusCode(204).payload(payloadFromResource("/server_allowed_arguments.json")).build()).getServerClient(); - ServerDetails actual = client.getServerDetails(serverId); - assertEquals(actual, ParseServerDetailsTest.getData()); - assertEquals(actual.toString(), ParseServerDetailsTest.getData().toString()); + assertEquals(client.getServerAllowedArguments(), new ParseServerAllowedArgumentsTest().expected()); } - + + public void testGetTemplatesWhenResponseIs2xx() throws Exception { + ServerClient client = requestSendsResponse( + HttpRequest.builder().method("GET").endpoint(URI.create("https://api.glesys.com/server/templates/format/json")) + .headers(ImmutableMultimap.builder() + .put("Accept", "application/json") + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()).build(), + HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_templates.json")).build()).getServerClient(); + + assertEquals(client.getTemplates(), new ParseServerTemplatesTest().expected()); + } + + public void testGetServerWhenResponseIs2xx() throws Exception { + ServerClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/details/format/json")) + .headers(ImmutableMultimap.builder() + .put("Accept", "application/json") + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("serverid", "server1ssg-1.1").build())).build(), + HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_details.json")).build()).getServerClient(); + + ServerDetails actual = client.getServerDetails("server1ssg-1.1"); + assertEquals(actual.toString(), new ParseServerDetailsTest().expected().toString()); + } + @Test - public void testCreateServer() throws Exception { + public void testCreateServerWhenResponseIs2xx() throws Exception { + ServerClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/create/format/json")) + .headers(ImmutableMultimap.builder() + .put("Accept", "application/json") + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("cpucores", "1").put("memorysize", "512") + .put("datacenter", "Falkenberg") + .put("transfer", "50") + .put("rootpw", "password") + .put("hostname", "jclouds-test") + .put("platform", "OpenVZ") + .put("template", "Ubuntu 32-bit") + .put("disksize", "5").build())).build(), + HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_created.json")).build()).getServerClient(); ServerCreated expected = ServerCreated.builder().hostname("jclouds-test").id("xm3630641").ips(ServerCreatedIp.builder().ip("109.74.10.27").build()).build(); - ServerClient client = createMock("create", "POST", 200, "/server_created.json", - entry("cpucores", 1), entry("memorysize", 512), - entry("datacenter", "Falkenberg"), entry("transfer", 50), - entry("rootpw", "password"), entry("hostname", "jclouds-test"), entry("platform", "OpenVZ"), - entry("template", "Ubuntu 32-bit"), - entry("disksize", 5)); + assertEquals(client.createServer("Falkenberg", "OpenVZ", "jclouds-test", "Ubuntu 32-bit", 5, 512, 1, "password", 50), expected); - + } + + public void testCreateServerWithOptsWhenResponseIs2xx() throws Exception { + ServerClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/create/format/json")) + .headers(ImmutableMultimap.builder() + .put("Accept", "application/json") + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("cpucores", "1").put("memorysize", "512") + .put("datacenter", "Falkenberg") + .put("transfer", "50") + .put("rootpw", "password") + .put("hostname", "jclouds-test") + .put("platform", "OpenVZ") + .put("template", "Ubuntu 32-bit") + .put("disksize", "5") + .put("description", "Description-of-server") + .put("ip", "10.0.0.1").build())).build(), + HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_created.json")).build()).getServerClient(); ServerCreateOptions options = ServerCreateOptions.Builder.description("Description-of-server").ip("10.0.0.1"); - client = createMock("create", "POST", 200, "/server_created.json", - entry("cpucores", 1), entry("memorysize", 512), - entry("datacenter", "Falkenberg"), entry("transfer", 50), - entry("rootpw", "password"), entry("hostname", "jclouds-test"), entry("platform", "OpenVZ"), - entry("template", "Ubuntu 32-bit"), - entry("disksize", 5), options); + ServerCreated expected = ServerCreated.builder().hostname("jclouds-test").id("xm3630641").ips(ServerCreatedIp.builder().ip("109.74.10.27").build()).build(); + assertEquals(client.createServer("Falkenberg", "OpenVZ", "jclouds-test", "Ubuntu 32-bit", 5, 512, 1, "password", 50, options), expected); } @Test - public void testEditServer() throws Exception { - createMock("edit", "POST", 200, null, serverIdOnly).editServer(serverId); - ServerEditOptions options = - ServerEditOptions.Builder.description("Description-of-server").disksize(1).memorysize(512).cpucores(1).hostname("jclouds-test"); - createMock("edit", "POST", 200, null, serverIdOnly, options).editServer(serverId, options); + public void testEditServerWhenResponseIs2xx() throws Exception { + ServerClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/edit/format/json")) + .headers(ImmutableMultimap.builder() + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("serverid", "server111").build())).build(), + HttpResponse.builder().statusCode(206).build()).getServerClient(); + + client.editServer("server111"); } @Test - public void testCloneServer() throws Exception { - createMock("clone", "POST", 200, "/server_created.json", serverIdOnly, entry("hostname", "somename")).cloneServer(serverId, "somename"); + public void testEditServerWithOptsWhenResponseIs2xx() throws Exception { + ServerClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/edit/format/json")) + .headers(ImmutableMultimap.builder() + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("serverid", "server111") + .put("description", "Description-of-server") + .put("disksize", "1") + .put("memorysize", "512") + .put("cpucores", "1") + .put("hostname", "jclouds-test") + .build())).build(), + HttpResponse.builder().statusCode(200).build()).getServerClient(); + + ServerEditOptions options = + ServerEditOptions.Builder.description("Description-of-server").disksize(1).memorysize(512).cpucores(1).hostname("jclouds-test"); + + client.editServer("server111", options); + } + + @Test + public void testCloneServerWhenResponseIs2xx() throws Exception { + ServerClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/clone/format/json")) + .headers(ImmutableMultimap.builder() + .put("Accept", "application/json") + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("serverid", "server111") + .put("hostname", "hostname1").build())).build(), + HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_created.json")).build()).getServerClient(); + ServerCreated expected = ServerCreated.builder().hostname("jclouds-test").id("xm3630641").ips(ServerCreatedIp.builder().ip("109.74.10.27").build()).build(); + + assertEquals(client.cloneServer("server111", "hostname1"), expected); + } + + @Test + public void testCloneServerWithOptsWhenResponseIs2xx() throws Exception { + ServerClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/clone/format/json")) + .headers(ImmutableMultimap.builder() + .put("Accept", "application/json") + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("serverid", "server111") + .put("hostname", "hostname1") + .put("description", "Description-of-server") + .put("disksize", "1") + .put("memorysize", "512") + .put("cpucores", "1").build())).build(), + HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_created.json")).build()).getServerClient(); ServerCloneOptions options = (ServerCloneOptions) ServerCloneOptions.Builder.description("Description-of-server").disksize(1).memorysize(512).cpucores(1); - createMock("clone", "POST", 200, "/server_created.json", serverIdOnly, entry("hostname", "somename"), options).cloneServer(serverId, "somename", options); + ServerCreated expected = ServerCreated.builder().hostname("jclouds-test").id("xm3630641").ips(ServerCreatedIp.builder().ip("109.74.10.27").build()).build(); + + assertEquals(client.cloneServer("server111", "hostname1", options), expected); } - public void testGetServerStatus() throws Exception { - createMock("status", "POST", 200, "/server_status.json", serverIdOnly).getServerStatus(serverId); - createMock("status", "POST", 200, "/server_status.json", serverIdOnly, ServerStatusOptions.Builder.state()). - getServerStatus(serverId, ServerStatusOptions.Builder.state()); - createMock("status", "POST", 404, "Not found", serverIdOnly).getServerStatus(serverId); + @Test(expectedExceptions = {ResourceNotFoundException.class}) + public void testCloneServerWhenResponseIs4xx() throws Exception { + ServerClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/clone/format/json")) + .headers(ImmutableMultimap.builder() + .put("Accept", "application/json") + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("serverid", "server111") + .put("hostname", "hostname1").build())).build(), + HttpResponse.builder().statusCode(404).build()).getServerClient(); + + client.cloneServer("server111", "hostname1"); } - public void testGetServerLimits() throws Exception { - createMock("limits", "POST", 200, "/server_limits.json", serverIdOnly).getServerLimits(serverId); - assertNull(createMock("limits", "POST", 404, "Not found", serverIdOnly).getServerLimits(serverId)); + public void testGetServerStatusWhenResponseIs2xx() throws Exception { + ServerClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/status/format/json")) + .headers(ImmutableMultimap.builder() + .put("Accept", "application/json") + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("serverid", "server111").build())).build(), + HttpResponse.builder().statusCode(206).payload(payloadFromResource("/server_status.json")).build()) + .getServerClient(); + + assertEquals(client.getServerStatus("server111"), new ParseServerStatusTest().expected()); } - public void testGetServerConsole() throws Exception { - createMock("console", "POST", 200, "/server_console.json", serverIdOnly).getServerConsole(serverId); - assertNull(createMock("console", "POST", 404, "Not found", serverIdOnly).getServerConsole(serverId)); + public void testGetServerStatusWithOptsWhenResponseIs2xx() throws Exception { + ServerClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/status/format/json")) + .headers(ImmutableMultimap.builder() + .put("Accept", "application/json") + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("serverid", "server321").put("statustype", "state").build())).build(), + HttpResponse.builder().statusCode(206).payload(payloadFromResource("/server_status.json")).build()) + .getServerClient(); + + assertEquals(client.getServerStatus("server321", ServerStatusOptions.Builder.state()), new ParseServerStatusTest().expected()); } - public void testStartServer() throws Exception { - createMock("start", "POST", 200, null, serverIdOnly).startServer(serverId); - } - - public void testStopServer() throws Exception { - createMock("stop", "POST", 200, null, serverIdOnly).stopServer(serverId); - createMock("stop", "POST", 200, null, serverIdOnly, ServerStopOptions.Builder.hard()).stopServer(serverId, ServerStopOptions.Builder.hard()); + public void testGetServerStatusWhenResponseIs4xx() throws Exception { + ServerClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/status/format/json")) + .headers(ImmutableMultimap.builder() + .put("Accept", "application/json") + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("serverid", "server321").put("statustype", "state").build())).build(), + HttpResponse.builder().statusCode(404).build()) + .getServerClient(); + + assertNull(client.getServerStatus("server321", ServerStatusOptions.Builder.state())); } - public void testRebootServer() throws Exception { - createMock("reboot", "POST", 200, null, serverIdOnly).rebootServer(serverId); + public void testGetServerLimitsWhenResponseIs2xx() throws Exception { + ServerClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/limits/format/json")) + .headers(ImmutableMultimap.builder() + .put("Accept", "application/json") + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("serverid", "server321").build())).build(), + HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_limits.json")).build()) + .getServerClient(); + + client.getServerLimits("server321"); } - public void testDestroyServer() throws Exception { - createMock("destroy", "POST", 200, null, serverIdOnly, ServerDestroyOptions.Builder.keepIp()).destroyServer(serverId, ServerDestroyOptions.Builder.keepIp()); - createMock("destroy", "POST", 200, null, serverIdOnly, ServerDestroyOptions.Builder.discardIp()).destroyServer(serverId, ServerDestroyOptions.Builder.discardIp()); + public void testGetServerConsoleWhenResponseIs2xx() throws Exception { + ServerClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/console/format/json")) + .headers(ImmutableMultimap.builder() + .put("Accept", "application/json") + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("serverid", "server322").build())).build(), + HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_console.json")).build()) + .getServerClient(); + + assertEquals(client.getServerConsole("server322"), new ParseServerConsoleTest().expected()); } - @Override - protected ServerClient getClient(GleSYSClient gleSYSClient) { - return gleSYSClient.getServerClient(); + public void testGetServerConsoleWhenResponseIs4xx() throws Exception { + ServerClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/console/format/json")) + .headers(ImmutableMultimap.builder() + .put("Accept", "application/json") + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("serverid", "server322").build())).build(), + HttpResponse.builder().statusCode(404).build()) + .getServerClient(); + + assertNull(client.getServerConsole("server322")); + } + + public void testStartServerWhenResponseIs2xx() throws Exception { + ServerClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/start/format/json")) + .headers(ImmutableMultimap.builder() + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("serverid", "server777").build())).build(), + HttpResponse.builder().statusCode(200).build()) + .getServerClient(); + + client.startServer("server777"); + } + + @Test(expectedExceptions = {AuthorizationException.class}) + public void testStartServerWhenResponseIs4xx() throws Exception { + ServerClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/start/format/json")) + .headers(ImmutableMultimap.builder() + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("serverid", "server777").build())).build(), + HttpResponse.builder().statusCode(401).build()) + .getServerClient(); + + client.startServer("server777"); + } + + public void testStopServerWhenResponseIs2xx() throws Exception { + ServerClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/stop/format/json")) + .headers(ImmutableMultimap.builder() + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("serverid", "server777").build())).build(), + HttpResponse.builder().statusCode(200).build()) + .getServerClient(); + + client.stopServer("server777"); + } + + public void testHardStopServerWhenResponseIs2xx() throws Exception { + ServerClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/stop/format/json")) + .headers(ImmutableMultimap.builder() + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("serverid", "server777").put("type", "hard").build())).build(), + HttpResponse.builder().statusCode(200).build()) + .getServerClient(); + + client.stopServer("server777", ServerStopOptions.Builder.hard()); + } + + @Test(expectedExceptions = {AuthorizationException.class}) + public void testStopServerWhenResponseIs4xx() throws Exception { + ServerClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/stop/format/json")) + .headers(ImmutableMultimap.builder() + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("serverid", "server777").build())).build(), + HttpResponse.builder().statusCode(401).build()) + .getServerClient(); + + client.stopServer("server777"); + } + + public void testRebootServerWhenResponseIs2xx() throws Exception { + ServerClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/reboot/format/json")) + .headers(ImmutableMultimap.builder() + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("serverid", "server777").build())).build(), + HttpResponse.builder().statusCode(200).build()) + .getServerClient(); + + client.rebootServer("server777"); + } + + @Test(expectedExceptions = {AuthorizationException.class}) + public void testRebootServerWhenResponseIs4xx() throws Exception { + ServerClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/reboot/format/json")) + .headers(ImmutableMultimap.builder() + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("serverid", "server777").build())).build(), + HttpResponse.builder().statusCode(401).build()) + .getServerClient(); + + client.rebootServer("server777"); + } + + public void testDestroyServerWhenResponseIs2xx() throws Exception { + ServerClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/destroy/format/json")) + .headers(ImmutableMultimap.builder() + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("serverid", "server777").put("keepip", "1").build())).build(), + HttpResponse.builder().statusCode(200).build()) + .getServerClient(); + + client.destroyServer("server777", ServerDestroyOptions.Builder.keepIp()); + } + + @Test(expectedExceptions = {AuthorizationException.class}) + public void testDestroyServerWhenResponseIs4xx() throws Exception { + ServerClient client = requestSendsResponse( + HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/destroy/format/json")) + .headers(ImmutableMultimap.builder() + .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()) + .payload(newUrlEncodedFormPayload(ImmutableMultimap.builder() + .put("serverid", "server777").put("keepip", "0").build())).build(), + HttpResponse.builder().statusCode(401).build()) + .getServerClient(); + + client.destroyServer("server777", ServerDestroyOptions.Builder.discardIp()); } } diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseServerAllowedArgumentsTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseServerAllowedArgumentsTest.java index ca7cee8fec..7d1c4810f9 100644 --- a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseServerAllowedArgumentsTest.java +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseServerAllowedArgumentsTest.java @@ -47,38 +47,34 @@ public class ParseServerAllowedArgumentsTest extends BaseItemParserTest expected() { - return getData(); + Map result = new LinkedHashMap(); + ServerAllowedArguments openvz = ServerAllowedArguments.builder() + .dataCenters("Amsterdam", "Falkenberg", "New York City", "Stockholm") + .memorySizes(128, 256, 512, 768, 1024, 1536, 2048, 2560, 3072, 3584, 4096, 5120, 6144, 7168, 8192, 9216, 10240, 11264, 12288) + .diskSizes(5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 120, 140, 150) + .cpuCores(1, 2, 3, 4, 5, 6, 7, 8) + .templates("Centos 5", "Centos 5 64-bit", "Centos 6 32-bit", "Centos 6 64-bit", "Debian 5.0 32-bit", + "Debian 5.0 64-bit", "Debian 6.0 32-bit", "Debian 6.0 64-bit", "Fedora Core 11", "Fedora Core 11 64-bit", + "Gentoo", "Gentoo 64-bit", "Scientific Linux 6", "Scientific Linux 6 64-bit", "Slackware 12", + "Ubuntu 10.04 LTS 32-bit", "Ubuntu 10.04 LTS 64-bit", "Ubuntu 11.04 64-bit") + .transfers(50, 100, 250, 500, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000) + .build(); + ServerAllowedArguments xen = ServerAllowedArguments.builder() + .memorySizes(512, 768, 1024, 1536, 2048, 2560, 3072, 3584, 4096, 5120, 6144, 7168, 8192, 9216, 10240, 11264, 12288, 14336, 16384) + .diskSizes(5, 10, 20, 30, 40, 50, 80, 100, 120, 140, 150, 160, 160, 200, 250, 300) + .cpuCores(1, 2, 3, 4, 5, 6, 7, 8) + .templates("CentOS 5.5 x64", "CentOS 5.5 x86", "Centos 6 x64", "Centos 6 x86", "Debian-6 x64", + "Debian 5.0.1 x64", "FreeBSD 8.2", "Gentoo 10.1 x64", "Ubuntu 8.04 x64", "Ubuntu 10.04 LTS 64-bit", + "Ubuntu 10.10 x64", "Ubuntu 11.04 x64", "Windows Server 2008 R2 x64 std", + "Windows Server 2008 R2 x64 web", "Windows Server 2008 x64 web", "Windows Server 2008 x86 web") + .transfers(50, 100, 250, 500, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000) + .dataCenters("Falkenberg") + .build(); + result.put("Xen", xen); + result.put("OpenVZ", openvz); + return result; } - public static Map getData() { - Map result = new LinkedHashMap(); - ServerAllowedArguments openvz = ServerAllowedArguments.builder() - .dataCenters("Amsterdam", "Falkenberg", "New York City", "Stockholm") - .memorySizes(128, 256, 512, 768, 1024, 1536, 2048, 2560, 3072, 3584, 4096, 5120, 6144, 7168, 8192, 9216, 10240, 11264, 12288) - .diskSizes(5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 120, 140, 150) - .cpuCores(1, 2, 3, 4, 5, 6, 7, 8) - .templates("Centos 5", "Centos 5 64-bit", "Centos 6 32-bit", "Centos 6 64-bit", "Debian 5.0 32-bit", - "Debian 5.0 64-bit", "Debian 6.0 32-bit", "Debian 6.0 64-bit", "Fedora Core 11", "Fedora Core 11 64-bit", - "Gentoo", "Gentoo 64-bit", "Scientific Linux 6", "Scientific Linux 6 64-bit", "Slackware 12", - "Ubuntu 10.04 LTS 32-bit", "Ubuntu 10.04 LTS 64-bit", "Ubuntu 11.04 64-bit") - .transfers(50, 100, 250, 500, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000) - .build(); - ServerAllowedArguments xen = ServerAllowedArguments.builder() - .memorySizes(512, 768, 1024, 1536, 2048, 2560, 3072, 3584, 4096, 5120, 6144, 7168, 8192, 9216, 10240, 11264, 12288, 14336, 16384) - .diskSizes(5, 10, 20, 30, 40, 50, 80, 100, 120, 140, 150, 160, 160, 200, 250, 300) - .cpuCores(1, 2, 3, 4, 5, 6, 7, 8) - .templates("CentOS 5.5 x64", "CentOS 5.5 x86", "Centos 6 x64", "Centos 6 x86", "Debian-6 x64", - "Debian 5.0.1 x64", "FreeBSD 8.2", "Gentoo 10.1 x64", "Ubuntu 8.04 x64", "Ubuntu 10.04 LTS 64-bit", - "Ubuntu 10.10 x64", "Ubuntu 11.04 x64", "Windows Server 2008 R2 x64 std", - "Windows Server 2008 R2 x64 web", "Windows Server 2008 x64 web", "Windows Server 2008 x86 web") - .transfers(50, 100, 250, 500, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000) - .dataCenters("Falkenberg") - .build(); - result.put("Xen", xen); - result.put("OpenVZ", openvz); - return result; - } - protected Injector injector() { return Guice.createInjector(new GleSYSParserModule(), new GsonModule()); } diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseServerDetailsTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseServerDetailsTest.java index 80e19c035b..c0c89eb14a 100644 --- a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseServerDetailsTest.java +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseServerDetailsTest.java @@ -49,10 +49,6 @@ public class ParseServerDetailsTest extends BaseItemParserTest { @SelectJson("server") @Consumes(MediaType.APPLICATION_JSON) public ServerDetails expected() { - return getData(); - } - - public static ServerDetails getData() { Cost cost = Cost.builder().amount(6.38).currency("EUR").timePeriod("month").build(); return ServerDetails.builder().id("vz1908384").hostname("jclouds-unit").cpuCores(1). memory(128).disk(5). From 6a838984068981dad3b23cca049aa183850eee18 Mon Sep 17 00:00:00 2001 From: Adam Lowe Date: Wed, 11 Jan 2012 01:07:16 +0000 Subject: [PATCH 5/6] Fixing bugs found by new ClientExpectTests --- .../src/main/java/org/jclouds/glesys/domain/ServerStatus.java | 2 +- .../src/main/java/org/jclouds/glesys/options/DomainOptions.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerStatus.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerStatus.java index 9e802c34d9..8b8d01ceb0 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerStatus.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerStatus.java @@ -150,7 +150,7 @@ public class ServerStatus { && Objects.equal(memory, other.memory) && Objects.equal(disk, other.disk) && Objects.equal(bandwidth, other.bandwidth) - && uptime == other.uptime; + && Objects.equal(uptime, other.uptime); } else { return false; } diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/DomainOptions.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/DomainOptions.java index 0a322890f5..c2f6e80999 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/DomainOptions.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/DomainOptions.java @@ -130,7 +130,7 @@ public class DomainOptions extends BaseHttpRequestOptions { * Configure the number of seconds a master or slave will wait before considering the data stale if it cannot reach the primary name server */ public DomainOptions expire(int expire) { - formParameters.put("primary_ns", Integer.toString(expire)); + formParameters.put("expire", Integer.toString(expire)); return this; } From 87cc6cc870c20c77cf256c5949c8e74cb151fa5a Mon Sep 17 00:00:00 2001 From: Adam Lowe Date: Wed, 11 Jan 2012 14:12:51 +0000 Subject: [PATCH 6/6] Adding class headers --- .../glesys/options/DomainAddOptions.java | 18 ++++++++++++++++++ .../options/DomainRecordEditOptions.java | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/DomainAddOptions.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/DomainAddOptions.java index cba2b0b0c3..645b5977ae 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/DomainAddOptions.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/DomainAddOptions.java @@ -1,3 +1,21 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.jclouds.glesys.options; import org.jclouds.http.options.BaseHttpRequestOptions; diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/DomainRecordEditOptions.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/DomainRecordEditOptions.java index f375375320..60b8cded8d 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/DomainRecordEditOptions.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/DomainRecordEditOptions.java @@ -1,3 +1,21 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.jclouds.glesys.options; /**