EventsAsyncClient and test implmentation

This commit is contained in:
vijaykiran 2011-11-12 06:13:50 +01:00
parent ee5f2bbcb0
commit 0dba1c4f5d
5 changed files with 102 additions and 14 deletions

View File

@ -24,12 +24,15 @@ import javax.ws.rs.core.MediaType;
import java.util.Set; import java.util.Set;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import org.jclouds.cloudstack.domain.Event;
import org.jclouds.cloudstack.filters.QuerySigner; import org.jclouds.cloudstack.filters.QuerySigner;
import org.jclouds.cloudstack.functions.ParseEventTypesFromHttpResponse; import org.jclouds.cloudstack.functions.ParseEventTypesFromHttpResponse;
import org.jclouds.cloudstack.options.ListEventsOptions;
import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.QueryParams; import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
/** /**
@ -53,4 +56,14 @@ public interface EventAsyncClient {
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<String>> listEventTypes(); ListenableFuture<Set<String>> listEventTypes();
/**
* @see EventClient#listEventTypes()
*/
@GET
@QueryParams(keys = "command", values = "listEvents")
@SelectJson("event")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<Event>> listEvents(ListEventsOptions...options);
} }

View File

@ -21,6 +21,8 @@ package org.jclouds.cloudstack.features;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.jclouds.cloudstack.domain.Event;
import org.jclouds.cloudstack.options.ListEventsOptions;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
/** /**
@ -40,6 +42,12 @@ public interface EventClient {
*/ */
Set<String> listEventTypes(); Set<String> listEventTypes();
/**
* List Events
*
* @return event list or null if not found
*/
Set<Event> listEvents(ListEventsOptions... options);
} }

View File

@ -74,23 +74,56 @@ public class ListEventsOptions extends BaseHttpRequestOptions {
return this; return this;
} }
// page public ListEventsOptions type(String type) {
// pagesize this.queryParameters.replaceValues("type", ImmutableSet.of(type));
// startdate
// type
/**
* @param name the SSHKeyPair name
*/
public ListEventsOptions name(String name) {
this.queryParameters.replaceValues("name", ImmutableSet.of(name));
return this; return this;
} }
public static class Builder { public static class Builder {
public static ListEventsOptions name(String name) { public static ListEventsOptions account(String account) {
ListEventsOptions options = new ListEventsOptions(); final ListEventsOptions options = new ListEventsOptions();
return options.name(name); return options.account(account);
}
public static ListEventsOptions domainId(long domainId) {
final ListEventsOptions options = new ListEventsOptions();
return options.domainId(domainId);
}
public static ListEventsOptions duration(String duration) {
final ListEventsOptions options = new ListEventsOptions();
return options.duration(duration);
}
public static ListEventsOptions endDate(Date enddate) {
final ListEventsOptions options = new ListEventsOptions();
return options.endDate(enddate);
}
public static ListEventsOptions entryTime(Date entrytime) {
final ListEventsOptions options = new ListEventsOptions();
return options.entryTime(entrytime);
}
public static ListEventsOptions id(String id) {
final ListEventsOptions options = new ListEventsOptions();
return options.id(id);
}
public static ListEventsOptions keyword(String keyword) {
final ListEventsOptions options = new ListEventsOptions();
return options.keyword(keyword);
}
public static ListEventsOptions level(String level) {
final ListEventsOptions options = new ListEventsOptions();
return options.level(level);
}
public static ListEventsOptions type(String type) {
final ListEventsOptions options = new ListEventsOptions();
return options.type(type);
} }
} }

View File

@ -23,7 +23,9 @@ import java.lang.reflect.Method;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
import org.jclouds.cloudstack.functions.ParseEventTypesFromHttpResponse; import org.jclouds.cloudstack.functions.ParseEventTypesFromHttpResponse;
import org.jclouds.cloudstack.options.ListEventsOptions;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -51,6 +53,39 @@ public class EventAsyncClientTest extends BaseCloudStackAsyncClientTest<EventAsy
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class); assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testListEvents() throws SecurityException, NoSuchMethodException, IOException {
Method method = EventAsyncClient.class.getMethod("listEvents", ListEventsOptions[].class);
HttpRequest httpRequest = processor.createRequest(method);
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=listEvents HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testEventsListOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = EventAsyncClient.class.getMethod("listEvents", ListEventsOptions[].class);
HttpRequest httpRequest = processor.createRequest(method, ListEventsOptions.Builder.account("jclouds"));
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=listEvents&account=jclouds HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
checkFilters(httpRequest); checkFilters(httpRequest);
} }

View File

@ -40,7 +40,6 @@ public class LimitClientLiveTest extends BaseCloudStackClientLiveTest {
} }
private void checkResourceLimit(ResourceLimit resourceLimit) { private void checkResourceLimit(ResourceLimit resourceLimit) {
System.out.println(resourceLimit);
assert resourceLimit.getAccount() != null : resourceLimit; assert resourceLimit.getAccount() != null : resourceLimit;
assert resourceLimit.getDomain() != null : resourceLimit; assert resourceLimit.getDomain() != null : resourceLimit;
assert resourceLimit.getResourceType() != ResourceLimit.ResourceType.UNRECOGNIZED : resourceLimit; assert resourceLimit.getResourceType() != ResourceLimit.ResourceType.UNRECOGNIZED : resourceLimit;