mirror of https://github.com/apache/jclouds.git
EventsAsyncClient and test implmentation
This commit is contained in:
parent
ee5f2bbcb0
commit
0dba1c4f5d
|
@ -24,12 +24,15 @@ import javax.ws.rs.core.MediaType;
|
|||
import java.util.Set;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import org.jclouds.cloudstack.domain.Event;
|
||||
import org.jclouds.cloudstack.filters.QuerySigner;
|
||||
import org.jclouds.cloudstack.functions.ParseEventTypesFromHttpResponse;
|
||||
import org.jclouds.cloudstack.options.ListEventsOptions;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.QueryParams;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.ResponseParser;
|
||||
import org.jclouds.rest.annotations.SelectJson;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
|
||||
/**
|
||||
|
@ -53,4 +56,14 @@ public interface EventAsyncClient {
|
|||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
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);
|
||||
|
||||
}
|
||||
|
|
|
@ -21,6 +21,8 @@ package org.jclouds.cloudstack.features;
|
|||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.cloudstack.domain.Event;
|
||||
import org.jclouds.cloudstack.options.ListEventsOptions;
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
|
||||
/**
|
||||
|
@ -40,6 +42,12 @@ public interface EventClient {
|
|||
*/
|
||||
Set<String> listEventTypes();
|
||||
|
||||
/**
|
||||
* List Events
|
||||
*
|
||||
* @return event list or null if not found
|
||||
*/
|
||||
Set<Event> listEvents(ListEventsOptions... options);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -74,23 +74,56 @@ public class ListEventsOptions extends BaseHttpRequestOptions {
|
|||
return this;
|
||||
}
|
||||
|
||||
// page
|
||||
// pagesize
|
||||
// startdate
|
||||
// type
|
||||
|
||||
/**
|
||||
* @param name the SSHKeyPair name
|
||||
*/
|
||||
public ListEventsOptions name(String name) {
|
||||
this.queryParameters.replaceValues("name", ImmutableSet.of(name));
|
||||
public ListEventsOptions type(String type) {
|
||||
this.queryParameters.replaceValues("type", ImmutableSet.of(type));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public static class Builder {
|
||||
public static ListEventsOptions name(String name) {
|
||||
ListEventsOptions options = new ListEventsOptions();
|
||||
return options.name(name);
|
||||
public static ListEventsOptions account(String account) {
|
||||
final ListEventsOptions options = new ListEventsOptions();
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,7 +23,9 @@ import java.lang.reflect.Method;
|
|||
|
||||
import com.google.inject.TypeLiteral;
|
||||
import org.jclouds.cloudstack.functions.ParseEventTypesFromHttpResponse;
|
||||
import org.jclouds.cloudstack.options.ListEventsOptions;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -51,6 +53,39 @@ public class EventAsyncClientTest extends BaseCloudStackAsyncClientTest<EventAsy
|
|||
assertSaxResponseParserClassEquals(method, null);
|
||||
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);
|
||||
|
||||
}
|
||||
|
|
|
@ -40,7 +40,6 @@ public class LimitClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
}
|
||||
|
||||
private void checkResourceLimit(ResourceLimit resourceLimit) {
|
||||
System.out.println(resourceLimit);
|
||||
assert resourceLimit.getAccount() != null : resourceLimit;
|
||||
assert resourceLimit.getDomain() != null : resourceLimit;
|
||||
assert resourceLimit.getResourceType() != ResourceLimit.ResourceType.UNRECOGNIZED : resourceLimit;
|
||||
|
|
Loading…
Reference in New Issue