added unit test to rimu

This commit is contained in:
Adrian Cole 2010-07-19 13:07:25 -07:00
parent 889f47078d
commit 45450e1b8f
4 changed files with 110 additions and 36 deletions

View File

@ -19,7 +19,7 @@
package org.jclouds.rimuhosting.miro; package org.jclouds.rimuhosting.miro;
import java.util.List; import java.util.List;
import java.util.SortedSet; import java.util.Set;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE; import javax.ws.rs.DELETE;
@ -76,7 +76,7 @@ public interface RimuHostingAsyncClient {
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ParseRimuHostingException.class) @ExceptionParser(ParseRimuHostingException.class)
ListenableFuture<SortedSet<Image>> getImageList(); ListenableFuture<Set<Image>> getImageList();
/** /**
* @see RimuHostingClient#getServerList * @see RimuHostingClient#getServerList
@ -88,7 +88,7 @@ public interface RimuHostingAsyncClient {
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ParseRimuHostingException.class) @ExceptionParser(ParseRimuHostingException.class)
ListenableFuture<SortedSet<Server>> getServerList(); ListenableFuture<Set<Server>> getServerList();
/** /**
* @see RimuHostingClient#getPricingPlanList * @see RimuHostingClient#getPricingPlanList
@ -99,7 +99,7 @@ public interface RimuHostingAsyncClient {
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ParseRimuHostingException.class) @ExceptionParser(ParseRimuHostingException.class)
@ResponseParser(ParsePricingPlansFromJsonResponse.class) @ResponseParser(ParsePricingPlansFromJsonResponse.class)
ListenableFuture<SortedSet<PricingPlan>> getPricingPlanList(); ListenableFuture<Set<PricingPlan>> getPricingPlanList();
/** /**
* @see RimuHostingClient#createServer * @see RimuHostingClient#createServer
@ -111,10 +111,8 @@ public interface RimuHostingAsyncClient {
@ExceptionParser(ParseRimuHostingException.class) @ExceptionParser(ParseRimuHostingException.class)
@Unwrap @Unwrap
@MapBinder(CreateServerOptions.class) @MapBinder(CreateServerOptions.class)
ListenableFuture<NewServerResponse> createServer( ListenableFuture<NewServerResponse> createServer(@MapPayloadParam("name") String name,
@MapPayloadParam("name") String name, @MapPayloadParam("imageId") String imageId, @MapPayloadParam("planId") String planId,
@MapPayloadParam("imageId") String imageId,
@MapPayloadParam("planId") String planId,
CreateServerOptions... options); CreateServerOptions... options);
/** /**

View File

@ -18,19 +18,24 @@
*/ */
package org.jclouds.rimuhosting.miro; package org.jclouds.rimuhosting.miro;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
import org.jclouds.rimuhosting.miro.binder.CreateServerOptions; import org.jclouds.rimuhosting.miro.binder.CreateServerOptions;
import org.jclouds.rimuhosting.miro.domain.*; import org.jclouds.rimuhosting.miro.domain.Image;
import org.jclouds.rimuhosting.miro.domain.MetaData;
import java.util.List; import org.jclouds.rimuhosting.miro.domain.NewServerResponse;
import java.util.SortedSet; import org.jclouds.rimuhosting.miro.domain.PricingPlan;
import java.util.concurrent.TimeUnit; import org.jclouds.rimuhosting.miro.domain.Server;
import org.jclouds.rimuhosting.miro.domain.ServerInfo;
/** /**
* Provides synchronous access to RimuHosting. * Provides synchronous access to RimuHosting.
* <p/> * <p/>
* *
* @author Ivan Meredith * @author Ivan Meredith
* @see RimuHostingAsyncClient * @see RimuHostingAsyncClient
* @see <a href="TODO: insert URL of client documentation" /> * @see <a href="TODO: insert URL of client documentation" />
*/ */
@ -38,38 +43,42 @@ import java.util.concurrent.TimeUnit;
public interface RimuHostingClient { public interface RimuHostingClient {
/** /**
* This operation returns a list of images that can be used for server creation. * This operation returns a list of images that can be used for server
*c * creation. c
*
* @see Image * @see Image
*/ */
SortedSet<Image> getImageList(); Set<Image> getImageList();
/** /**
* Returns a list of servers that belong to this identity. * Returns a list of servers that belong to this identity.
* *
* @return An empty set if there are no servers. * @return An empty set if there are no servers.
* @see Server * @see Server
*/ */
SortedSet<Server> getServerList(); Set<Server> getServerList();
/** /**
* Returns a list of pricing plans that can be used for server creation. * Returns a list of pricing plans that can be used for server creation.
*
* @see PricingPlan * @see PricingPlan
*/ */
SortedSet<PricingPlan> getPricingPlanList(); Set<PricingPlan> getPricingPlanList();
/** /**
* This operation creates a node based on its name, imageId and planId. * This operation creates a node based on its name, imageId and planId.
* *
* A password can be specified with the option {@link CreateServerOptions#withPassword(String) | withPassword()} * A password can be specified with the option
* {@link CreateServerOptions#withPassword(String) | withPassword()}
* *
* Key-Value @{link {@link MetaData | metadata} can be included with the option {@link CreateServerOptions#withMetaData(List) | withMetaData()} * Key-Value @{link {@link MetaData | metadata} can be included with the
* option {@link CreateServerOptions#withMetaData(List) | withMetaData()}
* *
* @see CreateServerOptions * @see CreateServerOptions
* *
* TODO: add more CreateServerOptions * TODO: add more CreateServerOptions
*/ */
NewServerResponse createServer(String name, String imageId, String planId, CreateServerOptions ... options); NewServerResponse createServer(String name, String imageId, String planId, CreateServerOptions... options);
/** /**
* Gets a server based on its id. * Gets a server based on its id.
@ -78,18 +87,19 @@ public interface RimuHostingClient {
* @see Server * @see Server
*/ */
Server getServer(Long id); Server getServer(Long id);
/** /**
* Restarts a server. * Restarts a server.
* *
* @return State of the server. * @return State of the server.
*/ */
ServerInfo restartServer(Long id); ServerInfo restartServer(Long id);
/** /**
* Destroys a server. This an async operation. * Destroys a server. This an async operation.
* *
* @return A list of messages that have something to do with the shutdown. Can ignore safely. * @return A list of messages that have something to do with the shutdown.
* Can ignore safely.
*/ */
List<String> destroyServer(Long id); List<String> destroyServer(Long id);
} }

