Created new TaskClient and updated domain objects and tests accordingly

This commit is contained in:
Andrew Donald Kennedy 2012-02-07 11:35:33 +00:00
parent 3623918de5
commit 78fb8bd919
12 changed files with 563 additions and 30 deletions

View File

@ -22,13 +22,13 @@ import org.jclouds.rest.annotations.Delegate;
import org.jclouds.vcloud.director.v1_5.domain.Session; import org.jclouds.vcloud.director.v1_5.domain.Session;
import org.jclouds.vcloud.director.v1_5.features.NetworkAsyncClient; import org.jclouds.vcloud.director.v1_5.features.NetworkAsyncClient;
import org.jclouds.vcloud.director.v1_5.features.OrgAsyncClient; import org.jclouds.vcloud.director.v1_5.features.OrgAsyncClient;
import org.jclouds.vcloud.director.v1_5.features.TaskAsyncClient;
import com.google.inject.Provides; import com.google.inject.Provides;
/** /**
* Provides asynchronous access to VCloudDirector via their REST API. * Provides asynchronous access to VCloudDirector via their REST API.
* <p/>
* *
* @see VCloudDirectorClient * @see VCloudDirectorClient
* @author Adrian Cole * @author Adrian Cole
@ -47,6 +47,12 @@ public interface VCloudDirectorAsyncClient {
@Delegate @Delegate
OrgAsyncClient getOrgClient(); OrgAsyncClient getOrgClient();
/**
* @return asynchronous access to Task features
*/
@Delegate
TaskAsyncClient getTaskClient();
/** /**
* @return asynchronous access to Network features * @return asynchronous access to Network features
*/ */

View File

