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;
|
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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -18,13 +18,18 @@
|
||||||
*/
|
*/
|
||||||
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.
|
||||||
|
@ -38,11 +43,12 @@ 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.
|
||||||
|
@ -50,20 +56,23 @@ public interface RimuHostingClient {
|
||||||
* @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
|
||||||
*
|
*
|
||||||
|
@ -89,7 +98,8 @@ public interface RimuHostingClient {
|
||||||
/**
|
/**
|
||||||
* 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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.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());
|
||||||
|
|
Loading…
Reference in New Issue