mirror of https://github.com/apache/jclouds.git
gogrid: fixed description and added 500 character length validation
This commit is contained in:
parent
57f84c3b27
commit
a8bfa608f2
|
@ -23,32 +23,53 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.gogrid.options;
|
package org.jclouds.gogrid.options;
|
||||||
|
|
||||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
import static org.jclouds.gogrid.reference.GoGridQueryParams.*;
|
import static org.jclouds.gogrid.reference.GoGridQueryParams.DESCRIPTION_KEY;
|
||||||
|
import static org.jclouds.gogrid.reference.GoGridQueryParams.IS_SANDBOX_KEY;
|
||||||
|
|
||||||
|
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Oleksiy Yarmula
|
* @author Oleksiy Yarmula
|
||||||
*/
|
*/
|
||||||
public class AddServerOptions extends BaseHttpRequestOptions {
|
public class AddServerOptions extends BaseHttpRequestOptions {
|
||||||
|
|
||||||
public AddServerOptions setDescription(String description) {
|
public AddServerOptions withDescription(String description) {
|
||||||
checkState(!queryParameters.containsKey(DESCRIPTION_KEY), "Can't have duplicate server description");
|
checkArgument(description.length() <= 500, "Description cannot be longer than 500 characters");
|
||||||
queryParameters.put(DESCRIPTION_KEY, description);
|
checkState(!queryParameters.containsKey(DESCRIPTION_KEY),
|
||||||
return this;
|
"Can't have duplicate server description");
|
||||||
}
|
queryParameters.put(DESCRIPTION_KEY, description);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make server a sandbox instance.
|
* Make server a sandbox instance. By default, it's not.
|
||||||
* By default, it's not.
|
*
|
||||||
*
|
* @return itself for convenience
|
||||||
* @return itself for convenience
|
*/
|
||||||
*/
|
public AddServerOptions asSandboxType() {
|
||||||
public AddServerOptions makeSandboxType() {
|
checkState(!queryParameters.containsKey(IS_SANDBOX_KEY),
|
||||||
checkState(!queryParameters.containsKey(IS_SANDBOX_KEY), "Can only have one sandbox option per server");
|
"Can only have one sandbox option per server");
|
||||||
queryParameters.put(IS_SANDBOX_KEY, "true");
|
queryParameters.put(IS_SANDBOX_KEY, "true");
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
/**
|
||||||
|
* @see AddServerOptions#withDescription(String)
|
||||||
|
*/
|
||||||
|
public static AddServerOptions withDescription(String description) {
|
||||||
|
AddServerOptions options = new AddServerOptions();
|
||||||
|
return options.withDescription(description);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see AddServerOptions#asSandboxType()
|
||||||
|
*/
|
||||||
|
public static AddServerOptions asSandboxType() {
|
||||||
|
AddServerOptions options = new AddServerOptions();
|
||||||
|
return options.asSandboxType();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,44 +28,44 @@ package org.jclouds.gogrid.reference;
|
||||||
*/
|
*/
|
||||||
public interface GoGridQueryParams {
|
public interface GoGridQueryParams {
|
||||||
|
|
||||||
public static final String ID_KEY = "id";
|
public static final String ID_KEY = "id";
|
||||||
public static final String NAME_KEY = "name";
|
public static final String NAME_KEY = "name";
|
||||||
public static final String SERVER_ID_OR_NAME_KEY = "server";
|
public static final String SERVER_ID_OR_NAME_KEY = "server";
|
||||||
public static final String SERVER_TYPE_KEY = "server.type";
|
public static final String SERVER_TYPE_KEY = "server.type";
|
||||||
|
|
||||||
public static final String IS_SANDBOX_KEY = "isSandbox";
|
public static final String IS_SANDBOX_KEY = "isSandbox";
|
||||||
public static final String IMAGE_KEY = "image";
|
public static final String IMAGE_KEY = "image";
|
||||||
public static final String IP_KEY = "ip";
|
public static final String IP_KEY = "ip";
|
||||||
|
|
||||||
public static final String SERVER_RAM_KEY = "server.ram";
|
public static final String SERVER_RAM_KEY = "server.ram";
|
||||||
|
|
||||||
public static final String DESCRIPTION_KEY = "server.ram";
|
public static final String DESCRIPTION_KEY = "description";
|
||||||
public static final String POWER_KEY = "power";
|
public static final String POWER_KEY = "power";
|
||||||
|
|
||||||
public static final String MAX_NUMBER_KEY = "num_items";
|
public static final String MAX_NUMBER_KEY = "num_items";
|
||||||
public static final String START_DATE_KEY = "startdate";
|
public static final String START_DATE_KEY = "startdate";
|
||||||
public static final String END_DATE_KEY = "enddate";
|
public static final String END_DATE_KEY = "enddate";
|
||||||
public static final String OWNER_KEY = "owner";
|
public static final String OWNER_KEY = "owner";
|
||||||
|
|
||||||
public static final String JOB_STATE_KEY = "job.state";
|
public static final String JOB_STATE_KEY = "job.state";
|
||||||
public static final String JOB_OBJECT_TYPE_KEY = "job.objecttype";
|
public static final String JOB_OBJECT_TYPE_KEY = "job.objecttype";
|
||||||
|
|
||||||
public static final String OBJECT_KEY = "object";
|
public static final String OBJECT_KEY = "object";
|
||||||
|
|
||||||
public static final String IP_STATE_KEY = "ip.state";
|
public static final String IP_STATE_KEY = "ip.state";
|
||||||
public static final String IP_TYPE_KEY = "ip.type";
|
public static final String IP_TYPE_KEY = "ip.type";
|
||||||
|
|
||||||
public static final String LOAD_BALANCER_KEY = "loadbalancer";
|
public static final String LOAD_BALANCER_KEY = "loadbalancer";
|
||||||
public static final String LOAD_BALANCER_TYPE_KEY = "loadbalancer.type";
|
public static final String LOAD_BALANCER_TYPE_KEY = "loadbalancer.type";
|
||||||
public static final String LOAD_BALANCER_PERSISTENCE_TYPE_KEY = "loadbalancer.persistence";
|
public static final String LOAD_BALANCER_PERSISTENCE_TYPE_KEY = "loadbalancer.persistence";
|
||||||
public static final String VIRTUAL_IP_KEY = "virtualip.";
|
public static final String VIRTUAL_IP_KEY = "virtualip.";
|
||||||
public static final String REAL_IP_LIST_KEY = "realiplist.";
|
public static final String REAL_IP_LIST_KEY = "realiplist.";
|
||||||
|
|
||||||
public static final String IS_PUBLIC_KEY = "isPublic";
|
public static final String IS_PUBLIC_KEY = "isPublic";
|
||||||
public static final String IMAGE_TYPE_KEY = "image.type";
|
public static final String IMAGE_TYPE_KEY = "image.type";
|
||||||
public static final String IMAGE_STATE_KEY = "image.state";
|
public static final String IMAGE_STATE_KEY = "image.state";
|
||||||
public static final String IMAGE_FRIENDLY_NAME_KEY = "friendlyName";
|
public static final String IMAGE_FRIENDLY_NAME_KEY = "friendlyName";
|
||||||
public static final String IMAGE_DESCRIPTION_KEY = "description";
|
public static final String IMAGE_DESCRIPTION_KEY = "description";
|
||||||
|
|
||||||
public static final String LOOKUP_LIST_KEY = "lookup";
|
public static final String LOOKUP_LIST_KEY = "lookup";
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,13 +18,40 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.gogrid;
|
package org.jclouds.gogrid;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import com.google.common.collect.Iterables;
|
import static java.lang.String.format;
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.assertNotNull;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import org.jclouds.domain.Credentials;
|
import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.gogrid.domain.*;
|
import org.jclouds.gogrid.domain.Ip;
|
||||||
|
import org.jclouds.gogrid.domain.IpPortPair;
|
||||||
|
import org.jclouds.gogrid.domain.Job;
|
||||||
|
import org.jclouds.gogrid.domain.LoadBalancer;
|
||||||
|
import org.jclouds.gogrid.domain.LoadBalancerPersistenceType;
|
||||||
|
import org.jclouds.gogrid.domain.LoadBalancerType;
|
||||||
|
import org.jclouds.gogrid.domain.PowerCommand;
|
||||||
|
import org.jclouds.gogrid.domain.Server;
|
||||||
|
import org.jclouds.gogrid.domain.ServerImage;
|
||||||
|
import org.jclouds.gogrid.domain.ServerImageType;
|
||||||
import org.jclouds.gogrid.options.AddLoadBalancerOptions;
|
import org.jclouds.gogrid.options.AddLoadBalancerOptions;
|
||||||
|
import org.jclouds.gogrid.options.AddServerOptions;
|
||||||
import org.jclouds.gogrid.options.GetImageListOptions;
|
import org.jclouds.gogrid.options.GetImageListOptions;
|
||||||
import org.jclouds.gogrid.options.GetIpListOptions;
|
|
||||||
import org.jclouds.gogrid.predicates.LoadBalancerLatestJobCompleted;
|
import org.jclouds.gogrid.predicates.LoadBalancerLatestJobCompleted;
|
||||||
import org.jclouds.gogrid.predicates.ServerLatestJobCompleted;
|
import org.jclouds.gogrid.predicates.ServerLatestJobCompleted;
|
||||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||||
|
@ -38,314 +65,327 @@ import org.testng.annotations.AfterTest;
|
||||||
import org.testng.annotations.BeforeGroups;
|
import org.testng.annotations.BeforeGroups;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import com.google.common.base.Predicate;
|
||||||
import java.io.IOException;
|
import com.google.common.collect.Iterables;
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
|
||||||
import static org.testng.Assert.*;
|
|
||||||
import static java.lang.String.format;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* End to end live test for GoGrid
|
* End to end live test for GoGrid
|
||||||
*
|
*
|
||||||
* @author Oleksiy Yarmula
|
* @author Oleksiy Yarmula
|
||||||
*/
|
*/
|
||||||
@Test(groups = "live", testName = "gogrid.GoGridLiveTest")
|
@Test(groups = "live", testName = "gogrid.GoGridLiveTest")
|
||||||
|
|
||||||
public class GoGridLiveTest {
|
public class GoGridLiveTest {
|
||||||
|
|
||||||
private GoGridClient client;
|
private GoGridClient client;
|
||||||
|
|
||||||
private RetryablePredicate<Server> serverLatestJobCompleted;
|
private RetryablePredicate<Server> serverLatestJobCompleted;
|
||||||
private RetryablePredicate<LoadBalancer> loadBalancerLatestJobCompleted;
|
private RetryablePredicate<LoadBalancer> loadBalancerLatestJobCompleted;
|
||||||
/**
|
/**
|
||||||
* Keeps track of the servers, created during the tests,
|
* Keeps track of the servers, created during the tests, to remove them after all tests complete
|
||||||
* to remove them after all tests complete
|
*/
|
||||||
*/
|
private List<String> serversToDeleteAfterTheTests = new ArrayList<String>();
|
||||||
private List<String> serversToDeleteAfterTheTests = new ArrayList<String>();
|
private List<String> loadBalancersToDeleteAfterTest = new ArrayList<String>();
|
||||||
private List<String> loadBalancersToDeleteAfterTest = new ArrayList<String>();
|
|
||||||
|
|
||||||
@BeforeGroups(groups = { "live" })
|
@BeforeGroups(groups = { "live" })
|
||||||
public void setupClient() {
|
public void setupClient() {
|
||||||
String user = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
|
String user = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
|
||||||
String password = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
|
String password = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
|
||||||
|
|
||||||
client = GoGridContextFactory.createContext(user, password, new Log4JLoggingModule())
|
client = GoGridContextFactory.createContext(user, password, new Log4JLoggingModule())
|
||||||
.getApi();
|
.getApi();
|
||||||
|
|
||||||
serverLatestJobCompleted = new RetryablePredicate<Server>(
|
serverLatestJobCompleted = new RetryablePredicate<Server>(new ServerLatestJobCompleted(client
|
||||||
new ServerLatestJobCompleted(client.getJobServices()),
|
.getJobServices()), 800, 20, TimeUnit.SECONDS);
|
||||||
800, 20, TimeUnit.SECONDS);
|
loadBalancerLatestJobCompleted = new RetryablePredicate<LoadBalancer>(
|
||||||
loadBalancerLatestJobCompleted = new RetryablePredicate<LoadBalancer>(
|
new LoadBalancerLatestJobCompleted(client.getJobServices()), 800, 20,
|
||||||
new LoadBalancerLatestJobCompleted(client.getJobServices()),
|
TimeUnit.SECONDS);
|
||||||
800, 20, TimeUnit.SECONDS);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
@Test(enabled = false)
|
||||||
* Tests server start, reboot and deletion.
|
public void testDescriptionIs500Characters() {
|
||||||
* Also verifies IP services and job services.
|
final String nameOfServer = "Description" + String.valueOf(new Date().getTime()).substring(6);
|
||||||
*/
|
serversToDeleteAfterTheTests.add(nameOfServer);
|
||||||
@Test(enabled=true)
|
|
||||||
public void testServerLifecycle() {
|
|
||||||
int serverCountBeforeTest = client.getServerServices().getServerList().size();
|
|
||||||
|
|
||||||
final String nameOfServer = "Server" + String.valueOf(new Date().getTime()).substring(6);
|
Set<Ip> availableIps = client.getIpServices().getUnassignedPublicIpList();
|
||||||
serversToDeleteAfterTheTests.add(nameOfServer);
|
Ip availableIp = Iterables.getLast(availableIps);
|
||||||
|
|
||||||
Set<Ip> availableIps = client.getIpServices().getUnassignedPublicIpList();
|
String ram = Iterables.get(client.getServerServices().getRamSizes(), 0).getName();
|
||||||
Ip availableIp = Iterables.getLast(availableIps);
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
String ram = Iterables.get(client.getServerServices().getRamSizes(), 0).getName();
|
for (int i = 0; i < 1 * 500; i++)
|
||||||
|
builder.append('a');
|
||||||
|
|
||||||
Server createdServer = client.getServerServices().addServer(nameOfServer,
|
String description = builder.toString();
|
||||||
"GSI-f8979644-e646-4711-ad58-d98a5fa3612c",
|
|
||||||
ram,
|
|
||||||
availableIp.getIp());
|
|
||||||
assertNotNull(createdServer);
|
|
||||||
assert serverLatestJobCompleted.apply(createdServer);
|
|
||||||
|
|
||||||
//get server by name
|
Server createdServer = client.getServerServices().addServer(nameOfServer,
|
||||||
Set<Server> response = client.getServerServices().getServersByName(nameOfServer);
|
"GSI-f8979644-e646-4711-ad58-d98a5fa3612c", ram, availableIp.getIp(),
|
||||||
assert (response.size() == 1);
|
new AddServerOptions().withDescription(description));
|
||||||
|
assertNotNull(createdServer);
|
||||||
|
assert serverLatestJobCompleted.apply(createdServer);
|
||||||
|
|
||||||
//restart the server
|
assertEquals(Iterables.getLast(client.getServerServices().getServersByName(nameOfServer))
|
||||||
client.getServerServices().power(nameOfServer, PowerCommand.RESTART);
|
.getDescription(), description);
|
||||||
|
|
||||||
Set<Job> jobs = client.getJobServices().getJobsForObjectName(nameOfServer);
|
}
|
||||||
assert("RestartVirtualServer".equals(Iterables.getLast(jobs).getCommand().getName()));
|
|
||||||
|
|
||||||
assert serverLatestJobCompleted.apply(createdServer);
|
/**
|
||||||
|
* Tests server start, reboot and deletion. Also verifies IP services and job services.
|
||||||
|
*/
|
||||||
|
@Test(enabled = false)
|
||||||
|
public void testServerLifecycle() {
|
||||||
|
int serverCountBeforeTest = client.getServerServices().getServerList().size();
|
||||||
|
|
||||||
int serverCountAfterAddingOneServer = client.getServerServices().getServerList().size();
|
final String nameOfServer = "Server" + String.valueOf(new Date().getTime()).substring(6);
|
||||||
assert serverCountAfterAddingOneServer == serverCountBeforeTest + 1 :
|
serversToDeleteAfterTheTests.add(nameOfServer);
|
||||||
"There should be +1 increase in the number of servers since the test started";
|
|
||||||
|
|
||||||
//delete the server
|
Set<Ip> availableIps = client.getIpServices().getUnassignedPublicIpList();
|
||||||
client.getServerServices().deleteByName(nameOfServer);
|
Ip availableIp = Iterables.getLast(availableIps);
|
||||||
|
|
||||||
jobs = client.getJobServices().getJobsForObjectName(nameOfServer);
|
String ram = Iterables.get(client.getServerServices().getRamSizes(), 0).getName();
|
||||||
assert("DeleteVirtualServer".equals(Iterables.getLast(jobs).getCommand().getName()));
|
|
||||||
|
|
||||||
assert serverLatestJobCompleted.apply(createdServer);
|
Server createdServer = client.getServerServices().addServer(nameOfServer,
|
||||||
|
"GSI-f8979644-e646-4711-ad58-d98a5fa3612c", ram, availableIp.getIp());
|
||||||
|
assertNotNull(createdServer);
|
||||||
|
assert serverLatestJobCompleted.apply(createdServer);
|
||||||
|
|
||||||
int serverCountAfterDeletingTheServer = client.getServerServices().getServerList().size();
|
// get server by name
|
||||||
assert serverCountAfterDeletingTheServer == serverCountBeforeTest :
|
Set<Server> response = client.getServerServices().getServersByName(nameOfServer);
|
||||||
"There should be the same # of servers as since the test started";
|
assert (response.size() == 1);
|
||||||
|
|
||||||
//make sure that IP is put back to "unassigned"
|
// restart the server
|
||||||
assert client.getIpServices().getUnassignedIpList().contains(availableIp);
|
client.getServerServices().power(nameOfServer, PowerCommand.RESTART);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
Set<Job> jobs = client.getJobServices().getJobsForObjectName(nameOfServer);
|
||||||
* Starts a servers, verifies that jobs are created correctly and
|
assert ("RestartVirtualServer".equals(Iterables.getLast(jobs).getCommand().getName()));
|
||||||
* an be retrieved from the job services
|
|
||||||
*/
|
|
||||||
@Test(dependsOnMethods = "testServerLifecycle", enabled=true)
|
|
||||||
public void testJobs() {
|
|
||||||
final String nameOfServer = "Server" + String.valueOf(new Date().getTime()).substring(6);
|
|
||||||
serversToDeleteAfterTheTests.add(nameOfServer);
|
|
||||||
|
|
||||||
Set<Ip> availableIps = client.getIpServices().getUnassignedPublicIpList();
|
assert serverLatestJobCompleted.apply(createdServer);
|
||||||
|
|
||||||
String ram = Iterables.get(client.getServerServices().getRamSizes(), 0).getName();
|
int serverCountAfterAddingOneServer = client.getServerServices().getServerList().size();
|
||||||
|
assert serverCountAfterAddingOneServer == serverCountBeforeTest + 1 : "There should be +1 increase in the number of servers since the test started";
|
||||||
|
|
||||||
Server createdServer = client.getServerServices().addServer(nameOfServer,
|
// delete the server
|
||||||
"GSI-f8979644-e646-4711-ad58-d98a5fa3612c",
|
client.getServerServices().deleteByName(nameOfServer);
|
||||||
ram,
|
|
||||||
Iterables.getLast(availableIps).getIp());
|
|
||||||
|
|
||||||
assert serverLatestJobCompleted.apply(createdServer);
|
jobs = client.getJobServices().getJobsForObjectName(nameOfServer);
|
||||||
|
assert ("DeleteVirtualServer".equals(Iterables.getLast(jobs).getCommand().getName()));
|
||||||
|
|
||||||
//restart the server
|
assert serverLatestJobCompleted.apply(createdServer);
|
||||||
client.getServerServices().power(nameOfServer, PowerCommand.RESTART);
|
|
||||||
|
|
||||||
Set<Job> jobs = client.getJobServices().getJobsForObjectName(nameOfServer);
|
int serverCountAfterDeletingTheServer = client.getServerServices().getServerList().size();
|
||||||
|
assert serverCountAfterDeletingTheServer == serverCountBeforeTest : "There should be the same # of servers as since the test started";
|
||||||
|
|
||||||
Job latestJob = Iterables.getLast(jobs);
|
// make sure that IP is put back to "unassigned"
|
||||||
Long latestJobId = latestJob.getId();
|
assert client.getIpServices().getUnassignedIpList().contains(availableIp);
|
||||||
|
}
|
||||||
|
|
||||||
Job latestJobFetched = Iterables.getOnlyElement(client.getJobServices().getJobsById(latestJobId));
|
/**
|
||||||
|
* Starts a servers, verifies that jobs are created correctly and an be retrieved from the job
|
||||||
|
* services
|
||||||
|
*/
|
||||||
|
@Test(dependsOnMethods = "testServerLifecycle", enabled = false)
|
||||||
|
public void testJobs() {
|
||||||
|
final String nameOfServer = "Server" + String.valueOf(new Date().getTime()).substring(6);
|
||||||
|
serversToDeleteAfterTheTests.add(nameOfServer);
|
||||||
|
|
||||||
assert latestJob.equals(latestJobFetched) : "Job and its reprentation found by ID don't match";
|
Set<Ip> availableIps = client.getIpServices().getUnassignedPublicIpList();
|
||||||
|
|
||||||
List<Long> idsOfAllJobs = new ArrayList<Long>();
|
String ram = Iterables.get(client.getServerServices().getRamSizes(), 0).getName();
|
||||||
for(Job job : jobs) {
|
|
||||||
idsOfAllJobs.add(job.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<Job> jobsFetched = client.getJobServices().getJobsById(idsOfAllJobs.toArray(new Long[jobs.size()]));
|
Server createdServer = client.getServerServices().addServer(nameOfServer,
|
||||||
assert jobsFetched.size() == jobs.size() : format("Number of jobs fetched by ids doesn't match the number of jobs " +
|
"GSI-f8979644-e646-4711-ad58-d98a5fa3612c", ram,
|
||||||
"requested. Requested/expected: %d. Found: %d.",
|
Iterables.getLast(availableIps).getIp());
|
||||||
jobs.size(), jobsFetched.size());
|
|
||||||
|
|
||||||
//delete the server
|
assert serverLatestJobCompleted.apply(createdServer);
|
||||||
client.getServerServices().deleteByName(nameOfServer);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// restart the server
|
||||||
|
client.getServerServices().power(nameOfServer, PowerCommand.RESTART);
|
||||||
|
|
||||||
/**
|
Set<Job> jobs = client.getJobServices().getJobsForObjectName(nameOfServer);
|
||||||
* Tests common load balancer operations.
|
|
||||||
* Also verifies IP services and job services.
|
|
||||||
*/
|
|
||||||
@Test(enabled=true)
|
|
||||||
public void testLoadBalancerLifecycle() {
|
|
||||||
int lbCountBeforeTest = client.getLoadBalancerServices().getLoadBalancerList().size();
|
|
||||||
|
|
||||||
final String nameOfLoadBalancer = "LoadBalancer" + String.valueOf(new Date().getTime()).substring(6);
|
Job latestJob = Iterables.getLast(jobs);
|
||||||
loadBalancersToDeleteAfterTest.add(nameOfLoadBalancer);
|
Long latestJobId = latestJob.getId();
|
||||||
|
|
||||||
Set<Ip> availableIps = client.getIpServices().getUnassignedPublicIpList();
|
Job latestJobFetched = Iterables.getOnlyElement(client.getJobServices().getJobsById(
|
||||||
|
latestJobId));
|
||||||
|
|
||||||
if(availableIps.size() < 4) throw new SkipException("Not enough available IPs (4 needed) to run the test");
|
assert latestJob.equals(latestJobFetched) : "Job and its reprentation found by ID don't match";
|
||||||
Iterator<Ip> ipIterator = availableIps.iterator();
|
|
||||||
Ip vip = ipIterator.next();
|
|
||||||
Ip realIp1 = ipIterator.next();
|
|
||||||
Ip realIp2 = ipIterator.next();
|
|
||||||
Ip realIp3 = ipIterator.next();
|
|
||||||
|
|
||||||
AddLoadBalancerOptions options = new AddLoadBalancerOptions.Builder().
|
List<Long> idsOfAllJobs = new ArrayList<Long>();
|
||||||
create(LoadBalancerType.LEAST_CONNECTED, LoadBalancerPersistenceType.SOURCE_ADDRESS);
|
for (Job job : jobs) {
|
||||||
LoadBalancer createdLoadBalancer = client.getLoadBalancerServices().
|
idsOfAllJobs.add(job.getId());
|
||||||
addLoadBalancer(nameOfLoadBalancer, new IpPortPair(vip, 80),
|
}
|
||||||
Arrays.asList(new IpPortPair(realIp1, 80),
|
|
||||||
new IpPortPair(realIp2, 80)), options);
|
|
||||||
assertNotNull(createdLoadBalancer);
|
|
||||||
assert loadBalancerLatestJobCompleted.apply(createdLoadBalancer);
|
|
||||||
|
|
||||||
//get load balancer by name
|
Set<Job> jobsFetched = client.getJobServices().getJobsById(
|
||||||
Set<LoadBalancer> response = client.getLoadBalancerServices().getLoadBalancersByName(nameOfLoadBalancer);
|
idsOfAllJobs.toArray(new Long[jobs.size()]));
|
||||||
assert (response.size() == 1);
|
assert jobsFetched.size() == jobs.size() : format(
|
||||||
createdLoadBalancer = Iterables.getOnlyElement(response);
|
"Number of jobs fetched by ids doesn't match the number of jobs "
|
||||||
assertNotNull(createdLoadBalancer.getRealIpList());
|
+ "requested. Requested/expected: %d. Found: %d.", jobs.size(), jobsFetched
|
||||||
assertEquals(createdLoadBalancer.getRealIpList().size(), 2);
|
.size());
|
||||||
assertNotNull(createdLoadBalancer.getVirtualIp());
|
|
||||||
assertEquals(createdLoadBalancer.getVirtualIp().getIp().getIp(), vip.getIp());
|
|
||||||
|
|
||||||
LoadBalancer editedLoadBalancer = client.getLoadBalancerServices().
|
// delete the server
|
||||||
editLoadBalancer(nameOfLoadBalancer, Arrays.asList(new IpPortPair(realIp3, 8181)));
|
client.getServerServices().deleteByName(nameOfServer);
|
||||||
assert loadBalancerLatestJobCompleted.apply(editedLoadBalancer);
|
}
|
||||||
assertNotNull(editedLoadBalancer.getRealIpList());
|
|
||||||
assertEquals(editedLoadBalancer.getRealIpList().size(), 1);
|
|
||||||
assertEquals(Iterables.getOnlyElement(editedLoadBalancer.getRealIpList()).getIp().getIp(), realIp3.getIp());
|
|
||||||
|
|
||||||
int lbCountAfterAddingOneServer = client.getLoadBalancerServices().getLoadBalancerList().size();
|
/**
|
||||||
assert lbCountAfterAddingOneServer == lbCountBeforeTest + 1 :
|
* Tests common load balancer operations. Also verifies IP services and job services.
|
||||||
"There should be +1 increase in the number of load balancers since the test started";
|
*/
|
||||||
|
@Test(enabled = false)
|
||||||
|
public void testLoadBalancerLifecycle() {
|
||||||
|
int lbCountBeforeTest = client.getLoadBalancerServices().getLoadBalancerList().size();
|
||||||
|
|
||||||
//delete the load balancer
|
final String nameOfLoadBalancer = "LoadBalancer"
|
||||||
client.getLoadBalancerServices().deleteByName(nameOfLoadBalancer);
|
+ String.valueOf(new Date().getTime()).substring(6);
|
||||||
|
loadBalancersToDeleteAfterTest.add(nameOfLoadBalancer);
|
||||||
|
|
||||||
Set<Job> jobs = client.getJobServices().getJobsForObjectName(nameOfLoadBalancer);
|
Set<Ip> availableIps = client.getIpServices().getUnassignedPublicIpList();
|
||||||
assert("DeleteLoadBalancer".equals(Iterables.getLast(jobs).getCommand().getName()));
|
|
||||||
|
|
||||||
assert loadBalancerLatestJobCompleted.apply(createdLoadBalancer);
|
if (availableIps.size() < 4)
|
||||||
|
throw new SkipException("Not enough available IPs (4 needed) to run the test");
|
||||||
|
Iterator<Ip> ipIterator = availableIps.iterator();
|
||||||
|
Ip vip = ipIterator.next();
|
||||||
|
Ip realIp1 = ipIterator.next();
|
||||||
|
Ip realIp2 = ipIterator.next();
|
||||||
|
Ip realIp3 = ipIterator.next();
|
||||||
|
|
||||||
int lbCountAfterDeletingTheServer = client.getLoadBalancerServices().getLoadBalancerList().size();
|
AddLoadBalancerOptions options = new AddLoadBalancerOptions.Builder().create(
|
||||||
assert lbCountAfterDeletingTheServer == lbCountBeforeTest :
|
LoadBalancerType.LEAST_CONNECTED, LoadBalancerPersistenceType.SOURCE_ADDRESS);
|
||||||
"There should be the same # of load balancers as since the test started";
|
LoadBalancer createdLoadBalancer = client.getLoadBalancerServices().addLoadBalancer(
|
||||||
}
|
nameOfLoadBalancer, new IpPortPair(vip, 80),
|
||||||
|
Arrays.asList(new IpPortPair(realIp1, 80), new IpPortPair(realIp2, 80)), options);
|
||||||
|
assertNotNull(createdLoadBalancer);
|
||||||
|
assert loadBalancerLatestJobCompleted.apply(createdLoadBalancer);
|
||||||
|
|
||||||
/**
|
// get load balancer by name
|
||||||
* Tests common server image operations.
|
Set<LoadBalancer> response = client.getLoadBalancerServices().getLoadBalancersByName(
|
||||||
*/
|
nameOfLoadBalancer);
|
||||||
@Test(enabled=true)
|
assert (response.size() == 1);
|
||||||
public void testImageLifecycle() {
|
createdLoadBalancer = Iterables.getOnlyElement(response);
|
||||||
GetImageListOptions options = new GetImageListOptions.Builder().publicDatabaseServers();
|
assertNotNull(createdLoadBalancer.getRealIpList());
|
||||||
Set<ServerImage> images = client.getImageServices().getImageList(options);
|
assertEquals(createdLoadBalancer.getRealIpList().size(), 2);
|
||||||
|
assertNotNull(createdLoadBalancer.getVirtualIp());
|
||||||
|
assertEquals(createdLoadBalancer.getVirtualIp().getIp().getIp(), vip.getIp());
|
||||||
|
|
||||||
Predicate<ServerImage> isDatabaseServer = new Predicate<ServerImage>() {
|
LoadBalancer editedLoadBalancer = client.getLoadBalancerServices().editLoadBalancer(
|
||||||
@Override
|
nameOfLoadBalancer, Arrays.asList(new IpPortPair(realIp3, 8181)));
|
||||||
public boolean apply(@Nullable ServerImage serverImage) {
|
assert loadBalancerLatestJobCompleted.apply(editedLoadBalancer);
|
||||||
return checkNotNull(serverImage).getType() == ServerImageType.DATABASE_SERVER;
|
assertNotNull(editedLoadBalancer.getRealIpList());
|
||||||
}
|
assertEquals(editedLoadBalancer.getRealIpList().size(), 1);
|
||||||
};
|
assertEquals(Iterables.getOnlyElement(editedLoadBalancer.getRealIpList()).getIp().getIp(),
|
||||||
|
realIp3.getIp());
|
||||||
|
|
||||||
assert Iterables.all(images, isDatabaseServer) : "All of the images should've been of database type";
|
int lbCountAfterAddingOneServer = client.getLoadBalancerServices().getLoadBalancerList()
|
||||||
|
.size();
|
||||||
|
assert lbCountAfterAddingOneServer == lbCountBeforeTest + 1 : "There should be +1 increase in the number of load balancers since the test started";
|
||||||
|
|
||||||
ServerImage image = Iterables.getLast(images);
|
// delete the load balancer
|
||||||
ServerImage imageFromServer = Iterables.getOnlyElement(
|
client.getLoadBalancerServices().deleteByName(nameOfLoadBalancer);
|
||||||
client.getImageServices().getImagesByName(image.getName()));
|
|
||||||
assertEquals(image, imageFromServer);
|
|
||||||
|
|
||||||
try {
|
Set<Job> jobs = client.getJobServices().getJobsForObjectName(nameOfLoadBalancer);
|
||||||
client.getImageServices().editImageDescription(image.getName(), "newDescription");
|
assert ("DeleteLoadBalancer".equals(Iterables.getLast(jobs).getCommand().getName()));
|
||||||
throw new TestException("An exception hasn't been thrown where expected; expected GoGridResponseException");
|
|
||||||
} catch(GoGridResponseException e) {
|
|
||||||
//expected situation - check and proceed
|
|
||||||
assertTrue(e.getMessage().contains("GoGridIllegalArgumentException"));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
assert loadBalancerLatestJobCompleted.apply(createdLoadBalancer);
|
||||||
|
|
||||||
@Test(enabled=true)
|
int lbCountAfterDeletingTheServer = client.getLoadBalancerServices().getLoadBalancerList()
|
||||||
public void testShellAccess() throws IOException {
|
.size();
|
||||||
final String nameOfServer = "Server" + String.valueOf(new Date().getTime()).substring(6);
|
assert lbCountAfterDeletingTheServer == lbCountBeforeTest : "There should be the same # of load balancers as since the test started";
|
||||||
serversToDeleteAfterTheTests.add(nameOfServer);
|
}
|
||||||
|
|
||||||
Set<Ip> availableIps = client.getIpServices().getUnassignedIpList();
|
/**
|
||||||
Ip availableIp = Iterables.getLast(availableIps);
|
* Tests common server image operations.
|
||||||
|
*/
|
||||||
|
@Test(enabled = false)
|
||||||
|
public void testImageLifecycle() {
|
||||||
|
GetImageListOptions options = new GetImageListOptions.Builder().publicDatabaseServers();
|
||||||
|
Set<ServerImage> images = client.getImageServices().getImageList(options);
|
||||||
|
|
||||||
Server createdServer = client.getServerServices().addServer(nameOfServer,
|
Predicate<ServerImage> isDatabaseServer = new Predicate<ServerImage>() {
|
||||||
"GSI-f8979644-e646-4711-ad58-d98a5fa3612c",
|
@Override
|
||||||
"1",
|
public boolean apply(@Nullable ServerImage serverImage) {
|
||||||
availableIp.getIp());
|
return checkNotNull(serverImage).getType() == ServerImageType.DATABASE_SERVER;
|
||||||
assertNotNull(createdServer);
|
}
|
||||||
assert serverLatestJobCompleted.apply(createdServer);
|
};
|
||||||
|
|
||||||
//get server by name
|
assert Iterables.all(images, isDatabaseServer) : "All of the images should've been of database type";
|
||||||
Set<Server> response = client.getServerServices().getServersByName(nameOfServer);
|
|
||||||
assert (response.size() == 1);
|
|
||||||
createdServer = Iterables.getOnlyElement(response);
|
|
||||||
|
|
||||||
Map<String, Credentials> credsMap = client.getServerServices().getServerCredentialsList();
|
ServerImage image = Iterables.getLast(images);
|
||||||
Credentials instanceCredentials = credsMap.get(createdServer.getName());
|
ServerImage imageFromServer = Iterables.getOnlyElement(client.getImageServices()
|
||||||
assertNotNull(instanceCredentials);
|
.getImagesByName(image.getName()));
|
||||||
|
assertEquals(image, imageFromServer);
|
||||||
|
|
||||||
InetSocketAddress socket = new InetSocketAddress(InetAddress.getByName(createdServer.getIp().getIp()), 22);
|
try {
|
||||||
|
client.getImageServices().editImageDescription(image.getName(), "newDescription");
|
||||||
|
throw new TestException(
|
||||||
|
"An exception hasn't been thrown where expected; expected GoGridResponseException");
|
||||||
|
} catch (GoGridResponseException e) {
|
||||||
|
// expected situation - check and proceed
|
||||||
|
assertTrue(e.getMessage().contains("GoGridIllegalArgumentException"));
|
||||||
|
}
|
||||||
|
|
||||||
Predicate<InetSocketAddress> socketOpen =
|
}
|
||||||
new RetryablePredicate<InetSocketAddress>(new SocketOpen(), 180, 5, TimeUnit.SECONDS);
|
|
||||||
|
|
||||||
socketOpen.apply(socket);
|
@Test(enabled = false)
|
||||||
|
public void testShellAccess() throws IOException {
|
||||||
|
final String nameOfServer = "Server" + String.valueOf(new Date().getTime()).substring(6);
|
||||||
|
serversToDeleteAfterTheTests.add(nameOfServer);
|
||||||
|
|
||||||
SshClient sshClient =
|
Set<Ip> availableIps = client.getIpServices().getUnassignedIpList();
|
||||||
new JschSshClient(socket, 60000,
|
Ip availableIp = Iterables.getLast(availableIps);
|
||||||
instanceCredentials.account, instanceCredentials.key);
|
|
||||||
sshClient.connect();
|
|
||||||
String output = sshClient.exec("df").getOutput();
|
|
||||||
assertTrue(output.contains("Filesystem"),
|
|
||||||
"The output should've contained filesystem information, but it didn't. Output: " + output);
|
|
||||||
sshClient.disconnect();
|
|
||||||
|
|
||||||
//delete the server
|
Server createdServer = client.getServerServices().addServer(nameOfServer,
|
||||||
client.getServerServices().deleteByName(nameOfServer);
|
"GSI-f8979644-e646-4711-ad58-d98a5fa3612c", "1", availableIp.getIp());
|
||||||
}
|
assertNotNull(createdServer);
|
||||||
|
assert serverLatestJobCompleted.apply(createdServer);
|
||||||
|
|
||||||
/**
|
// get server by name
|
||||||
* In case anything went wrong during the tests, removes the objects
|
Set<Server> response = client.getServerServices().getServersByName(nameOfServer);
|
||||||
* created in the tests.
|
assert (response.size() == 1);
|
||||||
*/
|
createdServer = Iterables.getOnlyElement(response);
|
||||||
@AfterTest
|
|
||||||
public void cleanup() {
|
|
||||||
for(String serverName : serversToDeleteAfterTheTests) {
|
|
||||||
try {
|
|
||||||
client.getServerServices().deleteByName(serverName);
|
|
||||||
} catch(Exception e) {
|
|
||||||
// it's already been deleted - proceed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(String loadBalancerName : loadBalancersToDeleteAfterTest) {
|
|
||||||
try {
|
|
||||||
client.getLoadBalancerServices().deleteByName(loadBalancerName);
|
|
||||||
} catch(Exception e) {
|
|
||||||
// it's already been deleted - proceed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
Map<String, Credentials> credsMap = client.getServerServices().getServerCredentialsList();
|
||||||
|
Credentials instanceCredentials = credsMap.get(createdServer.getName());
|
||||||
|
assertNotNull(instanceCredentials);
|
||||||
|
|
||||||
|
InetSocketAddress socket = new InetSocketAddress(InetAddress.getByName(createdServer.getIp()
|
||||||
|
.getIp()), 22);
|
||||||
|
|
||||||
|
Predicate<InetSocketAddress> socketOpen = new RetryablePredicate<InetSocketAddress>(
|
||||||
|
new SocketOpen(), 180, 5, TimeUnit.SECONDS);
|
||||||
|
|
||||||
|
socketOpen.apply(socket);
|
||||||
|
|
||||||
|
SshClient sshClient = new JschSshClient(socket, 60000, instanceCredentials.account,
|
||||||
|
instanceCredentials.key);
|
||||||
|
sshClient.connect();
|
||||||
|
String output = sshClient.exec("df").getOutput();
|
||||||
|
assertTrue(output.contains("Filesystem"),
|
||||||
|
"The output should've contained filesystem information, but it didn't. Output: "
|
||||||
|
+ output);
|
||||||
|
sshClient.disconnect();
|
||||||
|
|
||||||
|
// delete the server
|
||||||
|
client.getServerServices().deleteByName(nameOfServer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In case anything went wrong during the tests, removes the objects created in the tests.
|
||||||
|
*/
|
||||||
|
@AfterTest
|
||||||
|
public void cleanup() {
|
||||||
|
for (String serverName : serversToDeleteAfterTheTests) {
|
||||||
|
try {
|
||||||
|
client.getServerServices().deleteByName(serverName);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// it's already been deleted - proceed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (String loadBalancerName : loadBalancersToDeleteAfterTest) {
|
||||||
|
try {
|
||||||
|
client.getLoadBalancerServices().deleteByName(loadBalancerName);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// it's already been deleted - proceed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,113 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
|
package org.jclouds.gogrid.options;
|
||||||
|
|
||||||
|
import static org.jclouds.gogrid.options.AddServerOptions.Builder.asSandboxType;
|
||||||
|
import static org.jclouds.gogrid.options.AddServerOptions.Builder.withDescription;
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import org.jclouds.http.options.HttpRequestOptions;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests possible uses of AddServerOptions and AddServerOptions.Builder.*
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public class AddServerOptionsTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAssignability() {
|
||||||
|
assert HttpRequestOptions.class.isAssignableFrom(AddServerOptions.class);
|
||||||
|
assert !String.class.isAssignableFrom(AddServerOptions.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWithDescription() {
|
||||||
|
AddServerOptions options = new AddServerOptions();
|
||||||
|
options.withDescription("test");
|
||||||
|
assertEquals(options.buildQueryParameters().get("description"), Collections
|
||||||
|
.singletonList("test"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
|
public void testWith501LengthDescription() {
|
||||||
|
AddServerOptions options = new AddServerOptions();
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
|
for (int i = 0; i < 1 * 501; i++)
|
||||||
|
builder.append('a');
|
||||||
|
|
||||||
|
String description = builder.toString();
|
||||||
|
|
||||||
|
options.withDescription(description);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWith500LengthDescription() {
|
||||||
|
AddServerOptions options = new AddServerOptions();
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
|
for (int i = 0; i < 1 * 500; i++)
|
||||||
|
builder.append('a');
|
||||||
|
|
||||||
|
String description = builder.toString();
|
||||||
|
|
||||||
|
options.withDescription(description);
|
||||||
|
assertEquals(options.buildQueryParameters().get("description"), Collections
|
||||||
|
.singletonList(description));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNullWithDescription() {
|
||||||
|
AddServerOptions options = new AddServerOptions();
|
||||||
|
assertEquals(options.buildQueryParameters().get("description"), Collections.EMPTY_LIST);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWithDescriptionStatic() {
|
||||||
|
AddServerOptions options = withDescription("test");
|
||||||
|
assertEquals(options.buildQueryParameters().get("description"), Collections
|
||||||
|
.singletonList("test"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expectedExceptions = NullPointerException.class)
|
||||||
|
public void testWithDescriptionNPE() {
|
||||||
|
withDescription(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAsSandboxType() {
|
||||||
|
AddServerOptions options = new AddServerOptions();
|
||||||
|
options.asSandboxType();
|
||||||
|
assertEquals(options.buildQueryParameters().get("isSandbox"), Collections
|
||||||
|
.singletonList("true"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAsSandboxTypeStatic() {
|
||||||
|
AddServerOptions options = asSandboxType();
|
||||||
|
assertEquals(options.buildQueryParameters().get("isSandbox"), Collections
|
||||||
|
.singletonList("true"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -50,24 +50,23 @@ import java.net.URI;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
import org.jclouds.encryption.EncryptionService;
|
||||||
import org.jclouds.gogrid.GoGrid;
|
import org.jclouds.gogrid.GoGrid;
|
||||||
import org.jclouds.gogrid.domain.PowerCommand;
|
import org.jclouds.gogrid.domain.PowerCommand;
|
||||||
import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
|
import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
|
||||||
import org.jclouds.gogrid.functions.ParseOptionsFromJsonResponse;
|
import org.jclouds.gogrid.functions.ParseOptionsFromJsonResponse;
|
||||||
import org.jclouds.gogrid.functions.ParseServerFromJsonResponse;
|
import org.jclouds.gogrid.functions.ParseServerFromJsonResponse;
|
||||||
|
import org.jclouds.gogrid.functions.ParseServerListFromJsonResponse;
|
||||||
import org.jclouds.gogrid.options.AddServerOptions;
|
import org.jclouds.gogrid.options.AddServerOptions;
|
||||||
import org.jclouds.gogrid.options.GetServerListOptions;
|
import org.jclouds.gogrid.options.GetServerListOptions;
|
||||||
import org.jclouds.gogrid.services.GridServerAsyncClient;
|
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.logging.Logger.LoggerFactory;
|
import org.jclouds.logging.Logger.LoggerFactory;
|
||||||
import org.jclouds.rest.RestClientTest;
|
import org.jclouds.rest.RestClientTest;
|
||||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||||
import org.jclouds.gogrid.functions.ParseServerListFromJsonResponse;
|
|
||||||
import org.jclouds.encryption.EncryptionService;
|
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
@ -75,272 +74,278 @@ import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests annotation parsing of {@code GoGridAsyncClient}
|
* Tests annotation parsing of {@code GoGridAsyncClient}
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
* @author Oleksiy Yarmula
|
* @author Oleksiy Yarmula
|
||||||
*/
|
*/
|
||||||
@Test(groups = "unit", testName = "gogrid.GoGridAsyncClientTest")
|
@Test(groups = "unit", testName = "gogrid.GoGridAsyncClientTest")
|
||||||
public class GridServerAsyncClientTest extends RestClientTest<GridServerAsyncClient> {
|
public class GridServerAsyncClientTest extends RestClientTest<GridServerAsyncClient> {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetServerListNoOptions() throws NoSuchMethodException, IOException {
|
public void testGetServerListNoOptions() throws NoSuchMethodException, IOException {
|
||||||
Method method = GridServerAsyncClient.class.getMethod("getServerList", GetServerListOptions[].class);
|
Method method = GridServerAsyncClient.class.getMethod("getServerList",
|
||||||
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method);
|
GetServerListOptions[].class);
|
||||||
|
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method);
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/server/list?v=1.3 HTTP/1.1");
|
assertRequestLineEquals(httpRequest,
|
||||||
assertHeadersEqual(httpRequest, "");
|
"GET https://api.gogrid.com/api/grid/server/list?v=1.3 HTTP/1.1");
|
||||||
assertPayloadEquals(httpRequest, null);
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseServerListFromJsonResponse.class);
|
assertResponseParserClassEquals(method, httpRequest, ParseServerListFromJsonResponse.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
checkFilters(httpRequest);
|
checkFilters(httpRequest);
|
||||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest,
|
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/server/list?"
|
||||||
"GET https://api.gogrid.com/api/grid/server/list?" +
|
+ "v=1.3&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||||
"v=1.3&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
assertHeadersEqual(httpRequest, "");
|
||||||
"HTTP/1.1");
|
assertPayloadEquals(httpRequest, null);
|
||||||
assertHeadersEqual(httpRequest, "");
|
}
|
||||||
assertPayloadEquals(httpRequest, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetServerListWithOptions() throws NoSuchMethodException, IOException {
|
public void testGetServerListWithOptions() throws NoSuchMethodException, IOException {
|
||||||
Method method = GridServerAsyncClient.class.getMethod("getServerList", GetServerListOptions[].class);
|
Method method = GridServerAsyncClient.class.getMethod("getServerList",
|
||||||
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method,
|
GetServerListOptions[].class);
|
||||||
new GetServerListOptions.Builder().onlySandboxServers());
|
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method,
|
||||||
|
new GetServerListOptions.Builder().onlySandboxServers());
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest,
|
assertRequestLineEquals(httpRequest,
|
||||||
"GET https://api.gogrid.com/api/grid/server/list?v=1.3&isSandbox=true HTTP/1.1");
|
"GET https://api.gogrid.com/api/grid/server/list?v=1.3&isSandbox=true HTTP/1.1");
|
||||||
assertHeadersEqual(httpRequest, "");
|
assertHeadersEqual(httpRequest, "");
|
||||||
assertPayloadEquals(httpRequest, null);
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseServerListFromJsonResponse.class);
|
assertResponseParserClassEquals(method, httpRequest, ParseServerListFromJsonResponse.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
checkFilters(httpRequest);
|
checkFilters(httpRequest);
|
||||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest,
|
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/server/list?"
|
||||||
"GET https://api.gogrid.com/api/grid/server/list?" +
|
+ "v=1.3&isSandbox=true&sig=3f446f171455fbb5574aecff4997b273&api_key=foo "
|
||||||
"v=1.3&isSandbox=true&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
+ "HTTP/1.1");
|
||||||
"HTTP/1.1");
|
assertHeadersEqual(httpRequest, "");
|
||||||
assertHeadersEqual(httpRequest, "");
|
assertPayloadEquals(httpRequest, null);
|
||||||
assertPayloadEquals(httpRequest, null);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetServersByName() throws NoSuchMethodException, IOException {
|
||||||
|
Method method = GridServerAsyncClient.class.getMethod("getServersByName", String[].class);
|
||||||
|
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method,
|
||||||
|
"server1");
|
||||||
|
|
||||||
@Test
|
assertRequestLineEquals(httpRequest,
|
||||||
public void testGetServersByName() throws NoSuchMethodException, IOException {
|
"GET https://api.gogrid.com/api/grid/server/get?v=1.3&name=server1 HTTP/1.1");
|
||||||
Method method = GridServerAsyncClient.class.getMethod("getServersByName", String[].class);
|
assertHeadersEqual(httpRequest, "");
|
||||||
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method, "server1");
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest,
|
assertResponseParserClassEquals(method, httpRequest, ParseServerListFromJsonResponse.class);
|
||||||
"GET https://api.gogrid.com/api/grid/server/get?v=1.3&name=server1 HTTP/1.1");
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertHeadersEqual(httpRequest, "");
|
assertExceptionParserClassEquals(method, null);
|
||||||
assertPayloadEquals(httpRequest, null);
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseServerListFromJsonResponse.class);
|
checkFilters(httpRequest);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||||
assertExceptionParserClassEquals(method, null);
|
|
||||||
|
|
||||||
checkFilters(httpRequest);
|
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/server/get?"
|
||||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
+ "v=1.3&name=server1&" + "sig=3f446f171455fbb5574aecff4997b273&api_key=foo "
|
||||||
|
+ "HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
}
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest,
|
@Test
|
||||||
"GET https://api.gogrid.com/api/grid/server/get?" +
|
public void testGetServersById() throws NoSuchMethodException, IOException {
|
||||||
"v=1.3&name=server1&" +
|
Method method = GridServerAsyncClient.class.getMethod("getServersById", Long[].class);
|
||||||
"sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method,
|
||||||
"HTTP/1.1");
|
123L);
|
||||||
assertHeadersEqual(httpRequest, "");
|
|
||||||
assertPayloadEquals(httpRequest, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/server/get?v=1.3&id=123 HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
@Test
|
assertResponseParserClassEquals(method, httpRequest, ParseServerListFromJsonResponse.class);
|
||||||
public void testGetServersById() throws NoSuchMethodException, IOException {
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
Method method = GridServerAsyncClient.class.getMethod("getServersById", Long[].class);
|
assertExceptionParserClassEquals(method, null);
|
||||||
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method, 123L);
|
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest,
|
checkFilters(httpRequest);
|
||||||
"GET https://api.gogrid.com/api/grid/server/get?v=1.3&id=123 HTTP/1.1");
|
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||||
assertHeadersEqual(httpRequest, "");
|
|
||||||
assertPayloadEquals(httpRequest, null);
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseServerListFromJsonResponse.class);
|
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/server/get?"
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
+ "v=1.3&id=123&" + "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
}
|
||||||
|
|
||||||
checkFilters(httpRequest);
|
@Test
|
||||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
public void testAddServerNoOptions() throws NoSuchMethodException, IOException {
|
||||||
|
Method method = GridServerAsyncClient.class.getMethod("addServer", String.class,
|
||||||
|
String.class, String.class, String.class, AddServerOptions[].class);
|
||||||
|
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method,
|
||||||
|
"serverName", "img55", "memory", "127.0.0.1");
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest,
|
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/server/add?v=1.3&"
|
||||||
"GET https://api.gogrid.com/api/grid/server/get?" +
|
+ "name=serverName&server.ram=memory&image=img55&ip=127.0.0.1 " + "HTTP/1.1");
|
||||||
"v=1.3&id=123&" +
|
assertHeadersEqual(httpRequest, "");
|
||||||
"sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
assertPayloadEquals(httpRequest, null);
|
||||||
"HTTP/1.1");
|
|
||||||
assertHeadersEqual(httpRequest, "");
|
|
||||||
assertPayloadEquals(httpRequest, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
assertResponseParserClassEquals(method, httpRequest, ParseServerFromJsonResponse.class);
|
||||||
public void testAddServerNoOptions() throws NoSuchMethodException, IOException {
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
Method method = GridServerAsyncClient.class.getMethod("addServer", String.class, String.class,
|
assertExceptionParserClassEquals(method, null);
|
||||||
String.class, String.class,
|
|
||||||
AddServerOptions[].class);
|
|
||||||
GeneratedHttpRequest<GridServerAsyncClient> httpRequest =
|
|
||||||
processor.createRequest(method, "serverName", "img55",
|
|
||||||
"memory", "127.0.0.1");
|
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest,
|
checkFilters(httpRequest);
|
||||||
"GET https://api.gogrid.com/api/grid/server/add?v=1.3&" +
|
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||||
"name=serverName&server.ram=memory&image=img55&ip=127.0.0.1 " +
|
|
||||||
"HTTP/1.1");
|
|
||||||
assertHeadersEqual(httpRequest, "");
|
|
||||||
assertPayloadEquals(httpRequest, null);
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseServerFromJsonResponse.class);
|
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/server/add?"
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
+ "v=1.3&name=serverName&server.ram=memory&" + "image=img55&ip=127.0.0.1&"
|
||||||
assertExceptionParserClassEquals(method, null);
|
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
}
|
||||||
|
|
||||||
checkFilters(httpRequest);
|
@Test
|
||||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
public void testAddServerOptions() throws NoSuchMethodException, IOException {
|
||||||
|
Method method = GridServerAsyncClient.class.getMethod("addServer", String.class,
|
||||||
|
String.class, String.class, String.class, AddServerOptions[].class);
|
||||||
|
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method,
|
||||||
|
"serverName", "img55", "memory", "127.0.0.1", new AddServerOptions()
|
||||||
|
.asSandboxType().withDescription("fooy"));
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest,
|
assertRequestLineEquals(
|
||||||
"GET https://api.gogrid.com/api/grid/server/add?" +
|
httpRequest,
|
||||||
"v=1.3&name=serverName&server.ram=memory&" +
|
"GET https://api.gogrid.com/api/grid/server/add?v=1.3&name=serverName&server.ram=memory&image=img55&ip=127.0.0.1&isSandbox=true&description=fooy HTTP/1.1");
|
||||||
"image=img55&ip=127.0.0.1&" +
|
assertHeadersEqual(httpRequest, "");
|
||||||
"sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
assertPayloadEquals(httpRequest, null);
|
||||||
"HTTP/1.1");
|
|
||||||
assertHeadersEqual(httpRequest, "");
|
|
||||||
assertPayloadEquals(httpRequest, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, httpRequest, ParseServerFromJsonResponse.class);
|
||||||
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
@Test
|
checkFilters(httpRequest);
|
||||||
public void testPowerServer() throws NoSuchMethodException, IOException {
|
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||||
Method method = GridServerAsyncClient.class.getMethod("power", String.class, PowerCommand.class);
|
|
||||||
GeneratedHttpRequest<GridServerAsyncClient> httpRequest =
|
|
||||||
processor.createRequest(method, "PowerServer", PowerCommand.RESTART);
|
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest,
|
assertRequestLineEquals(
|
||||||
"GET https://api.gogrid.com/api/grid/server/power?v=1.3&" +
|
httpRequest,
|
||||||
"server=PowerServer&power=restart " +
|
"GET https://api.gogrid.com/api/grid/server/add?v=1.3&name=serverName&server.ram=memory&image=img55&ip=127.0.0.1&isSandbox=true&description=fooy&sig=3f446f171455fbb5574aecff4997b273&api_key=foo HTTP/1.1");
|
||||||
"HTTP/1.1");
|
assertHeadersEqual(httpRequest, "");
|
||||||
assertHeadersEqual(httpRequest, "");
|
assertPayloadEquals(httpRequest, null);
|
||||||
assertPayloadEquals(httpRequest, null);
|
}
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseServerFromJsonResponse.class);
|
@Test
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
public void testPowerServer() throws NoSuchMethodException, IOException {
|
||||||
assertExceptionParserClassEquals(method, null);
|
Method method = GridServerAsyncClient.class.getMethod("power", String.class,
|
||||||
|
PowerCommand.class);
|
||||||
|
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method,
|
||||||
|
"PowerServer", PowerCommand.RESTART);
|
||||||
|
|
||||||
checkFilters(httpRequest);
|
assertRequestLineEquals(httpRequest,
|
||||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
"GET https://api.gogrid.com/api/grid/server/power?v=1.3&"
|
||||||
|
+ "server=PowerServer&power=restart " + "HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest,
|
assertResponseParserClassEquals(method, httpRequest, ParseServerFromJsonResponse.class);
|
||||||
"GET https://api.gogrid.com/api/grid/server/power?v=1.3&" +
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
"server=PowerServer&power=restart&" +
|
assertExceptionParserClassEquals(method, null);
|
||||||
"sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
|
||||||
"HTTP/1.1");
|
|
||||||
assertHeadersEqual(httpRequest, "");
|
|
||||||
assertPayloadEquals(httpRequest, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
checkFilters(httpRequest);
|
||||||
@Test
|
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||||
public void testDeleteByName() throws NoSuchMethodException, IOException {
|
|
||||||
Method method = GridServerAsyncClient.class.getMethod("deleteByName", String.class);
|
|
||||||
GeneratedHttpRequest<GridServerAsyncClient> httpRequest =
|
|
||||||
processor.createRequest(method, "PowerServer");
|
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest,
|
assertRequestLineEquals(httpRequest,
|
||||||
"GET https://api.gogrid.com/api/grid/server/delete?v=1.3&" +
|
"GET https://api.gogrid.com/api/grid/server/power?v=1.3&"
|
||||||
"name=PowerServer " +
|
+ "server=PowerServer&power=restart&"
|
||||||
"HTTP/1.1");
|
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||||
assertHeadersEqual(httpRequest, "");
|
assertHeadersEqual(httpRequest, "");
|
||||||
assertPayloadEquals(httpRequest, null);
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
}
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseServerFromJsonResponse.class);
|
@Test
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
public void testDeleteByName() throws NoSuchMethodException, IOException {
|
||||||
assertExceptionParserClassEquals(method, null);
|
Method method = GridServerAsyncClient.class.getMethod("deleteByName", String.class);
|
||||||
|
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method,
|
||||||
|
"PowerServer");
|
||||||
|
|
||||||
checkFilters(httpRequest);
|
assertRequestLineEquals(httpRequest,
|
||||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
"GET https://api.gogrid.com/api/grid/server/delete?v=1.3&" + "name=PowerServer "
|
||||||
|
+ "HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest,
|
assertResponseParserClassEquals(method, httpRequest, ParseServerFromJsonResponse.class);
|
||||||
"GET https://api.gogrid.com/api/grid/server/delete?v=1.3&" +
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
"name=PowerServer&" +
|
assertExceptionParserClassEquals(method, null);
|
||||||
"sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
|
||||||
"HTTP/1.1");
|
|
||||||
assertHeadersEqual(httpRequest, "");
|
|
||||||
assertPayloadEquals(httpRequest, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
checkFilters(httpRequest);
|
||||||
|
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||||
|
|
||||||
@Test
|
assertRequestLineEquals(httpRequest,
|
||||||
public void testGetRamSizes() throws NoSuchMethodException, IOException {
|
"GET https://api.gogrid.com/api/grid/server/delete?v=1.3&" + "name=PowerServer&"
|
||||||
Method method = GridServerAsyncClient.class.getMethod("getRamSizes");
|
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||||
GeneratedHttpRequest<GridServerAsyncClient> httpRequest =
|
assertHeadersEqual(httpRequest, "");
|
||||||
processor.createRequest(method);
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
}
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest,
|
@Test
|
||||||
"GET https://api.gogrid.com/api/common/lookup/list?v=1.3&lookup=server.ram " +
|
public void testGetRamSizes() throws NoSuchMethodException, IOException {
|
||||||
"HTTP/1.1");
|
Method method = GridServerAsyncClient.class.getMethod("getRamSizes");
|
||||||
assertHeadersEqual(httpRequest, "");
|
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method);
|
||||||
assertPayloadEquals(httpRequest, null);
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseOptionsFromJsonResponse.class);
|
assertRequestLineEquals(httpRequest,
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
"GET https://api.gogrid.com/api/common/lookup/list?v=1.3&lookup=server.ram "
|
||||||
assertExceptionParserClassEquals(method, null);
|
+ "HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
checkFilters(httpRequest);
|
assertResponseParserClassEquals(method, httpRequest, ParseOptionsFromJsonResponse.class);
|
||||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest,
|
checkFilters(httpRequest);
|
||||||
"GET https://api.gogrid.com/api/common/lookup/list?v=1.3&lookup=server.ram&" +
|
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||||
"sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
|
||||||
"HTTP/1.1");
|
|
||||||
assertHeadersEqual(httpRequest, "");
|
|
||||||
assertPayloadEquals(httpRequest, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/common/lookup/list?v=1.3&lookup=server.ram&"
|
||||||
|
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void checkFilters(GeneratedHttpRequest<GridServerAsyncClient> httpMethod) {
|
protected void checkFilters(GeneratedHttpRequest<GridServerAsyncClient> httpMethod) {
|
||||||
assertEquals(httpMethod.getFilters().size(), 1);
|
assertEquals(httpMethod.getFilters().size(), 1);
|
||||||
assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class);
|
assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected TypeLiteral<RestAnnotationProcessor<GridServerAsyncClient>> createTypeLiteral() {
|
protected TypeLiteral<RestAnnotationProcessor<GridServerAsyncClient>> createTypeLiteral() {
|
||||||
return new TypeLiteral<RestAnnotationProcessor<GridServerAsyncClient>>() {
|
return new TypeLiteral<RestAnnotationProcessor<GridServerAsyncClient>>() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Module createModule() {
|
protected Module createModule() {
|
||||||
return new AbstractModule() {
|
return new AbstractModule() {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(URI.class).annotatedWith(GoGrid.class).toInstance(
|
bind(URI.class).annotatedWith(GoGrid.class).toInstance(
|
||||||
URI.create("https://api.gogrid.com/api"));
|
URI.create("https://api.gogrid.com/api"));
|
||||||
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
|
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
|
||||||
public Logger getLogger(String category) {
|
public Logger getLogger(String category) {
|
||||||
return Logger.NULL;
|
return Logger.NULL;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@SuppressWarnings("unused")
|
||||||
@Singleton
|
@Provides
|
||||||
public SharedKeyLiteAuthentication provideAuthentication(EncryptionService encryptionService)
|
@Singleton
|
||||||
throws UnsupportedEncodingException {
|
public SharedKeyLiteAuthentication provideAuthentication(
|
||||||
return new SharedKeyLiteAuthentication("foo", "bar", 1267243795L, encryptionService);
|
EncryptionService encryptionService) throws UnsupportedEncodingException {
|
||||||
}
|
return new SharedKeyLiteAuthentication("foo", "bar", 1267243795L, encryptionService);
|
||||||
};
|
}
|
||||||
}
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue