Issue 695: Added getTasksByVirtualMachine method call

This commit is contained in:
Jason King 2011-11-22 14:31:59 +00:00
parent f823a4d9de
commit c4f1fa040f
4 changed files with 47 additions and 10 deletions

View File

@ -62,4 +62,13 @@ public interface TaskAsyncClient {
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Task> getTask(@EndpointParam URI taskId); ListenableFuture<Task> getTask(@EndpointParam URI taskId);
/**
* @see TaskClient#getTasksByVirtualMachine
*/
@GET
@Consumes("application/vnd.tmrk.cloud.task; type=collection")
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Tasks> getTasksByVirtualMachine(@EndpointParam URI uri);
} }

View File

@ -52,6 +52,14 @@ public interface TaskClient {
* *
* @return the task or null if not found * @return the task or null if not found
*/ */
Task getTask(URI taskId); Task getTask(URI taskUri);
/**
* The Get Tasks by Virtual Machine call returns information regarding tasks
* for a specified virtual machine in an environment.
* @param uri The uri corresponding to the tasks. e.g. /cloudapi/ecloud/tasks/virtualmachines/{id}
* @return Tasks
*/
Tasks getTasksByVirtualMachine(URI uri);
} }

View File

@ -52,12 +52,11 @@ public class TaskAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncClient
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class); assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
checkFilters(httpRequest); checkFilters(httpRequest);
} }
public void testGetTask() throws SecurityException, NoSuchMethodException, IOException { public void testGetTask() throws SecurityException, NoSuchMethodException, IOException {
Method method = TaskAsyncClient.class.getMethod("getTask", URI.class); Method method = TaskAsyncClient.class.getMethod("getTask", URI.class);
HttpRequest httpRequest = processor.createRequest(method, URI.create("https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/tasks/1")); HttpRequest httpRequest = processor.createRequest(method, URI.create("/cloudapi/ecloud/tasks/1"));
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/tasks/1 HTTP/1.1"); assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/tasks/1 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.task\nx-tmrk-version: 2011-07-01\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.task\nx-tmrk-version: 2011-07-01\n");
@ -67,7 +66,20 @@ public class TaskAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncClient
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest); checkFilters(httpRequest);
}
public void testGetTasksByVirtualMachine() throws SecurityException, NoSuchMethodException, IOException {
Method method = TaskAsyncClient.class.getMethod("getTasksByVirtualMachine", URI.class);
HttpRequest httpRequest = processor.createRequest(method, URI.create("/cloudapi/ecloud/tasks/virtualmachines/5504"));
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/tasks/virtualmachines/5504 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.task; type=collection\nx-tmrk-version: 2011-07-01\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
} }
@Override @Override

View File

@ -43,18 +43,26 @@ public class TaskClientLiveTest extends BaseTerremarkEnterpriseCloudClientLiveTe
private TaskClient client; private TaskClient client;
@Test
public void testGetTasks() throws Exception { public void testGetTasks() throws Exception {
// TODO: don't hard-code id // TODO: don't hard-code id
// TODO: docs say don't parse the href, yet no xml includes "identifier",
// I suspect we may need to change to URI args as opposed to long
Tasks response = client.getTasksInEnvironment(new URI("/cloudapi/ecloud/tasks/environments/77")); Tasks response = client.getTasksInEnvironment(new URI("/cloudapi/ecloud/tasks/environments/77"));
assert null != response; assertTasks(response);
}
assertTrue(response.getTasks().size() >= 0); public void testGetTasksByVirtualMachine() throws Exception {
for (Task task : response.getTasks()) { // TODO: don't hard-code id
Tasks response = client.getTasksByVirtualMachine(URI.create("/cloudapi/ecloud/tasks/virtualmachines/5504"));
assertTasks(response);
}
private void assertTasks(final Tasks tasks) {
assert null != tasks;
assertTrue(tasks.getTasks().size() >= 0);
for (Task task : tasks.getTasks()) {
assertEquals(client.getTask(task.getHref()), task); assertEquals(client.getTask(task.getHref()), task);
assert task.getStatus() != Task.Status.UNRECOGNIZED : response; assert task.getStatus() != Task.Status.UNRECOGNIZED : tasks;
} }
} }
} }