Merge pull request #308 from aplowe/master

Improving javadoc comments and converting AsyncClientTests to ClientExpectTests
This commit is contained in:
Adrian Cole 2012-01-11 10:22:36 -08:00
commit 2f08d13fd6
42 changed files with 1631 additions and 676 deletions

View File

@ -74,18 +74,22 @@ public class Archive implements Comparable<Archive> {
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<Archive> {
this.locked = locked;
}
@Override
public int hashCode() {
return Objects.hashCode(username);

View File

@ -84,18 +84,22 @@ public class Domain implements Comparable<Domain> {
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;
}

View File

@ -95,26 +95,45 @@ public class DomainRecord implements Comparable<DomainRecord> {
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;
}

View File

@ -139,26 +139,32 @@ public class Email implements Comparable<Email> {
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<Email> {
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;
}

View File

@ -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 <a href="https://customer.glesys.com/api.php?a=doc#email_overview" />
*/
@ -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<EmailOverviewDomain> getDomains() {
return domains == null ? ImmutableSet.<EmailOverviewDomain>of() : domains;
}

View File

@ -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 <a href="https://customer.glesys.com/api.php?a=doc#email_overview" />
*/
@ -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;
}

View File

@ -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 <a href="https://customer.glesys.com/api.php?a=doc#email_overview" />
*/
@ -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;
}

View File

@ -30,7 +30,7 @@ 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 <a href="https://customer.glesys.com/api.php?a=doc#server_create" />
@ -49,6 +49,7 @@ public class ServerCreated {
this.id = id;
return this;
}
public Builder ips(List<ServerCreatedIp> ips) {
this.ips = ips;
return this;
@ -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<ServerCreatedIp> getIps() {
return ips == null ? ImmutableList.<ServerCreatedIp>of() : ips;
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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<ArchiveAllowedArguments> getArchiveAllowedArguments();
}

View File

@ -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<Void> addDomain(@FormParam("name") String name, DomainOptions... options);
ListenableFuture<Void> addDomain(@FormParam("name") String name, DomainAddOptions... options);
/**
* @see DomainClient#editDomain
@ -72,26 +73,42 @@ public interface DomainAsyncClient {
@Path("/domain/edit/format/json")
ListenableFuture<Void> editDomain(@FormParam("domain") String domain, DomainOptions... options);
/**
* @see DomainClient#deleteDomain
*/
@POST
@Path("/domain/delete/format/json")
ListenableFuture<Void> deleteDomain(@FormParam("domain") String domain);
/**
* @see DomainClient#listRecords
*/
@POST
@Path("/domain/list_records/format/json")
@SelectJson("records")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Set<DomainRecord>> listRecords(@FormParam("domain") String domain);
/**
* @see DomainClient#addRecord
*/
@POST
@Path("/domain/add_record/format/json")
ListenableFuture<Void> 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<Void> editRecord(@FormParam("record_id") String record_id, DomainRecordModifyOptions... options);
ListenableFuture<Void> editRecord(@FormParam("record_id") String record_id, DomainRecordEditOptions... options);
/**
* @see DomainClient#deleteRecord
*/
@POST
@Path("/domain/delete_record/format/json")
ListenableFuture<Void> deleteRecord(@FormParam("record_id") String recordId);

View File

@ -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.
* <p/>
*
* @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

View File

@ -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.
@ -50,13 +51,13 @@ 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")
@SelectJson("response")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<EmailOverview> getEmailOverview();
/**

View File

@ -32,7 +32,7 @@ import org.jclouds.glesys.options.EmailEditOptions;
* <p/>
*
* @author Adam Lowe
* @see org.jclouds.glesys.features.DomainAsyncClient
* @see org.jclouds.glesys.features.EmailAsyncClient
* @see <a href="https://customer.glesys.com/api.php" />
*/
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
@ -46,19 +46,52 @@ public interface EmailClient {
EmailOverview getEmailOverview();
/**
* Get the set of detailed information about e-mail accounts
*
* @return
* @return the relevant set of details
*/
Set<Email> 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);
}

View File

@ -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<String, Set<ServerTemplate>> getTemplates();
Set<ServerTemplate> getTemplates();
/**
* Get information about valid arguments to #createServer for each platform

View File

@ -0,0 +1,93 @@
/**
* 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;
/**
* @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;
}
}

View File

@ -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("expire", 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;
}
}

View File

@ -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;
}

View File

@ -0,0 +1,81 @@
/**
* 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 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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;

View File

@ -27,59 +27,48 @@ 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));
}
/**
* @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().transfer(transfer));
}
/**
* @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;

View File

@ -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;

View File

@ -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<ArchiveAsyncClient> {
public ArchiveAsyncClientTest() {
asyncClientClass = ArchiveAsyncClient.class;
remoteServicePrefix = "archive";
}
private Map.Entry<String, String> 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<RestAnnotationProcessor<ArchiveAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<ArchiveAsyncClient>>() {
};
}
}

View File

@ -0,0 +1,224 @@
/**
* 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 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.net.URI;
import java.util.List;
import static org.jclouds.io.Payloads.newUrlEncodedFormPayload;
import static org.testng.Assert.*;
/**
* Tests parsing of {@code ArchiveAsyncClient}
*
* @author Adam Lowe
*/
@Test(groups = "unit", testName = "ArchiveClientExpectTest")
public class ArchiveClientExpectTest extends BaseRestClientExpectTest<GleSYSClient> {
public ArchiveClientExpectTest() {
provider = "glesys";
}
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.<String, String>builder()
.put("Accept", "application/json")
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/archive_list.json")).build())
.getArchiveClient();
List<Archive> expected = ImmutableList.<Archive>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.<String, String>builder()
.put("Accept", "application/json")
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()).build(),
HttpResponse.builder().statusCode(404).build()).getArchiveClient();
assertTrue(client.listArchives().isEmpty());
}
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.<String, String>builder()
.put("Accept", "application/json")
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(
ImmutableMultimap.<String, String>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 testArchiveDetailsWhenResponseIs4xxReturnsNull() {
ArchiveClient client = requestSendsResponse(
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/archive/details/format/json"))
.headers(ImmutableMultimap.<String, String>builder()
.put("Accept", "application/json")
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(
ImmutableMultimap.<String, String>builder().put("username", "xxxxxx_test1").build())).build(),
HttpResponse.builder().statusCode(404).build())
.getArchiveClient();
assertNull(client.getArchiveDetails("xxxxxx_test1"));
}
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.<String, String>builder().put(
"Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>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.<String, String>builder().put(
"Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>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.<String, String>builder().put(
"Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>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.<String, String>builder().put(
"Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>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 testResizeArchiveWhenResponseIs4xxThrows() throws Exception {
ArchiveClient client = requestSendsResponse(
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/archive/resize/format/json"))
.headers(ImmutableMultimap.<String, String>builder().put(
"Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
.put("username", "username1")
.put("size", "5").build())).build(),
HttpResponse.builder().statusCode(404).build()).getArchiveClient();
client.resizeArchive("username1", 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.<String, String>builder().put(
"Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>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 testChangeArchivePasswordWhenResponseIs4xxThrows() throws Exception {
ArchiveClient client = requestSendsResponse(
HttpRequest.builder().method("POST")
.endpoint(URI.create("https://api.glesys.com/archive/changepassword/format/json"))
.headers(ImmutableMultimap.<String, String>builder().put(
"Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
.put("username", "username")
.put("password", "newpass").build())).build(),
HttpResponse.builder().statusCode(404).build()).getArchiveClient();
client.changeArchivePassword("username", "newpass");
}
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.<String, String>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);
}
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.<String, String>builder()
.put("Accept", "application/json")
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()).build(),
HttpResponse.builder().statusCode(404).build()).getArchiveClient();
assertNull(client.getArchiveAllowedArguments());
}
}