View File

@ -0,0 +1,67 @@
package org.jclouds.rimuhosting.miro;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Properties;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextFactory.ContextSpec;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.rimuhosting.miro.binder.CreateServerOptions;
import org.jclouds.rimuhosting.miro.filters.RimuHostingAuthentication;
import org.jclouds.rimuhosting.miro.functions.ParseRimuHostingException;
import org.testng.annotations.Test;
import com.google.inject.TypeLiteral;
/**
* Tests annotation parsing of {@code RimuHostingAsyncClient}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "rimuhosting.RimuHostingAsyncClientTest")
public class RimuHostingAsyncClientTest extends RestClientTest<RimuHostingAsyncClient> {
public void testCreateServer() throws SecurityException, NoSuchMethodException, IOException {
Method method = RimuHostingAsyncClient.class.getMethod("createServer", String.class, String.class, String.class,
CreateServerOptions[].class);
GeneratedHttpRequest<RimuHostingAsyncClient> httpRequest = processor.createRequest(method, "test.ivan.api.com",
"lenny", "MIRO1B");
assertRequestLineEquals(httpRequest, "POST https://rimuhosting.com/r/orders/new-vps HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(
httpRequest,
"{\"request\":{\"instantiation_options\":{\"distro\":\"lenny\",\"domain_name\":\"test.ivan.api.com\"},\"pricing_plan_code\":\"MIRO1B\",\"meta_data\":[]}}",
"application/json", false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ParseRimuHostingException.class);
checkFilters(httpRequest);
}
@Override
protected void checkFilters(HttpRequest request) {
assertEquals(request.getFilters().size(), 1);
assertEquals(request.getFilters().get(0).getClass(), RimuHostingAuthentication.class);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<RimuHostingAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<RimuHostingAsyncClient>>() {
};
}
@Override
public ContextSpec<RimuHostingClient, RimuHostingAsyncClient> createContextSpec() {
return new RestContextFactory().createContextSpec("rimuhosting", "apikey", "null", new Properties());
}
}

View File

@ -23,7 +23,7 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue; import static org.testng.Assert.assertTrue;
import java.util.SortedSet; import java.util.Set;
import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
@ -54,15 +54,15 @@ public class RimuHostingClientLiveTest {
@BeforeGroups(groups = { "live" }) @BeforeGroups(groups = { "live" })
public void setupClient() { public void setupClient() {
String credential = checkNotNull(System.getProperty("jclouds.test.credential"), "jclouds.test.credential"); String credential = checkNotNull(System.getProperty("jclouds.test.credential"), "jclouds.test.credential");
this.context = new RestContextFactory().createContext("rimuhosting", credential, credential, this.context = new RestContextFactory().createContext("rimuhosting", credential, credential, ImmutableSet
ImmutableSet.<Module> of(new Log4JLoggingModule())); .<Module> of(new Log4JLoggingModule()));
this.connection = context.getApi(); this.connection = context.getApi();
} }
@Test @Test
public void testPricingPlans() { public void testPricingPlans() {
SortedSet<PricingPlan> plans = connection.getPricingPlanList(); Set<PricingPlan> plans = connection.getPricingPlanList();
for (PricingPlan plan : plans) { for (PricingPlan plan : plans) {
if (plan.getId().equalsIgnoreCase("miro1")) { if (plan.getId().equalsIgnoreCase("miro1")) {
assertTrue(true); assertTrue(true);
@ -74,7 +74,7 @@ public class RimuHostingClientLiveTest {
@Test @Test
public void testImages() { public void testImages() {
SortedSet<Image> images = connection.getImageList(); Set<Image> images = connection.getImageList();
for (Image image : images) { for (Image image : images) {
if (image.getId().equalsIgnoreCase("lenny")) { if (image.getId().equalsIgnoreCase("lenny")) {
assertTrue(true); assertTrue(true);
@ -87,8 +87,7 @@ public class RimuHostingClientLiveTest {
@Test @Test
public void testLifeCycle() { public void testLifeCycle() {
// Get the first image, we dont really care what it is in this test. // Get the first image, we dont really care what it is in this test.
NewServerResponse serverResponse = connection.createServer("test.ivan.api.com", "lenny", NewServerResponse serverResponse = connection.createServer("test.ivan.api.com", "lenny", "MIRO1B");
"MIRO1B");
Server server = serverResponse.getServer(); Server server = serverResponse.getServer();
// Now we have the server, lets restart it // Now we have the server, lets restart it
assertNotNull(server.getId()); assertNotNull(server.getId());