@ -25,6 +25,7 @@ import org.jclouds.rest.annotations.Delegate;
import org.jclouds.vcloud.director.v1_5.domain.Session; import org.jclouds.vcloud.director.v1_5.domain.Session;
import org.jclouds.vcloud.director.v1_5.features.NetworkClient; import org.jclouds.vcloud.director.v1_5.features.NetworkClient;
import org.jclouds.vcloud.director.v1_5.features.OrgClient; import org.jclouds.vcloud.director.v1_5.features.OrgClient;
import org.jclouds.vcloud.director.v1_5.features.TaskClient;
import com.google.inject.Provides; import com.google.inject.Provides;
@ -50,6 +51,12 @@ public interface VCloudDirectorClient {
@Delegate @Delegate
OrgClient getOrgClient(); OrgClient getOrgClient();
/**
* @return synchronous access to Task features
*/
@Delegate
TaskClient getTaskClient();
/** /**
* @return synchronous access to Network features * @return synchronous access to Network features
*/ */

View File

@ -18,16 +18,13 @@
*/ */
package org.jclouds.vcloud.director.v1_5; package org.jclouds.vcloud.director.v1_5;
import javax.ws.rs.core.MediaType;
/** /**
* Resource Types used in VCloud * Resource Types used in VCloud.
* *
* <br/>
* The object type, specified as a MIME content type, of the object that the link references. This * The object type, specified as a MIME content type, of the object that the link references. This
* attribute is present only for links to objects. It is not present for links to actions. * attribute is present only for links to objects. It is not present for links to actions.
* *
* @see MediaType * @see javax.ws.rs.core.MediaType;
*/ */
public interface VCloudDirectorMediaType { public interface VCloudDirectorMediaType {
public final static String NS = "http://www.vmware.com/vcloud/v1.5"; public final static String NS = "http://www.vmware.com/vcloud/v1.5";
@ -44,4 +41,8 @@ public interface VCloudDirectorMediaType {
public static final String ORG_NETWORK_XML = "application/vnd.vmware.vcloud.orgNetwork+xml"; public static final String ORG_NETWORK_XML = "application/vnd.vmware.vcloud.orgNetwork+xml";
public final static String TASK_XML = "application/vnd.vmware.vcloud.task+xml";
public static final String TASKSLIST_XML = "application/vnd.vmware.vcloud.tasksList+xml";
} }

View File

@ -46,6 +46,8 @@ import org.jclouds.vcloud.director.v1_5.features.NetworkAsyncClient;
import org.jclouds.vcloud.director.v1_5.features.NetworkClient; import org.jclouds.vcloud.director.v1_5.features.NetworkClient;
import org.jclouds.vcloud.director.v1_5.features.OrgAsyncClient; import org.jclouds.vcloud.director.v1_5.features.OrgAsyncClient;
import org.jclouds.vcloud.director.v1_5.features.OrgClient; import org.jclouds.vcloud.director.v1_5.features.OrgClient;
import org.jclouds.vcloud.director.v1_5.features.TaskAsyncClient;
import org.jclouds.vcloud.director.v1_5.features.TaskClient;
import org.jclouds.vcloud.director.v1_5.functions.LoginUserInOrgWithPassword; import org.jclouds.vcloud.director.v1_5.functions.LoginUserInOrgWithPassword;
import org.jclouds.vcloud.director.v1_5.handlers.InvalidateSessionAndRetryOn401AndLogoutOnClose; import org.jclouds.vcloud.director.v1_5.handlers.InvalidateSessionAndRetryOn401AndLogoutOnClose;
import org.jclouds.vcloud.director.v1_5.handlers.VCloudDirectorErrorHandler; import org.jclouds.vcloud.director.v1_5.handlers.VCloudDirectorErrorHandler;
@ -75,6 +77,7 @@ public class VCloudDirectorRestClientModule extends RestClientModule<VCloudDirec
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()// public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()//
.put(OrgClient.class, OrgAsyncClient.class) .put(OrgClient.class, OrgAsyncClient.class)
.put(NetworkClient.class, NetworkAsyncClient.class) .put(NetworkClient.class, NetworkAsyncClient.class)
.put(TaskClient.class, TaskAsyncClient.class)
.build(); .build();
public VCloudDirectorRestClientModule() { public VCloudDirectorRestClientModule() {

View File

@ -59,7 +59,10 @@ public class Task extends EntityType<Task> {
public static class Builder extends EntityType.Builder<Task> { public static class Builder extends EntityType.Builder<Task> {
private Error error; private Error error;
private Org org; private Reference org;
private Reference owner;
private Reference user;
private Object params;
private Integer progress; private Integer progress;
private String status; private String status;
private String operation; private String operation;
@ -79,11 +82,35 @@ public class Task extends EntityType<Task> {
/** /**
* @see Task#getOrg() * @see Task#getOrg()
*/ */
public Builder org(Org org) { public Builder org(Reference org) {
this.org = org; this.org = org;
return this; return this;
} }
/**
* @see Task#getOwner()
*/
public Builder owner(Reference owner) {
this.owner = owner;
return this;
}
/**
* @see Task#getUser()
*/
public Builder user(Reference user) {
this.user = user;
return this;
}
/**
* @see Task#getParams()
*/
public Builder params(Object params) {
this.params = params;
return this;
}
/** /**
* @see Task#getProgress() * @see Task#getProgress()
*/ */
@ -143,8 +170,16 @@ public class Task extends EntityType<Task> {
@Override @Override
public Task build() { public Task build() {
Task task = new Task(href, name); Task task = new Task(href, name);
task.setDescription(description);
task.setTasksInProgress(tasksInProgress);
task.setId(id);
task.setType(type);
task.setLinks(links);
task.setError(error); task.setError(error);
task.setOrg(org); task.setOrg(org);
task.setOwner(owner);
task.setUser(user);
task.setParams(params);
task.setProgress(progress); task.setProgress(progress);
task.setStatus(status); task.setStatus(status);
task.setOperation(operation); task.setOperation(operation);
@ -250,28 +285,31 @@ public class Task extends EntityType<Task> {
@XmlElement(namespace = NS, name = "Error") @XmlElement(namespace = NS, name = "Error")
private Error error; private Error error;
@XmlElement(namespace = NS, name = "Organization") @XmlElement(namespace = NS, name = "Organization")
private Org org; private Reference org;
@XmlElement(namespace = NS, name = "Progress") @XmlElement(namespace = NS, name = "Progress")
private Integer progress; private Integer progress;
@XmlElement(namespace = NS, name = "Owner") @XmlElement(namespace = NS, name = "Owner")
private Entity owner; private Reference owner;
@XmlElement(namespace = NS, name = "User") @XmlElement(namespace = NS, name = "User")
private Entity user; private Reference user;
@XmlElement(namespace = NS, name = "Params") @XmlElement(namespace = NS, name = "Params")
private Object params; private Object params;
@XmlAttribute(namespace = NS, name = "status") @XmlAttribute
private String status; private String status;
@XmlAttribute(namespace = NS, name = "operation") @XmlAttribute
private String operation; private String operation;
@XmlAttribute(namespace = NS, name = "operationName") @XmlAttribute
private String operationName; private String operationName;
@XmlAttribute(namespace = NS, name = "startTime") @XmlAttribute
private Date startTime; private Date startTime;
@XmlAttribute(namespace = NS, name = "endTime") @XmlAttribute
private Date endTime; private Date endTime;
@XmlAttribute(namespace = NS, name = "expiryTime") @XmlAttribute
private Date expiryTime; private Date expiryTime;
/**
* Represents an error information if the task failed.
*/
public Error getError() { public Error getError() {
return error; return error;
} }
@ -280,14 +318,56 @@ public class Task extends EntityType<Task> {
this.error = error; this.error = error;
} }
public Org getOrg() { /**
* The organization that started the task.
*/
public Reference getOrg() {
return org; return org;
} }
public void setOrg(Org org) { public void setOrg(Reference org) {
this.org = org; this.org = org;
} }
/**
* Reference to the owner of the task.
*/
public Reference getOwner() {
return owner;
}
public void setOwner(Reference owner) {
this.owner = owner;
}
/**
* The user who started the task.
*/
public Reference getUser() {
return user;
}
public void setUser(Reference user) {
this.user = user;
}
/**
* The parameters with which this task has been run.
*/
public Object getParams() {
return params;
}
public void setParams(Object params) {
this.params = params;
}
/**
* The progress of a long running asynchronous task.
*
* The value is between 0 - 100. Not all tasks have progress, the value is not
* present for task which progress is not available.
*/
public Integer getProgress() { public Integer getProgress() {
return progress; return progress;
} }
@ -296,6 +376,20 @@ public class Task extends EntityType<Task> {
this.progress = progress; this.progress = progress;
} }
/**
* The execution status of the task.
*
* One of:
* <ul>
* <li>queued - The task has been queued for execution.
* <li>preRunning - The task is awaiting preprocessing or, if it is a blocking task, administrative action.
* <li>running - The task is runnning.
* <li>success - The task completed with a status of success.
* <li>error - The task encountered an error while running.
* <li>canceled - The task was canceled by the owner or an administrator.
* <li>aborted - The task was aborted by an administrative action.
* </ul>
*/
public String getStatus() { public String getStatus() {
return status; return status;
} }
@ -304,6 +398,9 @@ public class Task extends EntityType<Task> {
this.status = status; this.status = status;
} }
/**
* The display name of the operation that is tracked by this task.
*/
public String getOperation() { public String getOperation() {
return operation; return operation;
} }
@ -312,6 +409,9 @@ public class Task extends EntityType<Task> {
this.operation = operation; this.operation = operation;
} }
/**
* The name of the operation that is tracked by this task.
*/
public String getOperationName() { public String getOperationName() {
return operationName; return operationName;
} }
@ -320,6 +420,11 @@ public class Task extends EntityType<Task> {
this.operationName = operationName; this.operationName = operationName;
} }
/**
* The date and time the system started executing the task.
*
* May not be present if the task hasn't been executed yet.
*/
public Date getStartTime() { public Date getStartTime() {
return startTime; return startTime;
} }
@ -328,6 +433,11 @@ public class Task extends EntityType<Task> {
this.startTime = startTime; this.startTime = startTime;
} }
/**
* The date and time that processing of the task was completed.
*
* May not be present if the task is still being executed.
*/
public Date getEndTime() { public Date getEndTime() {
return endTime; return endTime;
} }
@ -336,6 +446,11 @@ public class Task extends EntityType<Task> {
this.endTime = endTime; this.endTime = endTime;
} }
/**
* The date and time at which the task resource will be destroyed and no longer available for retrieval.
*
* May not be present if the task has not been executed or is still being executed.
*/
public Date getExpiryTime() { public Date getExpiryTime() {
return expiryTime; return expiryTime;
} }

View File

@ -28,6 +28,8 @@ import java.util.Set;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import org.jclouds.vcloud.director.v1_5.domain.Org.Builder;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
@ -81,8 +83,85 @@ public class TasksList extends EntityType<TasksList> {
return taskslist; return taskslist;
} }
/**
* @see EntityType#getName()
*/
@Override
public Builder name(String name) {
this.name = name;
return this;
}
/**
* @see EntityType#getDescription()
*/
@Override
public Builder description(String description) {
this.description = description;
return this;
}
/**
* @see EntityType#getId()
*/
@Override
public Builder id(String id) {
this.id = id;
return this;
}
/**
* @see EntityType#getTasksInProgress()
*/
@Override
public Builder tasksInProgress(TasksInProgress tasksInProgress) {
this.tasksInProgress = tasksInProgress;
return this;
}
/**
* @see ReferenceType#getHref()
*/
@Override
public Builder href(URI href) {
this.href = href;
return this;
}
/**
* @see ReferenceType#getType()
*/
@Override
public Builder type(String type) {
this.type = type;
return this;
}
/**
* @see ReferenceType#getLinks()
*/
@Override
public Builder links(Set<Link> links) {
this.links = Sets.newLinkedHashSet(checkNotNull(links, "links"));
return this;
}
/**
* @see ReferenceType#getLinks()
*/
@Override
public Builder link(Link link) {
this.links.add(checkNotNull(link, "link"));
return this;
}
@Override
public Builder fromEntityType(EntityType<TasksList> in) {
return Builder.class.cast(super.fromEntityType(in));
}
public Builder fromTasksList(TasksList in) { public Builder fromTasksList(TasksList in) {
return tasks(in.getTasks()); return fromEntityType(in).tasks(in.getTasks());
} }
} }

View File

@ -38,7 +38,6 @@ import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
/** /**
* @see OrgClient * @see OrgClient
* @author Adrian Cole * @author Adrian Cole
*/ */

View File

@ -0,0 +1,75 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.vcloud.director.v1_5.features;
import java.net.URI;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.JAXBResponseParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.vcloud.director.v1_5.domain.Task;
import org.jclouds.vcloud.director.v1_5.domain.TasksList;
import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest;
import com.google.common.util.concurrent.ListenableFuture;
/**
* @see TaskClient
* @author grkvlt@apache.org
*/
@RequestFilters(AddVCloudAuthorizationToRequest.class)
public interface TaskAsyncClient {
/**
* @see TaskClient#getTaskList(URI)
*/
@GET
@Path("/tasksList/{id}")
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<TasksList> getTaskList(@PathParam("id") String orgId);
/**
* @see TaskClient#getTask(URI)
*/
@GET
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Task> getTask(@EndpointParam URI taskHref);
/**
* @see TaskClient#cancelTask(URI)
*/
@POST
@Path("/action/cancel")
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
void cancelTask(@EndpointParam URI taskHref);
}

View File

@ -0,0 +1,56 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.vcloud.director.v1_5.features;
import java.net.URI;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.director.v1_5.domain.Task;
import org.jclouds.vcloud.director.v1_5.domain.TasksList;
/**
* Provides synchronous access to {@link Task} objects.
*
* @see TaskAsyncClient
* @author grkvlt@apache.org
*/
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public interface TaskClient {
/**
* Retrieves a list of tasks.
*
* @param orgId the unique id for the organization
* @return a list of tasks
*/
TasksList getTaskList(String orgId);
/**
* Retrieves a task.
*
* @return the task or null if not found
*/
Task getTask(URI taskHref);
/**
* Cancels a task.
*/
void cancelTask(URI taskHref);
}

View File

@ -0,0 +1,123 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
*(Link.builder().regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless(Link.builder().required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.vcloud.director.v1_5.features;
import static org.testng.Assert.*;
import java.net.URI;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.Task;
import org.jclouds.vcloud.director.v1_5.domain.TasksList;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest;
import org.testng.annotations.Test;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Iterables;
/**
* Test the {@link TaskClient} by observing its side effects.
*
* @author grkvlt@apache.org
*/
@Test(groups = "unit", singleThreaded = true, testName = "TaskClientExpectTest")
public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest {
@Test
public void testTaskListForValidOrg() {
HttpRequest orgListRequest = HttpRequest.builder()
.method("GET")
.endpoint(URI.create("http://localhost/api/tasksList/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.headers(ImmutableMultimap.<String, String> builder()
.put("Accept", "*/*")
.put("x-vcloud-authorization", token)
.build())
.build();
HttpResponse orgListResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/taskslist.xml", VCloudDirectorMediaType.TASKSLIST_XML + ";version=1.5"))
.build();
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, orgListRequest, orgListResponse);
String orgId =Iterables.getLast(Splitter.on("/").split(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0").getPath()));
assertEquals(client.getTaskClient().getTaskList(orgId), TasksList.builder()
.name("Tasks Lists")
.type("application/vnd.vmware.vcloud.tasksList+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/tasksList/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.task(Task.builder()
.type("application/vnd.vmware.vcloud.task+xml")
.name("task")
.id("urn:vcloud:task:5fcd2af3-d0ec-45ce-9451-8c585a2c766b")
.href(URI.create("https://vcloudbeta.bluelock.com/api/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b"))
.status("success")
.operation("Created Catalog QunyingTestCatalog(7212e451-76e1-4631-b2de-ba1dfd8080e4)")
.operationName("catalogCreateCatalog")
.startTime(dateService.iso8601DateParse("2012-02-07T00:16:28.450-05:00"))
.endTime(dateService.iso8601DateParse("2012-02-07T00:16:28.867-05:00"))
.expiryTime(dateService.iso8601DateParse("2012-05-07T00:16:28.450-04:00"))
.owner(Reference.builder()
.type("application/vnd.vmware.vcloud.catalog+xml")
.name("QunyingTestCatalog")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4"))
.build())
.user(Reference.builder()
.type("application/vnd.vmware.admin.user+xml")
.name("JClouds")
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.build())
.org(Reference.builder()
.type("application/vnd.vmware.vcloud.org+xml")
.name("JClouds")
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.build())
.build())
.task(Task.builder()
.type("application/vnd.vmware.vcloud.task+xml")
.name("task")
.id("urn:vcloud:task:bd22e745-9c2a-4f82-a954-0e35b6f76ba5")
.href(URI.create("https://vcloudbeta.bluelock.com/api/task/bd22e745-9c2a-4f82-a954-0e35b6f76ba5"))
.status("success")
.operation("Enabled User (967d317c-4273-4a95-b8a4-bf63b78e9c69)")
.operationName("jobEnable")
.startTime(dateService.iso8601DateParse("2012-02-06T17:30:38.507-05:00"))
.endTime(dateService.iso8601DateParse("2012-02-06T17:30:38.507-05:00"))
.expiryTime(dateService.iso8601DateParse("2012-05-06T17:30:38.507-04:00"))
.user(Reference.builder()
.type("application/vnd.vmware.admin.user+xml")
.name("adrian@jclouds.org")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/8c360b93-ed25-4c9a-8e24-d48cd9966d93"))
.build())
.org(Reference.builder()
.type("application/vnd.vmware.vcloud.org+xml")
.name("JClouds")
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.build())
.build())
.build()
);
}
}

View File

@ -20,13 +20,16 @@ package org.jclouds.vcloud.director.v1_5.internal;
import java.net.URI; import java.net.URI;
import org.jclouds.date.DateService;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.rest.BaseRestClientExpectTest; import org.jclouds.rest.BaseRestClientExpectTest;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.testng.annotations.BeforeTest;
import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableMultimap;
import com.google.inject.Guice;
/** /**
* Base class for writing KeyStone Rest Client Expect tests * Base class for writing KeyStone Rest Client Expect tests
@ -40,15 +43,30 @@ public class BaseVCloudDirectorRestClientExpectTest extends BaseRestClientExpect
public static final String password = "password"; public static final String password = "password";
public static final String token = "mIaR3/6Lna8DWImd7/JPR5rK8FcUHabt+G/UCJV5pJQ="; public static final String token = "mIaR3/6Lna8DWImd7/JPR5rK8FcUHabt+G/UCJV5pJQ=";
protected HttpRequest loginRequest = HttpRequest.builder().method("POST").endpoint( protected DateService dateService;
URI.create("http://localhost/api/sessions")).headers(
ImmutableMultimap.<String, String> builder().put("Accept", "*/*").put("Authorization",
"Basic YWRyaWFuQGpjbG91ZHMub3JnQEpDbG91ZHM6cGFzc3dvcmQ=").build()).build();
protected HttpResponse sessionResponse = HttpResponse.builder().statusCode(200).headers( @BeforeTest
ImmutableMultimap.<String, String> builder().put("x-vcloud-authorization", token).put("Set-Cookie", protected void setUpInjector() {
String.format("vcloud-token=%s; Secure; Path=/", token)).build()).payload( dateService = Guice.createInjector().getInstance(DateService.class);
payloadFromResourceWithContentType("/session.xml", VCloudDirectorMediaType.SESSION_XML + ";version=1.5")) assert dateService != null;
}
protected HttpRequest loginRequest = HttpRequest.builder()
.method("POST")
.endpoint(URI.create("http://localhost/api/sessions"))
.headers(ImmutableMultimap.<String, String>builder()
.put("Accept", "*/*")
.put("Authorization", "Basic YWRyaWFuQGpjbG91ZHMub3JnQEpDbG91ZHM6cGFzc3dvcmQ=")
.build())
.build();
protected HttpResponse sessionResponse = HttpResponse.builder()
.statusCode(200)
.headers(ImmutableMultimap.<String, String> builder()
.put("x-vcloud-authorization", token)
.put("Set-Cookie", String.format("vcloud-token=%s; Secure; Path=/", token))
.build())
.payload(payloadFromResourceWithContentType("/session.xml", VCloudDirectorMediaType.SESSION_XML + ";version=1.5"))
.build(); .build();
public BaseVCloudDirectorRestClientExpectTest() { public BaseVCloudDirectorRestClientExpectTest() {

View File

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<TasksList xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://vcloudbeta.bluelock.com/api/v1.5/schema/master.xsd"
name="Tasks Lists"
type="application/vnd.vmware.vcloud.tasksList+xml"
href="https://vcloudbeta.bluelock.com/api/tasksList/6f312e42-cd2b-488d-a2bb-97519cd57ed0">
<Task
status="success"
startTime="2012-02-07T00:16:28.450-05:00"
operationName="catalogCreateCatalog"
operation="Created Catalog QunyingTestCatalog(7212e451-76e1-4631-b2de-ba1dfd8080e4)"
expiryTime="2012-05-07T00:16:28.450-04:00"
endTime="2012-02-07T00:16:28.867-05:00"
name="task"
id="urn:vcloud:task:5fcd2af3-d0ec-45ce-9451-8c585a2c766b"
type="application/vnd.vmware.vcloud.task+xml"
href="https://vcloudbeta.bluelock.com/api/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b">
<Owner
type="application/vnd.vmware.vcloud.catalog+xml"
name="QunyingTestCatalog"
href="https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4" />
<User
type="application/vnd.vmware.admin.user+xml"
name="qunying.huang@enstratus.com"
href="https://vcloudbeta.bluelock.com/api/admin/user/967d317c-4273-4a95-b8a4-bf63b78e9c69" />
<Organization
type="application/vnd.vmware.vcloud.org+xml"
name="JClouds"
href="https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0" />
</Task>
<Task
status="success"
startTime="2012-02-06T17:30:38.507-05:00"
operationName="jobEnable"
operation="Enabled User (967d317c-4273-4a95-b8a4-bf63b78e9c69)"
expiryTime="2012-05-06T17:30:38.507-04:00"
endTime="2012-02-06T17:30:38.507-05:00"
name="task"
id="urn:vcloud:task:bd22e745-9c2a-4f82-a954-0e35b6f76ba5"
type="application/vnd.vmware.vcloud.task+xml"
href="https://vcloudbeta.bluelock.com/api/task/bd22e745-9c2a-4f82-a954-0e35b6f76ba5">
<User
type="application/vnd.vmware.admin.user+xml"
name="adrian@jclouds.org"
href="https://vcloudbeta.bluelock.com/api/admin/user/8c360b93-ed25-4c9a-8e24-d48cd9966d93" />
<Organization
type="application/vnd.vmware.vcloud.org+xml"
name="JClouds"
href="https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0" />
</Task>
</TasksList>