View File

@ -45,11 +45,8 @@ import com.google.common.collect.Maps;
/**
* @author Adrian Cole
* @author Adam Lowe
*/
public abstract class BaseGleSYSAsyncClientTest<T> extends RestClientTest<T> {
protected Class<T> asyncClientClass;
protected String remoteServicePrefix;
@Override
protected void checkFilters(HttpRequest request) {
@ -62,83 +59,4 @@ public abstract class BaseGleSYSAsyncClientTest<T> extends RestClientTest<T> {
Properties props = new Properties();
return new RestContextFactory().createContextSpec("glesys", "username", "apiKey", props);
}
@Deprecated
protected Map.Entry<String, String> newEntry(String key, Object value) {
return Maps.immutableEntry(key, value.toString());
}
/**
* Test that a method call is annotated correctly.
* <p/>
* @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<GleSYSClient>
@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<String> argStrings = new ArrayList<String>();
List<Object> argValues = new ArrayList<Object>();
for (Object arg : args) {
if (arg instanceof BaseHttpRequestOptions) {
for (Map.Entry<String, String> httpEntry : ((BaseHttpRequestOptions) arg).buildFormParameters().entries()) {
argStrings.add(httpEntry.getKey() + "=" + httpEntry.getValue());
}
argValues.add(arg);
} else {
Map.Entry<String, String> entry = (Map.Entry<String, String>) 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<String> 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);
}
}

View File

@ -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<DomainAsyncClient> {
public DomainAsyncClientTest() {
asyncClientClass = DomainAsyncClient.class;
remoteServicePrefix = "domain";
}
private Map.Entry<String, String> 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<RestAnnotationProcessor<DomainAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<DomainAsyncClient>>() {
};
}
}

View File

@ -0,0 +1,164 @@
/**
* 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.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;
/**
* Tests annotation parsing of {@code DomainAsyncClient}
*
* @author Adam Lowe
*/
@Test(groups = "unit", testName = "DomainClientExpectTest")
public class DomainClientExpectTest extends BaseRestClientExpectTest<GleSYSClient> {
public DomainClientExpectTest() {
provider = "glesys";
}
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.<String, String>builder()
.put("Accept", "application/json")
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/domain_list.json")).build()).getDomainClient();
Set<Domain> expected = ImmutableSet.<Domain>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.<String, String>builder()
.put("Accept", "application/json")
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.build(),
HttpResponse.builder().statusCode(404).build()).getDomainClient();
assertTrue(client.listDomains().isEmpty());
}
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.<String, String>builder().put(
"Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
.put("name", "cl66666_x").build())).build(),
HttpResponse.builder().statusCode(200).build()).getDomainClient();
client.addDomain("cl66666_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.<String, String>builder().put(
"Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>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.<String, String>builder().put(
"Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
.put("domain", "x").build())).build(),
HttpResponse.builder().statusCode(200).build()).getDomainClient();
client.editDomain("x");
}
@Test(expectedExceptions = {ResourceNotFoundException.class})
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.<String, String>builder().put(
"Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
.put("domain", "x").build())).build(),
HttpResponse.builder().statusCode(404).build()).getDomainClient();
client.editDomain("x");
}
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.<String, String>builder().put(
"Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
.put("domain", "x").build())).build(),
HttpResponse.builder().statusCode(200).build()).getDomainClient();
client.deleteDomain("x");
}
@Test(expectedExceptions = {ResourceNotFoundException.class})
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.<String, String>builder().put(
"Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
.put("domain", "x").build())).build(),
HttpResponse.builder().statusCode(404).build()).getDomainClient();
client.deleteDomain("x");
}
}

