Issue 830: refactored Org, Network, Task, User apis to support URN; removed 'id' from Reference type

This commit is contained in:
Adrian Cole 2012-08-19 15:23:20 -07:00
parent 9e69626413
commit 206af90b77
76 changed files with 2607 additions and 1974 deletions

View File

@ -44,8 +44,10 @@
<test.vcloud-director.catalog-id></test.vcloud-director.catalog-id>
<test.vcloud-director.media-id></test.vcloud-director.media-id>
<test.vcloud-director.vapptemplate-id></test.vcloud-director.vapptemplate-id>
<!-- URN format: ex. urn:vcloud:network:7212e451-76e1-4631-b2de-ba1dfd8080e4 -->
<test.vcloud-director.network-id></test.vcloud-director.network-id>
<test.vcloud-director.vdc-id></test.vcloud-director.vdc-id>
<!-- URN format: ex. urn:vcloud:user:7212e451-76e1-4631-b2de-ba1dfd8080e4 -->
<test.vcloud-director.user-id></test.vcloud-director.user-id>
<jclouds.osgi.export>org.jclouds.vcloud.director.v1_5*;version="${project.version}"</jclouds.osgi.export>

View File

@ -53,8 +53,8 @@ public class CatalogReference extends Reference {
super(builder);
}
public CatalogReference(URI href, String id, String name, String type) {
super(href, id, name, type);
public CatalogReference(URI href, String name, String type) {
super(href, name, type);
}
protected CatalogReference() {

View File

@ -29,6 +29,7 @@ import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.bind.annotation.XmlType;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorApi;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
@ -38,17 +39,14 @@ import com.google.common.base.Objects.ToStringHelper;
*
* Contains an href attribute and optional name and type attributes.
* <p>
*
* <pre>
* &lt;xs:complexType name="ReferenceType"&gt;
* </pre>
*
* @author grkvlt@apache.org
*/
@XmlSeeAlso({
VAppReference.class,
CatalogReference.class,
RoleReference.class
})
@XmlSeeAlso({ VAppReference.class, CatalogReference.class, RoleReference.class })
@XmlRootElement(name = "Reference")
@XmlType(name = "ReferenceType")
public class Reference {
@ -70,7 +68,6 @@ public class Reference {
public static class Builder<B extends Builder<B>> {
private URI href;
private String id;
private String name;
private String type;
@ -87,14 +84,6 @@ public class Reference {
return self();
}
/**
* @see Reference#getId()
*/
public B id(String id) {
this.id = id;
return self();
}
/**
* @see Reference#getType()
*/
@ -116,37 +105,33 @@ public class Reference {
}
public B fromReference(Reference in) {
return href(in.getHref()).id(in.getId()).name(in.getName()).type(in.getType());
return href(in.getHref()).name(in.getName()).type(in.getType());
}
public B fromEntity(Entity in) {
return href(in.getHref()).id(in.getId()).name(in.getName()).type(in.getType());
return href(in.getHref()).name(in.getName()).type(in.getType());
}
protected B fromAttributes(Map<String, String> attributes) {
return href(URI.create(attributes.get("href"))).id(attributes.get("id")).name(attributes.get("name")).type(attributes.get("type"));
return href(URI.create(attributes.get("href"))).name(attributes.get("name")).type(attributes.get("type"));
}
}
@XmlAttribute(required = true)
private URI href;
@XmlAttribute
private String id;
@XmlAttribute
private String name;
@XmlAttribute
private String type;
protected Reference(Builder<?> builder) {
this.href = builder.href;
this.id = builder.id;
this.name = builder.name;
this.type = builder.type;
}
protected Reference(URI href, String id, String name, String type) {
protected Reference(URI href, String name, String type) {
this.href = href;
this.id = id;
this.name = name;
this.type = type;
}
@ -172,16 +157,6 @@ public class Reference {
return href;
}
/**
* The resource identifier, expressed in URN format.
* <p/>
* The value of this attribute uniquely identifies the resource, persists for the life of the
* resource, and is never reused.
*/
public String getId() {
return id;
}
/**
* Contains the name of the the entity.
* <p/>
@ -213,12 +188,12 @@ public class Reference {
if (o == null || getClass() != o.getClass())
return false;
Reference that = Reference.class.cast(o);
return equal(this.href, that.href) && equal(this.id, that.id) && equal(this.name, that.name) && equal(this.type, that.type);
return equal(this.href, that.href) && equal(this.name, that.name) && equal(this.type, that.type);
}
@Override
public int hashCode() {
return Objects.hashCode(href, id, name, type);
return Objects.hashCode(href, name, type);
}
@Override
@ -227,13 +202,15 @@ public class Reference {
}
protected ToStringHelper string() {
return Objects.toStringHelper("").add("href", href).add("id", id).add("name", name).add("type", type);
return Objects.toStringHelper("").add("href", href).add("name", name).add("type", type);
}
/**
* @see VCloudDirectorApi#resolveEntity
*/
@Deprecated
public Reference toAdminReference(String endpoint) {
return toBuilder()
.type(null)
.href(URI.create(getHref().toASCIIString().replace(endpoint, endpoint+"/admin")))
return toBuilder().type(null).href(URI.create(getHref().toASCIIString().replace(endpoint, endpoint + "/admin")))
.build();
}
}

View File

@ -53,8 +53,8 @@ public class RoleReference extends Reference {
super(builder);
}
public RoleReference(URI href, String id, String name, String type) {
super(href, id, name, type);
public RoleReference(URI href, String name, String type) {
super(href, name, type);
}
protected RoleReference() {

View File

@ -70,7 +70,7 @@ public class Session {
}
/**
* @see Session#getOrg()
* @see Session#get()
*/
public Builder org(String org) {
this.org = org;
@ -106,7 +106,7 @@ public class Session {
}
public Builder fromSession(Session in) {
return user(in.getUser()).org(in.getOrg()).href(in.getHref()).links(in.getLinks());
return user(in.getUser()).org(in.get()).href(in.getHref()).links(in.getLinks());
}
}
@ -144,7 +144,7 @@ public class Session {
/**
* @return is the name of an organization of which the user is a member
*/
public String getOrg() {
public String get() {
return org;
}

View File

@ -138,7 +138,7 @@ public class Task extends Entity {
}
/**
* @see Task#getOrg()
* @see Task#get()
*/
public B org(Reference org) {
this.org = org;
@ -241,7 +241,7 @@ public class Task extends Entity {
public B fromTask(Task in) {
return fromEntityType(in)
.error(in.getError())
.org(in.getOrg())
.org(in.get())
.progress(in.getProgress())
.owner(in.getOwner())
.user(in.getUser())
@ -310,7 +310,7 @@ public class Task extends Entity {
/**
* The organization that started the task.
*/
public Reference getOrg() {
public Reference get() {
return org;
}

View File

@ -53,8 +53,8 @@ public class VAppReference extends Reference {
super(builder);
}
public VAppReference(URI href, String id, String name, String type) {
super(href, id, name, type);
public VAppReference(URI href, String name, String type) {
super(href, name, type);
}
protected VAppReference() {

View File

@ -64,7 +64,7 @@ public class QueryResultAdminGroupRecord extends QueryResultRecordType {
}
/**
* @see QueryResultAdminGroupRecord#getOrg()
* @see QueryResultAdminGroupRecord#get()
*/
public B org(String val) {
this.org = val;
@ -95,7 +95,7 @@ public class QueryResultAdminGroupRecord extends QueryResultRecordType {
public B fromQueryResultAdminGroupRecord(QueryResultAdminGroupRecord in) {
return fromQueryResultRecordType(in)
.name(in.getName())
.org(in.getOrg())
.org(in.get())
.roleName(in.getRoleName())
.isReadOnly(in.isReadOnly());
}
@ -133,7 +133,7 @@ public class QueryResultAdminGroupRecord extends QueryResultRecordType {
/**
* Organization reference or id
*/
public String getOrg() {
public String get() {
return org;
}

View File

@ -71,7 +71,7 @@ public class QueryResultAdminUserRecord extends QueryResultRecordType {
}
/**
* @see QueryResultAdminUserRecord#getOrg()
* @see QueryResultAdminUserRecord#get()
*/
public B org(String val) {
this.org = val;
@ -158,7 +158,7 @@ public class QueryResultAdminUserRecord extends QueryResultRecordType {
public B fromQueryResultAdminUserRecord(QueryResultAdminUserRecord in) {
return fromQueryResultRecordType(in)
.name(in.getName())
.org(in.getOrg())
.org(in.get())
.fullName(in.getFullName())
.isEnabled(in.isEnabled())
.numberOfDeployedVMs(in.getNumberOfDeployedVMs())
@ -224,7 +224,7 @@ public class QueryResultAdminUserRecord extends QueryResultRecordType {
/**
* Organization reference or id
*/
public String getOrg() {
public String get() {
return org;
}

View File

@ -186,7 +186,7 @@ public class QueryResultAdminVdcRecord extends QueryResultRecordType {
}
/**
* @see QueryResultAdminVdcRecord#getOrg()
* @see QueryResultAdminVdcRecord#get()
*/
public B org(String val) {
this.org = val;
@ -270,7 +270,7 @@ public class QueryResultAdminVdcRecord extends QueryResultRecordType {
.providerVdcName(in.getProviderVdcName())
.providerVdc(in.getProviderVdc())
.orgName(in.getOrgName())
.org(in.getOrg())
.org(in.get())
.numberOfVApps(in.getNumberOfVApps())
.numberOfMedia(in.getNumberOfMedia())
.numberOfVAppTemplates(in.getNumberOfVAppTemplates())
@ -458,7 +458,7 @@ public class QueryResultAdminVdcRecord extends QueryResultRecordType {
/**
* Organization reference or id
*/
public String getOrg() {
public String get() {
return org;
}

View File

@ -112,7 +112,7 @@ public class QueryResultMediaRecord extends QueryResultRecordType {
}
/**
* @see QueryResultMediaRecord#getOrg()
* @see QueryResultMediaRecord#get()
*/
public B org(String val) {
this.org = val;
@ -188,7 +188,7 @@ public class QueryResultMediaRecord extends QueryResultRecordType {
.name(in.getName())
.vdc(in.getVdc())
.vdcName(in.getVdcName())
.org(in.getOrg())
.org(in.get())
.creationDate(in.getCreationDate())
.isBusy(in.isBusy())
.storageB(in.getStorageB())
@ -296,7 +296,7 @@ public class QueryResultMediaRecord extends QueryResultRecordType {
/**
* Organization reference or id
*/
public String getOrg() {
public String get() {
return org;
}

View File

@ -119,7 +119,7 @@ public class QueryResultVAppTemplateRecord extends QueryResultRecordType {
}
/**
* @see QueryResultVAppTemplateRecord#getOrg()
* @see QueryResultVAppTemplateRecord#get()
*/
public B org(String val) {
this.org = val;
@ -187,7 +187,7 @@ public class QueryResultVAppTemplateRecord extends QueryResultRecordType {
.isPublished(in.isPublished())
.vdc(in.getVdc())
.vdcName(in.getVdcName())
.org(in.getOrg())
.org(in.get())
.creationDate(in.getCreationDate())
.isBusy(in.isBusy())
.isGoldMaster(in.isGoldMaster())
@ -292,7 +292,7 @@ public class QueryResultVAppTemplateRecord extends QueryResultRecordType {
/**
* Organization reference or id
*/
public String getOrg() {
public String get() {
return org;
}

View File

@ -23,13 +23,14 @@ import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.network.Network;
/**
* Provides synchronous access to {@link Network}.
*
* @see NetworkAsyncApi
* @author danikov
* @author danikov, Adrian Cole
*/
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public interface NetworkApi {
@ -39,7 +40,9 @@ public interface NetworkApi {
*
* @return the network or null if not found
*/
Network getNetwork(URI networkUri);
Network get(String networkUrn);
Network get(URI networkHref);
/**
* @return synchronous access to {@link Metadata.Readable} features

View File

@ -29,8 +29,10 @@ 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.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.network.Network;
import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationAndCookieToRequest;
import org.jclouds.vcloud.director.v1_5.functions.href.NetworkURNToHref;
import com.google.common.util.concurrent.ListenableFuture;
@ -42,13 +44,22 @@ import com.google.common.util.concurrent.ListenableFuture;
public interface NetworkAsyncApi {
/**
* @see NetworkApi#getNetwork(URI)
* @see NetworkApi#get(String)
*/
@GET
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends Network> getNetwork(@EndpointParam URI networkUri);
ListenableFuture<? extends Network> get(@EndpointParam(parser = NetworkURNToHref.class) String networkUrn);
/**
* @see NetworkApi#get(URI)
*/
@GET
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends Network> get(@EndpointParam URI networkHref);
/**
* @return asynchronous access to {@link Metadata.Readable} features

View File

@ -23,9 +23,9 @@ import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.org.Org;
import org.jclouds.vcloud.director.v1_5.domain.org.OrgList;
import org.jclouds.vcloud.director.v1_5.domain.params.ControlAccessParams;
/**
* Provides synchronous access to {@link Org}.
@ -45,7 +45,7 @@ public interface OrgApi {
*
* @return a list of organizations
*/
OrgList getOrgList();
OrgList list();
/**
* Retrieves an organization.
@ -56,29 +56,9 @@ public interface OrgApi {
*
* @return the org or null if not found
*/
Org getOrg(URI orgRef);
Org get(String orgUrn);
/**
* Modifies a catalog control access.
*
* <pre>
* POST /org/{id}/catalog/{catalogId}/action/controlAccess
* </pre>
*
* @return the control access information
*/
ControlAccessParams modifyControlAccess(URI orgRef, String catalogId, ControlAccessParams params);
/**
* Retrieves the catalog control access information.
*
* <pre>
* GET /org/{id}/catalog/{catalogId}/controlAccess
* </pre>
*
* @return the control access information
*/
ControlAccessParams getControlAccess(URI orgRef, String catalogId);
Org get(URI orgHref);
/**
* @return synchronous access to {@link Metadata.Readable} features

View File

@ -18,29 +18,23 @@
*/
package org.jclouds.vcloud.director.v1_5.features;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.CONTROL_ACCESS;
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 javax.ws.rs.Produces;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Delegate;
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.binders.BindToXMLPayload;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.org.Org;
import org.jclouds.vcloud.director.v1_5.domain.org.OrgList;
import org.jclouds.vcloud.director.v1_5.domain.params.ControlAccessParams;
import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationAndCookieToRequest;
import org.jclouds.vcloud.director.v1_5.functions.href.OrgURNToHref;
import com.google.common.util.concurrent.ListenableFuture;
@ -52,45 +46,31 @@ import com.google.common.util.concurrent.ListenableFuture;
public interface OrgAsyncApi {
/**
* @see OrgApi#getOrgList()
* @see OrgApi#list()
*/
@GET
@Path("/org/")
@Consumes
@JAXBResponseParser
ListenableFuture<OrgList> getOrgList();
ListenableFuture<OrgList> list();
/**
* @see OrgApi#getOrg(URI)
* @see OrgApi#get(String)
*/
@GET
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends Org> getOrg(@EndpointParam URI orgUri);
ListenableFuture<? extends Org> get(@EndpointParam(parser = OrgURNToHref.class) String orgUrn);
/**
* @see OrgApi#modifyControlAccess(URI, URI, ControlAccessParams)
*/
@POST
@Path("/catalog/{catalogId}/action/controlAccess")
@Produces(CONTROL_ACCESS)
@Consumes(CONTROL_ACCESS)
@JAXBResponseParser
ListenableFuture<ControlAccessParams> modifyControlAccess(@EndpointParam URI orgRef,
@PathParam("catalogId") String catalogId,
@BinderParam(BindToXMLPayload.class) ControlAccessParams params);
/**
* @see OrgApi#getControlAccess(URI, URI, ControlAccessParams)
* @see OrgApi#get(URI)
*/
@GET
@Path("/catalog/{catalogId}/controlAccess")
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<ControlAccessParams> getControlAccess(@EndpointParam URI orgRef,
@PathParam("catalogId") String catalogId);
ListenableFuture<? extends Org> get(@EndpointParam URI orgHref);
/**
* @return asynchronous access to {@link Metadata.Readable} features

View File

@ -22,14 +22,17 @@ import java.net.URI;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Link;
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.domain.org.Org;
/**
* Provides synchronous access to {@link Task} objects.
*
* @see TaskAsyncApi
* @author grkvlt@apache.org
* @author grkvlt@apache.org, Adrian Cole
*/
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public interface TaskApi {
@ -41,10 +44,12 @@ public interface TaskApi {
* GET /tasksList/{id}
* </pre>
*
* @param orgURI the URI of the organization
* @param tasksListUrn
* from {@link Org#getLinks()} where {@link Link#getType} is
* {@link VCloudDirectorMediaType#TASKS_LIST}
* @return a list of tasks
*/
TasksList getTaskList(URI orgURI);
TasksList getTasksList(URI tasksListHref);
/**
* Retrieves a task.
@ -55,7 +60,9 @@ public interface TaskApi {
*
* @return the task or null if not found
*/
Task getTask(URI taskUri);
Task get(String taskUrn);
Task get(URI taskHref);
/**
* Cancels a task.
@ -64,5 +71,7 @@ public interface TaskApi {
* POST /task/{id}/action/cancel
* </pre>
*/
void cancelTask(URI taskUri);
void cancel(String taskUrn);
void cancel(URI taskHref);
}

View File

@ -33,41 +33,59 @@ 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.AddVCloudAuthorizationAndCookieToRequest;
import org.jclouds.vcloud.director.v1_5.functions.OrgReferenceToTaskListEndpoint;
import org.jclouds.vcloud.director.v1_5.functions.href.TaskURNToHref;
import com.google.common.util.concurrent.ListenableFuture;
/**
* @see TaskApi
* @author grkvlt@apache.org
* @author grkvlt@apache.org, Adrian Cole
*/
@RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class)
public interface TaskAsyncApi {
/**
* @see TaskApi#getTaskList(URISupplier)
* @see TaskApi#getTasksList(URI)
*/
@GET
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<TasksList> getTaskList(@EndpointParam(parser = OrgReferenceToTaskListEndpoint.class) URI orgURI);
ListenableFuture<TasksList> getTasksList(@EndpointParam URI tasksListHref);
/**
* @see TaskApi#getTask(URI)
* @see TaskApi#get(String)
*/
@GET
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Task> getTask(@EndpointParam URI taskURI);
ListenableFuture<Task> get(@EndpointParam(parser = TaskURNToHref.class) String taskUrn);
/**
* @see TaskApi#cancelTask(URI)
* @see TaskApi#get(URI)
*/
@GET
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Task> get(@EndpointParam URI taskURI);
/**
* @see TaskApi#cancel(String)
*/
@POST
@Path("/action/cancel")
@Consumes
@JAXBResponseParser
ListenableFuture<Void> cancelTask(@EndpointParam URI taskURI);
ListenableFuture<Void> cancel(@EndpointParam(parser = TaskURNToHref.class) String taskUrn);
/**
* @see TaskApi#cancel(URI)
*/
@POST
@Path("/action/cancel")
@Consumes
@JAXBResponseParser
ListenableFuture<Void> cancel(@EndpointParam URI taskURI);
}

View File

@ -225,6 +225,7 @@ public interface VAppApi {
*
* @since 0.9
*/
//TODO: revise
ControlAccessParams getControlAccess(URI vAppURI);
/**

View File

@ -40,8 +40,7 @@ import org.jclouds.vcloud.director.v1_5.domain.params.UploadVAppTemplateParams;
* Provides synchronous access to a vDC.
*
* @see VdcAsyncApi
* @see <a href= "http://support.theenterprisecloud.com/kb/default.asp?id=984&Lang=1&SID=" />
* @author danikov
* @author danikov, Adrian Cole
*/
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public interface VdcApi {

View File

@ -26,6 +26,7 @@ import org.jclouds.rest.annotations.Delegate;
import org.jclouds.vcloud.director.v1_5.domain.AdminCatalog;
import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.Owner;
import org.jclouds.vcloud.director.v1_5.domain.params.ControlAccessParams;
import org.jclouds.vcloud.director.v1_5.domain.params.PublishCatalogParams;
import org.jclouds.vcloud.director.v1_5.features.CatalogApi;
import org.jclouds.vcloud.director.v1_5.features.MetadataApi;
@ -52,7 +53,7 @@ public interface AdminCatalogApi extends CatalogApi {
*/
AdminCatalog createCatalogInOrg(AdminCatalog catalog, String orgUrn);
AdminCatalog createCatalogInOrg(AdminCatalog catalog, URI adminCatalogHref);
AdminCatalog createCatalogInOrg(AdminCatalog catalog, URI catalogAdminHref);
/**
* Retrieves a catalog.
@ -69,7 +70,7 @@ public interface AdminCatalogApi extends CatalogApi {
AdminCatalog get(String catalogUrn);
@Override
AdminCatalog get(URI adminCatalogHref);
AdminCatalog get(URI catalogAdminHref);
/**
* Modifies a catalog. A catalog could be published or unpublished. The IsPublished property is
@ -84,7 +85,7 @@ public interface AdminCatalogApi extends CatalogApi {
*/
AdminCatalog update(String catalogUrn, AdminCatalog catalog);
AdminCatalog update(URI adminCatalogHref, AdminCatalog catalog);
AdminCatalog update(URI catalogAdminHref, AdminCatalog catalog);
/**
* Deletes a catalog. The catalog could be deleted if it is either published or unpublished.
@ -95,7 +96,7 @@ public interface AdminCatalogApi extends CatalogApi {
*/
void delete(String catalogUrn);
void delete(URI adminCatalogHref);
void delete(URI catalogAdminHref);
/**
* Retrieves the owner of a catalog.
@ -108,7 +109,7 @@ public interface AdminCatalogApi extends CatalogApi {
*/
Owner getOwner(String catalogUrn);
Owner getOwner(URI adminCatalogHref);
Owner getOwner(URI catalogAdminHref);
/**
* Changes owner for catalog.
@ -119,7 +120,11 @@ public interface AdminCatalogApi extends CatalogApi {
*/
void setOwner(String catalogUrn, Owner newOwner);
void setOwner(URI adminCatalogHref, Owner newOwner);
void setOwner(URI catalogAdminHref, Owner newOwner);
// TODO: lot of work to pass in a single boolean, would like to polymorphically include something
// like:
// void publishCatalog(String catalogUrn)
/**
* Publish a catalog. Publishing a catalog makes the catalog visible to all organizations in a
@ -128,11 +133,33 @@ public interface AdminCatalogApi extends CatalogApi {
*/
void publish(String catalogUrn, PublishCatalogParams params);
void publish(URI adminCatalogHref, PublishCatalogParams params);
void publish(URI catalogAdminHref, PublishCatalogParams params);
// TODO: lot of work to pass in a single boolean, would like to polymorphically include something
// like:
// void publishCatalog(String catalogUrn)
/**
* Modifies a catalog control access.
*
* <pre>
* POST /org/{id}/catalog/{catalogId}/action/controlAccess
* </pre>
*
* @return the control access information
*/
ControlAccessParams modifyAccessControl(String catalogUrn, ControlAccessParams params);
ControlAccessParams modifyAccessControl(URI catalogAdminHref, ControlAccessParams params);
/**
* Retrieves the catalog control access information.
*
* <pre>
* GET /org/{id}/catalog/{catalogId}/controlAccess
* </pre>
*
* @return the control access information
*/
ControlAccessParams getAccessControl(String catalogUrn);
ControlAccessParams getAccessControl(URI catalogAdminHref);
/**
* @return synchronous access to {@link Metadata.Writeable} features

View File

@ -18,6 +18,8 @@
*/
package org.jclouds.vcloud.director.v1_5.features.admin;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.CONTROL_ACCESS;
import java.net.URI;
import javax.ws.rs.Consumes;
@ -40,6 +42,7 @@ import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.AdminCatalog;
import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.Owner;
import org.jclouds.vcloud.director.v1_5.domain.params.ControlAccessParams;
import org.jclouds.vcloud.director.v1_5.domain.params.PublishCatalogParams;
import org.jclouds.vcloud.director.v1_5.features.CatalogAsyncApi;
import org.jclouds.vcloud.director.v1_5.features.MetadataAsyncApi;
@ -115,7 +118,7 @@ public interface AdminCatalogAsyncApi extends CatalogAsyncApi {
@Consumes(VCloudDirectorMediaType.ADMIN_CATALOG)
@Produces(VCloudDirectorMediaType.ADMIN_CATALOG)
@JAXBResponseParser
ListenableFuture<AdminCatalog> update(@EndpointParam URI adminCatalogHref,
ListenableFuture<AdminCatalog> update(@EndpointParam URI catalogAdminHref,
@BinderParam(BindToXMLPayload.class) AdminCatalog catalog);
/**
@ -132,7 +135,7 @@ public interface AdminCatalogAsyncApi extends CatalogAsyncApi {
@DELETE
@Consumes
@JAXBResponseParser
ListenableFuture<Void> delete(@EndpointParam URI adminCatalogHref);
ListenableFuture<Void> delete(@EndpointParam URI catalogAdminHref);
/**
* @see AdminCatalogApi#getOwner(String)
@ -152,7 +155,7 @@ public interface AdminCatalogAsyncApi extends CatalogAsyncApi {
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Owner> getOwner(@EndpointParam URI adminCatalogHref);
ListenableFuture<Owner> getOwner(@EndpointParam URI catalogAdminHref);
/**
* @see AdminCatalogApi#setOwner(String, Owner)
@ -173,7 +176,7 @@ public interface AdminCatalogAsyncApi extends CatalogAsyncApi {
@Consumes
@Produces(VCloudDirectorMediaType.OWNER)
@JAXBResponseParser
ListenableFuture<Void> setOwner(@EndpointParam URI adminCatalogHref,
ListenableFuture<Void> setOwner(@EndpointParam URI catalogAdminHref,
@BinderParam(BindToXMLPayload.class) Owner newOwner);
/**
@ -195,9 +198,51 @@ public interface AdminCatalogAsyncApi extends CatalogAsyncApi {
@Consumes
@Produces(VCloudDirectorMediaType.PUBLISH_CATALOG_PARAMS)
@JAXBResponseParser
ListenableFuture<Void> publish(@EndpointParam URI adminCatalogHref,
ListenableFuture<Void> publish(@EndpointParam URI catalogAdminHref,
@BinderParam(BindToXMLPayload.class) PublishCatalogParams params);
/**
* @see AdminCatalogApi#modifyAccessControl(String, ControlAccessParams)
*/
@POST
@Path("/action/controlAccess")
@Produces(CONTROL_ACCESS)
@Consumes(CONTROL_ACCESS)
@JAXBResponseParser
ListenableFuture<ControlAccessParams> modifyAccessControl(@EndpointParam(parser = CatalogURNToAdminHref.class) String catalogUrn,
@BinderParam(BindToXMLPayload.class) ControlAccessParams params);
/**
* @see AdminCatalogApi#modifyAccessControl(URI, ControlAccessParams)
*/
@POST
@Path("/action/controlAccess")
@Produces(CONTROL_ACCESS)
@Consumes(CONTROL_ACCESS)
@JAXBResponseParser
ListenableFuture<ControlAccessParams> modifyAccessControl(@EndpointParam URI catalogAdminHref,
@BinderParam(BindToXMLPayload.class) ControlAccessParams params);
/**
* @see AdminCatalogApi#getAccessControl(String)
*/
@GET
@Path("/controlAccess")
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<ControlAccessParams> getAccessControl(@EndpointParam(parser = CatalogURNToAdminHref.class) String catalogUrn);
/**
* @see AdminCatalogApi#getAccessControl(URI)
*/
@GET
@Path("/controlAccess")
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<ControlAccessParams> getAccessControl(@EndpointParam URI catalogAdminHref);
/**
* @return synchronous access to {@link Metadata.Writeable} features
*/

View File

@ -33,25 +33,28 @@ import org.jclouds.vcloud.director.v1_5.features.NetworkApi;
* Provides synchronous access to admin {@link Network} objects.
*
* @see AdminNetworkAsyncApi
* @author danikov
* @author danikov, Adrian Cole
*/
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public interface AdminNetworkApi extends NetworkApi {
/**
* Gets admin representation of network. This operation could return admin
* representation of organization network or external network. vApp networks
* do not have admin representation.
* Gets admin representation of network. This operation could return admin representation of
* organization network or external network. vApp networks do not have admin representation.
*
* <pre>
* GET /admin/network/{id}
* </pre>
*
* @param networkRef the reference for the network
* @param networkUrn
* the reference for the network
* @return the network
*/
@Override
Network getNetwork(URI networkRef);
Network get(String networkUrn);
@Override
Network get(URI networkAdminHref);
/**
* Modifies an org network
@ -60,30 +63,34 @@ public interface AdminNetworkApi extends NetworkApi {
* PUT /admin/network/{id}
* </pre>
*
* @param networkRef the reference for the network
* @param network the updated network
* @return a task. This operation is asynchronous and the user should monitor the
* returned task status in order to check when it is completed.
* @param networkUrn
* the reference for the network
* @param network
* the updated network
* @return a task. This operation is asynchronous and the user should monitor the returned task
* status in order to check when it is completed.
*/
Task updateNetwork(URI networkRef, OrgNetwork network);
Task update(String networkUrn, OrgNetwork network);
Task update(URI networkAdminHref, OrgNetwork network);
/**
* Reset(undeploy & redeploy) networking services on a logical network.
* The reset operation can be performed on:
* - external networks
* - organization networks
* - vApp networks
* The reset operation can be performed only on deployed networks.
* Reset(undeploy & redeploy) networking services on a logical network. The reset operation can
* be performed on: - external networks - organization networks - vApp networks The reset
* operation can be performed only on deployed networks.
*
* <pre>
* POST /admin/network/{id}/action/reset
* </pre>
*
* @param networkRef the reference for the network
* @return a task. This operation is asynchronous and the user should monitor the
* returned task status in order to check when it is completed.
* @param networkUrn
* the reference for the network
* @return a task. This operation is asynchronous and the user should monitor the returned task
* status in order to check when it is completed.
*/
Task resetNetwork(URI networkRef);
Task reset(String networkUrn);
Task reset(URI networkAdminHref);
/**
* @return synchronous access to admin {@link MetadataApi.Writeable} features

View File

@ -37,11 +37,12 @@ import org.jclouds.rest.binders.BindToXMLPayload;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Task;
import org.jclouds.vcloud.director.v1_5.domain.network.ExternalNetwork;
import org.jclouds.vcloud.director.v1_5.domain.network.Network;
import org.jclouds.vcloud.director.v1_5.domain.org.OrgNetwork;
import org.jclouds.vcloud.director.v1_5.features.MetadataAsyncApi;
import org.jclouds.vcloud.director.v1_5.features.NetworkAsyncApi;
import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationAndCookieToRequest;
import org.jclouds.vcloud.director.v1_5.functions.href.NetworkURNToAdminHref;
import com.google.common.util.concurrent.ListenableFuture;
@ -53,33 +54,62 @@ import com.google.common.util.concurrent.ListenableFuture;
public interface AdminNetworkAsyncApi extends NetworkAsyncApi {
/**
* @see AdminNetworkApi#getNetwork(URI)
* @see AdminNetworkApi#get(String)
*/
@Override
@GET
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<ExternalNetwork> getNetwork(@EndpointParam URI networkRef);
ListenableFuture<? extends Network> get(@EndpointParam(parser = NetworkURNToAdminHref.class) String networkUrn);
/**
* @see AdminNetworkApi#updateNetwork(URI, OrgNetwork)
* @see AdminNetworkApi#get(URI)
*/
@Override
@GET
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends Network> get(@EndpointParam URI networkAdminHref);
/**
* @see AdminNetworkApi#update(String, OrgNetwork)
*/
@PUT
@Consumes(VCloudDirectorMediaType.TASK)
@Produces(VCloudDirectorMediaType.ADMIN_ORG_NETWORK)
@JAXBResponseParser
ListenableFuture<Task> updateNetwork(@EndpointParam URI networkRef,
ListenableFuture<Task> update(@EndpointParam(parser = NetworkURNToAdminHref.class) String networkUrn,
@BinderParam(BindToXMLPayload.class) OrgNetwork network);
/**
* @see AdminNetworkApi#resetNetwork(URI)
* @see AdminNetworkApi#update(URI, OrgNetwork)
*/
@PUT
@Consumes(VCloudDirectorMediaType.TASK)
@Produces(VCloudDirectorMediaType.ADMIN_ORG_NETWORK)
@JAXBResponseParser
ListenableFuture<Task> update(@EndpointParam URI networkAdminHref,
@BinderParam(BindToXMLPayload.class) OrgNetwork network);
/**
* @see AdminNetworkApi#reset(String)
*/
@POST
@Path("/action/reset")
@Consumes
@JAXBResponseParser
ListenableFuture<Task> resetNetwork(@EndpointParam URI networkRef);
ListenableFuture<Task> reset(@EndpointParam(parser = NetworkURNToAdminHref.class) String networkUrn);
/**
* @see AdminNetworkApi#reset(URI)
*/
@POST
@Path("/action/reset")
@Consumes
@JAXBResponseParser
ListenableFuture<Task> reset(@EndpointParam URI networkAdminHref);
/**
* @return asynchronous access to admin {@link MetadataAsyncApi.Writeable} features

View File

@ -24,6 +24,7 @@ import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.vcloud.director.v1_5.domain.org.AdminOrg;
import org.jclouds.vcloud.director.v1_5.domain.org.Org;
import org.jclouds.vcloud.director.v1_5.domain.org.OrgEmailSettings;
import org.jclouds.vcloud.director.v1_5.domain.org.OrgGeneralSettings;
import org.jclouds.vcloud.director.v1_5.domain.org.OrgLdapSettings;
@ -37,26 +38,29 @@ import org.jclouds.vcloud.director.v1_5.features.OrgApi;
/**
* Provides synchronous access to {@link Org} objects.
*
* @see GroupAsyncApi
* @author danikov
* @see AdminOrgAsyncApi
* @author danikov, Adrian Cole
*/
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public interface AdminOrgApi extends OrgApi {
/**
* Retrieves an admin view of an organization.
* The organization might be enabled or disabled.
* If enabled, the organization allows login and all other operations.
* Retrieves an admin view of an organization. The organization might be enabled or disabled. If
* enabled, the organization allows login and all other operations.
*
* <pre>
* GET /admin/org/{id}
* </pre>
*
* @param orgRef the reference for the admin org
* @param orgUrn
* the reference for the admin org
* @return the admin org
*/
@Override
AdminOrg getOrg(URI orgRef);
AdminOrg get(String orgUrn);
@Override
AdminOrg get(URI orgAdminHref);
/**
* Gets organizational settings for this organization.
@ -65,10 +69,13 @@ public interface AdminOrgApi extends OrgApi {
* GET /admin/org/{id}/settings
* </pre>
*
* @param orgRef the reference for the admin org
* @param orgUrn
* the reference for the admin org
* @return the settings
*/
OrgSettings getSettings(URI orgRef);
OrgSettings getSettings(String orgUrn);
OrgSettings getSettings(URI orgAdminHref);
/**
* Updates organizational settings for this organization.
@ -76,11 +83,16 @@ public interface AdminOrgApi extends OrgApi {
* <pre>
* PUT /admin/org/{id}/settings
* </pre>
* @param orgRef the reference for the admin org
* @param newSettings the requested updated settings
*
* @param orgUrn
* the reference for the admin org
* @param newSettings
* the requested updated settings
* @return the resultant settings
*/
OrgSettings updateSettings(URI orgRef, OrgSettings newSettings);
OrgSettings updateSettings(String orgUrn, OrgSettings newSettings);
OrgSettings updateSettings(URI orgAdminHref, OrgSettings newSettings);
/**
* Retrieves email settings for an organization.
@ -89,10 +101,13 @@ public interface AdminOrgApi extends OrgApi {
* GET /admin/org/{id}/settings/email
* </pre>
*
* @param orgRef the reference for the admin org
* @param orgUrn
* the reference for the admin org
* @return the email settings
*/
OrgEmailSettings getEmailSettings(URI orgRef);
OrgEmailSettings getEmailSettings(String orgUrn);
OrgEmailSettings getEmailSettings(URI orgAdminHref);
/**
* Updates email policy settings for organization.
@ -100,12 +115,16 @@ public interface AdminOrgApi extends OrgApi {
* <pre>
* PUT /admin/org/{id}/settings/email
* </pre>
* @param orgRef the reference for the admin org
* @param newSettings the requested updated settings
*
* @param orgUrn
* the reference for the admin org
* @param newSettings
* the requested updated settings
* @return the resultant settings
*/
OrgEmailSettings updateEmailSettings(URI orgRef,
OrgEmailSettings newSettings);
OrgEmailSettings updateEmailSettings(String orgUrn, OrgEmailSettings newSettings);
OrgEmailSettings updateEmailSettings(URI orgAdminHref, OrgEmailSettings newSettings);
/**
* Gets general organization settings.
@ -114,10 +133,13 @@ public interface AdminOrgApi extends OrgApi {
* GET /admin/org/{id}/settings/general
* </pre>
*
* @param orgRef the reference for the admin org
* @param orgUrn
* the reference for the admin org
* @return the lease settings
*/
OrgGeneralSettings getGeneralSettings(URI orgRef);
OrgGeneralSettings getGeneralSettings(String orgUrn);
OrgGeneralSettings getGeneralSettings(URI orgAdminHref);
/**
* Updates general organization settings.
@ -125,12 +147,16 @@ public interface AdminOrgApi extends OrgApi {
* <pre>
* PUT /admin/org/{id}/settings/general
* </pre>
* @param orgRef the reference for the admin org
* @param newSettings the requested updated settings
*
* @param orgUrn
* the reference for the admin org
* @param newSettings
* the requested updated settings
* @return the resultant settings
*/
OrgGeneralSettings updateGeneralSettings(URI orgRef,
OrgGeneralSettings newSettings);
OrgGeneralSettings updateGeneralSettings(String orgUrn, OrgGeneralSettings newSettings);
OrgGeneralSettings updateGeneralSettings(URI orgAdminHref, OrgGeneralSettings newSettings);
/**
* Retrieves LDAP settings for an organization.
@ -139,10 +165,13 @@ public interface AdminOrgApi extends OrgApi {
* GET /admin/org/{id}/settings/ldap
* </pre>
*
* @param orgRef the reference for the admin org
* @param orgUrn
* the reference for the admin org
* @return the ldap settings
*/
OrgLdapSettings getLdapSettings(URI orgRef);
OrgLdapSettings getLdapSettings(String orgUrn);
OrgLdapSettings getLdapSettings(URI orgAdminHref);
/**
* Retrieves password policy settings for an organization.
@ -151,10 +180,13 @@ public interface AdminOrgApi extends OrgApi {
* GET /admin/org/{id}/settings/passwordPolicy
* </pre>
*
* @param orgRef the reference for the admin org
* @param orgUrn
* the reference for the admin org
* @return the lease settings
*/
OrgPasswordPolicySettings getPasswordPolicy(URI orgRef);
OrgPasswordPolicySettings getPasswordPolicy(String orgUrn);
OrgPasswordPolicySettings getPasswordPolicy(URI orgAdminHref);
/**
* Updates password policy settings for organization.
@ -162,12 +194,16 @@ public interface AdminOrgApi extends OrgApi {
* <pre>
* PUT /admin/org/{id}/settings/passwordPolicy
* </pre>
* @param orgRef the reference for the admin org
* @param newSettings the requested updated settings
*
* @param orgUrn
* the reference for the admin org
* @param newSettings
* the requested updated settings
* @return the resultant settings
*/
OrgPasswordPolicySettings updatePasswordPolicy(URI orgRef,
OrgPasswordPolicySettings newSettings);
OrgPasswordPolicySettings updatePasswordPolicy(String orgUrn, OrgPasswordPolicySettings newSettings);
OrgPasswordPolicySettings updatePasswordPolicy(URI orgAdminHref, OrgPasswordPolicySettings newSettings);
/**
* Gets organization resource cleanup settings on the level of vApp.
@ -176,10 +212,13 @@ public interface AdminOrgApi extends OrgApi {
* GET /admin/org/{id}/settings/vAppLeaseSettings
* </pre>
*
* @param orgRef the reference for the admin org
* @param orgUrn
* the reference for the admin org
* @return the lease settings
*/
OrgLeaseSettings getVAppLeaseSettings(URI orgRef);
OrgLeaseSettings getVAppLeaseSettings(String orgUrn);
OrgLeaseSettings getVAppLeaseSettings(URI orgAdminHref);
/**
* Updates organization resource cleanup settings on the level of vApp.
@ -187,12 +226,16 @@ public interface AdminOrgApi extends OrgApi {
* <pre>
* PUT /admin/org/{id}/settings/vAppLeaseSettings
* </pre>
* @param orgRef the reference for the admin org
* @param newSettings the requested updated settings
*
* @param orgUrn
* the reference for the admin org
* @param newSettings
* the requested updated settings
* @return the resultant settings
*/
OrgLeaseSettings updateVAppLeaseSettings(URI orgRef,
OrgLeaseSettings newSettings);
OrgLeaseSettings updateVAppLeaseSettings(String orgUrn, OrgLeaseSettings newSettings);
OrgLeaseSettings updateVAppLeaseSettings(URI orgAdminHref, OrgLeaseSettings newSettings);
/**
* Retrieves expiration and storage policy for vApp templates in an organization.
@ -201,10 +244,13 @@ public interface AdminOrgApi extends OrgApi {
* GET /admin/org/{id}/settings/vAppTemplateLeaseSettings
* </pre>
*
* @param orgRef the reference for the admin org
* @param orgUrn
* the reference for the admin org
* @return the lease settings
*/
OrgVAppTemplateLeaseSettings getVAppTemplateLeaseSettings(URI orgRef);
OrgVAppTemplateLeaseSettings getVAppTemplateLeaseSettings(String orgUrn);
OrgVAppTemplateLeaseSettings getVAppTemplateLeaseSettings(URI orgAdminHref);
/**
* Updates vApp template policy settings for organization.
@ -212,12 +258,16 @@ public interface AdminOrgApi extends OrgApi {
* <pre>
* PUT /admin/org/{id}/settings/vAppTemplateLeaseSettings
* </pre>
* @param orgRef the reference for the admin org
* @param newSettings the requested updated settings
*
* @param orgUrn
* the reference for the admin org
* @param newSettings
* the requested updated settings
* @return the resultant settings
*/
OrgVAppTemplateLeaseSettings updateVAppTemplateLeaseSettings(URI orgRef,
OrgVAppTemplateLeaseSettings newSettings);
OrgVAppTemplateLeaseSettings updateVAppTemplateLeaseSettings(String orgUrn, OrgVAppTemplateLeaseSettings newSettings);
OrgVAppTemplateLeaseSettings updateVAppTemplateLeaseSettings(URI orgAdminHref, OrgVAppTemplateLeaseSettings newSettings);
/**
* @return synchronous access to admin {@link MetadataApi.Writeable} features

View File

@ -46,25 +46,46 @@ import org.jclouds.vcloud.director.v1_5.domain.org.OrgVAppTemplateLeaseSettings;
import org.jclouds.vcloud.director.v1_5.features.MetadataAsyncApi;
import org.jclouds.vcloud.director.v1_5.features.OrgAsyncApi;
import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationAndCookieToRequest;
import org.jclouds.vcloud.director.v1_5.functions.href.OrgURNToAdminHref;
import com.google.common.util.concurrent.ListenableFuture;
/**
* @see AdminOrgApi
* @author danikov
* @author danikov, Adrian Cole
*/
@RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class)
public interface AdminOrgAsyncApi extends OrgAsyncApi {
/**
* @see AdminOrgApi#getOrg(URI)
* @see AdminOrgApi#get(String)
*/
@Override
@GET
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<AdminOrg> getOrg(@EndpointParam URI orgRef);
ListenableFuture<AdminOrg> get(@EndpointParam(parser = OrgURNToAdminHref.class) String orgUrn);
/**
* @see AdminOrgApi#get(URI)
*/
@Override
@GET
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<AdminOrg> get(@EndpointParam URI adminOrgHref);
/**
* @see AdminOrgApi#getSettings(String)
*/
@GET
@Path("/settings")
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<OrgSettings> getSettings(@EndpointParam(parser = OrgURNToAdminHref.class) String orgUrn);
/**
* @see AdminOrgApi#getSettings(URI)
@ -74,7 +95,18 @@ public interface AdminOrgAsyncApi extends OrgAsyncApi {
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<OrgSettings> getSettings(@EndpointParam URI orgRef);
ListenableFuture<OrgSettings> getSettings(@EndpointParam URI adminOrgHref);
/**
* @see AdminOrgApi#updateSettings(String, OrgSettings)
*/
@PUT
@Path("/settings")
@Consumes(VCloudDirectorMediaType.ORG_SETTINGS)
@Produces(VCloudDirectorMediaType.ORG_SETTINGS)
@JAXBResponseParser
ListenableFuture<OrgSettings> updateSettings(@EndpointParam(parser = OrgURNToAdminHref.class) String orgUrn,
@BinderParam(BindToXMLPayload.class) OrgSettings settings);
/**
* @see AdminOrgApi#updateSettings(URI, OrgSettings)
@ -84,9 +116,19 @@ public interface AdminOrgAsyncApi extends OrgAsyncApi {
@Consumes(VCloudDirectorMediaType.ORG_SETTINGS)
@Produces(VCloudDirectorMediaType.ORG_SETTINGS)
@JAXBResponseParser
ListenableFuture<OrgSettings> updateSettings(@EndpointParam URI orgRef,
ListenableFuture<OrgSettings> updateSettings(@EndpointParam URI adminOrgHref,
@BinderParam(BindToXMLPayload.class) OrgSettings settings);
/**
* @see AdminOrgApi#getEmailSettings(String)
*/
@GET
@Path("/settings/email")
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<OrgEmailSettings> getEmailSettings(@EndpointParam(parser = OrgURNToAdminHref.class) String orgUrn);
/**
* @see AdminOrgApi#getEmailSettings(URI)
*/
@ -95,7 +137,19 @@ public interface AdminOrgAsyncApi extends OrgAsyncApi {
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<OrgEmailSettings> getEmailSettings(@EndpointParam URI orgRef);
ListenableFuture<OrgEmailSettings> getEmailSettings(@EndpointParam URI adminOrgHref);
/**
* @see AdminOrgApi#updateEmailSettings(String, OrgEmailSettings)
*/
@PUT
@Path("/settings/email")
@Consumes(VCloudDirectorMediaType.ORG_EMAIL_SETTINGS)
@Produces(VCloudDirectorMediaType.ORG_EMAIL_SETTINGS)
@JAXBResponseParser
ListenableFuture<OrgEmailSettings> updateEmailSettings(
@EndpointParam(parser = OrgURNToAdminHref.class) String orgUrn,
@BinderParam(BindToXMLPayload.class) OrgEmailSettings settings);
/**
* @see AdminOrgApi#updateEmailSettings(URI, OrgEmailSettings)
@ -105,9 +159,20 @@ public interface AdminOrgAsyncApi extends OrgAsyncApi {
@Consumes(VCloudDirectorMediaType.ORG_EMAIL_SETTINGS)
@Produces(VCloudDirectorMediaType.ORG_EMAIL_SETTINGS)
@JAXBResponseParser
ListenableFuture<OrgEmailSettings> updateEmailSettings(@EndpointParam URI orgRef,
ListenableFuture<OrgEmailSettings> updateEmailSettings(@EndpointParam URI adminOrgHref,
@BinderParam(BindToXMLPayload.class) OrgEmailSettings settings);
/**
* @see AdminOrgApi#getGeneralSettings(String)
*/
@GET
@Path("/settings/general")
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<OrgGeneralSettings> getGeneralSettings(
@EndpointParam(parser = OrgURNToAdminHref.class) String orgUrn);
/**
* @see AdminOrgApi#getGeneralSettings(URI)
*/
@ -116,7 +181,19 @@ public interface AdminOrgAsyncApi extends OrgAsyncApi {
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<OrgGeneralSettings> getGeneralSettings(@EndpointParam URI orgRef);
ListenableFuture<OrgGeneralSettings> getGeneralSettings(@EndpointParam URI adminOrgHref);
/**
* @see AdminOrgApi#updateGeneralSettings(String, OrgGeneralSettings)
*/
@PUT
@Path("/settings/general")
@Consumes(VCloudDirectorMediaType.ORG_GENERAL_SETTINGS)
@Produces(VCloudDirectorMediaType.ORG_GENERAL_SETTINGS)
@JAXBResponseParser
ListenableFuture<OrgGeneralSettings> updateGeneralSettings(
@EndpointParam(parser = OrgURNToAdminHref.class) String orgUrn,
@BinderParam(BindToXMLPayload.class) OrgGeneralSettings settings);
/**
* @see AdminOrgApi#updateGeneralSettings(URI, OrgGeneralSettings)
@ -126,10 +203,19 @@ public interface AdminOrgAsyncApi extends OrgAsyncApi {
@Consumes(VCloudDirectorMediaType.ORG_GENERAL_SETTINGS)
@Produces(VCloudDirectorMediaType.ORG_GENERAL_SETTINGS)
@JAXBResponseParser
ListenableFuture<OrgGeneralSettings> updateGeneralSettings(
@EndpointParam URI orgRef,
ListenableFuture<OrgGeneralSettings> updateGeneralSettings(@EndpointParam URI adminOrgHref,
@BinderParam(BindToXMLPayload.class) OrgGeneralSettings settings);
/**
* @see AdminOrgApi#getPasswordPolicy(String)
*/
@GET
@Path("/settings/ldap")
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<OrgLdapSettings> getLdapSettings(@EndpointParam(parser = OrgURNToAdminHref.class) String orgUrn);
/**
* @see AdminOrgApi#getPasswordPolicy(URI)
*/
@ -138,7 +224,18 @@ public interface AdminOrgAsyncApi extends OrgAsyncApi {
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<OrgLdapSettings> getLdapSettings(@EndpointParam URI orgRef);
ListenableFuture<OrgLdapSettings> getLdapSettings(@EndpointParam URI adminOrgHref);
/**
* @see AdminOrgApi#getPasswordPolicy(String)
*/
@GET
@Path("/settings/passwordPolicy")
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<OrgPasswordPolicySettings> getPasswordPolicy(
@EndpointParam(parser = OrgURNToAdminHref.class) String orgUrn);
/**
* @see AdminOrgApi#getPasswordPolicy(URI)
@ -148,7 +245,19 @@ public interface AdminOrgAsyncApi extends OrgAsyncApi {
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<OrgPasswordPolicySettings> getPasswordPolicy(@EndpointParam URI orgRef);
ListenableFuture<OrgPasswordPolicySettings> getPasswordPolicy(@EndpointParam URI adminOrgHref);
/**
* @see AdminOrgApi#updatePasswordPolicy(String, OrgPasswordPolicySettings)
*/
@PUT
@Path("/settings/passwordPolicy")
@Consumes(VCloudDirectorMediaType.ORG_PASSWORD_POLICY_SETTINGS)
@Produces(VCloudDirectorMediaType.ORG_PASSWORD_POLICY_SETTINGS)
@JAXBResponseParser
ListenableFuture<OrgPasswordPolicySettings> updatePasswordPolicy(
@EndpointParam(parser = OrgURNToAdminHref.class) String orgUrn,
@BinderParam(BindToXMLPayload.class) OrgPasswordPolicySettings settings);
/**
* @see AdminOrgApi#updatePasswordPolicy(URI, OrgPasswordPolicySettings)
@ -158,9 +267,20 @@ public interface AdminOrgAsyncApi extends OrgAsyncApi {
@Consumes(VCloudDirectorMediaType.ORG_PASSWORD_POLICY_SETTINGS)
@Produces(VCloudDirectorMediaType.ORG_PASSWORD_POLICY_SETTINGS)
@JAXBResponseParser
ListenableFuture<OrgPasswordPolicySettings> updatePasswordPolicy(@EndpointParam URI orgRef,
ListenableFuture<OrgPasswordPolicySettings> updatePasswordPolicy(@EndpointParam URI adminOrgHref,
@BinderParam(BindToXMLPayload.class) OrgPasswordPolicySettings settings);
/**
* @see AdminOrgApi#getVAppLeaseSettings(String)
*/
@GET
@Path("/settings/vAppLeaseSettings")
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<OrgLeaseSettings> getVAppLeaseSettings(
@EndpointParam(parser = OrgURNToAdminHref.class) String orgUrn);
/**
* @see AdminOrgApi#getVAppLeaseSettings(URI)
*/
@ -169,7 +289,19 @@ public interface AdminOrgAsyncApi extends OrgAsyncApi {
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<OrgLeaseSettings> getVAppLeaseSettings(@EndpointParam URI orgRef);
ListenableFuture<OrgLeaseSettings> getVAppLeaseSettings(@EndpointParam URI adminOrgHref);
/**
* @see AdminOrgApi#updateVAppLeaseSettings(String, OrgVAppLeaseSettings)
*/
@PUT
@Path("/settings/vAppLeaseSettings")
@Consumes(VCloudDirectorMediaType.ORG_LEASE_SETTINGS)
@Produces(VCloudDirectorMediaType.ORG_LEASE_SETTINGS)
@JAXBResponseParser
ListenableFuture<OrgLeaseSettings> updateVAppLeaseSettings(
@EndpointParam(parser = OrgURNToAdminHref.class) String orgUrn,
@BinderParam(BindToXMLPayload.class) OrgLeaseSettings settings);
/**
* @see AdminOrgApi#updateVAppLeaseSettings(URI, OrgVAppLeaseSettings)
@ -179,9 +311,20 @@ public interface AdminOrgAsyncApi extends OrgAsyncApi {
@Consumes(VCloudDirectorMediaType.ORG_LEASE_SETTINGS)
@Produces(VCloudDirectorMediaType.ORG_LEASE_SETTINGS)
@JAXBResponseParser
ListenableFuture<OrgLeaseSettings> updateVAppLeaseSettings(@EndpointParam URI orgRef,
ListenableFuture<OrgLeaseSettings> updateVAppLeaseSettings(@EndpointParam URI adminOrgHref,
@BinderParam(BindToXMLPayload.class) OrgLeaseSettings settings);
/**
* @see AdminOrgApi#getVAppTemplateLeaseSettings(String)
*/
@GET
@Path("/settings/vAppTemplateLeaseSettings")
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<OrgVAppTemplateLeaseSettings> getVAppTemplateLeaseSettings(
@EndpointParam(parser = OrgURNToAdminHref.class) String orgUrn);
/**
* @see AdminOrgApi#getVAppTemplateLeaseSettings(URI)
*/
@ -190,7 +333,19 @@ public interface AdminOrgAsyncApi extends OrgAsyncApi {
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<OrgVAppTemplateLeaseSettings> getVAppTemplateLeaseSettings(@EndpointParam URI orgRef);
ListenableFuture<OrgVAppTemplateLeaseSettings> getVAppTemplateLeaseSettings(@EndpointParam URI adminOrgHref);
/**
* @see AdminOrgApi#updateVAppTemplateLeaseSettings(String, OrgVAppTemplateLeaseSettings)
*/
@PUT
@Path("/settings/vAppTemplateLeaseSettings")
@Consumes(VCloudDirectorMediaType.ORG_VAPP_TEMPLATE_LEASE_SETTINGS)
@Produces(VCloudDirectorMediaType.ORG_VAPP_TEMPLATE_LEASE_SETTINGS)
@JAXBResponseParser
ListenableFuture<OrgVAppTemplateLeaseSettings> updateVAppTemplateLeaseSettings(
@EndpointParam(parser = OrgURNToAdminHref.class) String orgUrn,
@BinderParam(BindToXMLPayload.class) OrgVAppTemplateLeaseSettings settings);
/**
* @see AdminOrgApi#updateVAppTemplateLeaseSettings(URI, OrgVAppTemplateLeaseSettings)
@ -200,7 +355,7 @@ public interface AdminOrgAsyncApi extends OrgAsyncApi {
@Consumes(VCloudDirectorMediaType.ORG_VAPP_TEMPLATE_LEASE_SETTINGS)
@Produces(VCloudDirectorMediaType.ORG_VAPP_TEMPLATE_LEASE_SETTINGS)
@JAXBResponseParser
ListenableFuture<OrgVAppTemplateLeaseSettings> updateVAppTemplateLeaseSettings(@EndpointParam URI orgRef,
ListenableFuture<OrgVAppTemplateLeaseSettings> updateVAppTemplateLeaseSettings(@EndpointParam URI adminOrgHref,
@BinderParam(BindToXMLPayload.class) OrgVAppTemplateLeaseSettings settings);
/**

View File

@ -28,7 +28,7 @@ import org.jclouds.vcloud.director.v1_5.domain.User;
* Provides synchronous access to {@link User} objects.
*
* @see UserAsyncApi
* @author danikov
* @author danikov, Adrian Cole
*/
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public interface UserApi {
@ -40,10 +40,13 @@ public interface UserApi {
* POST /admin/org/{id}/users
* </pre>
*
* @param orgRef the reference for the org
* @param orgUrn
* the urn for the org
* @return the created user
*/
User createUser(URI orgRef, User user);
User createUserInOrg(User user, String orgUrn);
User createUserInOrg(User user, URI orgAdminHref);
/**
* Retrieves a user. This entity could be enabled or disabled.
@ -52,23 +55,29 @@ public interface UserApi {
* GET /admin/user/{id}
* </pre>
*
* @param userRef the reference for the user
* @param userUrn
* the reference for the user
* @return a user
*/
User getUser(URI userRef);
User get(String userUrn);
User get(URI userHref);
/**
* Modifies a user. The user object could be enabled or disabled.
* Note: the lock status cannot be changed using this call: use unlockUser.
* Modifies a user. The user object could be enabled or disabled. Note: the lock status cannot be
* changed using this call: use unlockUser.
*
* <pre>
* PUT /admin/user/{id}
* </pre>
*
* @param userRef the reference for the user
* @param userUrn
* the reference for the user
* @return the modified user
*/
User updateUser(URI userRef, User user);
User update(String userUrn, User user);
User update(URI userHref, User user);
/**
* Deletes a user. Enabled and disabled users could be deleted.
@ -77,7 +86,9 @@ public interface UserApi {
* DELETE /admin/catalog/{id}
* </pre>
*/
void deleteUser(URI userRef);
void delete(String userUrn);
void delete(URI userHref);
/**
* Unlocks a user.
@ -86,5 +97,7 @@ public interface UserApi {
* POST /admin/user/{id}/action/unlock
* </pre>
*/
void unlockUser(URI userRef);
void unlock(String userUrn);
void unlock(URI userHref);
}

View File

@ -38,60 +38,108 @@ import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.User;
import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationAndCookieToRequest;
import org.jclouds.vcloud.director.v1_5.functions.href.OrgURNToAdminHref;
import org.jclouds.vcloud.director.v1_5.functions.href.UserURNToHref;
import com.google.common.util.concurrent.ListenableFuture;
/**
* @see UserApi
* @author danikov
* @author danikov, Adrian Cole
*/
@RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class)
public interface UserAsyncApi {
/**
* @see UserApi#createUser(URI, User)
* @see UserApi#createUserInOrg(User, String)
*/
@POST
@Path("/users")
@Consumes(VCloudDirectorMediaType.USER)
@Produces(VCloudDirectorMediaType.USER)
@JAXBResponseParser
ListenableFuture<User> createUser(@EndpointParam URI userRef,
@BinderParam(BindToXMLPayload.class) User user);
ListenableFuture<User> createUserInOrg(@BinderParam(BindToXMLPayload.class) User user,
@EndpointParam(parser = OrgURNToAdminHref.class) String orgUrn);
/**
* @see UserApi#getUser(URI)
* @see UserApi#createUserInOrg(User, URI)
*/
@POST
@Path("/users")
@Consumes(VCloudDirectorMediaType.USER)
@Produces(VCloudDirectorMediaType.USER)
@JAXBResponseParser
ListenableFuture<User> createUserInOrg(@BinderParam(BindToXMLPayload.class) User user,
@EndpointParam URI orgAdminHref);
/**
* @see UserApi#get(String)
*/
@GET
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<User> getUser(@EndpointParam URI userRef);
ListenableFuture<User> get(@EndpointParam(parser = UserURNToHref.class) String userUrn);
/**
* @see UserApi#updateUser(URI, User)
* @see UserApi#get(URI)
*/
@GET
@Consumes
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<User> get(@EndpointParam URI userHref);
/**
* @see UserApi#update(String, User)
*/
@PUT
@Consumes(VCloudDirectorMediaType.USER)
@Produces(VCloudDirectorMediaType.USER)
@JAXBResponseParser
ListenableFuture<User> updateUser(@EndpointParam URI userRef,
ListenableFuture<User> update(@EndpointParam(parser = UserURNToHref.class) String userUrn,
@BinderParam(BindToXMLPayload.class) User user);
/**
* @see UserApi#deleteUser(URI)
* @see UserApi#update(URI, User)
*/
@PUT
@Consumes(VCloudDirectorMediaType.USER)
@Produces(VCloudDirectorMediaType.USER)
@JAXBResponseParser
ListenableFuture<User> update(@EndpointParam URI userHref, @BinderParam(BindToXMLPayload.class) User user);
/**
* @see UserApi#delete(String)
*/
@DELETE
@Consumes
@JAXBResponseParser
ListenableFuture<Void> deleteUser(@EndpointParam URI userRef);
ListenableFuture<Void> delete(@EndpointParam(parser = UserURNToHref.class) String userUrn);
/**
* @see UserApi#unlockUser(URI)
* @see UserApi#delete(URI)
*/
@DELETE
@Consumes
@JAXBResponseParser
ListenableFuture<Void> delete(@EndpointParam URI userHref);
/**
* @see UserApi#unlock(String)
*/
@POST
@Path("/action/unlock")
@Consumes
@JAXBResponseParser
ListenableFuture<Void> unlockUser(@EndpointParam URI userRef);
ListenableFuture<Void> unlock(@EndpointParam(parser = UserURNToHref.class) String userUrn);
/**
* @see UserApi#unlock(URI)
*/
@POST
@Path("/action/unlock")
@Consumes
@JAXBResponseParser
ListenableFuture<Void> unlock(@EndpointParam URI userHref);
}

View File

@ -1,63 +0,0 @@
/**
* 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.functions;
import java.net.URI;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.rest.ResourceNotFoundException;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Link;
import org.jclouds.vcloud.director.v1_5.domain.org.Org;
import org.jclouds.vcloud.director.v1_5.features.OrgApi;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
/**
* @author grkvlt@apache.org
*/
@Singleton
public class OrgReferenceToTaskListEndpoint implements Function<Object, URI> {
private final OrgApi api;
@Inject
public OrgReferenceToTaskListEndpoint(OrgApi api) {
this.api = api;
}
@Override
public URI apply(Object input) {
Preconditions.checkNotNull(input);
Preconditions.checkArgument(input instanceof URI);
URI reference = (URI) input;
Org org = api.getOrg(reference);
if (org == null) {
throw new ResourceNotFoundException();
}
for (Link link : org.getLinks()) {
if (link.getType().equals(VCloudDirectorMediaType.TASKS_LIST)) {
return link.getHref();
}
}
throw new RuntimeException(String.format("Could not find a link of type %s", VCloudDirectorMediaType.TASKS_LIST));
};
}

View File

@ -18,75 +18,52 @@
*/
package org.jclouds.vcloud.director.v1_5.functions;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.transform;
import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.net.URI;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.logging.Logger;
import org.jclouds.location.predicates.LocationPredicates;
import org.jclouds.vcloud.director.v1_5.domain.org.Org;
import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorAsyncApi;
import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorApi;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Sets;
import static com.google.common.collect.FluentIterable.*;
/**
* @author danikov
* @author danikov, Adrian Cole
*/
@Singleton
public class OrgsForLocations implements Function<Iterable<Location>, Iterable<? extends Org>> {
@Resource
public Logger logger = Logger.NULL;
private final VCloudDirectorAsyncApi aapi;
private final ExecutorService executor;
private final VCloudDirectorApi api;
@Inject
OrgsForLocations(VCloudDirectorAsyncApi aapi, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.aapi = aapi;
this.executor = executor;
OrgsForLocations(VCloudDirectorApi api) {
this.api = api;
}
/**
* Zones are assignable, but we want regions. so we look for zones, whose
* parent is region. then, we use a set to extract the unique set.
* Zones are assignable, but we want regions. so we look for zones, whose parent is region. then,
* we use a set to extract the unique set.
*/
@Override
public Iterable<? extends Org> apply(Iterable<Location> from) {
return transformParallel(Sets.newLinkedHashSet(transform(filter(from, new Predicate<Location>() {
return from(from)
.filter(LocationPredicates.isZone())
.transform(new Function<Location, String>() {
@Override
public String apply(Location from) {
return from.getParent().getId();
}
})
.transform(new Function<String, Org>() {
@Override
public boolean apply(Location input) {
return input.getScope() == LocationScope.ZONE;
public Org apply(String from) {
return api.getOrgApi().get(from);
}
}), new Function<Location, URI>() {
@Override
public URI apply(Location from) {
return URI.create(from.getParent().getId());
}
})), new Function<URI, Future<? extends Org>>() {
@Override
public Future<? extends Org> apply(URI from) {
return aapi.getOrgApi().getOrg(from);
}
}, executor, null, logger, "organizations for uris");
});
}
}

View File

@ -18,26 +18,17 @@
*/
package org.jclouds.vcloud.director.v1_5.functions;
import static org.jclouds.concurrent.FutureIterables.transformParallel;
import static org.jclouds.vcloud.director.v1_5.predicates.ReferencePredicates.nameEquals;
import static com.google.common.collect.FluentIterable.from;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.org.Org;
import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorAsyncApi;
import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorApi;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
/**
@ -45,33 +36,28 @@ import com.google.common.collect.Iterables;
*/
@Singleton
public class OrgsForNames implements Function<Iterable<String>, Iterable<? extends Org>> {
@Resource
public Logger logger = Logger.NULL;
private final VCloudDirectorAsyncApi aapi;
private final VCloudDirectorApi sapi;
private final ExecutorService executor;
private final VCloudDirectorApi api;
@Inject
OrgsForNames(VCloudDirectorAsyncApi aapi,
VCloudDirectorApi sapi,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.aapi = aapi;
this.sapi = sapi;
this.executor = executor;
OrgsForNames(VCloudDirectorApi api) {
this.api = api;
}
@Override
public Iterable<? extends Org> apply(Iterable<String> from) {
final Set<Reference> orgs = sapi.getOrgApi().getOrgList();
return transformParallel(from, new Function<String, Future<? extends Org>>() {
public Iterable<? extends Org> apply(final Iterable<String> from) {
return from(api.getOrgApi().list()).filter(new Predicate<Reference>() {
@Override
public boolean apply(Reference in) {
return Iterables.contains(from, in.getName());
}
}).transform(new Function<Reference, Org>() {
@Override
public Future<? extends Org> apply(String from) {
return aapi.getOrgApi().getOrg(Iterables.find(orgs, nameEquals(from)).getHref());
public Org apply(Reference in) {
return api.getOrgApi().get(in.getHref());
}
}, executor, null, logger, "organizations for names");
});
}
}

View File

@ -0,0 +1,43 @@
/*
* 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.functions.href;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Entity;
import org.jclouds.vcloud.director.v1_5.functions.URNToHref;
import com.google.common.cache.LoadingCache;
@Singleton
public class NetworkURNToAdminHref extends URNToHref {
@Inject
public NetworkURNToAdminHref(LoadingCache<String, Entity> resolveEntityCache) {
super(resolveEntityCache);
}
@Override
protected String type() {
return VCloudDirectorMediaType.ADMIN_NETWORK;
}
}

View File

@ -0,0 +1,43 @@
/*
* 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.functions.href;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Entity;
import org.jclouds.vcloud.director.v1_5.functions.URNToHref;
import com.google.common.cache.LoadingCache;
@Singleton
public class NetworkURNToHref extends URNToHref {
@Inject
public NetworkURNToHref(LoadingCache<String, Entity> resolveEntityCache) {
super(resolveEntityCache);
}
@Override
protected String type() {
return VCloudDirectorMediaType.NETWORK;
}
}

View File

@ -0,0 +1,43 @@
/*
* 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.functions.href;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Entity;
import org.jclouds.vcloud.director.v1_5.functions.URNToHref;
import com.google.common.cache.LoadingCache;
@Singleton
public class TaskURNToHref extends URNToHref {
@Inject
public TaskURNToHref(LoadingCache<String, Entity> resolveEntityCache) {
super(resolveEntityCache);
}
@Override
protected String type() {
return VCloudDirectorMediaType.TASK;
}
}

View File

@ -0,0 +1,43 @@
/*
* 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.functions.href;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Entity;
import org.jclouds.vcloud.director.v1_5.functions.URNToHref;
import com.google.common.cache.LoadingCache;
@Singleton
public class TasksListURNToHref extends URNToHref {
@Inject
public TasksListURNToHref(LoadingCache<String, Entity> resolveEntityCache) {
super(resolveEntityCache);
}
@Override
protected String type() {
return VCloudDirectorMediaType.TASKS_LIST;
}
}

View File

@ -0,0 +1,43 @@
/*
* 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.functions.href;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Entity;
import org.jclouds.vcloud.director.v1_5.functions.URNToHref;
import com.google.common.cache.LoadingCache;
@Singleton
public class UserURNToHref extends URNToHref {
@Inject
public UserURNToHref(LoadingCache<String, Entity> resolveEntityCache) {
super(resolveEntityCache);
}
@Override
protected String type() {
return VCloudDirectorMediaType.USER;
}
}

View File

@ -30,10 +30,33 @@ import com.google.common.collect.Iterables;
/**
* Predicates for working with {@link EntityType} collections.
*
* @author grkvlt@apache.org
* @author grkvlt@apache.org, Adrian Cole
*/
public class EntityPredicates {
/**
* Matches {@link EntityType entities} with the given id.
*
* @param T type of the entity, for example {@link Vm}
* @param id value of the id attribute of the entity
* @return predicate that will match entities of the given id
*/
public static <T extends Entity> Predicate<T> idEquals(final String id) {
checkNotNull(id, "id must be defined");
return new Predicate<T>() {
@Override
public boolean apply(T entity) {
return id.equals(entity.getId());
}
@Override
public String toString() {
return "idEquals(" + id + ")";
}
};
}
/**
* Matches {@link EntityType entities} with the given name.
*

View File

@ -39,7 +39,7 @@ public class LinkPredicates {
/**
* matches links of the given relation
*
* @param rel from {@code context.getApi().getCurrentSession().getOrg().getLinks()}
* @param rel from {@code context.getApi().getCurrentSession().get().getLinks()}
* @return predicate that will match links of the given rel
*/
public static Predicate<Link> relEquals(final String rel) {

View File

@ -67,7 +67,7 @@ public class TaskStatusEquals implements Predicate<Task> {
logger.trace("looking for status on task %s", task);
// TODO shouldn't we see if it's already done before getting it from API server?
task = taskApi.getTask(task.getHref());
task = taskApi.get(task.getHref());
// perhaps task isn't available, yet
if (task == null) return false;

View File

@ -58,7 +58,7 @@ public class TaskSuccess implements Predicate<Task> {
logger.trace("looking for status on task %s", task.getOperationName());
// TODO shouldn't we see if it's already done before getting it from API server?
task = taskApi.getTask(task.getHref());
task = taskApi.get(task.getHref());
// perhaps task isn't available, yet
if (task == null) return false;

View File

@ -54,7 +54,7 @@ public interface VCloudDirectorApi {
* GET /entity/{id}
* </pre>
*/
Entity resolveEntity(String id);
Entity resolveEntity(String urn);
/**
* @return the current login session

View File

@ -79,7 +79,7 @@ public class HttpClientLiveTest extends BaseVCloudDirectorApiLiveTest {
sessionWithToken = SessionWithToken.builder().session(session).token(response.getFirstHeaderOrNull("x-vcloud-authorization")).build();
assertEquals(sessionWithToken.getSession().getUser(), user);
assertEquals(sessionWithToken.getSession().getOrg(), org);
assertEquals(sessionWithToken.getSession().get(), org);
assertTrue(sessionWithToken.getSession().getLinks().size() > 0);
assertNotNull(sessionWithToken.getToken());
@ -87,7 +87,7 @@ public class HttpClientLiveTest extends BaseVCloudDirectorApiLiveTest {
assertTrue(orgList.size() > 0, "must have orgs");
context.getApi().getOrgApi().getOrg(Iterables.getLast(orgList).getHref());
context.getApi().getOrgApi().get(Iterables.getLast(orgList).getHref());
}
@Test(description = "GET /schema/{schemaFileName}", dependsOnMethods = { "testPostLogin", "testGetLogin" })

View File

@ -38,8 +38,8 @@ public class VCloudDirectorApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "GET /entity/{id}")
public void testResolveEntity() {
for (Reference orgRef : context.getApi().getOrgApi().getOrgList()) {
Org org = context.getApi().getOrgApi().getOrg(orgRef.getHref());
for (Reference orgRef : context.getApi().getOrgApi().list()) {
Org org = context.getApi().getOrgApi().get(orgRef.getHref());
Entity entity = context.getApi().resolveEntity(org.getId());
checkEntityType(entity);
}

View File

@ -33,7 +33,7 @@ public class VCloudDirectorLiveTestConstants {
/* Error codes from 100 to 199 reflect parsing and other errors in domain object fields and attributes. */
public static final String REF_REQ_LIVE = "ERR-101: %s reference required to perform live tests";
public static final String URN_REQ_LIVE = "ERR-101: %s urn required to perform live tests";
public static final String OBJ_REQ_LIVE = "ERR-102: %s instance required to perform live tests";

View File

@ -165,8 +165,6 @@ public class Checks {
assertNotNull(reference.getHref(), String.format(NOT_NULL_OBJ_FIELD_FMT, "Href", "ReferenceType"));
// Check optional fields
String id = reference.getId();
if (id != null) checkId(id);
String type = reference.getType();
if (type != null) checkType(type, validTypes);
// NOTE name cannot be checked
@ -257,7 +255,7 @@ public class Checks {
if (error != null) checkError(error);
Reference user = task.getUser();
if (user != null) checkReferenceType(user);
Reference org = task.getOrg();
Reference org = task.get();
if (org != null) checkReferenceType(org);
Integer progress = task.getProgress();
if (progress != null) checkProgress(progress);

View File

@ -22,7 +22,7 @@ import static com.google.common.base.Predicates.and;
import static com.google.common.collect.Iterables.find;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.CORRECT_VALUE_OBJECT_FMT;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.REF_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.URN_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.TASK_COMPLETE_TIMELY;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkCatalogItem;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadata;
@ -83,7 +83,7 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
if (adminCatalog != null)
return;
catalogApi = context.getApi().getCatalogApi();
Org org = context.getApi().getOrgApi().getOrg(Iterables.get(context.getApi().getOrgApi().getOrgList(), 0).getHref());
Org org = context.getApi().getOrgApi().get(Iterables.get(context.getApi().getOrgApi().list(), 0).getHref());
if (adminContext != null) {
AdminCatalog newCatalog = AdminCatalog.builder().name(name("Test Catalog "))
@ -149,7 +149,7 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "POST /catalog/{id}/catalogItems")
public void testAddCatalogItem() {
assertNotNull(vdcURI, String.format(REF_REQ_LIVE, VDC));
assertNotNull(vdcURI, String.format(URN_REQ_LIVE, VDC));
byte[] iso = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
Vdc vdc = context.getApi().getVdcApi().getVdc(vdcURI);

View File

@ -98,7 +98,6 @@ public class MediaApiExpectTest extends VCloudDirectorAdminApiExpectTest {
.source(Reference.builder()
.type("application/vnd.vmware.vcloud.media+xml")
.name("copied test media")
.id("urn:vcloud:media:da8361af-cccd-4103-a71c-493513c49094")
.href(URI.create("https://mycloud.greenhousedata.com/api/media/da8361af-cccd-4103-a71c-493513c49094"))
.build())
.isSourceDelete(false)

View File

@ -35,7 +35,7 @@ import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.O
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_UPDATABLE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.REF_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.URN_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.TASK_COMPLETE_TIMELY;
import static org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates.relEquals;
import static org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates.typeEquals;
@ -128,7 +128,7 @@ public class MediaApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "POST /vdc/{id}/media")
public void testCreateMedia() throws URISyntaxException {
assertNotNull(vdcURI, String.format(REF_REQ_LIVE, VDC));
assertNotNull(vdcURI, String.format(URN_REQ_LIVE, VDC));
Vdc vdc = vdcApi.getVdc(vdcURI);
assertNotNull(vdc, String.format(OBJ_REQ_LIVE, VDC));
Link addMedia = find(vdc.getLinks(), and(relEquals("add"), typeEquals(VCloudDirectorMediaType.MEDIA)));
@ -190,7 +190,7 @@ public class MediaApiLiveTest extends BaseVCloudDirectorApiLiveTest {
public void testGetMediaOwner() {
Owner directOwner = mediaApi.getOwner(media.getHref());
assertEquals(owner.toBuilder()
.user(owner.getUser().toBuilder().id(null).build())
.user(owner.getUser())
.build(),
directOwner.toBuilder().links(Collections.<Link>emptySet()).build(),
String.format(GETTER_RETURNS_SAME_OBJ,

View File

@ -18,14 +18,22 @@
*/
package org.jclouds.vcloud.director.v1_5.features;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.ADMIN_NETWORK;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.ENTITY;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.ERROR;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.METADATA;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.METADATA_VALUE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NETWORK;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.ORG;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.fail;
import java.net.URI;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Error;
import org.jclouds.vcloud.director.v1_5.domain.Link;
import org.jclouds.vcloud.director.v1_5.domain.Metadata;
@ -36,7 +44,6 @@ import org.jclouds.vcloud.director.v1_5.domain.network.IpAddresses;
import org.jclouds.vcloud.director.v1_5.domain.network.IpRange;
import org.jclouds.vcloud.director.v1_5.domain.network.IpRanges;
import org.jclouds.vcloud.director.v1_5.domain.network.IpScope;
import org.jclouds.vcloud.director.v1_5.domain.network.Network;
import org.jclouds.vcloud.director.v1_5.domain.network.Network.FenceMode;
import org.jclouds.vcloud.director.v1_5.domain.network.NetworkConfiguration;
import org.jclouds.vcloud.director.v1_5.domain.network.NetworkFeatures;
@ -47,6 +54,7 @@ import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorApi;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.common.net.HttpHeaders;
/**
* Test the {@link NetworkApi} via its side effects.
@ -56,35 +64,38 @@ import com.google.common.collect.ImmutableSet;
@Test(groups = { "unit", "user" }, singleThreaded = true, testName = "NetworkApiExpectTest")
public class NetworkApiExpectTest extends VCloudDirectorAdminApiExpectTest {
static String network = "55a677cf-ab3f-48ae-b880-fab90421980c";
static String networkUrn = "urn:vcloud:network:" + network;
static URI networkHref = URI.create(endpoint + "/network/" + network);
HttpRequest get = HttpRequest.builder()
.method("GET")
.endpoint(networkHref)
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.build();
HttpResponse getResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/network/network.xml", ORG + ";version=1.5"))
.build();
@Test
public void testGetNetwork() {
URI networkUri = URI.create(endpoint + "/network/f3ba8256-6f48-4512-aad6-600e85b4dc38");
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("GET", "/network/f3ba8256-6f48-4512-aad6-600e85b4dc38")
.acceptAnyMedia()
.httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/network/network.xml", VCloudDirectorMediaType.ORG_NETWORK)
.httpResponseBuilder().build());
OrgNetwork expected = orgNetwork();
assertEquals(Network.<OrgNetwork>toSubType(api.getNetworkApi().getNetwork(networkUri)), expected);
public void testGetNetworkHref() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, get, getResponse);
assertEquals(api.getNetworkApi().get(networkHref), network());
}
@Test
public void testGetNetworkWithInvalidId() {
URI networkUri = URI.create(endpoint + "/network/NOTAUUID");
public void testGetNetworkHrefInvalidId() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("GET", "/network/NOTAUUID")
.acceptAnyMedia()
.httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/network/error400.xml", VCloudDirectorMediaType.ERROR)
.httpResponseBuilder().statusCode(400).build());
get.toBuilder().endpoint(endpoint + "/network/NOTAUUID").build(),
HttpResponse.builder()
.statusCode(400)
.payload(payloadFromResourceWithContentType("/network/error400.xml", ERROR + ";version=1.5"))
.build());
Error expected = Error.builder()
.message("validation error : EntityRef has incorrect type, expected type is com.vmware.vcloud.entity.network.")
@ -93,7 +104,7 @@ public class NetworkApiExpectTest extends VCloudDirectorAdminApiExpectTest {
.build();
try {
api.getNetworkApi().getNetwork(networkUri);
api.getNetworkApi().get(URI.create(endpoint + "/network/NOTAUUID"));
fail("Should give HTTP 400 error");
} catch (VCloudDirectorException vde) {
assertEquals(vde.getError(), expected);
@ -103,78 +114,113 @@ public class NetworkApiExpectTest extends VCloudDirectorAdminApiExpectTest {
}
@Test
public void testGetNetworkWithCatalogId() {
URI networkUri = URI.create(endpoint + "/network/9e08c2f6-077a-42ce-bece-d5332e2ebb5c");
public void testGetNetworkHrefCatalogId() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("GET", "/network/9e08c2f6-077a-42ce-bece-d5332e2ebb5c")
.acceptAnyMedia()
.httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/network/error403-catalog.xml", VCloudDirectorMediaType.ERROR)
.httpResponseBuilder().statusCode(403).build());
get.toBuilder().endpoint(endpoint + "/network/9e08c2f6-077a-42ce-bece-d5332e2ebb5c").build(),
HttpResponse.builder()
.statusCode(403)
.payload(payloadFromResourceWithContentType("/network/error403-catalog.xml", ERROR + ";version=1.5"))
.build());
assertNull(api.getNetworkApi().getNetwork(networkUri));
assertNull(api.getNetworkApi().get(URI.create(endpoint + "/network/9e08c2f6-077a-42ce-bece-d5332e2ebb5c")));
}
@Test
public void testGetNetworkWithFakeId() {
URI networkUri = URI.create(endpoint + "/network/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee");
public void testGetNetworkHrefFakeId() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("GET", "/network/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")
.acceptAnyMedia()
.httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/network/error403-fake.xml", VCloudDirectorMediaType.ERROR)
.httpResponseBuilder().statusCode(403).build());
get.toBuilder().endpoint(endpoint + "/network/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee").build(),
HttpResponse.builder()
.statusCode(403)
.payload(payloadFromResourceWithContentType("/network/error403-fake.xml", ERROR + ";version=1.5"))
.build());
assertNull(api.getNetworkApi().getNetwork(networkUri));
assertNull(api.getNetworkApi().get(URI.create(endpoint + "/network/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")));
}
HttpRequest resolveNetwork = HttpRequest.builder()
.method("GET")
.endpoint(endpoint + "/entity/" + networkUrn)
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.build();
String networkEntity = asString(createXMLBuilder("Entity").a("xmlns", "http://www.vmware.com/vcloud/v1.5")
.a("name", networkUrn)
.a("id", networkUrn)
.a("type", ENTITY)
.a("href", endpoint + "/entity/" + networkUrn)
.e("Link").a("rel", "alternate").a("type", NETWORK).a("href", networkHref.toString()).up()
// TODO: remove this when VCloudDirectorApiExpectTest no longer inherits from VCloudDirectorAdminApiExpectTest
.e("Link").a("rel", "alternate").a("type", ADMIN_NETWORK).a("href", networkHref.toString()).up());
HttpResponse resolveNetworkResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromStringWithContentType(networkEntity, ENTITY + ";version=1.5"))
.build();
@Test
public void testGetMetadata() {
URI networkUri = URI.create(endpoint + "/network/55a677cf-ab3f-48ae-b880-fab90421980c");
public void testGetNetworkUrn() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, resolveNetwork, resolveNetworkResponse, get, getResponse);
assertEquals(api.getNetworkApi().get(networkUrn), network());
}
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("GET", "/network/55a677cf-ab3f-48ae-b880-fab90421980c/metadata")
.acceptAnyMedia()
.httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/network/metadata.xml", VCloudDirectorMediaType.METADATA)
.httpResponseBuilder().build());
Metadata expected = Metadata.builder()
HttpRequest getMetadata = HttpRequest.builder()
.method("GET")
.endpoint(networkHref + "/metadata")
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build();
HttpResponse getMetadataResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/network/metadata.xml", METADATA))
.build();
@Test
public void testGetNetworkMetadataHref() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, getMetadata, getMetadataResponse);
assertEquals(api.getNetworkApi().getMetadataApi().get(networkHref), metadata());
}
static Metadata metadata() {
return Metadata.builder()
.type("application/vnd.vmware.vcloud.metadata+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c/metadata"))
.href(URI.create(endpoint + "/network/" + network + "/metadata"))
.link(Link.builder()
.rel("up")
.type("application/vnd.vmware.vcloud.network+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c"))
.href(networkHref)
.build())
.entries(ImmutableSet.of(MetadataEntry.builder().entry("key", "value").build()))
.entries(ImmutableSet.of(metadataEntry()))
.build();
assertEquals(api.getNetworkApi().getMetadataApi().get(networkUri), expected);
}
private static MetadataEntry metadataEntry() {
return MetadataEntry.builder().entry("key", "value").build();
}
HttpRequest getMetadataValue = HttpRequest.builder()
.method("GET")
.endpoint(networkHref + "/metadata/KEY")
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build();
HttpResponse getMetadataValueResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/network/metadataValue.xml", METADATA_VALUE))
.build();
@Test
public void testGetMetadataValue() {
URI networkUri = URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c");
public void testGetNetworkMetadataEntryHref() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, getMetadataValue, getMetadataValueResponse);
assertEquals(api.getNetworkApi().getMetadataApi().getValue(networkHref, "KEY"), metadataValue());
}
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("GET", "/network/55a677cf-ab3f-48ae-b880-fab90421980c/metadata/KEY")
.acceptAnyMedia()
.httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/network/metadataValue.xml", VCloudDirectorMediaType.METADATA_ENTRY)
.httpResponseBuilder().build());
MetadataValue expected = MetadataValue.builder()
private MetadataValue metadataValue() {
return MetadataValue.builder()
.href(URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c/metadata/key"))
.link(Link.builder()
.rel("up")
@ -183,11 +229,10 @@ public class NetworkApiExpectTest extends VCloudDirectorAdminApiExpectTest {
.build())
.value("value")
.build();
assertEquals(api.getNetworkApi().getMetadataApi().getValue(networkUri, "KEY"), expected);
}
public static OrgNetwork orgNetwork() {
public static OrgNetwork network() {
return OrgNetwork.builder()
.name("ilsolation01-Jclouds")
.id("urn:vcloud:network:f3ba8256-6f48-4512-aad6-600e85b4dc38")

View File

@ -22,7 +22,7 @@ import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.O
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_EQ;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.REF_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.URN_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.REQUIRED_VALUE_OBJECT_FMT;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkResourceType;
import static org.testng.Assert.assertEquals;
@ -60,18 +60,20 @@ public class NetworkApiLiveTest extends BaseVCloudDirectorApiLiveTest {
protected NetworkApi networkApi;
private boolean metadataSet = false;
private Network network;
@Override
@BeforeClass(alwaysRun = true)
public void setupRequiredApis() {
networkApi = context.getApi().getNetworkApi();
network = lazyGetNetwork();
}
@AfterClass(alwaysRun = true)
public void cleanUp() {
if (metadataSet) {
try {
Task delete = adminContext.getApi().getNetworkApi().getMetadataApi().deleteEntry(toAdminUri(networkURI), "key");
Task delete = adminContext.getApi().getNetworkApi().getMetadataApi().deleteEntry(network.getHref(), "key");
taskDoneEventually(delete);
} catch (Exception e) {
logger.warn(e, "Error when deleting metadata");
@ -82,9 +84,9 @@ public class NetworkApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "GET /network/{id}")
public void testGetNetwork() {
// required for testing
assertNotNull(networkURI, String.format(REF_REQ_LIVE, NETWORK));
assertNotNull(networkUrn, String.format(URN_REQ_LIVE, NETWORK));
Network abstractNetwork = networkApi.getNetwork(networkURI);
Network abstractNetwork = networkApi.get(networkUrn);
assertTrue(abstractNetwork instanceof OrgNetwork, String.format(REQUIRED_VALUE_OBJECT_FMT,
".class", NETWORK, abstractNetwork.getClass(),"OrgNetwork"));
OrgNetwork network = Network.toSubType(abstractNetwork);
@ -95,7 +97,7 @@ public class NetworkApiLiveTest extends BaseVCloudDirectorApiLiveTest {
}
private void setupMetadata() {
adminContext.getApi().getNetworkApi().getMetadataApi().putEntry(toAdminUri(networkURI),
adminContext.getApi().getNetworkApi().getMetadataApi().putEntry(network.getHref(),
"key", MetadataValue.builder().value("value").build());
metadataSet = true;
}
@ -106,7 +108,7 @@ public class NetworkApiLiveTest extends BaseVCloudDirectorApiLiveTest {
setupMetadata();
}
Metadata metadata = networkApi.getMetadataApi().get(networkURI);
Metadata metadata = networkApi.getMetadataApi().get(network.getHref());
// required for testing
assertFalse(Iterables.isEmpty(metadata.getMetadataEntries()),
String.format(OBJ_FIELD_REQ_LIVE, NETWORK, "metadata.entries"));
@ -128,7 +130,7 @@ public class NetworkApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "GET /network/{id}/metadata/{key}", dependsOnMethods = { "testGetMetadata" })
public void testGetMetadataValue() {
MetadataValue metadataValue = networkApi.getMetadataApi().getValue(networkURI, "key");
MetadataValue metadataValue = networkApi.getMetadataApi().getValue(network.getHref(), "key");
// Check parent type
checkResourceType(metadataValue);

View File

@ -18,15 +18,18 @@
*/
package org.jclouds.vcloud.director.v1_5.features;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.ADMIN_ORG;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.ENTITY;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.METADATA;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.METADATA_VALUE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.ORG;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.ORG_LIST;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.fail;
import java.net.URI;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Error;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.vcloud.director.v1_5.domain.Link;
import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry;
@ -39,7 +42,7 @@ import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorApi;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.net.HttpHeaders;
/**
* Allows us to test the {@link OrgApi} via its side effects.
@ -51,9 +54,21 @@ public class OrgApiExpectTest extends VCloudDirectorAdminApiExpectTest {
@Test
public void testGetOrgList() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse,
getStandardRequest("GET", "/org/"),
getStandardPayloadResponse("/org/orglist.xml", VCloudDirectorMediaType.ORG_LIST));
HttpRequest list = HttpRequest.builder()
.method("GET")
.endpoint(endpoint + "/org/")
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.build();
HttpResponse listResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/org/orglist.xml", ORG_LIST + ";version=1.5"))
.build();
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, list, listResponse);
OrgList expected = OrgList.builder()
.org(Reference.builder()
@ -63,128 +78,108 @@ public class OrgApiExpectTest extends VCloudDirectorAdminApiExpectTest {
.build())
.build();
assertEquals(api.getOrgApi().getOrgList(), expected);
assertEquals(api.getOrgApi().list(), expected);
}
@Test
public void testGetOrgFromOrgListReference() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse,
getStandardRequest("GET", "/org/"),
getStandardPayloadResponse("/org/orglist.xml", VCloudDirectorMediaType.ORG_LIST));
static String org = "6f312e42-cd2b-488d-a2bb-97519cd57ed0";
static String orgUrn = "urn:vcloud:org:" + org;
static URI orgHref = URI.create(endpoint + "/org/" + org);
Reference org = Iterables.getOnlyElement(api.getOrgApi().getOrgList());
api = requestsSendResponses(loginRequest, sessionResponse,
getStandardRequest("GET", org.getHref()),
getStandardPayloadResponse("/org/org.xml", VCloudDirectorMediaType.ORG));
Org expected = org();
assertEquals(api.getOrgApi().getOrg(org.getHref()), expected);
}
@Test
public void testGetOrg() {
URI orgUri = URI.create(endpoint + "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0");
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse,
getStandardRequest("GET", "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"),
getStandardPayloadResponse("/org/org.xml", VCloudDirectorMediaType.ORG));
Org expected = org();
assertEquals(api.getOrgApi().getOrg(orgUri), expected);
}
@Test
public void testGetOrgFailOnInvalidOrgId() {
URI orgUri = URI.create(endpoint + "/org/NOTAUUID");
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse,
getStandardRequest("GET", "/org/NOTAUUID"),
getStandardPayloadResponse(400, "/org/error400.xml", VCloudDirectorMediaType.ERROR));
Error expected = Error.builder()
.message("validation error on field 'id': String value has invalid format or length")
.majorErrorCode(400)
.minorErrorCode("BAD_REQUEST")
HttpRequest get = HttpRequest.builder()
.method("GET")
.endpoint(orgHref)
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.build();
try {
api.getOrgApi().getOrg(orgUri);
fail("Should give HTTP 400 error");
} catch (VCloudDirectorException vde) {
assertEquals(vde.getError(), expected);
} catch (Exception e) {
fail("Should have thrown a VCloudDirectorException");
}
}
HttpResponse getResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/org/org.xml", ORG + ";version=1.5"))
.build();
@Test
public void testGetOrgFailOnWrongOrgId() {
URI orgUri = URI.create(endpoint + "/org/9e08c2f6-077a-42ce-bece-d5332e2ebb5c");
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse,
getStandardRequest("GET", "/org/9e08c2f6-077a-42ce-bece-d5332e2ebb5c"),
getStandardPayloadResponse(403, "/org/error403-catalog.xml", VCloudDirectorMediaType.ERROR));
assertNull(api.getOrgApi().getOrg(orgUri));
public void testGetOrgHref() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, get, getResponse);
assertEquals(api.getOrgApi().get(orgHref), org());
}
HttpRequest resolveOrg = HttpRequest.builder()
.method("GET")
.endpoint(endpoint + "/entity/" + orgUrn)
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.build();
String orgEntity = asString(createXMLBuilder("Entity").a("xmlns", "http://www.vmware.com/vcloud/v1.5")
.a("name", orgUrn)
.a("id", orgUrn)
.a("type", ENTITY)
.a("href", endpoint + "/entity/" + orgUrn)
.e("Link").a("rel", "alternate").a("type", ORG).a("href", orgHref.toString()).up()
// TODO: remove this when VCloudDirectorApiExpectTest no longer inherits from VCloudDirectorAdminApiExpectTest
.e("Link").a("rel", "alternate").a("type", ADMIN_ORG).a("href", orgHref.toString()).up());
HttpResponse resolveOrgResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromStringWithContentType(orgEntity, ENTITY + ";version=1.5"))
.build();
@Test
public void testGetOrgFailOnFakeOrgId() {
URI orgUri = URI.create(endpoint + "/org/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee");
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse,
getStandardRequest("GET", "/org/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"),
getStandardPayloadResponse(403, "/org/error403-fake.xml", VCloudDirectorMediaType.ERROR));
assertNull(api.getOrgApi().getOrg(orgUri));
public void testGetOrgUrn() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, resolveOrg, resolveOrgResponse, get, getResponse);
assertEquals(api.getOrgApi().get(orgUrn), org());
}
HttpRequest getMetadata = HttpRequest.builder()
.method("GET")
.endpoint(orgHref + "/metadata")
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build();
HttpResponse getMetadataResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/org/orgMetadata.xml", METADATA))
.build();
@Test
public void testGetOrgMetadata() {
URI orgUri = URI.create(endpoint + "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0");
public void testGetOrgMetadataHref() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, getMetadata, getMetadataResponse);
assertEquals(api.getOrgApi().getMetadataApi().get(orgHref), metadata());
}
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("GET", "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata")
.acceptAnyMedia()
.httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/org/orgMetadata.xml", VCloudDirectorMediaType.METADATA)
.httpResponseBuilder().build());
Metadata expected = Metadata.builder()
static Metadata metadata() {
return Metadata.builder()
.type("application/vnd.vmware.vcloud.metadata+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata"))
.href(URI.create(endpoint + "/org/" + org + "/metadata"))
.link(Link.builder()
.rel("up")
.type("application/vnd.vmware.vcloud.org+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.href(orgHref)
.build())
.entries(ImmutableSet.of(metadataEntry()))
.build();
assertEquals(api.getOrgApi().getMetadataApi().get(orgUri), expected);
}
HttpRequest getMetadataValue = HttpRequest.builder()
.method("GET")
.endpoint(orgHref + "/metadata/KEY")
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build();
HttpResponse getMetadataValueResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/org/orgMetadataValue.xml", METADATA_VALUE))
.build();
@Test
public void testGetOrgMetadataValue() {
URI orgUri = URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0");
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("GET", "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata/KEY")
.acceptAnyMedia()
.httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/org/orgMetadataValue.xml", VCloudDirectorMediaType.METADATA_VALUE)
.httpResponseBuilder().build());
MetadataValue expected = metadataValue();
assertEquals(api.getOrgApi().getMetadataApi().getValue(orgUri, "KEY"), expected);
public void testGetOrgMetadataEntryHref() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, getMetadataValue, getMetadataValueResponse);
assertEquals(api.getOrgApi().getMetadataApi().getValue(orgHref, "KEY"), metadataValue());
}
public static Org org() {

View File

@ -21,7 +21,6 @@ package org.jclouds.vcloud.director.v1_5.features;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.CONDITION_FMT;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.CORRECT_VALUE_OBJECT_FMT;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.NOT_EMPTY_OBJECT_FMT;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkControlAccessParams;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadata;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadataValue;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkOrg;
@ -40,7 +39,6 @@ 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.org.Org;
import org.jclouds.vcloud.director.v1_5.domain.org.OrgList;
import org.jclouds.vcloud.director.v1_5.domain.params.ControlAccessParams;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorApiLiveTest;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
@ -97,7 +95,7 @@ public class OrgApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "GET /org")
public void testGetOrgList() {
// Call the method being tested
orgList = orgApi.getOrgList();
orgList = orgApi.list();
// NOTE The environment MUST have at least one organisation configured
@ -118,7 +116,9 @@ public class OrgApiLiveTest extends BaseVCloudDirectorApiLiveTest {
orgURI = orgRef.getHref();
// Call the method being tested
org = orgApi.getOrg(orgURI);
org = orgApi.get(orgURI);
assertEquals(orgApi.get(org.getId()), org);
checkOrg(org);
@ -172,24 +172,4 @@ public class OrgApiLiveTest extends BaseVCloudDirectorApiLiveTest {
assertEquals(value.getValue(), expected, String.format(CORRECT_VALUE_OBJECT_FMT, "Value", "MetadataValue", expected, value.getValue()));
}
@Test(description = "GET /org/{id}/catalog/{catalogId}/controlAccess", dependsOnMethods = { "testGetOrg" })
public void testGetControlAccess() {
// Call the method being tested
ControlAccessParams params = orgApi.getControlAccess(orgURI, catalogUrn);
// Check params are well formed
checkControlAccessParams(params);
}
@Test(description = "POST /org/{id}/catalog/{catalogId}/action/controlAccess", dependsOnMethods = { "testGetControlAccess" })
public void testModifyControlAccess() {
// Setup params
ControlAccessParams params = orgApi.getControlAccess(orgURI, catalogUrn);
// Call the method being tested
ControlAccessParams modified = orgApi.modifyControlAccess(orgURI, catalogUrn, params);
// Check params are well formed
checkControlAccessParams(modified);
}
}

View File

@ -156,25 +156,21 @@ public class QueryApiExpectTest extends VCloudDirectorAdminApiExpectTest {
.reference(CatalogReference.builder()
.type("application/vnd.vmware.vcloud.catalog+xml")
.name("QunyingTestCatalog")
.id("urn:vcloud:catalog:7212e451-76e1-4631-b2de-ba1dfd8080e4")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4"))
.build())
.reference(CatalogReference.builder()
.type("application/vnd.vmware.vcloud.catalog+xml")
.name("Public")
.id("urn:vcloud:catalog:9e08c2f6-077a-42ce-bece-d5332e2ebb5c")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c"))
.build())
.reference(CatalogReference.builder()
.type("application/vnd.vmware.vcloud.catalog+xml")
.name("dantest")
.id("urn:vcloud:catalog:b542aff4-9f97-4f51-a126-4330fbf62f02")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/b542aff4-9f97-4f51-a126-4330fbf62f02"))
.build())
.reference(CatalogReference.builder()
.type("application/vnd.vmware.vcloud.catalog+xml")
.name("test")
.id("urn:vcloud:catalog:b7289d54-4ca4-497f-9a93-2d4afc97e3da")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/b7289d54-4ca4-497f-9a93-2d4afc97e3da"))
.build())
.build();

View File

@ -18,9 +18,10 @@
*/
package org.jclouds.vcloud.director.v1_5.features;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.ENTITY;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.TASK;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.TASKS_LIST;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.fail;
import java.net.URI;
@ -28,9 +29,6 @@ import javax.ws.rs.core.HttpHeaders;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Error;
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;
@ -45,154 +43,88 @@ import org.testng.annotations.Test;
*/
@Test(groups = { "unit", "user" }, singleThreaded = true, testName = "TaskApiExpectTest")
public class TaskApiExpectTest extends VCloudDirectorAdminApiExpectTest {
static String tasksList = "6f312e42-cd2b-488d-a2bb-97519cd57ed0";
static URI tasksListHref = URI.create(endpoint + "/tasksList/" + tasksList);
HttpRequest getTasksList = HttpRequest.builder()
.method("GET")
.endpoint(tasksListHref)
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.build();
HttpResponse getTasksListResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/task/tasksList.xml", TASKS_LIST + ";version=1.5"))
.build();
@Test
public void testTaskListForValidOrg() {
HttpRequest taskRequest = HttpRequest.builder()
.method("GET")
.endpoint(endpoint + "/tasksList/6f312e42-cd2b-488d-a2bb-97519cd57ed0")
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build();
public void testGetTasksListHref() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, getTasksList, getTasksListResponse);
assertEquals(api.getTaskApi().getTasksList(tasksListHref), tasksList());
}
HttpResponse taskResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/task/taskslist.xml", VCloudDirectorMediaType.TASKS_LIST + ";version=1.5"))
.build();
HttpRequest orgRequest = HttpRequest.builder().method("GET")
.endpoint(endpoint + "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build();
HttpResponse orgResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/org/org.xml", VCloudDirectorMediaType.TASKS_LIST + ";version=1.5"))
.build();
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse, orgRequest, orgResponse);
TasksList expected = TasksList.builder()
private TasksList tasksList() {
return 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(taskOne())
.task(task())
.task(taskTwo())
.build();
assertEquals(api.getTaskApi().getTaskList(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")), expected);
}
@Test
public void testTaskListForInvalidOrgId() {
HttpRequest taskRequest = HttpRequest.builder().method("GET")
.endpoint(endpoint + "/tasksList/NOTAUUID")
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token).build();
static String task = "5fcd2af3-d0ec-45ce-9451-8c585a2c766b";
static String taskUrn = "urn:vcloud:task:" + task;
static URI taskHref = URI.create(endpoint + "/task/" + task);
HttpResponse taskResponse = HttpResponse.builder().build();
HttpRequest orgRequest = HttpRequest.builder().method("GET")
.endpoint(endpoint + "/org/NOTAUUID")
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build();
HttpResponse orgResponse = HttpResponse.builder()
.statusCode(400)
.payload(payloadFromResourceWithContentType("/org/error400.xml", VCloudDirectorMediaType.ERROR + ";version=1.5"))
.build();
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse, orgRequest, orgResponse);
Error expected = Error.builder()
.message("validation error on field 'id': String value has invalid format or length")
.majorErrorCode(400)
.minorErrorCode("BAD_REQUEST")
.build();
try {
api.getTaskApi().getTaskList(URI.create("https://vcloudbeta.bluelock.com/api/org/NOTAUUID"));
fail("Should give HTTP 400 error");
} catch (VCloudDirectorException vde) {
assertEquals(vde.getError(), expected);
} catch (Exception e) {
fail("Should have thrown a VCloudDirectorException");
}
}
@Test
public void testTaskListForNotFoundOrgId() {
HttpRequest taskRequest = HttpRequest.builder().method("GET")
.endpoint(endpoint + "/tasksList/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build();
HttpResponse taskResponse = HttpResponse.builder().build();
HttpRequest orgRequest = HttpRequest.builder().method("GET")
.endpoint(endpoint + "/org/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build();
HttpResponse orgResponse = HttpResponse.builder()
.statusCode(403)
.payload(payloadFromResourceWithContentType("/org/error403-fake.xml", VCloudDirectorMediaType.ERROR + ";version=1.5"))
.build();
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse, orgRequest, orgResponse);
assertNull(api.getTaskApi().getTaskList(URI.create("https://vcloudbeta.bluelock.com/api/org/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")));
}
@Test
public void testGetTaskForTaskRef() {
HttpRequest taskRequest = HttpRequest.builder()
HttpRequest get = HttpRequest.builder()
.method("GET")
.endpoint(endpoint + "/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b")
.endpoint(taskHref)
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build();
HttpResponse taskResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/task/task.xml", VCloudDirectorMediaType.TASK + ";version=1.5"))
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.build();
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse);
URI taskUri = URI.create(endpoint + "/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b");
//TODO: incorrect relationship, as task should not have a nested task container!!
Task expected = taskOne();
assertEquals(api.getTaskApi().getTask(taskUri), expected);
}
HttpResponse getResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/task/task.xml", TASK + ";version=1.5"))
.build();
@Test
public void testCancelTaskByTaskRef() {
HttpRequest taskRequest = HttpRequest.builder()
.method("POST")
.endpoint(endpoint + "/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b/action/cancel")
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build();
HttpResponse taskResponse = HttpResponse.builder()
.statusCode(200)
.build();
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse);
URI taskUri = URI.create(endpoint + "/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b");
api.getTaskApi().cancelTask(taskUri);
public void testGetTaskHref() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, get, getResponse);
assertEquals(api.getTaskApi().get(taskHref), task());
}
public static Task taskOne() {
HttpRequest resolveTask = HttpRequest.builder()
.method("GET")
.endpoint(endpoint + "/entity/" + taskUrn)
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.build();
String taskEntity = asString(createXMLBuilder("Entity").a("xmlns", "http://www.vmware.com/vcloud/v1.5")
.a("name", taskUrn)
.a("id", taskUrn)
.a("type", ENTITY)
.a("href", endpoint + "/entity/" + taskUrn)
.e("Link").a("rel", "alternate").a("type", TASK).a("href", taskHref.toString()).up());
HttpResponse resolveTaskResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromStringWithContentType(taskEntity, ENTITY + ";version=1.5"))
.build();
@Test
public void testGetTaskUrn() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, resolveTask, resolveTaskResponse, get, getResponse);
assertEquals(api.getTaskApi().get(taskUrn), task());
}
public static Task task() {
return Task.builder()
.type("application/vnd.vmware.vcloud.task+xml")
.name("task")
@ -222,6 +154,29 @@ public class TaskApiExpectTest extends VCloudDirectorAdminApiExpectTest {
.build();
}
HttpRequest cancel = HttpRequest.builder()
.method("POST")
.endpoint(taskHref+ "/action/cancel")
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build();
HttpResponse cancelResponse = HttpResponse.builder()
.statusCode(200)
.build();
@Test
public void testCancelTaskHref() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, cancel, cancelResponse);
api.getTaskApi().cancel(taskHref);
}
@Test
public void testCancelTaskUrn() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, resolveTask, resolveTaskResponse, cancel, cancelResponse);
api.getTaskApi().cancel(taskHref);
}
public static Task taskTwo() {
return Task.builder()
.type("application/vnd.vmware.vcloud.task+xml")

View File

@ -25,12 +25,15 @@ import static org.testng.Assert.assertNotNull;
import java.net.URI;
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.domain.VApp;
import org.jclouds.vcloud.director.v1_5.domain.org.Org;
import org.jclouds.vcloud.director.v1_5.domain.org.OrgList;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorApiLiveTest;
import org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@ -79,13 +82,17 @@ public class TaskApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "GET /tasksList/{id}")
public void testGetTaskList() {
orgList = orgApi.getOrgList();
orgList = orgApi.list();
Reference orgRef = Iterables.getFirst(orgList, null);
assertNotNull(orgRef);
orgURI = orgRef.getHref();
Org org = orgApi.get(orgURI);
URI taskListHref = Iterables.find(org.getLinks(), LinkPredicates.typeEquals(VCloudDirectorMediaType.TASKS_LIST)).getHref();
// Call the method being tested
taskList = taskApi.getTaskList(orgURI);
taskList = taskApi.getTasksList(taskListHref);
// NOTE The environment MUST have ...
@ -105,7 +112,7 @@ public class TaskApiLiveTest extends BaseVCloudDirectorApiLiveTest {
taskURI = taskRef.getHref();
// Call the method being tested
task = taskApi.getTask(taskURI);
task = taskApi.get(taskURI);
// Check required elements and attributes
checkTask(task);
@ -122,7 +129,7 @@ public class TaskApiLiveTest extends BaseVCloudDirectorApiLiveTest {
assertTaskStatusEventually(task, Task.Status.RUNNING, ImmutableSet.of(Task.Status.ERROR, Task.Status.ABORTED));
// Call the method being tested
taskApi.cancelTask(taskURI);
taskApi.cancel(taskURI);
assertTaskStatusEventually(task, Task.Status.CANCELED, ImmutableSet.of(Task.Status.ERROR, Task.Status.ABORTED, Task.Status.SUCCESS));
}
}

View File

@ -75,6 +75,7 @@ import org.jclouds.vcloud.director.v1_5.domain.ProductSectionList;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.ResourceEntity.Status;
import org.jclouds.vcloud.director.v1_5.domain.Task;
import org.jclouds.vcloud.director.v1_5.domain.User;
import org.jclouds.vcloud.director.v1_5.domain.VApp;
import org.jclouds.vcloud.director.v1_5.domain.VAppTemplate;
import org.jclouds.vcloud.director.v1_5.domain.Vm;
@ -117,9 +118,9 @@ public class VAppApiLiveTest extends AbstractVAppApiLiveTest {
private MetadataValue metadataValue;
private String key;
private URI testUserURI;
private boolean mediaCreated = false;
private boolean testUserCreated = false;
private User user;
@BeforeClass(alwaysRun = true)
protected void setupRequiredEntities() {
@ -161,10 +162,10 @@ public class VAppApiLiveTest extends AbstractVAppApiLiveTest {
if (adminContext != null) {
Link orgLink = find(links, and(relEquals("up"), typeEquals(VCloudDirectorMediaType.ORG)));
testUserURI = adminContext.getApi().getUserApi().createUser(toAdminUri(orgLink), randomTestUser("VAppAccessTest")).getHref();
} else {
testUserURI = userURI;
userUrn = adminContext.getApi().getUserApi()
.createUserInOrg(randomTestUser("VAppAccessTest"), toAdminUri(orgLink)).getId();
}
user = lazyGetUser();
}
@AfterClass(alwaysRun = true, dependsOnMethods = { "cleanUpEnvironment" })
@ -177,9 +178,9 @@ public class VAppApiLiveTest extends AbstractVAppApiLiveTest {
logger.warn(e, "Error when deleting media");
}
}
if (adminContext != null && testUserCreated && testUserURI != null) {
if (adminContext != null && testUserCreated && userUrn != null) {
try {
adminContext.getApi().getUserApi().deleteUser(testUserURI);
adminContext.getApi().getUserApi().delete(userUrn);
} catch (Exception e) {
logger.warn(e, "Error when deleting user");
}
@ -436,7 +437,7 @@ public class VAppApiLiveTest extends AbstractVAppApiLiveTest {
ControlAccessParams params = ControlAccessParams.builder()
.notSharedToEveryone()
.accessSetting(AccessSetting.builder()
.subject(Reference.builder().href(testUserURI).type(ADMIN_USER).build())
.subject(Reference.builder().href(user.getHref()).type(ADMIN_USER).build())
.accessLevel("ReadOnly")
.build())
.build();
@ -653,7 +654,7 @@ public class VAppApiLiveTest extends AbstractVAppApiLiveTest {
@Test(description = "PUT /vApp/{id}/owner", dependsOnMethods = { "testGetOwner" })
public void testModifyOwner() {
Owner newOwner = Owner.builder().user(Reference.builder().href(testUserURI).type(ADMIN_USER).build()).build();
Owner newOwner = Owner.builder().user(Reference.builder().href(user.getHref()).type(ADMIN_USER).build()).build();
// The method under test
vAppApi.modifyOwner(vApp.getHref(), newOwner);

View File

@ -18,12 +18,9 @@
*/
package org.jclouds.vcloud.director.v1_5.features;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.ENTITY_NON_NULL;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.TASK_COMPLETE_TIMELY;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkNetworkConfigSection;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import java.net.URI;
import java.util.List;
@ -33,7 +30,6 @@ import java.util.Set;
import org.jclouds.vcloud.director.v1_5.AbstractVAppApiLiveTest;
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.Vdc;
import org.jclouds.vcloud.director.v1_5.domain.Vm;
import org.jclouds.vcloud.director.v1_5.domain.network.FirewallRule;
import org.jclouds.vcloud.director.v1_5.domain.network.FirewallRuleProtocols;
@ -42,6 +38,7 @@ import org.jclouds.vcloud.director.v1_5.domain.network.IpRange;
import org.jclouds.vcloud.director.v1_5.domain.network.IpRanges;
import org.jclouds.vcloud.director.v1_5.domain.network.IpScope;
import org.jclouds.vcloud.director.v1_5.domain.network.NatService;
import org.jclouds.vcloud.director.v1_5.domain.network.Network;
import org.jclouds.vcloud.director.v1_5.domain.network.Network.FenceMode;
import org.jclouds.vcloud.director.v1_5.domain.network.NetworkConfiguration;
import org.jclouds.vcloud.director.v1_5.domain.network.NetworkConnection;
@ -57,11 +54,8 @@ import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
@ -78,9 +72,8 @@ public class VAppNetworksLiveTest extends AbstractVAppApiLiveTest {
private static final String HTTP_SECURITY_GROUP = "http";
private static final String DEFAULT_SECURITY_GROUP = "default";
private String key;
private Reference parentNetworkRef;
private Map<String, NetworkConfiguration> securityGroupToNetworkConfig;
private String orgNetworkName;
private Network network;
@AfterClass(alwaysRun = true, dependsOnMethods = { "cleanUpEnvironment" })
protected void tidyUp() {
@ -96,9 +89,8 @@ public class VAppNetworksLiveTest extends AbstractVAppApiLiveTest {
@BeforeClass
void setUp() {
parentNetworkRef = lookUpNewtorkInVdc(networkURI);
securityGroupToNetworkConfig = createSecurityGroupToNetworkConfiguration(parentNetworkRef);
orgNetworkName = parentNetworkRef.getName();
network = lazyGetNetwork();
securityGroupToNetworkConfig = createSecurityGroupToNetworkConfiguration(Reference.builder().fromEntity(network).build());
}
@AfterMethod
@ -164,7 +156,7 @@ public class VAppNetworksLiveTest extends AbstractVAppApiLiveTest {
}
private void createVAppNetworkWithSecurityGroupOnVApp(ImmutableList<String> securityGroups, URI vAppURI) {
String newVAppNetworkName = generateVAppNetworkName(orgNetworkName, securityGroups);
String newVAppNetworkName = generateVAppNetworkName(network.getName(), securityGroups);
// Create a vAppNetwork with firewall rules
NetworkConfigSection newSection = generateNetworkConfigSection(securityGroups, newVAppNetworkName);
Task modifyNetworkConfigSection = vAppApi.modifyNetworkConfigSection(vAppURI, newSection);
@ -185,7 +177,7 @@ public class VAppNetworksLiveTest extends AbstractVAppApiLiveTest {
IpScope ipScope = createNewIpScope();
NetworkConfiguration newConfiguration = NetworkConfiguration.builder()
.ipScope(ipScope)
.parentNetwork(parentNetworkRef)
.parentNetwork(Reference.builder().fromEntity(network).build())
.fenceMode(FenceMode.NAT_ROUTED)
.retainNetInfoAcrossDeployments(false)
.features(createNetworkFeatures(ImmutableSet.of(firewallService, natService)))
@ -241,25 +233,6 @@ public class VAppNetworksLiveTest extends AbstractVAppApiLiveTest {
return newIpRange;
}
private Reference lookUpNewtorkInVdc(final URI networkURI) {
Vdc vdc = context.getApi().getVdcApi().getVdc(vdcURI);
assertNotNull(vdc, String.format(ENTITY_NON_NULL, VDC));
Set<Reference> networks = vdc.getAvailableNetworks();
// Look up the network in the Vdc with the id configured for the tests
Optional<Reference> parentNetwork = Iterables.tryFind(networks, new Predicate<Reference>() {
@Override
public boolean apply(Reference reference) {
return reference.getHref().equals(networkURI);
}
});
if (!parentNetwork.isPresent()) {
fail(String.format("Could not find network %s in vdc", networkURI.toASCIIString()));
}
return parentNetwork.get();
}
private Set<FirewallRule> retrieveAllFirewallRules(NetworkFeatures networkFeatures) {
Set<FirewallRule> firewallRules = Sets.newLinkedHashSet();
for (NetworkServiceType<?> networkServiceType : networkFeatures.getNetworkServices()) {

View File

@ -331,7 +331,6 @@ public class VdcApiExpectTest extends VCloudDirectorAdminApiExpectTest {
.source(Reference.builder()
.type("application/vnd.vmware.vcloud.media+xml")
.name("copied test media")
.id("urn:vcloud:media:da8361af-cccd-4103-a71c-493513c49094")
.href(URI.create("https://mycloud.greenhousedata.com/api/media/da8361af-cccd-4103-a71c-493513c49094"))
.build())
.isSourceDelete(false)

View File

@ -21,7 +21,7 @@ package org.jclouds.vcloud.director.v1_5.features;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_EQ;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.REF_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.URN_REQ_LIVE;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
@ -40,6 +40,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Task;
import org.jclouds.vcloud.director.v1_5.domain.VApp;
import org.jclouds.vcloud.director.v1_5.domain.VAppTemplate;
import org.jclouds.vcloud.director.v1_5.domain.Vdc;
import org.jclouds.vcloud.director.v1_5.domain.network.Network;
import org.jclouds.vcloud.director.v1_5.domain.network.Network.FenceMode;
import org.jclouds.vcloud.director.v1_5.domain.network.NetworkConfiguration;
import org.jclouds.vcloud.director.v1_5.domain.network.VAppNetworkConfiguration;
@ -85,6 +86,7 @@ public class VdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
private VAppTemplate capturedVAppTemplate;
private VAppTemplate uploadedVAppTemplate;
private boolean metadataSet = false;
private Network network;
@Override
@BeforeClass(alwaysRun = true)
@ -93,7 +95,8 @@ public class VdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
vappTemplateApi = context.getApi().getVAppTemplateApi();
vappApi = context.getApi().getVAppApi();
assertNotNull(vdcURI, String.format(REF_REQ_LIVE, VDC));
assertNotNull(vdcURI, String.format(URN_REQ_LIVE, VDC));
network = lazyGetNetwork();
}
@AfterClass(alwaysRun = true)
@ -241,12 +244,12 @@ public class VdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
networks, new Predicate<Reference>() {
@Override
public boolean apply(Reference reference) {
return reference.getHref().equals(networkURI);
return reference.getHref().equals(network.getHref());
}
});
if (!parentNetwork.isPresent()) {
fail(String.format("Could not find network %s in vdc", networkURI.toASCIIString()));
fail(String.format("Could not find network %s in vdc", network.getHref().toASCIIString()));
}
NetworkConfiguration networkConfiguration = NetworkConfiguration.builder()

View File

@ -117,7 +117,6 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
private MetadataValue metadataValue;
private String key;
private URI testUserURI;
private boolean mediaCreated = false;
private boolean testUserCreated = false;
@ -161,9 +160,8 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
if (adminContext != null) {
Link orgLink = find(links, and(relEquals("up"), typeEquals(VCloudDirectorMediaType.ORG)));
testUserURI = adminContext.getApi().getUserApi().createUser(toAdminUri(orgLink), randomTestUser("VAppAccessTest")).getHref();
} else {
testUserURI = userURI;
userUrn = adminContext.getApi().getUserApi()
.createUserInOrg(randomTestUser("VAppAccessTest"), toAdminUri(orgLink)).getId();
}
}
@ -177,9 +175,9 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
logger.warn("Error when deleting media: %s", e.getMessage());
}
}
if (adminContext != null && testUserCreated && testUserURI != null) {
if (adminContext != null && testUserCreated && userUrn != null) {
try {
adminContext.getApi().getUserApi().deleteUser(testUserURI);
adminContext.getApi().getUserApi().delete(userUrn);
} catch (Exception e) {
logger.warn("Error when deleting user: %s", e.getMessage());
}

View File

@ -55,12 +55,12 @@ public class AdminCatalogApiExpectTest extends VCloudDirectorAdminApiExpectTest
static String catalog = "7212e451-76e1-4631-b2de-ba1dfd8080e4";
static String catalogUrn = "urn:vcloud:catalog:" + catalog;
static URI adminCatalogHref = URI.create(endpoint + "/admin/catalog/" + catalog);
static URI catalogAdminHref = URI.create(endpoint + "/admin/catalog/" + catalog);
static URI catalogHref = URI.create(endpoint + "/catalog/" + catalog);
HttpRequest get = HttpRequest.builder()
.method("GET")
.endpoint(adminCatalogHref)
.endpoint(catalogAdminHref)
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
@ -74,7 +74,7 @@ public class AdminCatalogApiExpectTest extends VCloudDirectorAdminApiExpectTest
@Test
public void testGetCatalogHref() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, get, getResponse);
assertEquals(api.getCatalogApi().get(adminCatalogHref), catalog());
assertEquals(api.getCatalogApi().get(catalogAdminHref), catalog());
}
HttpRequest resolveCatalog = HttpRequest.builder()
@ -91,7 +91,7 @@ public class AdminCatalogApiExpectTest extends VCloudDirectorAdminApiExpectTest
.a("type", ENTITY)
.a("href", endpoint + "/entity/" + catalogUrn)
.e("Link").a("rel", "alternate").a("type", CATALOG).a("href", catalogHref.toString()).up()
.e("Link").a("rel", "alternate").a("type", ADMIN_CATALOG).a("href", adminCatalogHref.toString()).up());
.e("Link").a("rel", "alternate").a("type", ADMIN_CATALOG).a("href", catalogAdminHref.toString()).up());
HttpResponse resolveCatalogResponse = HttpResponse.builder()
.statusCode(200)
@ -107,11 +107,11 @@ public class AdminCatalogApiExpectTest extends VCloudDirectorAdminApiExpectTest
static String org = "7212e451-76e1-4631-b2de-asdasdasd";
static String orgUrn = "urn:vcloud:org:" + org;
static URI orgHref = URI.create(endpoint + "/org/" + org);
static URI adminOrgHref = URI.create(endpoint + "/admin/org/" + org);
static URI orgAdminHref = URI.create(endpoint + "/admin/org/" + org);
HttpRequest create = HttpRequest.builder()
.method("POST")
.endpoint(adminOrgHref + "/catalogs")
.endpoint(orgAdminHref + "/catalogs")
.addHeader("Accept", ADMIN_CATALOG)
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
@ -126,7 +126,7 @@ public class AdminCatalogApiExpectTest extends VCloudDirectorAdminApiExpectTest
@Test
public void testCreateCatalogHref() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, create, createResponse);
assertEquals(api.getCatalogApi().createCatalogInOrg(createCatalogInOrgSource(), adminOrgHref), createCatalogInOrg());
assertEquals(api.getCatalogApi().createCatalogInOrg(createCatalogInOrgSource(), orgAdminHref), createCatalogInOrg());
}
HttpRequest resolveOrg = HttpRequest.builder()
@ -143,7 +143,7 @@ public class AdminCatalogApiExpectTest extends VCloudDirectorAdminApiExpectTest
.a("type", ENTITY)
.a("href", endpoint + "/entity/" + catalogUrn)
.e("Link").a("rel", "alternate").a("type", ORG).a("href", orgHref.toString()).up()
.e("Link").a("rel", "alternate").a("type", ADMIN_ORG).a("href", adminOrgHref.toString()).up());
.e("Link").a("rel", "alternate").a("type", ADMIN_ORG).a("href", orgAdminHref.toString()).up());
HttpResponse resolveOrgResponse = HttpResponse.builder()
.statusCode(200)
@ -158,7 +158,7 @@ public class AdminCatalogApiExpectTest extends VCloudDirectorAdminApiExpectTest
HttpRequest update = HttpRequest.builder()
.method("PUT")
.endpoint(adminCatalogHref)
.endpoint(catalogAdminHref)
.addHeader("Accept", ADMIN_CATALOG)
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
@ -173,7 +173,7 @@ public class AdminCatalogApiExpectTest extends VCloudDirectorAdminApiExpectTest
@Test
public void testUpdateCatalogHref() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, update, updateResponse);
assertEquals(api.getCatalogApi().update(adminCatalogHref, updateCatalog()), updateCatalog());
assertEquals(api.getCatalogApi().update(catalogAdminHref, updateCatalog()), updateCatalog());
}
@Test
@ -184,7 +184,7 @@ public class AdminCatalogApiExpectTest extends VCloudDirectorAdminApiExpectTest
HttpRequest getOwner = HttpRequest.builder()
.method("GET")
.endpoint(adminCatalogHref + "/owner")
.endpoint(catalogAdminHref + "/owner")
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
@ -211,7 +211,7 @@ public class AdminCatalogApiExpectTest extends VCloudDirectorAdminApiExpectTest
@Test
public void testGetCatalogOwnerHref() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, getOwner, getOwnerResponse);
assertEquals(api.getCatalogApi().getOwner(adminCatalogHref), expectedGetOwner);
assertEquals(api.getCatalogApi().getOwner(catalogAdminHref), expectedGetOwner);
}
@Test
@ -222,7 +222,7 @@ public class AdminCatalogApiExpectTest extends VCloudDirectorAdminApiExpectTest
HttpRequest setOwner = HttpRequest.builder()
.method("PUT")
.endpoint(adminCatalogHref + "/owner")
.endpoint(catalogAdminHref + "/owner")
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
@ -245,7 +245,7 @@ public class AdminCatalogApiExpectTest extends VCloudDirectorAdminApiExpectTest
@Test
public void testSetCatalogOwnerHref() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, setOwner, setOwnerResponse);
api.getCatalogApi().setOwner(adminCatalogHref, ownerToSet);
api.getCatalogApi().setOwner(catalogAdminHref, ownerToSet);
}
@Test
@ -256,7 +256,7 @@ public class AdminCatalogApiExpectTest extends VCloudDirectorAdminApiExpectTest
HttpRequest publishCatalog = HttpRequest.builder()
.method("POST")
.endpoint(adminCatalogHref + "/action/publish")
.endpoint(catalogAdminHref + "/action/publish")
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
@ -271,7 +271,7 @@ public class AdminCatalogApiExpectTest extends VCloudDirectorAdminApiExpectTest
public void testPublishCatalogHref() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, publishCatalog,
publishCatalogResponse);
api.getCatalogApi().publish(adminCatalogHref, PublishCatalogParams.builder().isPublished(true).build());
api.getCatalogApi().publish(catalogAdminHref, PublishCatalogParams.builder().isPublished(true).build());
}
@Test
@ -284,7 +284,7 @@ public class AdminCatalogApiExpectTest extends VCloudDirectorAdminApiExpectTest
HttpRequest deleteCatalog = HttpRequest.builder()
.method("DELETE")
.endpoint(adminCatalogHref)
.endpoint(catalogAdminHref)
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
@ -298,7 +298,7 @@ public class AdminCatalogApiExpectTest extends VCloudDirectorAdminApiExpectTest
public void testDeleteCatalogHref() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, deleteCatalog,
deleteCatalogResponse);
api.getCatalogApi().delete(adminCatalogHref);
api.getCatalogApi().delete(catalogAdminHref);
}
@Test
@ -308,6 +308,8 @@ public class AdminCatalogApiExpectTest extends VCloudDirectorAdminApiExpectTest
api.getCatalogApi().delete(catalogUrn);
}
//TODO: tests for access control!
public static final AdminCatalog createCatalogInOrgSource() {
return AdminCatalog.builder()
.name("Test Catalog")

View File

@ -23,14 +23,13 @@ import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.N
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_DEL;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_EQ;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_UPDATABLE;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkControlAccessParams;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import java.net.URI;
import java.util.Collections;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.AdminCatalog;
import org.jclouds.vcloud.director.v1_5.domain.Checks;
import org.jclouds.vcloud.director.v1_5.domain.Link;
@ -38,9 +37,9 @@ import org.jclouds.vcloud.director.v1_5.domain.Owner;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.User;
import org.jclouds.vcloud.director.v1_5.domain.org.Org;
import org.jclouds.vcloud.director.v1_5.domain.params.ControlAccessParams;
import org.jclouds.vcloud.director.v1_5.domain.params.PublishCatalogParams;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorApiLiveTest;
import org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@ -75,7 +74,7 @@ public class AdminCatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@BeforeClass(alwaysRun = true)
protected void setupRequiredApis() {
catalogApi = adminContext.getApi().getCatalogApi();
org = context.getApi().getOrgApi().getOrg(Iterables.get(context.getApi().getOrgApi().getOrgList(), 0).getHref());
org = context.getApi().getOrgApi().get(Iterables.get(context.getApi().getOrgApi().list(), 0).getHref());
}
@AfterClass(alwaysRun = true)
@ -115,10 +114,8 @@ public class AdminCatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "PUT /admin/catalog/{id}/owner", dependsOnMethods = { "testGetCatalog" })
public void updateCatalogOwner() {
URI adminOrgHref = Iterables.find(context.getApi().resolveEntity(org.getId()).getLinks(),
LinkPredicates.typeEquals(VCloudDirectorMediaType.ADMIN_ORG)).getHref();
User newOwnerUser = randomTestUser("testUpdateCatalogOwner");
newOwnerUser = adminContext.getApi().getUserApi().createUser(adminOrgHref, newOwnerUser);
newOwnerUser = adminContext.getApi().getUserApi().createUserInOrg(newOwnerUser, org.getId());
assertNotNull(newOwnerUser, "failed to create temp user to test updateCatalogOwner");
Owner oldOwner = owner;
@ -131,12 +128,12 @@ public class AdminCatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
Checks.checkOwner(owner);
assertTrue(
equal(owner.toBuilder().links(Collections.<Link> emptySet()).build(),
newOwner.toBuilder().user(newOwner.getUser().toBuilder().id(null).build()).build()),
newOwner.toBuilder().user(newOwner.getUser()).build()),
String.format(OBJ_FIELD_UPDATABLE, CATALOG, "owner"));
} finally {
catalogApi.setOwner(catalog.getId(), oldOwner);
owner = catalogApi.getOwner(catalog.getId());
adminContext.getApi().getUserApi().deleteUser(newOwnerUser.getHref());
adminContext.getApi().getUserApi().delete(newOwnerUser.getHref());
}
}
@ -192,6 +189,27 @@ public class AdminCatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
String.format(OBJ_FIELD_EQ, CATALOG, "isPublished", true, catalog.isPublished()));
}
@Test(description = "GET /org/{id}/catalog/{catalogId}/controlAccess", dependsOnMethods = { "testCreateCatalog" })
public void testGetControlAccessControl() {
// Call the method being tested
ControlAccessParams params = catalogApi.getAccessControl(catalog.getId());
// Check params are well formed
checkControlAccessParams(params);
}
@Test(description = "POST /org/{id}/catalog/{catalogId}/action/controlAccess", dependsOnMethods = { "testCreateCatalog" })
public void testModifyAccessControl() {
// Setup params
ControlAccessParams params = catalogApi.getAccessControl(catalog.getId());
// Call the method being tested
ControlAccessParams modified = catalogApi.modifyAccessControl(catalog.getId(), params);
// Check params are well formed
checkControlAccessParams(modified);
}
@Test(description = "DELETE /admin/catalog/{id}", dependsOnMethods = { "testCreateCatalog" })
public void testDeleteCatalog() {
// assertEquals(catalog.getCatalogItems().getCatalogItems().size(), 0,
@ -205,4 +223,6 @@ public class AdminCatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
deleteCatalog = catalogApi.get(deleteCatalog.getId());
assertNull(deleteCatalog, String.format(OBJ_DEL, CATALOG, deleteCatalog != null ? deleteCatalog.toString() : ""));
}
}

View File

@ -18,129 +18,233 @@
*/
package org.jclouds.vcloud.director.v1_5.features.admin;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.ADMIN_NETWORK;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.ENTITY;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NETWORK;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.ORG;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.ORG_NETWORK;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.TASK;
import static org.testng.Assert.assertEquals;
import java.net.URI;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminApi;
import org.jclouds.vcloud.director.v1_5.domain.Link;
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.network.DhcpService;
import org.jclouds.vcloud.director.v1_5.domain.network.IpAddresses;
import org.jclouds.vcloud.director.v1_5.domain.network.IpRange;
import org.jclouds.vcloud.director.v1_5.domain.network.IpRanges;
import org.jclouds.vcloud.director.v1_5.domain.network.IpScope;
import org.jclouds.vcloud.director.v1_5.domain.network.Network.FenceMode;
import org.jclouds.vcloud.director.v1_5.domain.network.NetworkConfiguration;
import org.jclouds.vcloud.director.v1_5.domain.network.NetworkFeatures;
import org.jclouds.vcloud.director.v1_5.domain.network.SyslogServerSettings;
import org.jclouds.vcloud.director.v1_5.domain.org.OrgNetwork;
import org.jclouds.vcloud.director.v1_5.features.NetworkApiExpectTest;
import org.jclouds.vcloud.director.v1_5.internal.VCloudDirectorAdminApiExpectTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.common.net.HttpHeaders;
/**
* Test the {@link AdminNetworkApi} by observing its side effects.
*
* @author danikov
* @author danikov, Adrian Cole
*/
@Test(groups = { "unit", "admin" }, singleThreaded = true, testName = "AdminNetworkApiExpectTest")
public class AdminNetworkApiExpectTest extends VCloudDirectorAdminApiExpectTest {
Reference networkRef = Reference.builder()
.href(URI.create(endpoint+"/admin/network/b466c0c5-8a5c-4335-b703-a2e2e6b5f3e1"))
static String network = "55a677cf-ab3f-48ae-b880-fab90421980c";
static String networkUrn = "urn:vcloud:network:" + network;
static URI networkHref = URI.create(endpoint + "/network/" + network);
static URI networkAdminHref = URI.create(endpoint + "/admin/network/" + network);
HttpRequest get = HttpRequest.builder()
.method("GET")
.endpoint(networkAdminHref)
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.build();
HttpResponse getResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/network/network.xml", ORG + ";version=1.5"))
.build();
@Test
public void testGetNetworkWithOrgNetwork() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("GET", "/admin/network/b466c0c5-8a5c-4335-b703-a2e2e6b5f3e1")
.acceptAnyMedia()
.httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/network/admin/orgNetwork.xml", VCloudDirectorMediaType.ORG_NETWORK)
.httpResponseBuilder().build());
public void testGetNetworkHref() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, get, getResponse);
assertEquals(api.getNetworkApi().get(networkAdminHref), network());
}
OrgNetwork expected = orgNetwork();
HttpRequest resolveNetwork = HttpRequest.builder()
.method("GET")
.endpoint(endpoint + "/entity/" + networkUrn)
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.build();
assertEquals(api.getNetworkApi().getNetwork(networkRef.getHref()), expected);
String networkEntity = asString(createXMLBuilder("Entity").a("xmlns", "http://www.vmware.com/vcloud/v1.5")
.a("name", networkUrn)
.a("id", networkUrn)
.a("type", ENTITY)
.a("href", endpoint + "/entity/" + networkUrn)
.e("Link").a("rel", "alternate").a("type", NETWORK).a("href", networkHref.toString()).up()
.e("Link").a("rel", "alternate").a("type", ADMIN_NETWORK).a("href", networkAdminHref.toString()).up());
HttpResponse resolveNetworkResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromStringWithContentType(networkEntity, ENTITY + ";version=1.5"))
.build();
@Test
public void testGetNetworkUrn() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, resolveNetwork, resolveNetworkResponse, get, getResponse);
assertEquals(api.getNetworkApi().get(networkUrn), network());
}
HttpRequest update = HttpRequest.builder()
.method("PUT")
.endpoint(networkAdminHref )
.addHeader("Accept", TASK)
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.payload(payloadFromResourceWithContentType("/network/admin/updateNetworkSource.xml", ORG_NETWORK))
.build();
HttpResponse updateResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/network/admin/updateNetworkTask.xml", TASK))
.build();
@Test
public void testUpdateNetworkHref() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, update, updateResponse);
assertEquals(api.getNetworkApi().update(networkAdminHref, updateNetwork()), updateNetworkTask());
}
@Test
public void testUpdateNetwork() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("PUT", "/admin/network/b466c0c5-8a5c-4335-b703-a2e2e6b5f3e1")
.xmlFilePayload("/network/admin/updateNetworkSource.xml", VCloudDirectorMediaType.ORG_NETWORK)
.acceptMedia(VCloudDirectorMediaType.TASK)
.httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/network/admin/updateNetworkTask.xml", VCloudDirectorMediaType.TASK)
.httpResponseBuilder().build());
Task expected = updateNetworkTask();
assertEquals(api.getNetworkApi().updateNetwork(networkRef.getHref(), updateNetwork()), expected);
public void testUpdateNetworkUrn() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, resolveNetwork, resolveNetworkResponse, update, updateResponse);
assertEquals(api.getNetworkApi().update(networkUrn, updateNetwork()), updateNetworkTask());
}
@Test(enabled = false)
public void testResetNetwork() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("POST", "/admin/network/b466c0c5-8a5c-4335-b703-a2e2e6b5f3e1/action/reset")
.acceptMedia(VCloudDirectorMediaType.TASK)
.httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/network/admin/resetNetworkTask.xml", VCloudDirectorMediaType.TASK)
.httpResponseBuilder().build());
HttpRequest reset = HttpRequest.builder()
.method("POST")
.endpoint(networkAdminHref + "/action/reset")
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.build();
Task expected = resetNetworkTask();
HttpResponse resetResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/network/admin/resetNetworkTask.xml", TASK))
.build();
assertEquals(api.getNetworkApi().resetNetwork(networkRef.getHref()), expected);
@Test
public void testResetNetworkHref() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, reset, resetResponse);
assertEquals(api.getNetworkApi().reset(networkAdminHref), resetNetworkTask());
}
public final OrgNetwork orgNetwork() {
return NetworkApiExpectTest.orgNetwork().toBuilder()
.href(toAdminUri(NetworkApiExpectTest.orgNetwork().getHref()))
.links(ImmutableSet.of(
Link.builder()
.rel("alternate")
@Test
public void testResetNetworkUrn() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, resolveNetwork, resolveNetworkResponse, reset, resetResponse);
assertEquals(api.getNetworkApi().reset(networkUrn), resetNetworkTask());
}
public static OrgNetwork network() {
return OrgNetwork.builder()
.name("ilsolation01-Jclouds")
.id("urn:vcloud:network:f3ba8256-6f48-4512-aad6-600e85b4dc38")
.type("application/vnd.vmware.vcloud.orgNetwork+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/network/f3ba8256-6f48-4512-aad6-600e85b4dc38"))
.build(),
Link.builder()
.rel("edit")
.type("application/vnd.vmware.admin.orgNetwork+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/network/f3ba8256-6f48-4512-aad6-600e85b4dc38"))
.build(),
Link.builder()
.link(Link.builder()
.rel("up")
.type("application/vnd.vmware.admin.organization+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.build(),
Link.builder()
.rel("repair")
.type("application/vnd.vmware.admin.orgNetwork+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/network/f3ba8256-6f48-4512-aad6-600e85b4dc38/action/reset"))
.build(),
Link.builder()
.type("application/vnd.vmware.vcloud.org+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.build())
.link(Link.builder()
.rel("down")
.type("application/vnd.vmware.vcloud.metadata+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/network/f3ba8256-6f48-4512-aad6-600e85b4dc38/metadata"))
.build()))
.networkPool(Reference.builder()
.type("application/vnd.vmware.admin.networkPool+xml")
.name("vcdni01")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/extension/networkPool/e86bfdb5-b3e0-4ece-9125-e764ac64c95c"))
.href(URI.create("https://vcloudbeta.bluelock.com/api/network/f3ba8256-6f48-4512-aad6-600e85b4dc38/metadata"))
.build())
.description("")
.configuration(NetworkConfiguration.builder()
.ipScope(IpScope.builder()
.isInherited(false)
.gateway("192.168.1.1")
.netmask("255.255.255.0")
.dns1("173.240.111.52")
.dns2("173.240.111.53")
.ipRanges(IpRanges.builder()
.ipRange(IpRange.builder()
.startAddress("192.168.1.100")
.endAddress("192.168.1.199")
.build())
.build())
.build())
.fenceMode(FenceMode.ISOLATED)
.retainNetInfoAcrossDeployments(false)
.features(NetworkFeatures.builder()
.service(DhcpService.builder()
.enabled(false)
.defaultLeaseTime(3600)
.maxLeaseTime(7200)
.ipRange(IpRange.builder()
.startAddress("192.168.1.2")
.endAddress("192.168.1.99")
.build())
.build())
.build())
.syslogServerSettings(SyslogServerSettings.builder().build())
.build())
.allowedExternalIpAddresses(IpAddresses.builder().build())
.build();
}
public final OrgNetwork updateNetwork() {
return orgNetwork().toBuilder()
return network().toBuilder()
.build();
}
public final Task resetNetworkTask() {
return Task.builder()
.status("running")
.startTime(dateService.iso8601DateParse("2012-03-14T12:39:23.720-04:00"))
.operationName("networkResetNetwork")
.operation("Resetting Network ilsolation01-Jclouds(f3ba8256-6f48-4512-aad6-600e85b4dc38)")
.expiryTime(dateService.iso8601DateParse("2012-06-12T12:39:23.720-04:00"))
.name("task")
.id("urn:vcloud:task:49d2e180-7921-4902-ac39-b4ff5406bb94")
.type("application/vnd.vmware.vcloud.task+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/task/49d2e180-7921-4902-ac39-b4ff5406bb94"))
.link(Link.builder()
.rel("task:cancel")
.href(URI.create("https://vcloudbeta.bluelock.com/api/task/49d2e180-7921-4902-ac39-b4ff5406bb94/action/cancel"))
.build())
.owner(Reference.builder()
.type("application/vnd.vmware.vcloud.network+xml")
.name("ilsolation01-Jclouds")
.href(URI.create("https://vcloudbeta.bluelock.com/api/network/f3ba8256-6f48-4512-aad6-600e85b4dc38"))
.build())
.user(Reference.builder()
.type("application/vnd.vmware.admin.user+xml")
.name("dan@cloudsoftcorp.com")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/ae75edd2-12de-414c-8e85-e6ea10442c08"))
.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();
}

View File

@ -20,18 +20,15 @@ package org.jclouds.vcloud.director.v1_5.features.admin;
import static com.google.common.base.Objects.equal;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_UPDATABLE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.REF_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.REQUIRED_VALUE_OBJECT_FMT;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.TASK_COMPLETE_TIMELY;
import static org.testng.Assert.assertNotNull;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.URN_REQ_LIVE;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import java.util.Collections;
import org.jclouds.vcloud.director.v1_5.domain.Checks;
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.network.ExternalNetwork;
import org.jclouds.vcloud.director.v1_5.domain.network.IpScope;
@ -60,24 +57,19 @@ public class AdminNetworkApiLiveTest extends BaseVCloudDirectorApiLiveTest {
*/
private AdminNetworkApi networkApi;
/*
* Shared state between dependant tests.
*/
Reference networkRef;
Network network;
private Network network;
@Override
@BeforeClass(alwaysRun = true)
protected void setupRequiredApis() {
networkApi = adminContext.getApi().getNetworkApi();
networkRef = Reference.builder().href(networkURI).build().toAdminReference(endpoint);
}
@Test(description = "GET /admin/network/{id}")
public void testGetNetwork() {
//TODO: test both org and external networks
assertNotNull(networkRef, String.format(OBJ_REQ_LIVE, NETWORK));
network = networkApi.getNetwork(networkRef.getHref());
network = lazyGetNetwork();
if(network instanceof ExternalNetwork) {
Checks.checkExternalNetwork(Network.<ExternalNetwork>toSubType(network));
@ -93,7 +85,7 @@ public class AdminNetworkApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "PUT /admin/network/{id}" )
public void testUpdateNetwork() {
//TODO: ensure network instanceof OrgNetwork, may require queries
assertTrue(network instanceof OrgNetwork, String.format(REF_REQ_LIVE, "OrgNetwork"));
assertTrue(network instanceof OrgNetwork, String.format(URN_REQ_LIVE, "OrgNetwork"));
OrgNetwork oldNetwork = Network.<OrgNetwork>toSubType(network)
.toBuilder()
@ -103,10 +95,10 @@ public class AdminNetworkApiLiveTest extends BaseVCloudDirectorApiLiveTest {
OrgNetwork updateNetwork = getMutatedOrgNetwork(oldNetwork);
try {
Task updateNetworkTask = networkApi.updateNetwork(network.getHref(), updateNetwork);
Task updateNetworkTask = networkApi.update(networkUrn, updateNetwork);
Checks.checkTask(updateNetworkTask);
assertTrue(retryTaskSuccess.apply(updateNetworkTask), String.format(TASK_COMPLETE_TIMELY, "updateNetworkTask"));
network = networkApi.getNetwork(network.getHref());
network = networkApi.get(networkUrn);
Checks.checkOrgNetwork(Network.<OrgNetwork>toSubType(network));
@ -140,20 +132,20 @@ public class AdminNetworkApiLiveTest extends BaseVCloudDirectorApiLiveTest {
// updateNetwork.getAllowedExternalIpAddresses()),
// String.format(OBJ_FIELD_UPDATABLE, NETWORK, "allowedExternalIpAddresses"));
} finally {
Task updateNetworkTask = networkApi.updateNetwork(network.getHref(), oldNetwork);
Task updateNetworkTask = networkApi.update(networkUrn, oldNetwork);
Checks.checkTask(updateNetworkTask);
assertTrue(retryTaskSuccess.apply(updateNetworkTask), String.format(TASK_COMPLETE_TIMELY, "updateNetworkTask"));
network = networkApi.getNetwork(network.getHref());
network = networkApi.get(networkUrn);
}
}
@Test(description = "POST /admin/network/{id}/action/reset")
public void testResetNetwork() {
// TODO assert that network is deployed somehow
Task resetNetworkTask = networkApi.resetNetwork(networkRef.getHref());
Task resetNetworkTask = networkApi.reset(networkUrn);
Checks.checkTask(resetNetworkTask);
assertTrue(retryTaskSuccess.apply(resetNetworkTask), String.format(TASK_COMPLETE_TIMELY, "resetNetworkTask"));
network = networkApi.getNetwork(network.getHref());
network = networkApi.get(networkUrn);
Checks.checkOrgNetwork(Network.<OrgNetwork>toSubType(network));
// TODO: other assertions about the reset? that network is deployed when task is complete, for example

View File

@ -39,7 +39,8 @@ import org.jclouds.vcloud.director.v1_5.internal.VCloudDirectorAdminApiExpectTes
import org.testng.annotations.Test;
/**
* Test the {@link AdminOrgApi} by observing its side effects.
* Test the {@link AdminOrgApi} by observing its side effects. TODO: this needs to be rewritten to
* test both URN and href access
*
* @author danikov
*/
@ -47,72 +48,77 @@ import org.testng.annotations.Test;
public class AdminOrgApiExpectTest extends VCloudDirectorAdminApiExpectTest {
private Reference orgRef = Reference.builder()
.href(URI.create(endpoint + "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.build();
.href(URI.create(endpoint + "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")).build();
@Test
public void testGetOrg() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("GET", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")
.acceptAnyMedia()
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, new VcloudHttpRequestPrimer()
.apiCommand("GET", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0").acceptAnyMedia()
.httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/org/admin/org.xml",
VCloudDirectorMediaType.ADMIN_ORG)
new VcloudHttpResponsePrimer().xmlFilePayload("/org/admin/org.xml", VCloudDirectorMediaType.ADMIN_ORG)
.httpResponseBuilder().build());
AdminOrg expected = adminOrg();
assertEquals(api.getOrgApi().getOrg(orgRef.getHref()), expected);
assertEquals(api.getOrgApi().get(orgRef.getHref()), expected);
}
public static final AdminOrg adminOrg() {
return AdminOrg.builder()
return AdminOrg
.builder()
.name("JClouds")
.id("urn:vcloud:org:6f312e42-cd2b-488d-a2bb-97519cd57ed0")
.type("application/vnd.vmware.admin.organization+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.link(Link.builder()
.link(Link
.builder()
.rel("down")
.type("application/vnd.vmware.vcloud.tasksList+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/tasksList/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.build())
.link(Link.builder()
.link(Link
.builder()
.rel("down")
.type("application/vnd.vmware.vcloud.metadata+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata"))
.build())
.link(Link.builder()
.link(Link
.builder()
.rel("add")
.type("application/vnd.vmware.admin.catalog+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/catalogs"))
.build())
.link(Link.builder()
.link(Link
.builder()
.rel("add")
.type("application/vnd.vmware.admin.user+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/users"))
.build())
.link(Link.builder()
.link(Link
.builder()
.rel("add")
.type("application/vnd.vmware.admin.group+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/groups"))
.build())
.link(Link.builder()
.link(Link
.builder()
.rel("add")
.type("application/vnd.vmware.admin.orgNetwork+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/networks"))
.build())
.link(Link.builder()
.link(Link
.builder()
.rel("edit")
.type("application/vnd.vmware.admin.organization+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.build())
.link(Link.builder()
.link(Link
.builder()
.rel("remove")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.build())
.link(Link.builder()
.link(Link
.builder()
.rel("alternate")
.type("application/vnd.vmware.vcloud.org+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
@ -121,79 +127,90 @@ public class AdminOrgApiExpectTest extends VCloudDirectorAdminApiExpectTest {
.fullName("JClouds")
.isEnabled(true)
.settings(settings())
.user(Reference.builder()
.user(Reference
.builder()
.type("application/vnd.vmware.admin.user+xml")
.name("adam.lowe@cloudsoftcorp.com")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/672ebb67-d8ff-4201-9c1b-c1be869e526c"))
.build())
.user(Reference.builder()
.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())
.user(Reference.builder()
.user(Reference
.builder()
.type("application/vnd.vmware.admin.user+xml")
.name("qunying.huang@enstratus.com")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/967d317c-4273-4a95-b8a4-bf63b78e9c69"))
.build())
.user(Reference.builder()
.user(Reference
.builder()
.type("application/vnd.vmware.admin.user+xml")
.name("dan@cloudsoftcorp.com")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/ae75edd2-12de-414c-8e85-e6ea10442c08"))
.build())
.user(Reference.builder()
.user(Reference
.builder()
.type("application/vnd.vmware.admin.user+xml")
.name("adk@cloudsoftcorp.com")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/e9eb1b29-0404-4c5e-8ef7-e584acc51da9"))
.build())
.catalog(Reference.builder()
.catalog(Reference
.builder()
.type("application/vnd.vmware.admin.catalog+xml")
.name("QunyingTestCatalog")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4"))
.build())
.catalog(Reference.builder()
.catalog(Reference
.builder()
.type("application/vnd.vmware.admin.catalog+xml")
.name("Public")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c"))
.build())
.catalog(Reference.builder()
.catalog(Reference
.builder()
.type("application/vnd.vmware.admin.catalog+xml")
.name("dantest")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/catalog/b542aff4-9f97-4f51-a126-4330fbf62f02"))
.build())
.catalog(Reference.builder()
.catalog(Reference
.builder()
.type("application/vnd.vmware.admin.catalog+xml")
.name("test")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/catalog/b7289d54-4ca4-497f-9a93-2d4afc97e3da"))
.build())
.vdc(Reference.builder()
.vdc(Reference
.builder()
.type("application/vnd.vmware.vcloud.vdc+xml")
.name("Cluster01-JClouds")
.href(URI.create("https://vcloudbeta.bluelock.com/api/vdc/d16d333b-e3c0-4176-845d-a5ee6392df07"))
.build())
.network(Reference.builder()
.network(Reference
.builder()
.type("application/vnd.vmware.admin.network+xml")
.name("ilsolation01-Jclouds")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/network/f3ba8256-6f48-4512-aad6-600e85b4dc38"))
.build())
.network(Reference.builder()
.network(Reference
.builder()
.type("application/vnd.vmware.admin.network+xml")
.name("internet01-Jclouds")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/network/55a677cf-ab3f-48ae-b880-fab90421980c"))
.build())
.build();
.build()).build();
}
@Test(enabled = false)
public void testGetSettings() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse,
VCloudDirectorAdminApi api = requestsSendResponses(
loginRequest,
sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("GET", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/")
.acceptAnyMedia()
.httpRequestBuilder().build(),
.acceptAnyMedia().httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/org/admin/settings.xml",
VCloudDirectorMediaType.ORG_SETTINGS)
.xmlFilePayload("/org/admin/settings.xml", VCloudDirectorMediaType.ORG_SETTINGS)
.httpResponseBuilder().build());
OrgSettings expected = settings();
@ -203,16 +220,15 @@ public class AdminOrgApiExpectTest extends VCloudDirectorAdminApiExpectTest {
@Test(enabled = false)
public void testUpdateSettings() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse,
VCloudDirectorAdminApi api = requestsSendResponses(
loginRequest,
sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("PUT", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/")
.xmlFilePayload("/org/admin/updateSettingsSource.xml",
VCloudDirectorMediaType.ORG_SETTINGS)
.acceptMedia(VCloudDirectorMediaType.ORG_SETTINGS)
.httpRequestBuilder().build(),
.xmlFilePayload("/org/admin/updateSettingsSource.xml", VCloudDirectorMediaType.ORG_SETTINGS)
.acceptMedia(VCloudDirectorMediaType.ORG_SETTINGS).httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/org/admin/updateSettings.xml",
VCloudDirectorMediaType.ORG_SETTINGS)
.xmlFilePayload("/org/admin/updateSettings.xml", VCloudDirectorMediaType.ORG_SETTINGS)
.httpResponseBuilder().build());
OrgSettings expected = updateSettings();
@ -222,14 +238,14 @@ public class AdminOrgApiExpectTest extends VCloudDirectorAdminApiExpectTest {
@Test
public void testGetEmailSettings() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse,
VCloudDirectorAdminApi api = requestsSendResponses(
loginRequest,
sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("GET", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/email")
.acceptAnyMedia()
.httpRequestBuilder().build(),
.acceptAnyMedia().httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/org/admin/emailSettings.xml",
VCloudDirectorMediaType.ORG_GENERAL_SETTINGS)
.xmlFilePayload("/org/admin/emailSettings.xml", VCloudDirectorMediaType.ORG_GENERAL_SETTINGS)
.httpResponseBuilder().build());
OrgEmailSettings expected = emailSettings();
@ -239,17 +255,17 @@ public class AdminOrgApiExpectTest extends VCloudDirectorAdminApiExpectTest {
@Test
public void testUpdateEmailSettings() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse,
VCloudDirectorAdminApi api = requestsSendResponses(
loginRequest,
sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("PUT", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/email")
.xmlFilePayload("/org/admin/updateEmailSettingsSource.xml",
VCloudDirectorMediaType.ORG_EMAIL_SETTINGS)
.acceptMedia(VCloudDirectorMediaType.ORG_EMAIL_SETTINGS)
.httpRequestBuilder().build(),
.acceptMedia(VCloudDirectorMediaType.ORG_EMAIL_SETTINGS).httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/org/admin/updateEmailSettings.xml",
VCloudDirectorMediaType.ORG_EMAIL_SETTINGS)
.httpResponseBuilder().build());
VCloudDirectorMediaType.ORG_EMAIL_SETTINGS).httpResponseBuilder().build());
OrgEmailSettings expected = updateEmailSettings();
@ -258,14 +274,14 @@ public class AdminOrgApiExpectTest extends VCloudDirectorAdminApiExpectTest {
@Test(enabled = false)
public void testGetGeneralSettings() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse,
VCloudDirectorAdminApi api = requestsSendResponses(
loginRequest,
sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("GET", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/general")
.acceptAnyMedia()
.httpRequestBuilder().build(),
.acceptAnyMedia().httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/org/admin/generalSettings.xml",
VCloudDirectorMediaType.ORG_GENERAL_SETTINGS)
.xmlFilePayload("/org/admin/generalSettings.xml", VCloudDirectorMediaType.ORG_GENERAL_SETTINGS)
.httpResponseBuilder().build());
OrgGeneralSettings expected = generalSettings();
@ -274,35 +290,32 @@ public class AdminOrgApiExpectTest extends VCloudDirectorAdminApiExpectTest {
}
public static final OrgGeneralSettings generalSettings() {
return OrgGeneralSettings.builder()
return OrgGeneralSettings
.builder()
.type("application/vnd.vmware.admin.organizationGeneralSettings+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/general"))
.link(Link.builder()
.link(Link
.builder()
.rel("edit")
.type("application/vnd.vmware.admin.organizationGeneralSettings+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/general"))
.build())
.canPublishCatalogs(false)
.deployedVMQuota(0)
.storedVmQuota(0)
.useServerBootSequence(false)
.delayAfterPowerOnSeconds(0)
.build();
.build()).canPublishCatalogs(false).deployedVMQuota(0).storedVmQuota(0)
.useServerBootSequence(false).delayAfterPowerOnSeconds(0).build();
}
@Test(enabled = false)
public void testUpdateGeneralSettings() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse,
VCloudDirectorAdminApi api = requestsSendResponses(
loginRequest,
sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("PUT", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/general")
.xmlFilePayload("/org/admin/updateGeneralSettingsSource.xml",
VCloudDirectorMediaType.ORG_GENERAL_SETTINGS)
.acceptMedia(VCloudDirectorMediaType.ORG_GENERAL_SETTINGS)
.httpRequestBuilder().build(),
.acceptMedia(VCloudDirectorMediaType.ORG_GENERAL_SETTINGS).httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/org/admin/updateGeneralSettings.xml",
VCloudDirectorMediaType.ORG_GENERAL_SETTINGS)
.httpResponseBuilder().build());
VCloudDirectorMediaType.ORG_GENERAL_SETTINGS).httpResponseBuilder().build());
OrgGeneralSettings expected = updateGeneralSettings();
@ -317,14 +330,14 @@ public class AdminOrgApiExpectTest extends VCloudDirectorAdminApiExpectTest {
@Test
public void testGetLdapSettings() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse,
VCloudDirectorAdminApi api = requestsSendResponses(
loginRequest,
sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("GET", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/ldap")
.acceptAnyMedia()
.httpRequestBuilder().build(),
.acceptAnyMedia().httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/org/admin/ldapSettings.xml",
VCloudDirectorMediaType.ORG_LDAP_SETTINGS)
.xmlFilePayload("/org/admin/ldapSettings.xml", VCloudDirectorMediaType.ORG_LDAP_SETTINGS)
.httpResponseBuilder().build());
OrgLdapSettings expected = ldapSettings();
@ -333,24 +346,24 @@ public class AdminOrgApiExpectTest extends VCloudDirectorAdminApiExpectTest {
}
public static final OrgLdapSettings ldapSettings() {
return OrgLdapSettings.builder()
return OrgLdapSettings
.builder()
.type("application/vnd.vmware.admin.organizationLdapSettings+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/ldap"))
.ldapMode("NONE")
.build();
.ldapMode("NONE").build();
}
@Test
public void testGetPasswordPolicy() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse,
VCloudDirectorAdminApi api = requestsSendResponses(
loginRequest,
sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("GET", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/passwordPolicy")
.acceptAnyMedia()
.httpRequestBuilder().build(),
.acceptAnyMedia().httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/org/admin/passwordPolicy.xml",
VCloudDirectorMediaType.ORG_PASSWORD_POLICY_SETTINGS)
.httpResponseBuilder().build());
VCloudDirectorMediaType.ORG_PASSWORD_POLICY_SETTINGS).httpResponseBuilder().build());
OrgPasswordPolicySettings expected = passwordPolicy();
@ -358,33 +371,32 @@ public class AdminOrgApiExpectTest extends VCloudDirectorAdminApiExpectTest {
}
public static final OrgPasswordPolicySettings passwordPolicy() {
return OrgPasswordPolicySettings.builder()
return OrgPasswordPolicySettings
.builder()
.type("application/vnd.vmware.admin.organizationPasswordPolicySettings+xml")
.link(Link.builder()
.link(Link
.builder()
.rel("edit")
.type("application/vnd.vmware.admin.organizationPasswordPolicySettings+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/passwordPolicy"))
.build())
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/passwordPolicy"))
.accountLockoutEnabled(false)
.invalidLoginsBeforeLockout(5)
.accountLockoutIntervalMinutes(10)
.build();
.accountLockoutEnabled(false).invalidLoginsBeforeLockout(5).accountLockoutIntervalMinutes(10).build();
}
@Test
public void testUpdatePasswordPolicy() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse,
VCloudDirectorAdminApi api = requestsSendResponses(
loginRequest,
sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("PUT", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/passwordPolicy")
.xmlFilePayload("/org/admin/updatePasswordPolicySource.xml",
VCloudDirectorMediaType.ORG_PASSWORD_POLICY_SETTINGS)
.acceptMedia(VCloudDirectorMediaType.ORG_PASSWORD_POLICY_SETTINGS)
.httpRequestBuilder().build(),
.acceptMedia(VCloudDirectorMediaType.ORG_PASSWORD_POLICY_SETTINGS).httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/org/admin/updatePasswordPolicy.xml",
VCloudDirectorMediaType.ORG_PASSWORD_POLICY_SETTINGS)
.httpResponseBuilder().build());
VCloudDirectorMediaType.ORG_PASSWORD_POLICY_SETTINGS).httpResponseBuilder().build());
OrgPasswordPolicySettings expected = updateOrgPasswordPolicy();
@ -392,23 +404,20 @@ public class AdminOrgApiExpectTest extends VCloudDirectorAdminApiExpectTest {
}
public static final OrgPasswordPolicySettings updateOrgPasswordPolicy() {
return passwordPolicy().toBuilder()
.accountLockoutEnabled(true)
.invalidLoginsBeforeLockout(6)
.accountLockoutIntervalMinutes(11)
.build();
return passwordPolicy().toBuilder().accountLockoutEnabled(true).invalidLoginsBeforeLockout(6)
.accountLockoutIntervalMinutes(11).build();
}
@Test(enabled = false)
public void testGetVAppLeaseSettings() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse,
VCloudDirectorAdminApi api = requestsSendResponses(
loginRequest,
sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("GET", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/vAppLeaseSettings")
.acceptAnyMedia()
.httpRequestBuilder().build(),
.acceptAnyMedia().httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/org/admin/vAppLeaseSettings.xml",
VCloudDirectorMediaType.ORG_LEASE_SETTINGS)
.xmlFilePayload("/org/admin/vAppLeaseSettings.xml", VCloudDirectorMediaType.ORG_LEASE_SETTINGS)
.httpResponseBuilder().build());
OrgLeaseSettings expected = vAppLeaseSettings();
@ -417,33 +426,32 @@ public class AdminOrgApiExpectTest extends VCloudDirectorAdminApiExpectTest {
}
public static final OrgLeaseSettings vAppLeaseSettings() {
return OrgLeaseSettings.builder()
return OrgLeaseSettings
.builder()
.type("application/vnd.vmware.admin.vAppLeaseSettings+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/vAppLeaseSettings"))
.link(Link.builder()
.link(Link
.builder()
.rel("edit")
.type("application/vnd.vmware.admin.vAppLeaseSettings+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/vAppLeaseSettings"))
.build())
.deleteOnStorageLeaseExpiration(false)
.deploymentLeaseSeconds(0)
.storageLeaseSeconds(0)
.build();
.build()).deleteOnStorageLeaseExpiration(false).deploymentLeaseSeconds(0)
.storageLeaseSeconds(0).build();
}
@Test(enabled = false)
public void testUpdateOrgVAppLeaseSettings() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse,
VCloudDirectorAdminApi api = requestsSendResponses(
loginRequest,
sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("PUT", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/vAppLeaseSettings")
.xmlFilePayload("/org/admin/updateVAppLeaseSettingsSource.xml",
VCloudDirectorMediaType.ORG_LEASE_SETTINGS)
.acceptMedia(VCloudDirectorMediaType.ORG_LEASE_SETTINGS)
.httpRequestBuilder().build(),
.acceptMedia(VCloudDirectorMediaType.ORG_LEASE_SETTINGS).httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/org/admin/updateVAppLeaseSettings.xml",
VCloudDirectorMediaType.ORG_LEASE_SETTINGS)
.httpResponseBuilder().build());
VCloudDirectorMediaType.ORG_LEASE_SETTINGS).httpResponseBuilder().build());
OrgLeaseSettings expected = updateVAppLeaseSettings();
@ -458,15 +466,17 @@ public class AdminOrgApiExpectTest extends VCloudDirectorAdminApiExpectTest {
@Test(enabled = false)
public void testGetVAppTemplateLeaseSettings() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse,
VCloudDirectorAdminApi api = requestsSendResponses(
loginRequest,
sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("GET", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/vAppTemplateLeaseSettings")
.acceptAnyMedia()
.httpRequestBuilder().build(),
.apiCommand("GET",
"/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/vAppTemplateLeaseSettings")
.acceptAnyMedia().httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/org/admin/vAppTemplateLeaseSettings.xml",
VCloudDirectorMediaType.ORG_VAPP_TEMPLATE_LEASE_SETTINGS)
.httpResponseBuilder().build());
VCloudDirectorMediaType.ORG_VAPP_TEMPLATE_LEASE_SETTINGS).httpResponseBuilder()
.build());
OrgVAppTemplateLeaseSettings expected = vAppTemplateLeaseSettings();
@ -474,32 +484,34 @@ public class AdminOrgApiExpectTest extends VCloudDirectorAdminApiExpectTest {
}
public static final OrgVAppTemplateLeaseSettings vAppTemplateLeaseSettings() {
return OrgVAppTemplateLeaseSettings.builder()
return OrgVAppTemplateLeaseSettings
.builder()
.type("application/vnd.vmware.admin.vAppTemplateLeaseSettings+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/vAppTemplateLeaseSettings"))
.link(Link.builder()
.link(Link
.builder()
.rel("edit")
.type("application/vnd.vmware.admin.vAppTemplateLeaseSettings+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/vAppTemplateLeaseSettings"))
.build())
.deleteOnStorageLeaseExpiration(false)
.storageLeaseSeconds(0)
.build();
.build()).deleteOnStorageLeaseExpiration(false).storageLeaseSeconds(0).build();
}
@Test(enabled = false)
public void testUpdateOrgVAppTemplateLeaseSettings() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse,
VCloudDirectorAdminApi api = requestsSendResponses(
loginRequest,
sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("PUT", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/vAppTemplateLeaseSettings")
.apiCommand("PUT",
"/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/vAppTemplateLeaseSettings")
.xmlFilePayload("/org/admin/updateVAppLeaseSettingsSource.xml",
VCloudDirectorMediaType.ORG_VAPP_TEMPLATE_LEASE_SETTINGS)
.acceptMedia(VCloudDirectorMediaType.ORG_VAPP_TEMPLATE_LEASE_SETTINGS)
.httpRequestBuilder().build(),
.acceptMedia(VCloudDirectorMediaType.ORG_VAPP_TEMPLATE_LEASE_SETTINGS).httpRequestBuilder()
.build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/org/admin/updateVAppLeaseSettings.xml",
VCloudDirectorMediaType.ORG_VAPP_TEMPLATE_LEASE_SETTINGS)
.httpResponseBuilder().build());
VCloudDirectorMediaType.ORG_VAPP_TEMPLATE_LEASE_SETTINGS).httpResponseBuilder()
.build());
OrgVAppTemplateLeaseSettings expected = updateVAppTemplateLeaseSettings();
@ -513,64 +525,68 @@ public class AdminOrgApiExpectTest extends VCloudDirectorAdminApiExpectTest {
}
public static final OrgSettings settings() {
return OrgSettings.builder()
return OrgSettings
.builder()
.type("application/vnd.vmware.admin.orgSettings+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings"))
.link(Link.builder()
.link(Link
.builder()
.rel("down")
.type("application/vnd.vmware.admin.vAppTemplateLeaseSettings+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/vAppTemplateLeaseSettings"))
.build())
.link(Link.builder()
.link(Link
.builder()
.rel("down")
.type("application/vnd.vmware.admin.organizationEmailSettings+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/email"))
.build())
.link(Link.builder()
.link(Link
.builder()
.rel("down")
.type("application/vnd.vmware.admin.vAppLeaseSettings+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/vAppLeaseSettings"))
.build())
.link(Link.builder()
.link(Link
.builder()
.rel("down")
.type("application/vnd.vmware.admin.organizationPasswordPolicySettings+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/passwordPolicy"))
.build())
.link(Link.builder()
.link(Link
.builder()
.rel("down")
.type("application/vnd.vmware.admin.organizationGeneralSettings+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/general"))
.build())
.link(Link.builder()
.link(Link
.builder()
.rel("down")
.type("application/vnd.vmware.admin.organizationLdapSettings+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/ldap"))
.build())
.link(Link.builder()
.link(Link
.builder()
.rel("edit")
.type("application/vnd.vmware.admin.orgSettings+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings"))
.build())
.generalSettings(generalSettings())
.vAppLeaseSettings(vAppLeaseSettings())
.vAppTemplateLeaseSettings(vAppTemplateLeaseSettings())
.ldapSettings(ldapSettings())
.emailSettings(emailSettings())
.passwordPolicy(passwordPolicy())
.build();
.build()).generalSettings(generalSettings()).vAppLeaseSettings(vAppLeaseSettings())
.vAppTemplateLeaseSettings(vAppTemplateLeaseSettings()).ldapSettings(ldapSettings())
.emailSettings(emailSettings()).passwordPolicy(passwordPolicy()).build();
}
@Test
public static final OrgSettings updateSettings() {
return settings().toBuilder()
.build();
return settings().toBuilder().build();
}
public static final OrgEmailSettings emailSettings() {
return OrgEmailSettings.builder()
return OrgEmailSettings
.builder()
.type("application/vnd.vmware.admin.organizationEmailSettings+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/email"))
.link(Link.builder()
.link(Link
.builder()
.rel("edit")
.type("application/vnd.vmware.admin.organizationEmailSettings+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/email"))
@ -580,29 +596,23 @@ public class AdminOrgApiExpectTest extends VCloudDirectorAdminApiExpectTest {
.fromEmailAddress("")
.defaultSubjectPrefix("")
.isAlertEmailToAllAdmins(true)
.smtpServerSettings(SmtpServerSettings.builder()
.useAuthentication(false)
.host("")
.username("")
.password("")
.build())
.build();
.smtpServerSettings(
SmtpServerSettings.builder().useAuthentication(false).host("").username("").password("")
.build()).build();
}
@Test
public static final OrgEmailSettings updateEmailSettings() {
return emailSettings().toBuilder()
return emailSettings()
.toBuilder()
.isDefaultSmtpServer(false)
.isDefaultOrgEmail(false)
.fromEmailAddress("test@test.com")
.defaultSubjectPrefix("new")
.isAlertEmailToAllAdmins(false)
.smtpServerSettings(emailSettings().getSmtpServerSettings().toBuilder()
.useAuthentication(true)
.host("new")
.username("new")
.build())
.build();
.smtpServerSettings(
emailSettings().getSmtpServerSettings().toBuilder().useAuthentication(true).host("new")
.username("new").build()).build();
}
}

View File

@ -20,12 +20,9 @@ package org.jclouds.vcloud.director.v1_5.features.admin;
import static com.google.common.base.Objects.equal;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_UPDATABLE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.REF_REQ_LIVE;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import org.jclouds.vcloud.director.v1_5.domain.Checks;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.network.SmtpServerSettings;
import org.jclouds.vcloud.director.v1_5.domain.org.AdminOrg;
import org.jclouds.vcloud.director.v1_5.domain.org.OrgEmailSettings;
@ -39,10 +36,8 @@ import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorApiLiveTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
/**
* Tests live behavior of {@link AdminGroupApi}.
* Tests live behavior of {@link AdminOrgApi}.
*
* @author danikov
*/
@ -60,7 +55,6 @@ public class AdminOrgApiLiveTest extends BaseVCloudDirectorApiLiveTest {
/*
* Shared state between dependant tests.
*/
private Reference orgRef;
private OrgSettings settings;
private OrgEmailSettings emailSettings;
private OrgGeneralSettings generalSettings;
@ -73,26 +67,23 @@ public class AdminOrgApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@BeforeClass(alwaysRun = true)
public void setupRequiredApis() {
orgApi = adminContext.getApi().getOrgApi();
orgRef = Iterables.getFirst(orgApi.getOrgList(), null).toAdminReference(endpoint);
assertNotNull(orgRef, String.format(REF_REQ_LIVE, "admin org"));
}
@Test(description = "GET /admin/org/{id}")
public void testGetAdminOrg() {
AdminOrg adminOrg = orgApi.getOrg(orgRef.getHref());
AdminOrg adminOrg = orgApi.get(org.getId());
Checks.checkAdminOrg(adminOrg);
}
@Test(description = "GET /admin/org/{id}/settings/email")
public void testGetEmailSettings() {
emailSettings = orgApi.getEmailSettings(orgRef.getHref());
emailSettings = orgApi.getEmailSettings(org.getId());
Checks.checkEmailSettings(emailSettings);
}
@Test(description = "PUT /admin/org/{id}/settings/email",
dependsOnMethods = { "testGetEmailSettings" })
@Test(description = "PUT /admin/org/{id}/settings/email", dependsOnMethods = { "testGetEmailSettings" })
public void testUpdateEmailSettings() {
boolean isDefaultSmtpServer = emailSettings.isDefaultSmtpServer();
boolean isDefaultOrgEmail = emailSettings.isDefaultOrgEmail();
@ -104,70 +95,51 @@ public class AdminOrgApiLiveTest extends BaseVCloudDirectorApiLiveTest {
SmtpServerSettings oldSmtpServerSettings = emailSettings.getSmtpServerSettings();
SmtpServerSettings newSmtpServerSettings = oldSmtpServerSettings.toBuilder()
.useAuthentication(!oldSmtpServerSettings.useAuthentication())
.host("new"+oldSmtpServerSettings.getHost())
.username("new"+oldSmtpServerSettings.getUsername())
.password("new"+oldSmtpServerSettings.getPassword())
.build();
.host("new" + oldSmtpServerSettings.getHost()).username("new" + oldSmtpServerSettings.getUsername())
.password("new" + oldSmtpServerSettings.getPassword()).build();
try {
OrgEmailSettings newEmailSettings = emailSettings.toBuilder()
.isDefaultSmtpServer(!isDefaultSmtpServer)
.isDefaultOrgEmail(!isDefaultOrgEmail)
.fromEmailAddress(newFromEmailAddress)
.defaultSubjectPrefix(newDefaultSubjectPrefix)
.isAlertEmailToAllAdmins(!isAlertEmailToAllAdmins)
.smtpServerSettings(newSmtpServerSettings)
.build();
OrgEmailSettings newEmailSettings = emailSettings.toBuilder().isDefaultSmtpServer(!isDefaultSmtpServer)
.isDefaultOrgEmail(!isDefaultOrgEmail).fromEmailAddress(newFromEmailAddress)
.defaultSubjectPrefix(newDefaultSubjectPrefix).isAlertEmailToAllAdmins(!isAlertEmailToAllAdmins)
.smtpServerSettings(newSmtpServerSettings).build();
emailSettings = orgApi.updateEmailSettings(
orgRef.getHref(), newEmailSettings);
emailSettings = orgApi.updateEmailSettings(org.getId(), newEmailSettings);
assertTrue(equal(emailSettings.isDefaultSmtpServer(), !isDefaultSmtpServer),
String.format(OBJ_FIELD_UPDATABLE,
"emailSettings", "isDefaultSmtpServer"));
String.format(OBJ_FIELD_UPDATABLE, "emailSettings", "isDefaultSmtpServer"));
assertTrue(equal(emailSettings.isDefaultOrgEmail(), !isDefaultOrgEmail),
String.format(OBJ_FIELD_UPDATABLE,
"emailSettings", "isDefaultOrgEmail"));
String.format(OBJ_FIELD_UPDATABLE, "emailSettings", "isDefaultOrgEmail"));
assertTrue(equal(emailSettings.getFromEmailAddress(), newFromEmailAddress),
String.format(OBJ_FIELD_UPDATABLE,
"emailSettings", "fromEmailAddress"));
String.format(OBJ_FIELD_UPDATABLE, "emailSettings", "fromEmailAddress"));
assertTrue(equal(emailSettings.getDefaultSubjectPrefix(), newDefaultSubjectPrefix),
String.format(OBJ_FIELD_UPDATABLE,
"emailSettings", "defaultSubjectPrefix"));
String.format(OBJ_FIELD_UPDATABLE, "emailSettings", "defaultSubjectPrefix"));
assertTrue(equal(emailSettings.isAlertEmailToAllAdmins(), !isAlertEmailToAllAdmins),
String.format(OBJ_FIELD_UPDATABLE,
"emailSettings", "isAlertEmailToAllAdmins"));
String.format(OBJ_FIELD_UPDATABLE, "emailSettings", "isAlertEmailToAllAdmins"));
assertTrue(equal(emailSettings.getSmtpServerSettings(), newSmtpServerSettings),
String.format(OBJ_FIELD_UPDATABLE,
"emailSettings", "smtpServerSettings"));
String.format(OBJ_FIELD_UPDATABLE, "emailSettings", "smtpServerSettings"));
// TODO negative tests?
Checks.checkEmailSettings(emailSettings);
} finally {
emailSettings = emailSettings.toBuilder()
.isDefaultSmtpServer(isDefaultSmtpServer)
.isDefaultOrgEmail(isDefaultOrgEmail)
.fromEmailAddress(oldFromEmailAddress)
.defaultSubjectPrefix(oldDefaultSubjectPrefix)
.isAlertEmailToAllAdmins(isAlertEmailToAllAdmins)
.smtpServerSettings(oldSmtpServerSettings)
.build();
emailSettings = emailSettings.toBuilder().isDefaultSmtpServer(isDefaultSmtpServer)
.isDefaultOrgEmail(isDefaultOrgEmail).fromEmailAddress(oldFromEmailAddress)
.defaultSubjectPrefix(oldDefaultSubjectPrefix).isAlertEmailToAllAdmins(isAlertEmailToAllAdmins)
.smtpServerSettings(oldSmtpServerSettings).build();
emailSettings = orgApi.updateEmailSettings(
orgRef.getHref(), emailSettings);
emailSettings = orgApi.updateEmailSettings(org.getId(), emailSettings);
}
}
@Test(description = "GET /admin/org/{id}/settings/general")
public void testGetGeneralSettings() {
generalSettings = orgApi.getGeneralSettings(orgRef.getHref());
generalSettings = orgApi.getGeneralSettings(org.getId());
Checks.checkGeneralSettings(generalSettings);
}
@Test(description = "PUT /admin/org/{id}/settings/general",
dependsOnMethods = { "testGetGeneralSettings" } )
@Test(description = "PUT /admin/org/{id}/settings/general", dependsOnMethods = { "testGetGeneralSettings" })
public void testUpdateGeneralSettings() {
// FIXME: canPublishCatalogs does not update
// boolean canPublishCatalogs = generalSettings.canPublishCatalogs();
@ -177,66 +149,57 @@ public class AdminOrgApiLiveTest extends BaseVCloudDirectorApiLiveTest {
Integer delayAfterPowerOnSeconds = generalSettings.getDelayAfterPowerOnSeconds();
try {
OrgGeneralSettings newGeneralSettings = generalSettings.toBuilder()
OrgGeneralSettings newGeneralSettings = generalSettings
.toBuilder()
// .canPublishCatalogs(!canPublishCatalogs)
.deployedVMQuota(deployedVMQuota+1)
.storedVmQuota(storedVmQuota+1)
.useServerBootSequence(!useServerBootSequence)
.delayAfterPowerOnSeconds(delayAfterPowerOnSeconds+1)
.deployedVMQuota(deployedVMQuota + 1).storedVmQuota(storedVmQuota + 1)
.useServerBootSequence(!useServerBootSequence).delayAfterPowerOnSeconds(delayAfterPowerOnSeconds + 1)
.build();
generalSettings = orgApi.updateGeneralSettings(
orgRef.getHref(), newGeneralSettings);
generalSettings = orgApi.updateGeneralSettings(org.getId(), newGeneralSettings);
// assertTrue(equal(generalSettings.canPublishCatalogs(), !canPublishCatalogs),
// String.format(OBJ_FIELD_UPDATABLE,
// "generalSettings", "canPublishCatalogs"));
assertTrue(equal(generalSettings.getDeployedVMQuota(), deployedVMQuota + 1),
String.format(OBJ_FIELD_UPDATABLE,
"generalSettings", "deployedVMQuota"));
String.format(OBJ_FIELD_UPDATABLE, "generalSettings", "deployedVMQuota"));
assertTrue(equal(generalSettings.getStoredVmQuota(), storedVmQuota + 1),
String.format(OBJ_FIELD_UPDATABLE,
"generalSettings", "storedVmQuota"));
String.format(OBJ_FIELD_UPDATABLE, "generalSettings", "storedVmQuota"));
assertTrue(equal(generalSettings.useServerBootSequence(), !useServerBootSequence),
String.format(OBJ_FIELD_UPDATABLE,
"generalSettings", "useServerBootSequence"));
String.format(OBJ_FIELD_UPDATABLE, "generalSettings", "useServerBootSequence"));
assertTrue(equal(generalSettings.getDelayAfterPowerOnSeconds(), delayAfterPowerOnSeconds + 1),
String.format(OBJ_FIELD_UPDATABLE,
"generalSettings", "delayAfterPowerOnSeconds"));
String.format(OBJ_FIELD_UPDATABLE, "generalSettings", "delayAfterPowerOnSeconds"));
// TODO negative tests?
Checks.checkGeneralSettings(generalSettings);
} finally {
generalSettings = generalSettings.toBuilder()
generalSettings = generalSettings
.toBuilder()
// .canPublishCatalogs(canPublishCatalogs)
.deployedVMQuota(deployedVMQuota)
.storedVmQuota(storedVmQuota)
.useServerBootSequence(useServerBootSequence)
.delayAfterPowerOnSeconds(delayAfterPowerOnSeconds)
.deployedVMQuota(deployedVMQuota).storedVmQuota(storedVmQuota)
.useServerBootSequence(useServerBootSequence).delayAfterPowerOnSeconds(delayAfterPowerOnSeconds)
.build();
generalSettings = orgApi.updateGeneralSettings(
orgRef.getHref(), generalSettings);
generalSettings = orgApi.updateGeneralSettings(org.getId(), generalSettings);
}
}
@Test(description = "GET /admin/org/{id}/settings/ldap")
public void testGetLdapSettings() {
ldapSettings = orgApi.getLdapSettings(orgRef.getHref());
ldapSettings = orgApi.getLdapSettings(org.getId());
Checks.checkLdapSettings(ldapSettings);
}
@Test(description = "GET /admin/org/{id}/settings/passwordPolicy")
public void testGetPasswordPolicy() {
passwordPolicy = orgApi.getPasswordPolicy(orgRef.getHref());
passwordPolicy = orgApi.getPasswordPolicy(org.getId());
Checks.checkPasswordPolicySettings(passwordPolicy);
}
@Test(description = "PUT /admin/org/{id}/settings/passwordPolicy",
dependsOnMethods = { "testGetPasswordPolicy" })
@Test(description = "PUT /admin/org/{id}/settings/passwordPolicy", dependsOnMethods = { "testGetPasswordPolicy" })
public void testUpdatePasswordPolicy() {
boolean accountLockoutEnabled = passwordPolicy.isAccountLockoutEnabled();
Integer invalidLoginsBeforeLockout = passwordPolicy.getInvalidLoginsBeforeLockout();
@ -246,46 +209,38 @@ public class AdminOrgApiLiveTest extends BaseVCloudDirectorApiLiveTest {
OrgPasswordPolicySettings newPasswordPolicy = passwordPolicy.toBuilder()
.accountLockoutEnabled(!accountLockoutEnabled)
.invalidLoginsBeforeLockout(invalidLoginsBeforeLockout + 1)
.accountLockoutIntervalMinutes(accountLockoutIntervalMinutes+1)
.build();
.accountLockoutIntervalMinutes(accountLockoutIntervalMinutes + 1).build();
passwordPolicy = orgApi.updatePasswordPolicy(
orgRef.getHref(), newPasswordPolicy);
passwordPolicy = orgApi.updatePasswordPolicy(org.getId(), newPasswordPolicy);
assertTrue(equal(passwordPolicy.isAccountLockoutEnabled(), !accountLockoutEnabled),
String.format(OBJ_FIELD_UPDATABLE,
"PasswordPolicySettings", "deleteOnStorageLeaseExpiration"));
String.format(OBJ_FIELD_UPDATABLE, "PasswordPolicySettings", "deleteOnStorageLeaseExpiration"));
assertTrue(equal(passwordPolicy.getInvalidLoginsBeforeLockout(), invalidLoginsBeforeLockout + 1),
String.format(OBJ_FIELD_UPDATABLE,
"PasswordPolicySettings", "storageLeaseSeconds"));
String.format(OBJ_FIELD_UPDATABLE, "PasswordPolicySettings", "storageLeaseSeconds"));
assertTrue(equal(passwordPolicy.getAccountLockoutIntervalMinutes(), accountLockoutIntervalMinutes + 1),
String.format(OBJ_FIELD_UPDATABLE,
"PasswordPolicySettings", "deploymentLeaseSeconds"));
String.format(OBJ_FIELD_UPDATABLE, "PasswordPolicySettings", "deploymentLeaseSeconds"));
// TODO negative tests?
Checks.checkPasswordPolicySettings(passwordPolicy);
} finally {
passwordPolicy = passwordPolicy.toBuilder()
.accountLockoutEnabled(accountLockoutEnabled)
passwordPolicy = passwordPolicy.toBuilder().accountLockoutEnabled(accountLockoutEnabled)
.invalidLoginsBeforeLockout(invalidLoginsBeforeLockout)
.accountLockoutIntervalMinutes(accountLockoutIntervalMinutes)
.build();
.accountLockoutIntervalMinutes(accountLockoutIntervalMinutes).build();
passwordPolicy = orgApi.updatePasswordPolicy(
orgRef.getHref(), passwordPolicy);
passwordPolicy = orgApi.updatePasswordPolicy(org.getId(), passwordPolicy);
}
}
@Test(description = "GET /admin/org/{id}/settings/vAppLeaseSettings")
public void testGetVAppLeaseSettings() {
vAppLeaseSettings = orgApi.getVAppLeaseSettings(orgRef.getHref());
vAppLeaseSettings = orgApi.getVAppLeaseSettings(org.getId());
Checks.checkVAppLeaseSettings(vAppLeaseSettings);
}
@Test(description = "PUT /admin/org/{id}/settings/vAppLeaseSettings",
dependsOnMethods = { "testGetVAppLeaseSettings" } ) // FIXME: fails with 403 forbidden
@Test(description = "PUT /admin/org/{id}/settings/vAppLeaseSettings", dependsOnMethods = { "testGetVAppLeaseSettings" })
// FIXME: fails with 403 forbidden
public void testUpdateVAppLeaseSettings() {
boolean deleteOnStorageLeaseExpiration = vAppLeaseSettings.deleteOnStorageLeaseExpiration();
Integer storageLeaseSeconds = vAppLeaseSettings.getStorageLeaseSeconds();
@ -294,22 +249,17 @@ public class AdminOrgApiLiveTest extends BaseVCloudDirectorApiLiveTest {
try {
OrgLeaseSettings newVAppLeaseSettings = vAppLeaseSettings.toBuilder()
.deleteOnStorageLeaseExpiration(!deleteOnStorageLeaseExpiration)
.storageLeaseSeconds(storageLeaseSeconds+1)
.deploymentLeaseSeconds(deploymentLeaseSeconds+1)
.storageLeaseSeconds(storageLeaseSeconds + 1).deploymentLeaseSeconds(deploymentLeaseSeconds + 1)
.build();
vAppLeaseSettings = orgApi.updateVAppLeaseSettings(
orgRef.getHref(), newVAppLeaseSettings);
vAppLeaseSettings = orgApi.updateVAppLeaseSettings(org.getId(), newVAppLeaseSettings);
assertTrue(equal(vAppLeaseSettings.deleteOnStorageLeaseExpiration(), !deleteOnStorageLeaseExpiration),
String.format(OBJ_FIELD_UPDATABLE,
"vAppLeaseSettings", "deleteOnStorageLeaseExpiration"));
String.format(OBJ_FIELD_UPDATABLE, "vAppLeaseSettings", "deleteOnStorageLeaseExpiration"));
assertTrue(equal(vAppLeaseSettings.getStorageLeaseSeconds(), storageLeaseSeconds + 1),
String.format(OBJ_FIELD_UPDATABLE,
"vAppLeaseSettings", "storageLeaseSeconds"));
String.format(OBJ_FIELD_UPDATABLE, "vAppLeaseSettings", "storageLeaseSeconds"));
assertTrue(equal(vAppLeaseSettings.getDeploymentLeaseSeconds(), deploymentLeaseSeconds + 1),
String.format(OBJ_FIELD_UPDATABLE,
"vAppLeaseSettings", "deploymentLeaseSeconds"));
String.format(OBJ_FIELD_UPDATABLE, "vAppLeaseSettings", "deploymentLeaseSeconds"));
// TODO negative tests?
@ -317,24 +267,21 @@ public class AdminOrgApiLiveTest extends BaseVCloudDirectorApiLiveTest {
} finally {
vAppLeaseSettings = vAppLeaseSettings.toBuilder()
.deleteOnStorageLeaseExpiration(deleteOnStorageLeaseExpiration)
.storageLeaseSeconds(storageLeaseSeconds)
.deploymentLeaseSeconds(deploymentLeaseSeconds)
.build();
.storageLeaseSeconds(storageLeaseSeconds).deploymentLeaseSeconds(deploymentLeaseSeconds).build();
vAppLeaseSettings = orgApi.updateVAppLeaseSettings(
orgRef.getHref(), vAppLeaseSettings);
vAppLeaseSettings = orgApi.updateVAppLeaseSettings(org.getId(), vAppLeaseSettings);
}
}
@Test(description = "GET /admin/org/{id}/settings/vAppTemplateLeaseSettings")
public void testGetVAppTemplateLeaseSettings() {
vAppTemplateLeaseSettings = orgApi.getVAppTemplateLeaseSettings(orgRef.getHref());
vAppTemplateLeaseSettings = orgApi.getVAppTemplateLeaseSettings(org.getId());
Checks.checkVAppTemplateLeaseSettings(vAppTemplateLeaseSettings);
}
@Test(description = "PUT /admin/org/{id}/settings/vAppTemplateLeaseSettings",
dependsOnMethods = { "testGetVAppTemplateLeaseSettings" }) // FIXME: fails with 403 forbidden
@Test(description = "PUT /admin/org/{id}/settings/vAppTemplateLeaseSettings", dependsOnMethods = { "testGetVAppTemplateLeaseSettings" })
// FIXME: fails with 403 forbidden
public void testUpdateVAppTemplateLeaseSettings() {
boolean deleteOnStorageLeaseExpiration = vAppTemplateLeaseSettings.deleteOnStorageLeaseExpiration();
Integer storageLeaseSeconds = vAppTemplateLeaseSettings.getStorageLeaseSeconds();
@ -342,18 +289,14 @@ public class AdminOrgApiLiveTest extends BaseVCloudDirectorApiLiveTest {
try {
OrgVAppTemplateLeaseSettings newVAppTemplateLeaseSettings = vAppTemplateLeaseSettings.toBuilder()
.deleteOnStorageLeaseExpiration(!deleteOnStorageLeaseExpiration)
.storageLeaseSeconds(storageLeaseSeconds+1)
.build();
.storageLeaseSeconds(storageLeaseSeconds + 1).build();
vAppTemplateLeaseSettings = orgApi.updateVAppTemplateLeaseSettings(
orgRef.getHref(), newVAppTemplateLeaseSettings);
vAppTemplateLeaseSettings = orgApi.updateVAppTemplateLeaseSettings(org.getId(), newVAppTemplateLeaseSettings);
assertTrue(equal(vAppTemplateLeaseSettings.deleteOnStorageLeaseExpiration(), !deleteOnStorageLeaseExpiration),
String.format(OBJ_FIELD_UPDATABLE,
"vAppTemplateLeaseSettings", "deleteOnStorageLeaseExpiration"));
String.format(OBJ_FIELD_UPDATABLE, "vAppTemplateLeaseSettings", "deleteOnStorageLeaseExpiration"));
assertTrue(equal(vAppTemplateLeaseSettings.getStorageLeaseSeconds(), storageLeaseSeconds + 1),
String.format(OBJ_FIELD_UPDATABLE,
"vAppTemplateLeaseSettings", "storageLeaseSeconds"));
String.format(OBJ_FIELD_UPDATABLE, "vAppTemplateLeaseSettings", "storageLeaseSeconds"));
// TODO negative tests?
@ -361,50 +304,41 @@ public class AdminOrgApiLiveTest extends BaseVCloudDirectorApiLiveTest {
} finally {
vAppTemplateLeaseSettings = vAppTemplateLeaseSettings.toBuilder()
.deleteOnStorageLeaseExpiration(deleteOnStorageLeaseExpiration)
.storageLeaseSeconds(storageLeaseSeconds)
.build();
.storageLeaseSeconds(storageLeaseSeconds).build();
vAppTemplateLeaseSettings = orgApi.updateVAppTemplateLeaseSettings(
orgRef.getHref(), vAppTemplateLeaseSettings);
vAppTemplateLeaseSettings = orgApi.updateVAppTemplateLeaseSettings(org.getId(), vAppTemplateLeaseSettings);
}
}
@Test(description = "GET /admin/org/{id}/settings")
public void testGetSettings() {
settings = orgApi.getSettings(orgRef.getHref());
settings = orgApi.getSettings(org.getId());
Checks.checkOrgSettings(settings);
}
@Test(description = "PUT /admin/org/{id}/settings",
dependsOnMethods = { "testGetEmailSettings" } )
@Test(description = "PUT /admin/org/{id}/settings", dependsOnMethods = { "testGetEmailSettings" })
public void testUpdateSettings() throws Exception {
String newFromEmailAddress = "test" + random.nextInt(Integer.MAX_VALUE) + "@test.com";
Exception exception = null;
try {
OrgSettings newSettings = OrgSettings.builder()
.emailSettings(emailSettings.toBuilder().fromEmailAddress(newFromEmailAddress).build())
.build();
.emailSettings(emailSettings.toBuilder().fromEmailAddress(newFromEmailAddress).build()).build();
OrgSettings modified = orgApi.updateSettings(
orgRef.getHref(), newSettings);
OrgSettings modified = orgApi.updateSettings(org.getId(), newSettings);
Checks.checkOrgSettings(settings);
assertTrue(equal(modified.getEmailSettings().getFromEmailAddress(), newFromEmailAddress),
String.format(OBJ_FIELD_UPDATABLE,
"orgSettings", "emailSettings"));
String.format(OBJ_FIELD_UPDATABLE, "orgSettings", "emailSettings"));
} catch (Exception e) {
exception = e;
} finally {
try {
OrgSettings restorableSettings = OrgSettings.builder()
.emailSettings(emailSettings)
.build();
OrgSettings restorableSettings = OrgSettings.builder().emailSettings(emailSettings).build();
settings = orgApi.updateSettings(
orgRef.getHref(), restorableSettings);
settings = orgApi.updateSettings(org.getId(), restorableSettings);
} catch (Exception e) {
if (exception != null) {
logger.warn(e, "Error resetting settings; rethrowing original test exception...");

View File

@ -19,7 +19,7 @@
package org.jclouds.vcloud.director.v1_5.features.admin;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.REF_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.URN_REQ_LIVE;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.fail;
@ -66,7 +66,7 @@ public class AdminVdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
public void setupRequiredApis() {
vdcApi = adminContext.getApi().getVdcApi();
metadataApi = vdcApi.getMetadataApi();
assertNotNull(vdcURI, String.format(REF_REQ_LIVE, VDC));
assertNotNull(vdcURI, String.format(URN_REQ_LIVE, VDC));
adminVdcUri = toAdminUri(vdcURI);
}

View File

@ -18,11 +18,18 @@
*/
package org.jclouds.vcloud.director.v1_5.features.admin;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.ADMIN_ORG;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.ENTITY;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.ERROR;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.ORG;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.USER;
import static org.testng.Assert.assertEquals;
import java.net.URI;
import java.util.Collections;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.rest.ResourceNotFoundException;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminApi;
@ -32,38 +39,197 @@ import org.jclouds.vcloud.director.v1_5.domain.User;
import org.jclouds.vcloud.director.v1_5.internal.VCloudDirectorAdminApiExpectTest;
import org.testng.annotations.Test;
import com.google.common.net.HttpHeaders;
/**
* Test the {@link UserApi} by observing its side effects.
*
* @author danikov
* @author danikov, Adrian Cole
*/
@Test(groups = { "unit", "admin" }, singleThreaded = true, testName = "UserApiExpectTest")
public class UserApiExpectTest extends VCloudDirectorAdminApiExpectTest {
private Reference orgRef = Reference.builder()
.href(URI.create(endpoint + "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
private static String user = "7212e451-76e1-4631-b2de-ba1dfd8080e4";
private static String userUrn = "urn:vcloud:user:" + user;
private static URI userHref = URI.create(endpoint + "/user/" + user);
private static String org = "7212e451-76e1-4631-b2de-asdasdasd";
private static String orgUrn = "urn:vcloud:org:" + org;
private static URI orgHref = URI.create(endpoint + "/org/" + org);
private static URI orgAdminHref = URI.create(endpoint + "/admin/org/" + org);
private HttpRequest create = HttpRequest.builder()
.method("POST")
.endpoint(orgAdminHref + "/users")
.addHeader("Accept", USER)
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.payload(payloadFromResourceWithContentType("/user/createUserSource.xml", VCloudDirectorMediaType.USER))
.build();
private Reference userRef = Reference.builder()
.href(URI.create(endpoint + "/admin/user/b37223f3-8792-477a-820f-334998f61cd6"))
private HttpResponse createResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/user/createUser.xml", USER + ";version=1.5"))
.build();
@Test
public void testCreateUser() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("POST", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/users")
.xmlFilePayload("/user/createUserSource.xml", VCloudDirectorMediaType.USER)
.acceptMedia(VCloudDirectorMediaType.USER)
.httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/user/createUser.xml", VCloudDirectorMediaType.USER)
.httpResponseBuilder().build());
public void testCreateUserHref() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, create, createResponse);
assertEquals(api.getUserApi().createUserInOrg(createUserSource(), orgAdminHref), createUser());
}
User source = createUserSource();
User expected = createUser();
private HttpRequest resolveOrg = HttpRequest.builder()
.method("GET")
.endpoint(endpoint + "/entity/" + orgUrn)
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.build();
assertEquals(api.getUserApi().createUser(orgRef.getHref(), source), expected);
private String orgEntity = asString(createXMLBuilder("Entity").a("xmlns", "http://www.vmware.com/vcloud/v1.5")
.a("name", orgUrn)
.a("id", orgUrn)
.a("type", ENTITY)
.a("href", endpoint + "/entity/" + userUrn)
.e("Link").a("rel", "alternate").a("type", ORG).a("href", orgHref.toString()).up()
.e("Link").a("rel", "alternate").a("type", ADMIN_ORG).a("href", orgAdminHref.toString()).up());
private HttpResponse resolveOrgResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromStringWithContentType(orgEntity, ENTITY + ";version=1.5"))
.build();
@Test
public void testCreateUserUrn() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, resolveOrg, resolveOrgResponse, create, createResponse);
assertEquals(api.getUserApi().createUserInOrg(createUserSource(), orgUrn), createUser());
}
HttpRequest get = HttpRequest.builder()
.method("GET")
.endpoint(userHref)
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.build();
HttpResponse getResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/user/user.xml", ORG + ";version=1.5"))
.build();
@Test
public void testGetUserHref() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, get, getResponse);
assertEquals(api.getUserApi().get(userHref), user());
}
HttpRequest resolveUser = HttpRequest.builder()
.method("GET")
.endpoint(endpoint + "/entity/" + userUrn)
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.build();
String userEntity = asString(createXMLBuilder("Entity").a("xmlns", "http://www.vmware.com/vcloud/v1.5")
.a("name", userUrn)
.a("id", userUrn)
.a("type", ENTITY)
.a("href", endpoint + "/entity/" + userUrn)
.e("Link").a("rel", "alternate").a("type", USER).a("href", userHref.toString()).up());
HttpResponse resolveUserResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromStringWithContentType(userEntity, ENTITY + ";version=1.5"))
.build();
@Test
public void testGetUserUrn() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, resolveUser, resolveUserResponse, get, getResponse);
assertEquals(api.getUserApi().get(userUrn), user());
}
HttpRequest update = HttpRequest.builder()
.method("PUT")
.endpoint(userHref)
.addHeader("Accept", USER)
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.payload(payloadFromResourceWithContentType("/user/updateUserSource.xml", USER))
.build();
HttpResponse updateResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/user/updateUser.xml", USER))
.build();
@Test
public void testUpdateUserHref() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, update, updateResponse);
assertEquals(api.getUserApi().update(userHref, updateUserSource()), updateUser());
}
@Test
public void testUpdateUserUrn() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, resolveUser, resolveUserResponse, update, updateResponse);
assertEquals(api.getUserApi().update(userUrn, updateUserSource()), updateUser());
}
HttpRequest unlock = HttpRequest.builder()
.method("POST")
.endpoint(userHref + "/action/unlock")
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
.build();
HttpResponse unlockResponse = HttpResponse.builder()
.statusCode(204)
.build();
@Test
public void testUnlockUserHref() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, unlock, unlockResponse);
api.getUserApi().unlock(userHref);
}
@Test(expectedExceptions = ResourceNotFoundException.class)
public void testUnlockUserHrefNotFound() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, unlock, HttpResponse.builder()
.statusCode(403)
.payload(payloadFromResourceWithContentType("/org/error400.xml", ERROR))
.build());
api.getUserApi().unlock(userHref);
}
@Test
public void testUnlockUserUrn() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, resolveUser, resolveUserResponse, unlock, unlockResponse);
api.getUserApi().unlock(userUrn);
}
HttpRequest delete = HttpRequest.builder()
.method("DELETE")
.endpoint(userHref)
.addHeader("Accept", "*/*")
.addHeader("x-vcloud-authorization", token)
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token).build();
HttpResponse deleteResponse = HttpResponse.builder()
.statusCode(200)
.build();
@Test
public void testDeleteUserHref() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, delete, deleteResponse);
api.getUserApi().delete(userHref);
}
@Test
public void testDeleteUserUrn() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, resolveUser, resolveUserResponse, delete, deleteResponse);
api.getUserApi().delete(userUrn);
}
public static final User createUserSource() {
@ -111,46 +277,12 @@ public class UserApiExpectTest extends VCloudDirectorAdminApiExpectTest {
.build();
}
@Test
public void testGetUser() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("GET", "/admin/user/b37223f3-8792-477a-820f-334998f61cd6")
.acceptAnyMedia()
.httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/user/user.xml", VCloudDirectorMediaType.USER)
.httpResponseBuilder().build());
User expected = user();
assertEquals(api.getUserApi().getUser(userRef.getHref()), expected);
}
public static final User user() {
return createUser().toBuilder()
.nameInSource("test")
.build();
}
@Test
public void testUpdateUser() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("PUT", "/admin/user/b37223f3-8792-477a-820f-334998f61cd6")
.xmlFilePayload("/user/updateUserSource.xml", VCloudDirectorMediaType.USER)
.acceptMedia(VCloudDirectorMediaType.USER)
.httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.xmlFilePayload("/user/updateUser.xml", VCloudDirectorMediaType.USER)
.httpResponseBuilder().build());
User source = updateUserSource();
User expected = updateUser();
assertEquals(api.getUserApi().updateUser(userRef.getHref(), source), expected);
}
public static final User updateUserSource() {
return user().toBuilder()
.fullName("new"+user().getFullName())
@ -173,44 +305,4 @@ public class UserApiExpectTest extends VCloudDirectorAdminApiExpectTest {
.build();
}
@Test
public void testDeleteUser() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("DELETE", "/admin/user/b37223f3-8792-477a-820f-334998f61cd6")
.acceptAnyMedia()
.httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.httpResponseBuilder().statusCode(204).build());
api.getUserApi().deleteUser(userRef.getHref());
}
@Test
public void testUnlockUser() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("POST", "/admin/user/b37223f3-8792-477a-820f-334998f61cd6/action/unlock")
.acceptAnyMedia()
.httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.httpResponseBuilder().statusCode(204).build());
api.getUserApi().unlockUser(userRef.getHref());
}
@Test(expectedExceptions = ResourceNotFoundException.class)
public void testUnlockUserFailNotFound() {
VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse,
new VcloudHttpRequestPrimer()
.apiCommand("POST", "/admin/user/b37223f3-8792-477a-820f-334998f61cd6/action/unlock")
.acceptAnyMedia()
.httpRequestBuilder().build(),
new VcloudHttpResponsePrimer()
.httpResponseBuilder().statusCode(403)
.payload(payloadFromResourceWithContentType("/org/error400.xml", VCloudDirectorMediaType.ERROR))
.build());
api.getUserApi().unlockUser(userRef.getHref());
}
}

View File

@ -30,7 +30,6 @@ import static org.testng.AssertJUnit.assertFalse;
import java.net.URI;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.Role.DefaultRoles;
import org.jclouds.vcloud.director.v1_5.domain.SessionWithToken;
import org.jclouds.vcloud.director.v1_5.domain.User;
@ -41,8 +40,6 @@ import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
/**
* Tests live behavior of {@link UserApi}.
*
@ -61,21 +58,19 @@ public class UserApiLiveTest extends BaseVCloudDirectorApiLiveTest {
/*
* Shared state between dependant tests.
*/
private Reference orgRef;
private User user;
@Override
@BeforeClass(alwaysRun = true)
public void setupRequiredApis() {
userApi = adminContext.getApi().getUserApi();
orgRef = Iterables.getFirst(context.getApi().getOrgApi().getOrgList(), null).toAdminReference(endpoint);
}
@AfterClass(alwaysRun = true)
public void cleanUp() throws Exception {
if (user != null) {
try {
userApi.deleteUser(user.getHref());
userApi.delete(user.getHref());
} catch (Exception e) {
logger.warn(e, "Error deleting user '%s'", user.getName());
}
@ -85,13 +80,13 @@ public class UserApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "POST /admin/org/{id}/users")
public void testCreateUser() {
User newUser = randomTestUser("testCreateUser");
user = userApi.createUser(orgRef.getHref(), newUser);
user = userApi.createUserInOrg(newUser, org.getId());
checkUser(newUser);
}
@Test(description = "GET /admin/user/{id}", dependsOnMethods = { "testCreateUser" })
public void testGetUser() {
user = userApi.getUser(user.getHref());
user = userApi.get(user.getHref());
checkUser(user);
}
@ -116,8 +111,8 @@ public class UserApiLiveTest extends BaseVCloudDirectorApiLiveTest {
.role(getRoleReferenceFor(DefaultRoles.AUTHOR.value()))
.build();
userApi.updateUser(user.getHref(), newUser);
user = userApi.getUser(user.getHref());
userApi.update(user.getHref(), newUser);
user = userApi.get(user.getHref());
checkUser(user);
assertTrue(equal(user.getFullName(), newUser.getFullName()),
@ -148,7 +143,7 @@ public class UserApiLiveTest extends BaseVCloudDirectorApiLiveTest {
// Check the user can really login with the changed password
// NOTE: the password is NOT returned in the User object returned from the server
SessionWithToken sessionWithToken = sessionApi.loginUserInOrgWithPassword(URI.create(endpoint + "/sessions"), user.getName(), orgRef.getName(), "newPassword");
SessionWithToken sessionWithToken = sessionApi.loginUserInOrgWithPassword(URI.create(endpoint + "/sessions"), user.getName(), org.getName(), "newPassword");
assertNotNull(sessionWithToken.getToken());
sessionApi.logoutSessionWithToken(sessionWithToken.getSession().getHref(), sessionWithToken.getToken());
}
@ -162,21 +157,21 @@ public class UserApiLiveTest extends BaseVCloudDirectorApiLiveTest {
// session api isn't typically exposed to the user, as it is implicit
SessionApi sessionApi = context.utils().injector().getInstance(SessionApi.class);
OrgPasswordPolicySettings settings = adminOrgApi.getSettings(orgRef.getHref()).getPasswordPolicy();
OrgPasswordPolicySettings settings = adminOrgApi.getSettings(org.getId()).getPasswordPolicy();
assertNotNull(settings);
// Adjust account settings so we can lock the account - be careful to not set invalidLoginsBeforeLockout too low!
if (!settings.isAccountLockoutEnabled()) {
settingsToRevertTo = settings;
settings = settings.toBuilder().accountLockoutEnabled(true).invalidLoginsBeforeLockout(5).build();
settings = adminOrgApi.updatePasswordPolicy(orgRef.getHref(), settings);
settings = adminOrgApi.updatePasswordPolicy(org.getId(), settings);
}
assertTrue(settings.isAccountLockoutEnabled());
for (int i = 0; i < settings.getInvalidLoginsBeforeLockout() + 1; i++) {
try {
sessionApi.loginUserInOrgWithPassword(URI.create(endpoint + "/sessions"), user.getName(), orgRef.getName(), "wrongpassword!");
sessionApi.loginUserInOrgWithPassword(URI.create(endpoint + "/sessions"), user.getName(), org.getName(), "wrongpassword!");
fail("Managed to login using the wrong password!");
} catch (AuthorizationException e) {
} catch (Exception e) {
@ -184,30 +179,30 @@ public class UserApiLiveTest extends BaseVCloudDirectorApiLiveTest {
}
}
user = userApi.getUser(user.getHref());
user = userApi.get(user.getHref());
assertTrue(user.isLocked());
try {
sessionApi.loginUserInOrgWithPassword(URI.create(endpoint + "/sessions"), user.getName(), orgRef.getName(), "newPassword");
sessionApi.loginUserInOrgWithPassword(URI.create(endpoint + "/sessions"), user.getName(), org.getName(), "newPassword");
fail("Managed to login to locked account!");
} catch (AuthorizationException e) {
} catch (Exception e) {
fail("Expected AuthorizationException", e);
}
userApi.unlockUser(user.getHref());
userApi.unlock(user.getHref());
user = userApi.getUser(user.getHref());
user = userApi.get(user.getHref());
assertFalse(user.isLocked());
// Double-check the user can now login again
SessionWithToken sessionWithToken = sessionApi.loginUserInOrgWithPassword(URI.create(endpoint + "/sessions"), user.getName(), orgRef.getName(), "newPassword");
SessionWithToken sessionWithToken = sessionApi.loginUserInOrgWithPassword(URI.create(endpoint + "/sessions"), user.getName(), org.getName(), "newPassword");
assertNotNull(sessionWithToken.getToken());
sessionApi.logoutSessionWithToken(sessionWithToken.getSession().getHref(), sessionWithToken.getToken());
// Return account settings to the previous values, if necessary
if (settingsToRevertTo != null) {
adminOrgApi.updatePasswordPolicy(orgRef.getHref(), settingsToRevertTo);
adminOrgApi.updatePasswordPolicy(org.getId(), settingsToRevertTo);
}
}
@ -215,13 +210,13 @@ public class UserApiLiveTest extends BaseVCloudDirectorApiLiveTest {
public void testDeleteUser() {
// Create a user to be deleted (so we remove dependencies on test ordering)
User newUser = randomTestUser("testDeleteUser"+getTestDateTimeStamp());
User userToBeDeleted = userApi.createUser(orgRef.getHref(), newUser);
User userToBeDeleted = userApi.createUserInOrg(newUser, org.getId());
// Delete the user
userApi.deleteUser(userToBeDeleted.getHref());
userApi.delete(userToBeDeleted.getHref());
// Confirm cannot no longer be accessed
User deleted = userApi.getUser(userToBeDeleted.getHref());
User deleted = userApi.get(userToBeDeleted.getHref());
assertNull(deleted);
}
}

View File

@ -18,8 +18,21 @@
*/
package org.jclouds.vcloud.director.v1_5.internal;
import static com.google.common.base.Strings.emptyToNull;
import static com.google.common.base.Strings.isNullOrEmpty;
import static com.google.common.collect.FluentIterable.from;
import static com.google.common.collect.Iterables.any;
import static com.google.common.collect.Iterables.find;
import static com.google.common.collect.Iterables.getFirst;
import static com.google.common.collect.Iterables.getLast;
import static com.google.common.collect.Iterables.tryFind;
import static com.google.common.io.Closeables.closeQuietly;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.ENTITY_NON_NULL;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.TASK_COMPLETE_TIMELY;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.URN_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.CATALOG;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NETWORK;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.ORG_NETWORK;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
@ -43,9 +56,8 @@ import org.jclouds.rest.RestContext;
import org.jclouds.vcloud.director.testng.FormatApiResultsListener;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorApiMetadata;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorContext;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminAsyncApi;
import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminApi;
import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminAsyncApi;
import org.jclouds.vcloud.director.v1_5.domain.Link;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.ResourceEntity.Status;
@ -69,26 +81,26 @@ import org.jclouds.vcloud.director.v1_5.features.TaskApi;
import org.jclouds.vcloud.director.v1_5.features.VAppApi;
import org.jclouds.vcloud.director.v1_5.features.VAppTemplateApi;
import org.jclouds.vcloud.director.v1_5.features.VdcApi;
import org.jclouds.vcloud.director.v1_5.predicates.EntityPredicates;
import org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates;
import org.jclouds.vcloud.director.v1_5.predicates.ReferencePredicates;
import org.jclouds.vcloud.director.v1_5.predicates.TaskStatusEquals;
import org.jclouds.vcloud.director.v1_5.predicates.TaskSuccess;
import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorAsyncApi;
import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorApi;
import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorAsyncApi;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.common.io.Closeables;
import com.google.common.reflect.TypeToken;
import com.google.inject.Guice;
@ -125,9 +137,11 @@ public abstract class BaseVCloudDirectorApiLiveTest extends BaseContextLiveTest<
protected String catalogUrn;
protected URI vAppTemplateURI;
protected URI mediaURI;
protected URI networkURI;
protected String networkUrn;
private Network network;
protected URI vdcURI;
protected URI userURI;
protected String userUrn;
private User user;
protected final Set<String> vAppNames = Sets.newLinkedHashSet();
protected static final Random random = new Random();
@ -140,6 +154,8 @@ public abstract class BaseVCloudDirectorApiLiveTest extends BaseContextLiveTest<
protected VCloudDirectorTestSession testSession;
protected Org org;
protected static String testStamp;
@BeforeClass(alwaysRun = true)
@ -163,7 +179,7 @@ public abstract class BaseVCloudDirectorApiLiveTest extends BaseContextLiveTest<
@AfterClass(alwaysRun = true)
protected void tearDownTestSession() {
Closeables.closeQuietly(testSession);
closeQuietly(testSession);
}
@Override
@ -207,7 +223,7 @@ public abstract class BaseVCloudDirectorApiLiveTest extends BaseContextLiveTest<
public static Reference getRoleReferenceFor(String name, RestContext<VCloudDirectorAdminApi, VCloudDirectorAdminAsyncApi> adminContext) {
RoleReferences roles = adminContext.getApi().getQueryApi().roleReferencesQueryAll();
// backend in a builder to strip out unwanted xml cruft that the api chokes on
return Reference.builder().fromReference(Iterables.find(roles.getReferences(), ReferencePredicates.nameEquals(name))).build();
return Reference.builder().fromReference(find(roles.getReferences(), ReferencePredicates.nameEquals(name))).build();
}
public User randomTestUser(String prefix) {
@ -233,50 +249,71 @@ public abstract class BaseVCloudDirectorApiLiveTest extends BaseContextLiveTest<
}
protected void initTestParametersFromPropertiesOrLazyDiscover() {
catalogUrn = Strings.emptyToNull(System.getProperty("test." + provider + ".catalog-id"));
catalogUrn = emptyToNull(System.getProperty("test." + provider + ".catalog-id"));
String vAppTemplateId = Strings.emptyToNull(System.getProperty("test." + provider + ".vapptemplate-id"));
String vAppTemplateId = emptyToNull(System.getProperty("test." + provider + ".vapptemplate-id"));
if (vAppTemplateId != null)
vAppTemplateURI = URI.create(endpoint + "/vAppTemplate/" + vAppTemplateId);
String vdcId = Strings.emptyToNull(System.getProperty("test." + provider + ".vdc-id"));
String vdcId = emptyToNull(System.getProperty("test." + provider + ".vdc-id"));
if (vdcId != null)
vdcURI = URI.create(endpoint + "/vdc/" + vdcId);
String mediaId = Strings.emptyToNull(System.getProperty("test." + provider + ".media-id"));
String mediaId = emptyToNull(System.getProperty("test." + provider + ".media-id"));
if (mediaId != null)
mediaURI = URI.create(endpoint + "/media/" + mediaId);
String networkId = Strings.emptyToNull(System.getProperty("test." + provider + ".network-id"));
if (networkId != null)
networkURI = URI.create(endpoint + "/network/" + networkId);
networkUrn = emptyToNull(System.getProperty("test." + provider + ".network-id"));
String userId = Strings.emptyToNull(System.getProperty("test." + provider + ".user-id"));
if (userId != null)
userURI = URI.create(endpoint + "/admin/user/" + userId);
userUrn = emptyToNull(System.getProperty("test." + provider + ".user-id"));
if (Iterables.any(Lists.newArrayList(vAppTemplateURI, networkURI, vdcURI), Predicates.isNull())) {
Org thisOrg = context.getApi().getOrgApi().getOrg(
Iterables.find(context.getApi().getOrgApi().getOrgList(),
ReferencePredicates.<Reference> nameEquals(session.getOrg())).getHref());
org = context.getApi().getOrgApi().get(
find(context.getApi().getOrgApi().list(),
ReferencePredicates.<Reference> nameEquals(session.get())).getHref());
if (any(Lists.newArrayList(vAppTemplateURI, networkUrn, vdcURI), Predicates.isNull())) {
if (vdcURI == null)
vdcURI = Iterables.find(thisOrg.getLinks(),
ReferencePredicates.<Link> typeEquals(VCloudDirectorMediaType.VDC)).getHref();
vdcURI = find(org.getLinks(),
ReferencePredicates.<Link> typeEquals(VDC)).getHref();
if (networkURI == null)
networkURI = Iterables.find(thisOrg.getLinks(),
ReferencePredicates.<Link> typeEquals(VCloudDirectorMediaType.ORG_NETWORK)).getHref();
if (networkUrn == null) {
network = context.getApi().getNetworkApi().get(find(org.getLinks(),
ReferencePredicates.<Link> typeEquals(ORG_NETWORK)).getHref());
networkUrn = network.getId();
}
// FIXME the URI should be opaque
if (Strings.isNullOrEmpty(catalogUrn)) {
String uri = Iterables.find(thisOrg.getLinks(),
ReferencePredicates.<Link> typeEquals(VCloudDirectorMediaType.CATALOG)).getHref().toASCIIString();
catalogUrn = Iterables.getLast(Splitter.on('/').split(uri));
if (isNullOrEmpty(catalogUrn)) {
String uri = find(org.getLinks(),
ReferencePredicates.<Link> typeEquals(CATALOG)).getHref().toASCIIString();
catalogUrn = getLast(Splitter.on('/').split(uri));
}
}
}
protected Network lazyGetNetwork() {
if (network == null) {
assertNotNull(networkUrn, String.format(URN_REQ_LIVE, NETWORK));
network = from(org.getLinks()).filter(LinkPredicates.typeEquals(ORG_NETWORK))
.transform(new Function<Link, Network>() {
@Override
public Network apply(Link in) {
return context.getApi().getNetworkApi().get(in.getHref());
}
}).firstMatch(EntityPredicates.idEquals(networkUrn)).get();
}
return network;
}
protected User lazyGetUser() {
if (user == null) {
user = adminContext.getApi().getUserApi().get(userUrn);
}
return user;
}
public URI toAdminUri(Reference ref) {
return toAdminUri(ref.getHref());
}
@ -343,7 +380,7 @@ public abstract class BaseVCloudDirectorApiLiveTest extends BaseContextLiveTest<
VApp vAppInstantiated = vdcApi.instantiateVApp(vdcURI, instantiate);
assertNotNull(vAppInstantiated, String.format(ENTITY_NON_NULL, VAPP));
Task instantiationTask = Iterables.getFirst(vAppInstantiated.getTasks(), null);
Task instantiationTask = getFirst(vAppInstantiated.getTasks(), null);
if (instantiationTask != null) assertTaskSucceedsLong(instantiationTask);
// Save VApp name for cleanUp
@ -384,16 +421,16 @@ public abstract class BaseVCloudDirectorApiLiveTest extends BaseContextLiveTest<
Set<Reference> networks = vdc.getAvailableNetworks();
// Look up the network in the Vdc with the id configured for the tests
Optional<Reference> parentNetwork = Iterables.tryFind(networks, new Predicate<Reference>() {
Optional<Reference> parentNetwork = tryFind(networks, new Predicate<Reference>() {
@Override
public boolean apply(Reference reference) {
return reference.getHref().equals(networkURI);
return reference.getHref().equals(network.getHref());
}
});
// Check we actually found a network reference
if (!parentNetwork.isPresent()) {
fail(String.format("Could not find network %s in vdc", networkURI.toASCIIString()));
fail(String.format("Could not find network %s in vdc", network.getHref().toASCIIString()));
}
// Build the configuration object

View File

@ -92,12 +92,12 @@ public class VCloudDirectorTestSession implements Closeable {
adminContext = userContext.getAdminContext();
// Lookup the user details
Reference orgRef = Iterables.getFirst(userContext.getApi().getOrgApi().getOrgList(), null)
Reference orgRef = Iterables.getFirst(userContext.getApi().getOrgApi().list(), null)
.toAdminReference(endpoint);
Reference userRef = Iterables.find(
adminContext.getApi().getOrgApi().getOrg(orgRef.getHref()).getUsers(),
adminContext.getApi().getOrgApi().get(orgRef.getHref()).getUsers(),
ReferencePredicates.nameEquals(adminContext.getApi().getCurrentSession().getUser()));
User user = adminContext.getApi().getUserApi().getUser(userRef.getHref());
User user = adminContext.getApi().getUserApi().get(userRef.getHref());
// Check that the user has the org admin role
Reference userRole = user.getRole();

View File

@ -72,7 +72,7 @@ public class SessionApiLiveTest extends BaseContextLiveTest<RestContext<SessionA
sessionWithToken = api.loginUserInOrgWithPassword(URI.create(endpoint + "/sessions"), user, org, password);
assertEquals(sessionWithToken.getSession().getUser(), user);
assertEquals(sessionWithToken.getSession().getOrg(), org);
assertEquals(sessionWithToken.getSession().get(), org);
assertTrue(sessionWithToken.getSession().getLinks().size() > 0);
assertNotNull(sessionWithToken.getToken());
}

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<CloneMediaParams name="moved test media" xmlns="http://www.vmware.com/vcloud/v1.5">
<Description>moved by testCloneMedia()</Description>
<Source type="application/vnd.vmware.vcloud.media+xml" name="copied test media" id="urn:vcloud:media:da8361af-cccd-4103-a71c-493513c49094" href="https://mycloud.greenhousedata.com/api/media/da8361af-cccd-4103-a71c-493513c49094"/>
<Source type="application/vnd.vmware.vcloud.media+xml" name="copied test media" href="https://mycloud.greenhousedata.com/api/media/da8361af-cccd-4103-a71c-493513c49094"/>
<IsSourceDelete>false</IsSourceDelete>
</CloneMediaParams>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Task xmlns="http://www.vmware.com/vcloud/v1.5" status="running" startTime="2012-03-14T12:39:23.720-04:00" operationName="networkResetNetwork" operation="Resetting Network ilsolation01-Jclouds(f3ba8256-6f48-4512-aad6-600e85b4dc38)" expiryTime="2012-06-12T12:39:23.720-04:00" name="task" id="urn:vcloud:task:49d2e180-7921-4902-ac39-b4ff5406bb94" type="application/vnd.vmware.vcloud.task+xml" href="https://vcloudbeta.bluelock.com/api/task/49d2e180-7921-4902-ac39-b4ff5406bb94" 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">
<Link rel="task:cancel" href="https://vcloudbeta.bluelock.com/api/task/49d2e180-7921-4902-ac39-b4ff5406bb94/action/cancel"/>
<Owner type="application/vnd.vmware.vcloud.network+xml" name="ilsolation01-Jclouds" href="https://vcloudbeta.bluelock.com/api/network/f3ba8256-6f48-4512-aad6-600e85b4dc38"/>
<User type="application/vnd.vmware.admin.user+xml" name="dan@cloudsoftcorp.com" href="https://vcloudbeta.bluelock.com/api/admin/user/ae75edd2-12de-414c-8e85-e6ea10442c08"/>
<Organization type="application/vnd.vmware.vcloud.org+xml" name="JClouds" href="https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"/>
</Task>

View File

@ -1,10 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<OrgNetwork name="ilsolation01-Jclouds" id="urn:vcloud:network:f3ba8256-6f48-4512-aad6-600e85b4dc38" type="application/vnd.vmware.vcloud.orgNetwork+xml" href="https://vcloudbeta.bluelock.com/api/admin/network/f3ba8256-6f48-4512-aad6-600e85b4dc38" xmlns="http://www.vmware.com/vcloud/v1.5">
<Link rel="alternate" type="application/vnd.vmware.vcloud.orgNetwork+xml" href="https://vcloudbeta.bluelock.com/api/network/f3ba8256-6f48-4512-aad6-600e85b4dc38"/>
<Link rel="edit" type="application/vnd.vmware.admin.orgNetwork+xml" href="https://vcloudbeta.bluelock.com/api/admin/network/f3ba8256-6f48-4512-aad6-600e85b4dc38"/>
<Link rel="up" type="application/vnd.vmware.admin.organization+xml" href="https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"/>
<Link rel="repair" type="application/vnd.vmware.admin.orgNetwork+xml" href="https://vcloudbeta.bluelock.com/api/admin/network/f3ba8256-6f48-4512-aad6-600e85b4dc38/action/reset"/>
<Link rel="down" type="application/vnd.vmware.vcloud.metadata+xml" href="https://vcloudbeta.bluelock.com/api/admin/network/f3ba8256-6f48-4512-aad6-600e85b4dc38/metadata"/>
<OrgNetwork name="ilsolation01-Jclouds" id="urn:vcloud:network:f3ba8256-6f48-4512-aad6-600e85b4dc38" type="application/vnd.vmware.vcloud.orgNetwork+xml" href="https://vcloudbeta.bluelock.com/api/network/f3ba8256-6f48-4512-aad6-600e85b4dc38" xmlns="http://www.vmware.com/vcloud/v1.5">
<Link rel="up" type="application/vnd.vmware.vcloud.org+xml" href="https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"/>
<Link rel="down" type="application/vnd.vmware.vcloud.metadata+xml" href="https://vcloudbeta.bluelock.com/api/network/f3ba8256-6f48-4512-aad6-600e85b4dc38/metadata"/>
<Description></Description>
<Configuration>
<IpScope>
@ -35,6 +32,5 @@
</Features>
<SyslogServerSettings/>
</Configuration>
<NetworkPool type="application/vnd.vmware.admin.networkPool+xml" name="vcdni01" href="https://vcloudbeta.bluelock.com/api/admin/extension/networkPool/e86bfdb5-b3e0-4ece-9125-e764ac64c95c"/>
<AllowedExternalIpAddresses/>
</OrgNetwork>