mirror of https://github.com/apache/jclouds.git
added unit test to rimu
This commit is contained in:
parent
889f47078d
commit
45450e1b8f
|
@ -19,7 +19,7 @@
|
|||
package org.jclouds.rimuhosting.miro;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.SortedSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DELETE;
|
||||
|
@ -76,7 +76,7 @@ public interface RimuHostingAsyncClient {
|
|||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ParseRimuHostingException.class)
|
||||
ListenableFuture<SortedSet<Image>> getImageList();
|
||||
ListenableFuture<Set<Image>> getImageList();
|
||||
|
||||
/**
|
||||
* @see RimuHostingClient#getServerList
|
||||
|
@ -88,7 +88,7 @@ public interface RimuHostingAsyncClient {
|
|||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ParseRimuHostingException.class)
|
||||
ListenableFuture<SortedSet<Server>> getServerList();
|
||||
ListenableFuture<Set<Server>> getServerList();
|
||||
|
||||
/**
|
||||
* @see RimuHostingClient#getPricingPlanList
|
||||
|
@ -99,7 +99,7 @@ public interface RimuHostingAsyncClient {
|
|||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ParseRimuHostingException.class)
|
||||
@ResponseParser(ParsePricingPlansFromJsonResponse.class)
|
||||
ListenableFuture<SortedSet<PricingPlan>> getPricingPlanList();
|
||||
ListenableFuture<Set<PricingPlan>> getPricingPlanList();
|
||||
|
||||
/**
|
||||
* @see RimuHostingClient#createServer
|
||||
|
@ -111,10 +111,8 @@ public interface RimuHostingAsyncClient {
|
|||
@ExceptionParser(ParseRimuHostingException.class)
|
||||
@Unwrap
|
||||
@MapBinder(CreateServerOptions.class)
|
||||
ListenableFuture<NewServerResponse> createServer(
|
||||
@MapPayloadParam("name") String name,
|
||||
@MapPayloadParam("imageId") String imageId,
|
||||
@MapPayloadParam("planId") String planId,
|
||||
ListenableFuture<NewServerResponse> createServer(@MapPayloadParam("name") String name,
|
||||
@MapPayloadParam("imageId") String imageId, @MapPayloadParam("planId") String planId,
|
||||
CreateServerOptions... options);
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,13 +18,18 @@
|
|||
*/
|
||||
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.rimuhosting.miro.binder.CreateServerOptions;
|
||||
import org.jclouds.rimuhosting.miro.domain.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.SortedSet;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.jclouds.rimuhosting.miro.domain.Image;
|
||||
import org.jclouds.rimuhosting.miro.domain.MetaData;
|
||||
import org.jclouds.rimuhosting.miro.domain.NewServerResponse;
|
||||
import org.jclouds.rimuhosting.miro.domain.PricingPlan;
|
||||
import org.jclouds.rimuhosting.miro.domain.Server;
|
||||
import org.jclouds.rimuhosting.miro.domain.ServerInfo;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to RimuHosting.
|
||||
|
@ -38,11 +43,12 @@ import java.util.concurrent.TimeUnit;
|
|||
public interface RimuHostingClient {
|
||||
|
||||
/**
|
||||
* This operation returns a list of images that can be used for server creation.
|
||||
*c
|
||||
* This operation returns a list of images that can be used for server
|
||||
* creation. c
|
||||
*
|
||||
* @see Image
|
||||
*/
|
||||
SortedSet<Image> getImageList();
|
||||
Set<Image> getImageList();
|
||||
|
||||
/**
|
||||
* Returns a list of servers that belong to this identity.
|
||||
|
@ -50,26 +56,29 @@ public interface RimuHostingClient {
|
|||
* @return An empty set if there are no servers.
|
||||
* @see Server
|
||||
*/
|
||||
SortedSet<Server> getServerList();
|
||||
Set<Server> getServerList();
|
||||
|
||||
/**
|
||||
* Returns a list of pricing plans that can be used for server creation.
|
||||
*
|
||||
* @see PricingPlan
|
||||
*/
|
||||
SortedSet<PricingPlan> getPricingPlanList();
|
||||
Set<PricingPlan> getPricingPlanList();
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* 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.
|
||||
|
@ -89,7 +98,8 @@ public interface RimuHostingClient {
|
|||
/**
|
||||
* 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);
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
|
@ -23,7 +23,7 @@ import static org.testng.Assert.assertEquals;
|
|||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.SortedSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
@ -54,15 +54,15 @@ public class RimuHostingClientLiveTest {
|
|||
@BeforeGroups(groups = { "live" })
|
||||
public void setupClient() {
|
||||
String credential = checkNotNull(System.getProperty("jclouds.test.credential"), "jclouds.test.credential");
|
||||
this.context = new RestContextFactory().createContext("rimuhosting", credential, credential,
|
||||
ImmutableSet.<Module> of(new Log4JLoggingModule()));
|
||||
this.context = new RestContextFactory().createContext("rimuhosting", credential, credential, ImmutableSet
|
||||
.<Module> of(new Log4JLoggingModule()));
|
||||
this.connection = context.getApi();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPricingPlans() {
|
||||
SortedSet<PricingPlan> plans = connection.getPricingPlanList();
|
||||
Set<PricingPlan> plans = connection.getPricingPlanList();
|
||||
for (PricingPlan plan : plans) {
|
||||
if (plan.getId().equalsIgnoreCase("miro1")) {
|
||||
assertTrue(true);
|
||||
|
@ -74,7 +74,7 @@ public class RimuHostingClientLiveTest {
|
|||
|
||||
@Test
|
||||
public void testImages() {
|
||||
SortedSet<Image> images = connection.getImageList();
|
||||
Set<Image> images = connection.getImageList();
|
||||
for (Image image : images) {
|
||||
if (image.getId().equalsIgnoreCase("lenny")) {
|
||||
assertTrue(true);
|
||||
|
@ -87,8 +87,7 @@ public class RimuHostingClientLiveTest {
|
|||
@Test
|
||||
public void testLifeCycle() {
|
||||
// Get the first image, we dont really care what it is in this test.
|
||||
NewServerResponse serverResponse = connection.createServer("test.ivan.api.com", "lenny",
|
||||
"MIRO1B");
|
||||
NewServerResponse serverResponse = connection.createServer("test.ivan.api.com", "lenny", "MIRO1B");
|
||||
Server server = serverResponse.getServer();
|
||||
// Now we have the server, lets restart it
|
||||
assertNotNull(server.getId());
|
||||
|
|
Loading…
Reference in New Issue