View File

@ -18,12 +18,17 @@
*/
package org.jclouds.glesys.features;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.jclouds.glesys.domain.Domain;
import org.jclouds.glesys.domain.DomainRecord;
import org.jclouds.glesys.options.DomainOptions;
import org.jclouds.glesys.options.DomainRecordEditOptions;
import org.jclouds.predicates.RetryablePredicate;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
@ -79,6 +84,12 @@ public class DomainClientLiveTest extends BaseGleSYSClientLiveTest {
private RetryablePredicate<Integer> domainCounter;
private RetryablePredicate<Integer> 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

View File

@ -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<EmailAsyncClient> {
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<RestAnnotationProcessor<EmailAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<EmailAsyncClient>>() {
};
}
}

View File

@ -0,0 +1,211 @@
/**
* 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.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 EmailClient}
*
* @author Adam Lowe
*/
@Test(groups = "unit", testName = "EmailAsyncClientTest")
public class EmailClientExpectTest extends BaseRestClientExpectTest<GleSYSClient> {
public EmailClientExpectTest() {
provider = "glesys";
}
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.<String, String>builder()
.put("Accept", "application/json")
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(
ImmutableMultimap.<String, String>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");
Set<Email> 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);
}
public void testListWhenResponseIs404IsEmpty() throws Exception {
EmailClient client = requestSendsResponse(
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/email/list/format/json"))
.headers(ImmutableMultimap.<String, String>builder()
.put("Accept", "application/json")
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(
ImmutableMultimap.<String, String>builder().put("domain", "test").build())).build(),
HttpResponse.builder().statusCode(404).build()).getEmailClient();
assertTrue(client.listAccounts("test").isEmpty());
}
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.<String, String>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);
}
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.<String, String>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.<String, String>builder()
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>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 testCreateAccountWhenResponseIs4xxThrows() throws Exception {
EmailClient client = requestSendsResponse(
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/email/createaccount/format/json"))
.headers(ImmutableMultimap.<String, String>builder()
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>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 testCreateAliasWhenResponseIs2xx() throws Exception {
EmailClient client = requestSendsResponse(
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/email/createalias/format/json"))
.headers(ImmutableMultimap.<String, String>builder()
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>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.<String, String>builder()
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>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.<String, String>builder()
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>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 testEditAliasWhenResponseIs4xxThrows() throws Exception {
EmailClient client = requestSendsResponse(
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/email/editalias/format/json"))
.headers(ImmutableMultimap.<String, String>builder()
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
.put("emailalias", "test2@jclouds.org")
.put("goto", "test@jclouds.org")
.build()))
.build(),
HttpResponse.builder().statusCode(404).build()).getEmailClient();
client.editAlias("test2@jclouds.org", "test@jclouds.org");
}
}

View File

@ -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,13 +46,6 @@ 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);
@ -80,14 +55,15 @@ 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());
@ -100,22 +76,34 @@ public class EmailClientLiveTest extends BaseGleSYSClientLiveTest {
private RetryablePredicate<Integer> 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());
@ -130,16 +118,16 @@ public class EmailClientLiveTest extends BaseGleSYSClientLiveTest {
assertTrue(overview.getDomains().contains(domain));
}
@Test(dependsOnMethods = "createEmail")
@Test(dependsOnMethods = "testCreateEmail")
public void testListAccounts() throws Exception {
Set<Email> accounts = client.listAccounts(testDomain);
assertTrue(accounts.size() >= 1);
}
@Test(dependsOnMethods = "createEmail")
@Test(dependsOnMethods = "testCreateEmail")
public void testEditAccount() throws Exception {
Set<Email> accounts = client.listAccounts(testDomain);
for(Email account : accounts) {
for (Email account : accounts) {
if (account.getAccount().equals("test@" + testDomain)) {
assertTrue(account.getAntiVirus());
}
@ -148,7 +136,7 @@ public class EmailClientLiveTest extends BaseGleSYSClientLiveTest {
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());
}

View File

@ -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<ServerAsyncClient> {
public ServerAsyncClientTest() {
asyncClientClass = ServerAsyncClient.class;
remoteServicePrefix = "server";
}
private Map.Entry<String, String> 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<RestAnnotationProcessor<ServerAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<ServerAsyncClient>>() {
};
}
}

View File

@ -0,0 +1,452 @@
/**
* 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.ImmutableSet;
import org.jclouds.glesys.GleSYSClient;
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 java.net.URI;
import static org.jclouds.io.Payloads.newUrlEncodedFormPayload;
import static org.testng.Assert.*;
/**
* Tests annotation parsing of {@code ServerAsyncClient}
*
* @author Adrian Cole
* @author Adam Lowe
*/
@Test(groups = "unit", testName = "ServerAsyncClientTest")
public class ServerClientExpectTest extends BaseRestClientExpectTest<GleSYSClient> {
public ServerClientExpectTest() {
provider = "glesys";
}
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.<String, String>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.<Server>of(expected));
}
public void testListServersWhenReponseIs404IsEmpty() {
ServerClient client = requestSendsResponse(
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/list/format/json"))
.headers(ImmutableMultimap.<String, String>builder()
.put("Accept", "application/json")
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()).build(),
HttpResponse.builder().statusCode(404).build()).getServerClient();
assertTrue(client.listServers().isEmpty());
}
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.<String, String>builder()
.put("Accept", "application/json")
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()).build(),
HttpResponse.builder().statusCode(204).payload(payloadFromResource("/server_allowed_arguments.json")).build()).getServerClient();
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.<String, String>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.<String, String>builder()
.put("Accept", "application/json")
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>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 testCreateServerWhenResponseIs2xx() throws Exception {
ServerClient client = requestSendsResponse(
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/create/format/json"))
.headers(ImmutableMultimap.<String, String>builder()
.put("Accept", "application/json")
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>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();
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.<String, String>builder()
.put("Accept", "application/json")
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>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");
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 testEditServerWhenResponseIs2xx() throws Exception {
ServerClient client = requestSendsResponse(
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/edit/format/json"))
.headers(ImmutableMultimap.<String, String>builder()
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
.put("serverid", "server111").build())).build(),
HttpResponse.builder().statusCode(206).build()).getServerClient();
client.editServer("server111");
}
@Test
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.<String, String>builder()
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>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.<String, String>builder()
.put("Accept", "application/json")
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>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.<String, String>builder()
.put("Accept", "application/json")
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>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);
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);
}
@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.<String, String>builder()
.put("Accept", "application/json")
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
.put("serverid", "server111")
.put("hostname", "hostname1").build())).build(),
HttpResponse.builder().statusCode(404).build()).getServerClient();
client.cloneServer("server111", "hostname1");
}
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.<String, String>builder()
.put("Accept", "application/json")
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>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 testGetServerStatusWithOptsWhenResponseIs2xx() throws Exception {
ServerClient client = requestSendsResponse(
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/status/format/json"))
.headers(ImmutableMultimap.<String, String>builder()
.put("Accept", "application/json")
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>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 testGetServerStatusWhenResponseIs4xx() throws Exception {
ServerClient client = requestSendsResponse(
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/status/format/json"))
.headers(ImmutableMultimap.<String, String>builder()
.put("Accept", "application/json")
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
.put("serverid", "server321").put("statustype", "state").build())).build(),
HttpResponse.builder().statusCode(404).build())
.getServerClient();
assertNull(client.getServerStatus("server321", ServerStatusOptions.Builder.state()));
}
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.<String, String>builder()
.put("Accept", "application/json")
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
.put("serverid", "server321").build())).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_limits.json")).build())
.getServerClient();
client.getServerLimits("server321");
}
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.<String, String>builder()
.put("Accept", "application/json")
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
.put("serverid", "server322").build())).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_console.json")).build())
.getServerClient();
assertEquals(client.getServerConsole("server322"), new ParseServerConsoleTest().expected());
}
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.<String, String>builder()
.put("Accept", "application/json")
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>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.<String, String>builder()
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>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.<String, String>builder()
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>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.<String, String>builder()
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>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.<String, String>builder()
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>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.<String, String>builder()
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>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.<String, String>builder()
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>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.<String, String>builder()
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>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.<String, String>builder()
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>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.<String, String>builder()
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
.put("serverid", "server777").put("keepip", "0").build())).build(),
HttpResponse.builder().statusCode(401).build())
.getServerClient();
client.destroyServer("server777", ServerDestroyOptions.Builder.discardIp());
}
}

View File

@ -98,26 +98,19 @@ public class ServerClientLiveTest extends BaseGleSYSClientLiveTest {
@Test
public void testListTemplates() throws Exception {
Map<String,Set<ServerTemplate>> templates = client.getTemplates();
Set<ServerTemplate> 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;
}

View File

@ -75,7 +75,6 @@ public class ParseServerAllowedArgumentsTest extends BaseItemParserTest<Map<Stri
return result;
}
protected Injector injector() {
return Guice.createInjector(new GleSYSParserModule(), new GsonModule());
}

View File

@ -0,0 +1,61 @@
/**
* 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<ServerDetails> {
@Override
public String resource() {
return "/server_details.json";
}
@Override
@SelectJson("server")
@Consumes(MediaType.APPLICATION_JSON)
public ServerDetails expected() {
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());
}
}

View File

@ -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"}}}}

View File

@ -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"}}}}