From 206af90b776724dfae38773fda6d7414b3f93d35 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 19 Aug 2012 15:23:20 -0700 Subject: [PATCH] Issue 830: refactored Org, Network, Task, User apis to support URN; removed 'id' from Reference type --- labs/vcloud-director/pom.xml | 2 + .../v1_5/domain/CatalogReference.java | 4 +- .../director/v1_5/domain/Reference.java | 73 +- .../director/v1_5/domain/RoleReference.java | 4 +- .../vcloud/director/v1_5/domain/Session.java | 6 +- .../vcloud/director/v1_5/domain/Task.java | 6 +- .../director/v1_5/domain/VAppReference.java | 4 +- .../query/QueryResultAdminGroupRecord.java | 6 +- .../query/QueryResultAdminUserRecord.java | 6 +- .../query/QueryResultAdminVdcRecord.java | 6 +- .../domain/query/QueryResultMediaRecord.java | 6 +- .../query/QueryResultVAppTemplateRecord.java | 6 +- .../director/v1_5/features/NetworkApi.java | 7 +- .../v1_5/features/NetworkAsyncApi.java | 19 +- .../vcloud/director/v1_5/features/OrgApi.java | 34 +- .../director/v1_5/features/OrgAsyncApi.java | 36 +- .../director/v1_5/features/TaskApi.java | 25 +- .../director/v1_5/features/TaskAsyncApi.java | 38 +- .../director/v1_5/features/VAppApi.java | 1 + .../vcloud/director/v1_5/features/VdcApi.java | 3 +- .../v1_5/features/admin/AdminCatalogApi.java | 47 +- .../features/admin/AdminCatalogAsyncApi.java | 55 +- .../v1_5/features/admin/AdminNetworkApi.java | 71 +- .../features/admin/AdminNetworkAsyncApi.java | 54 +- .../v1_5/features/admin/AdminOrgApi.java | 206 +++-- .../v1_5/features/admin/AdminOrgAsyncApi.java | 219 ++++- .../director/v1_5/features/admin/UserApi.java | 51 +- .../v1_5/features/admin/UserAsyncApi.java | 84 +- .../OrgReferenceToTaskListEndpoint.java | 63 -- .../v1_5/functions/OrgsForLocations.java | 75 +- .../director/v1_5/functions/OrgsForNames.java | 46 +- .../functions/href/NetworkURNToAdminHref.java | 43 + .../v1_5/functions/href/NetworkURNToHref.java | 43 + .../v1_5/functions/href/TaskURNToHref.java | 43 + .../functions/href/TasksListURNToHref.java | 43 + .../v1_5/functions/href/UserURNToHref.java | 43 + .../v1_5/predicates/EntityPredicates.java | 25 +- .../v1_5/predicates/LinkPredicates.java | 2 +- .../v1_5/predicates/TaskStatusEquals.java | 2 +- .../director/v1_5/predicates/TaskSuccess.java | 2 +- .../director/v1_5/user/VCloudDirectorApi.java | 2 +- .../director/v1_5/HttpClientLiveTest.java | 4 +- .../v1_5/VCloudDirectorApiLiveTest.java | 4 +- .../v1_5/VCloudDirectorLiveTestConstants.java | 2 +- .../vcloud/director/v1_5/domain/Checks.java | 4 +- .../v1_5/features/CatalogApiExpectTest.java | 2 +- .../v1_5/features/CatalogApiLiveTest.java | 6 +- .../v1_5/features/MediaApiExpectTest.java | 1 - .../v1_5/features/MediaApiLiveTest.java | 6 +- .../v1_5/features/NetworkApiExpectTest.java | 247 ++--- .../v1_5/features/NetworkApiLiveTest.java | 16 +- .../v1_5/features/OrgApiExpectTest.java | 243 +++-- .../v1_5/features/OrgApiLiveTest.java | 30 +- .../v1_5/features/QueryApiExpectTest.java | 4 - .../v1_5/features/TaskApiExpectTest.java | 301 +++--- .../v1_5/features/TaskApiLiveTest.java | 15 +- .../v1_5/features/VAppApiLiveTest.java | 17 +- .../v1_5/features/VAppNetworksLiveTest.java | 39 +- .../v1_5/features/VdcApiExpectTest.java | 1 - .../v1_5/features/VdcApiLiveTest.java | 11 +- .../director/v1_5/features/VmApiLiveTest.java | 10 +- .../admin/AdminCatalogApiExpectTest.java | 38 +- .../admin/AdminCatalogApiLiveTest.java | 38 +- .../admin/AdminNetworkApiExpectTest.java | 264 ++++-- .../admin/AdminNetworkApiLiveTest.java | 30 +- .../features/admin/AdminOrgApiExpectTest.java | 856 +++++++++--------- .../features/admin/AdminOrgApiLiveTest.java | 418 ++++----- .../features/admin/AdminVdcApiLiveTest.java | 4 +- .../features/admin/UserApiExpectTest.java | 280 ++++-- .../v1_5/features/admin/UserApiLiveTest.java | 41 +- .../BaseVCloudDirectorApiLiveTest.java | 111 ++- .../internal/VCloudDirectorTestSession.java | 6 +- .../v1_5/login/SessionApiLiveTest.java | 2 +- .../test/resources/media/cloneMediaParams.xml | 2 +- .../network/admin/resetNetworkTask.xml | 7 + .../network/admin/updateNetworkSource.xml | 10 +- 76 files changed, 2607 insertions(+), 1974 deletions(-) delete mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/OrgReferenceToTaskListEndpoint.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/href/NetworkURNToAdminHref.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/href/NetworkURNToHref.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/href/TaskURNToHref.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/href/TasksListURNToHref.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/href/UserURNToHref.java diff --git a/labs/vcloud-director/pom.xml b/labs/vcloud-director/pom.xml index 0d9de35ef5..acadb1c5e1 100644 --- a/labs/vcloud-director/pom.xml +++ b/labs/vcloud-director/pom.xml @@ -44,8 +44,10 @@ + + org.jclouds.vcloud.director.v1_5*;version="${project.version}" diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogReference.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogReference.java index 69b57d70b2..76904cce62 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogReference.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogReference.java @@ -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() { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Reference.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Reference.java index ee81e067c2..ba807117c1 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Reference.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Reference.java @@ -29,26 +29,24 @@ 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; /** * A reference to a resource. - * + * * Contains an href attribute and optional name and type attributes. *

+ * *

  * <xs:complexType name="ReferenceType">
  * 
- * + * * @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 { @@ -66,14 +64,13 @@ public class Reference { private static class ConcreteBuilder extends Builder { } - + public static class Builder> { private URI href; - private String id; private String name; private String type; - + @SuppressWarnings("unchecked") protected B self() { return (B) this; @@ -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 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; } @@ -165,29 +150,19 @@ public class Reference { * particular context. Although URLs have a well-known syntax and a well-understood * interpretation, a api should treat each href as an opaque string. The rules that govern how * the server constructs href strings might change in future releases. - * + * * @return an opaque reference and should never be parsed */ public URI getHref() { return href; } - /** - * The resource identifier, expressed in URN format. - *

- * 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. *

* The object type, specified as a MIME content type, of the object that the link references. * This attribute is present only for links to objects. It is not present for links to actions. - * + * * @return type definition, type, expressed as an HTTP Content-Type */ public String getName() { @@ -199,7 +174,7 @@ public class Reference { *

* The object type, specified as a MIME content type, of the object that the link references. * This attribute is present only for links to objects. It is not present for links to actions. - * + * * @return type definition, type, expressed as an HTTP Content-Type */ public String getType() { @@ -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"))) - .build(); + return toBuilder().type(null).href(URI.create(getHref().toASCIIString().replace(endpoint, endpoint + "/admin"))) + .build(); } } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/RoleReference.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/RoleReference.java index 2a9e54a009..f7850b65fe 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/RoleReference.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/RoleReference.java @@ -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() { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Session.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Session.java index 568c834f5b..fcb93190fe 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Session.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Session.java @@ -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; } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Task.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Task.java index 332a375161..c734ab28fe 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Task.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Task.java @@ -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; } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/VAppReference.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/VAppReference.java index 06f14d1d61..19cd9242ed 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/VAppReference.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/VAppReference.java @@ -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() { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultAdminGroupRecord.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultAdminGroupRecord.java index 083445a7d3..4880c13622 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultAdminGroupRecord.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultAdminGroupRecord.java @@ -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; } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultAdminUserRecord.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultAdminUserRecord.java index cc7c0a9d7f..159ace1b8e 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultAdminUserRecord.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultAdminUserRecord.java @@ -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; } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultAdminVdcRecord.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultAdminVdcRecord.java index a2cb3d97d9..4f53ebcba9 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultAdminVdcRecord.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultAdminVdcRecord.java @@ -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; } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultMediaRecord.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultMediaRecord.java index 475484e8e8..a6d32f099a 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultMediaRecord.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultMediaRecord.java @@ -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; } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultVAppTemplateRecord.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultVAppTemplateRecord.java index ba30b63ec0..04b52b31b6 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultVAppTemplateRecord.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultVAppTemplateRecord.java @@ -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; } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/NetworkApi.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/NetworkApi.java index 653110a3ed..f64065d36b 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/NetworkApi.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/NetworkApi.java @@ -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 diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/NetworkAsyncApi.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/NetworkAsyncApi.java index 49de11aad4..697ee8cb54 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/NetworkAsyncApi.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/NetworkAsyncApi.java @@ -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,18 +44,27 @@ 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 getNetwork(@EndpointParam URI networkUri); - + ListenableFuture get(@EndpointParam(parser = NetworkURNToHref.class) String networkUrn); + + /** + * @see NetworkApi#get(URI) + */ + @GET + @Consumes + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture get(@EndpointParam URI networkHref); + /** * @return asynchronous access to {@link Metadata.Readable} features */ @Delegate MetadataAsyncApi.Readable getMetadataApi(); - + } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgApi.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgApi.java index bf2bc32d02..b9f35a6b47 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgApi.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgApi.java @@ -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}. @@ -38,48 +38,28 @@ public interface OrgApi { /** * Retrieves a list of organizations. - * + * *

-    * GET /org
+    * GET / org
     * 
* * @return a list of organizations */ - OrgList getOrgList(); + OrgList list(); /** * Retrieves an organization. - * + * *
     * GET /org/{id}
     * 
* * @return the org or null if not found */ - Org getOrg(URI orgRef); + Org get(String orgUrn); - /** - * Modifies a catalog control access. - * - *
-    * POST /org/{id}/catalog/{catalogId}/action/controlAccess
-    * 
- * - * @return the control access information - */ - ControlAccessParams modifyControlAccess(URI orgRef, String catalogId, ControlAccessParams params); + Org get(URI orgHref); - /** - * Retrieves the catalog control access information. - * - *
-    * GET /org/{id}/catalog/{catalogId}/controlAccess
-    * 
- * - * @return the control access information - */ - ControlAccessParams getControlAccess(URI orgRef, String catalogId); - /** * @return synchronous access to {@link Metadata.Readable} features */ diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgAsyncApi.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgAsyncApi.java index eb776ac288..121ea8c6ea 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgAsyncApi.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgAsyncApi.java @@ -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 getOrgList(); + ListenableFuture list(); /** - * @see OrgApi#getOrg(URI) + * @see OrgApi#get(String) */ @GET @Consumes @JAXBResponseParser @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getOrg(@EndpointParam URI orgUri); + ListenableFuture 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 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 getControlAccess(@EndpointParam URI orgRef, - @PathParam("catalogId") String catalogId); + ListenableFuture get(@EndpointParam URI orgHref); /** * @return asynchronous access to {@link Metadata.Readable} features diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskApi.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskApi.java index 55357e55c2..78087c988a 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskApi.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskApi.java @@ -22,47 +22,56 @@ 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 { /** * Retrieves a list of tasks. - * + * *
     * GET /tasksList/{id}
     * 
* - * @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. - * + * *
     * GET /task/{id}
     * 
* * @return the task or null if not found */ - Task getTask(URI taskUri); + Task get(String taskUrn); + + Task get(URI taskHref); /** * Cancels a task. - * + * *
     * POST /task/{id}/action/cancel
     * 
*/ - void cancelTask(URI taskUri); + void cancel(String taskUrn); + + void cancel(URI taskHref); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskAsyncApi.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskAsyncApi.java index ee112d5d8f..e8f7a16578 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskAsyncApi.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskAsyncApi.java @@ -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 getTaskList(@EndpointParam(parser = OrgReferenceToTaskListEndpoint.class) URI orgURI); + ListenableFuture getTasksList(@EndpointParam URI tasksListHref); /** - * @see TaskApi#getTask(URI) + * @see TaskApi#get(String) */ @GET @Consumes @JAXBResponseParser @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getTask(@EndpointParam URI taskURI); - + ListenableFuture get(@EndpointParam(parser = TaskURNToHref.class) String taskUrn); + /** - * @see TaskApi#cancelTask(URI) + * @see TaskApi#get(URI) + */ + @GET + @Consumes + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture get(@EndpointParam URI taskURI); + + /** + * @see TaskApi#cancel(String) */ @POST @Path("/action/cancel") @Consumes @JAXBResponseParser - ListenableFuture cancelTask(@EndpointParam URI taskURI); + ListenableFuture cancel(@EndpointParam(parser = TaskURNToHref.class) String taskUrn); + + /** + * @see TaskApi#cancel(URI) + */ + @POST + @Path("/action/cancel") + @Consumes + @JAXBResponseParser + ListenableFuture cancel(@EndpointParam URI taskURI); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/VAppApi.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/VAppApi.java index 5d8bbb058a..9c56d728a0 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/VAppApi.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/VAppApi.java @@ -225,6 +225,7 @@ public interface VAppApi { * * @since 0.9 */ + //TODO: revise ControlAccessParams getControlAccess(URI vAppURI); /** diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/VdcApi.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/VdcApi.java index 5a049558c8..b5c4f46b04 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/VdcApi.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/VdcApi.java @@ -40,8 +40,7 @@ import org.jclouds.vcloud.director.v1_5.domain.params.UploadVAppTemplateParams; * Provides synchronous access to a vDC. * * @see VdcAsyncApi - * @see - * @author danikov + * @author danikov, Adrian Cole */ @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) public interface VdcApi { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminCatalogApi.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminCatalogApi.java index be6d248f90..d769b23b8e 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminCatalogApi.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminCatalogApi.java @@ -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,8 +120,12 @@ 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 * vCloud. @@ -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. + * + *
+    * POST /org/{id}/catalog/{catalogId}/action/controlAccess
+    * 
+ * + * @return the control access information + */ + ControlAccessParams modifyAccessControl(String catalogUrn, ControlAccessParams params); + + ControlAccessParams modifyAccessControl(URI catalogAdminHref, ControlAccessParams params); + + /** + * Retrieves the catalog control access information. + * + *
+    * GET /org/{id}/catalog/{catalogId}/controlAccess
+    * 
+ * + * @return the control access information + */ + ControlAccessParams getAccessControl(String catalogUrn); + + ControlAccessParams getAccessControl(URI catalogAdminHref); /** * @return synchronous access to {@link Metadata.Writeable} features diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminCatalogAsyncApi.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminCatalogAsyncApi.java index c2b50e511a..c01b803b0f 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminCatalogAsyncApi.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminCatalogAsyncApi.java @@ -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 update(@EndpointParam URI adminCatalogHref, + ListenableFuture update(@EndpointParam URI catalogAdminHref, @BinderParam(BindToXMLPayload.class) AdminCatalog catalog); /** @@ -132,7 +135,7 @@ public interface AdminCatalogAsyncApi extends CatalogAsyncApi { @DELETE @Consumes @JAXBResponseParser - ListenableFuture delete(@EndpointParam URI adminCatalogHref); + ListenableFuture delete(@EndpointParam URI catalogAdminHref); /** * @see AdminCatalogApi#getOwner(String) @@ -152,7 +155,7 @@ public interface AdminCatalogAsyncApi extends CatalogAsyncApi { @Consumes @JAXBResponseParser @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getOwner(@EndpointParam URI adminCatalogHref); + ListenableFuture getOwner(@EndpointParam URI catalogAdminHref); /** * @see AdminCatalogApi#setOwner(String, Owner) @@ -173,7 +176,7 @@ public interface AdminCatalogAsyncApi extends CatalogAsyncApi { @Consumes @Produces(VCloudDirectorMediaType.OWNER) @JAXBResponseParser - ListenableFuture setOwner(@EndpointParam URI adminCatalogHref, + ListenableFuture 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 publish(@EndpointParam URI adminCatalogHref, + ListenableFuture 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 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 modifyAccessControl(@EndpointParam URI catalogAdminHref, + @BinderParam(BindToXMLPayload.class) ControlAccessParams params); + + /** + * @see AdminCatalogApi#getAccessControl(String) + */ + @GET + @Path("/controlAccess") + @Consumes + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getAccessControl(@EndpointParam(parser = CatalogURNToAdminHref.class) String catalogUrn); + + /** + * @see AdminCatalogApi#getAccessControl(URI) + */ + @GET + @Path("/controlAccess") + @Consumes + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getAccessControl(@EndpointParam URI catalogAdminHref); + /** * @return synchronous access to {@link Metadata.Writeable} features */ diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminNetworkApi.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminNetworkApi.java index 241e5b2785..ba68607bb8 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminNetworkApi.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminNetworkApi.java @@ -33,61 +33,68 @@ 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. + * *
     * GET /admin/network/{id}
     * 
- * - * @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 - * + * *
     * PUT /admin/network/{id}
     * 
- * - * @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. + * *
     * POST /admin/network/{id}/action/reset
     * 
- * - * @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 - */ + * @return synchronous access to admin {@link MetadataApi.Writeable} features + */ @Override @Delegate MetadataApi.Writeable getMetadataApi(); diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminNetworkAsyncApi.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminNetworkAsyncApi.java index 76afd03263..39d58990b1 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminNetworkAsyncApi.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminNetworkAsyncApi.java @@ -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; @@ -51,36 +52,65 @@ import com.google.common.util.concurrent.ListenableFuture; */ @RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class) public interface AdminNetworkAsyncApi extends NetworkAsyncApi { - + /** - * @see AdminNetworkApi#getNetwork(URI) + * @see AdminNetworkApi#get(String) */ @Override @GET @Consumes @JAXBResponseParser @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getNetwork(@EndpointParam URI networkRef); - + ListenableFuture get(@EndpointParam(parser = NetworkURNToAdminHref.class) String networkUrn); + /** - * @see AdminNetworkApi#updateNetwork(URI, OrgNetwork) + * @see AdminNetworkApi#get(URI) + */ + @Override + @GET + @Consumes + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture get(@EndpointParam URI networkAdminHref); + + /** + * @see AdminNetworkApi#update(String, OrgNetwork) */ @PUT @Consumes(VCloudDirectorMediaType.TASK) @Produces(VCloudDirectorMediaType.ADMIN_ORG_NETWORK) @JAXBResponseParser - ListenableFuture updateNetwork(@EndpointParam URI networkRef, - @BinderParam(BindToXMLPayload.class) OrgNetwork network); - + ListenableFuture 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 update(@EndpointParam URI networkAdminHref, + @BinderParam(BindToXMLPayload.class) OrgNetwork network); + + /** + * @see AdminNetworkApi#reset(String) */ @POST @Path("/action/reset") @Consumes @JAXBResponseParser - ListenableFuture resetNetwork(@EndpointParam URI networkRef); - + ListenableFuture reset(@EndpointParam(parser = NetworkURNToAdminHref.class) String networkUrn); + + /** + * @see AdminNetworkApi#reset(URI) + */ + @POST + @Path("/action/reset") + @Consumes + @JAXBResponseParser + ListenableFuture reset(@EndpointParam URI networkAdminHref); + /** * @return asynchronous access to admin {@link MetadataAsyncApi.Writeable} features */ diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminOrgApi.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminOrgApi.java index 93610f8aa9..92f46f4b06 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminOrgApi.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminOrgApi.java @@ -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,193 +38,242 @@ 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. + * *
     * GET /admin/org/{id}
     * 
- * - * @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. - * + * *
     * GET /admin/org/{id}/settings
     * 
- * - * @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. * *
     * PUT /admin/org/{id}/settings
     * 
- * @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. - * + * *
     * GET /admin/org/{id}/settings/email
     * 
- * - * @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. * *
     * PUT /admin/org/{id}/settings/email
     * 
- * @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. - * + * *
     * GET /admin/org/{id}/settings/general
     * 
- * - * @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. * *
     * PUT /admin/org/{id}/settings/general
     * 
- * @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. - * + * *
     * GET /admin/org/{id}/settings/ldap
     * 
- * - * @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. - * + * *
     * GET /admin/org/{id}/settings/passwordPolicy
     * 
- * - * @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. * *
     * PUT /admin/org/{id}/settings/passwordPolicy
     * 
- * @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. - * + * *
     * GET /admin/org/{id}/settings/vAppLeaseSettings
     * 
- * - * @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. * *
     * PUT /admin/org/{id}/settings/vAppLeaseSettings
     * 
- * @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. - * + * *
     * GET /admin/org/{id}/settings/vAppTemplateLeaseSettings
     * 
- * - * @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. * *
     * PUT /admin/org/{id}/settings/vAppTemplateLeaseSettings
     * 
- * @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 */ - @Override - @Delegate - MetadataApi.Writeable getMetadataApi(); + @Override + @Delegate + MetadataApi.Writeable getMetadataApi(); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminOrgAsyncApi.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminOrgAsyncApi.java index 2cdc111917..945eafdb25 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminOrgAsyncApi.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminOrgAsyncApi.java @@ -46,26 +46,47 @@ 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 getOrg(@EndpointParam URI orgRef); - + ListenableFuture get(@EndpointParam(parser = OrgURNToAdminHref.class) String orgUrn); + + /** + * @see AdminOrgApi#get(URI) + */ + @Override + @GET + @Consumes + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture get(@EndpointParam URI adminOrgHref); + + /** + * @see AdminOrgApi#getSettings(String) + */ + @GET + @Path("/settings") + @Consumes + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture 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 getSettings(@EndpointParam URI orgRef); + ListenableFuture getSettings(@EndpointParam URI adminOrgHref); + + /** + * @see AdminOrgApi#updateSettings(String, OrgSettings) + */ + @PUT + @Path("/settings") + @Consumes(VCloudDirectorMediaType.ORG_SETTINGS) + @Produces(VCloudDirectorMediaType.ORG_SETTINGS) + @JAXBResponseParser + ListenableFuture 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 updateSettings(@EndpointParam URI orgRef, - @BinderParam(BindToXMLPayload.class) OrgSettings settings); - + ListenableFuture updateSettings(@EndpointParam URI adminOrgHref, + @BinderParam(BindToXMLPayload.class) OrgSettings settings); + + /** + * @see AdminOrgApi#getEmailSettings(String) + */ + @GET + @Path("/settings/email") + @Consumes + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture 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 getEmailSettings(@EndpointParam URI orgRef); + ListenableFuture 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 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 updateEmailSettings(@EndpointParam URI orgRef, - @BinderParam(BindToXMLPayload.class) OrgEmailSettings settings); - + ListenableFuture updateEmailSettings(@EndpointParam URI adminOrgHref, + @BinderParam(BindToXMLPayload.class) OrgEmailSettings settings); + + /** + * @see AdminOrgApi#getGeneralSettings(String) + */ + @GET + @Path("/settings/general") + @Consumes + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture 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 getGeneralSettings(@EndpointParam URI orgRef); + ListenableFuture 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 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 updateGeneralSettings( - @EndpointParam URI orgRef, - @BinderParam(BindToXMLPayload.class) OrgGeneralSettings settings); - + ListenableFuture updateGeneralSettings(@EndpointParam URI adminOrgHref, + @BinderParam(BindToXMLPayload.class) OrgGeneralSettings settings); + + /** + * @see AdminOrgApi#getPasswordPolicy(String) + */ + @GET + @Path("/settings/ldap") + @Consumes + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getLdapSettings(@EndpointParam(parser = OrgURNToAdminHref.class) String orgUrn); + /** * @see AdminOrgApi#getPasswordPolicy(URI) */ @@ -138,8 +224,19 @@ public interface AdminOrgAsyncApi extends OrgAsyncApi { @Consumes @JAXBResponseParser @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getLdapSettings(@EndpointParam URI orgRef); - + ListenableFuture getLdapSettings(@EndpointParam URI adminOrgHref); + + /** + * @see AdminOrgApi#getPasswordPolicy(String) + */ + @GET + @Path("/settings/passwordPolicy") + @Consumes + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture 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 getPasswordPolicy(@EndpointParam URI orgRef); + ListenableFuture 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 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 updatePasswordPolicy(@EndpointParam URI orgRef, - @BinderParam(BindToXMLPayload.class) OrgPasswordPolicySettings settings); - + ListenableFuture updatePasswordPolicy(@EndpointParam URI adminOrgHref, + @BinderParam(BindToXMLPayload.class) OrgPasswordPolicySettings settings); + + /** + * @see AdminOrgApi#getVAppLeaseSettings(String) + */ + @GET + @Path("/settings/vAppLeaseSettings") + @Consumes + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture 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 getVAppLeaseSettings(@EndpointParam URI orgRef); + ListenableFuture 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 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 updateVAppLeaseSettings(@EndpointParam URI orgRef, - @BinderParam(BindToXMLPayload.class) OrgLeaseSettings settings); - + ListenableFuture updateVAppLeaseSettings(@EndpointParam URI adminOrgHref, + @BinderParam(BindToXMLPayload.class) OrgLeaseSettings settings); + + /** + * @see AdminOrgApi#getVAppTemplateLeaseSettings(String) + */ + @GET + @Path("/settings/vAppTemplateLeaseSettings") + @Consumes + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture 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 getVAppTemplateLeaseSettings(@EndpointParam URI orgRef); + ListenableFuture 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 updateVAppTemplateLeaseSettings( + @EndpointParam(parser = OrgURNToAdminHref.class) String orgUrn, + @BinderParam(BindToXMLPayload.class) OrgVAppTemplateLeaseSettings settings); /** * @see AdminOrgApi#updateVAppTemplateLeaseSettings(URI, OrgVAppTemplateLeaseSettings) @@ -200,9 +355,9 @@ public interface AdminOrgAsyncApi extends OrgAsyncApi { @Consumes(VCloudDirectorMediaType.ORG_VAPP_TEMPLATE_LEASE_SETTINGS) @Produces(VCloudDirectorMediaType.ORG_VAPP_TEMPLATE_LEASE_SETTINGS) @JAXBResponseParser - ListenableFuture updateVAppTemplateLeaseSettings(@EndpointParam URI orgRef, - @BinderParam(BindToXMLPayload.class) OrgVAppTemplateLeaseSettings settings); - + ListenableFuture updateVAppTemplateLeaseSettings(@EndpointParam URI adminOrgHref, + @BinderParam(BindToXMLPayload.class) OrgVAppTemplateLeaseSettings settings); + /** * @return asynchronous access to admin {@link MetadataAsyncApi.Writeable} features */ diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/admin/UserApi.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/admin/UserApi.java index 05f8e9a62c..96d594e16b 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/admin/UserApi.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/admin/UserApi.java @@ -28,48 +28,57 @@ 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 { /** * Creates or imports a user in an organization. The user could be enabled or disabled. - * + * *
     * POST /admin/org/{id}/users
     * 
- * - * @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. - * + * *
     * GET /admin/user/{id}
     * 
- * - * @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. + * *
     * PUT /admin/user/{id}
     * 
- * - * @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,8 +86,10 @@ public interface UserApi { * DELETE /admin/catalog/{id} * */ - 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 * */ - void unlockUser(URI userRef); + void unlock(String userUrn); + + void unlock(URI userHref); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/admin/UserAsyncApi.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/admin/UserAsyncApi.java index c59c8b799e..70b9778ac1 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/admin/UserAsyncApi.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/admin/UserAsyncApi.java @@ -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 createUser(@EndpointParam URI userRef, - @BinderParam(BindToXMLPayload.class) User user); - + ListenableFuture 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 createUserInOrg(@BinderParam(BindToXMLPayload.class) User user, + @EndpointParam URI orgAdminHref); + + /** + * @see UserApi#get(String) */ @GET @Consumes @JAXBResponseParser @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getUser(@EndpointParam URI userRef); - + ListenableFuture get(@EndpointParam(parser = UserURNToHref.class) String userUrn); + /** - * @see UserApi#updateUser(URI, User) + * @see UserApi#get(URI) + */ + @GET + @Consumes + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture get(@EndpointParam URI userHref); + + /** + * @see UserApi#update(String, User) */ @PUT @Consumes(VCloudDirectorMediaType.USER) @Produces(VCloudDirectorMediaType.USER) @JAXBResponseParser - ListenableFuture updateUser(@EndpointParam URI userRef, - @BinderParam(BindToXMLPayload.class) User user); - + ListenableFuture 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 update(@EndpointParam URI userHref, @BinderParam(BindToXMLPayload.class) User user); + + /** + * @see UserApi#delete(String) */ @DELETE @Consumes @JAXBResponseParser - ListenableFuture deleteUser(@EndpointParam URI userRef); - + ListenableFuture delete(@EndpointParam(parser = UserURNToHref.class) String userUrn); + /** - * @see UserApi#unlockUser(URI) + * @see UserApi#delete(URI) + */ + @DELETE + @Consumes + @JAXBResponseParser + ListenableFuture delete(@EndpointParam URI userHref); + + /** + * @see UserApi#unlock(String) */ @POST @Path("/action/unlock") @Consumes @JAXBResponseParser - ListenableFuture unlockUser(@EndpointParam URI userRef); + ListenableFuture unlock(@EndpointParam(parser = UserURNToHref.class) String userUrn); + + /** + * @see UserApi#unlock(URI) + */ + @POST + @Path("/action/unlock") + @Consumes + @JAXBResponseParser + ListenableFuture unlock(@EndpointParam URI userHref); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/OrgReferenceToTaskListEndpoint.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/OrgReferenceToTaskListEndpoint.java deleted file mode 100644 index 4131b3c236..0000000000 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/OrgReferenceToTaskListEndpoint.java +++ /dev/null @@ -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 { - 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)); - }; -} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/OrgsForLocations.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/OrgsForLocations.java index 52346bde6d..334c9c5ba8 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/OrgsForLocations.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/OrgsForLocations.java @@ -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> { - @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 apply(Iterable from) { - - return transformParallel(Sets.newLinkedHashSet(transform(filter(from, new Predicate() { - - @Override - public boolean apply(Location input) { - return input.getScope() == LocationScope.ZONE; - } - - }), new Function() { - - @Override - public URI apply(Location from) { - return URI.create(from.getParent().getId()); - } - - })), new Function>() { - - @Override - public Future apply(URI from) { - return aapi.getOrgApi().getOrg(from); - } - - }, executor, null, logger, "organizations for uris"); + return from(from) + .filter(LocationPredicates.isZone()) + .transform(new Function() { + @Override + public String apply(Location from) { + return from.getParent().getId(); + } + }) + .transform(new Function() { + + @Override + public Org apply(String from) { + return api.getOrgApi().get(from); + } + + }); } } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/OrgsForNames.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/OrgsForNames.java index 33aebbdbac..5f307be8ca 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/OrgsForNames.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/OrgsForNames.java @@ -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> { - @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 apply(Iterable from) { - final Set orgs = sapi.getOrgApi().getOrgList(); - - return transformParallel(from, new Function>() { - + public Iterable apply(final Iterable from) { + return from(api.getOrgApi().list()).filter(new Predicate() { @Override - public Future apply(String from) { - return aapi.getOrgApi().getOrg(Iterables.find(orgs, nameEquals(from)).getHref()); + public boolean apply(Reference in) { + return Iterables.contains(from, in.getName()); + } + }).transform(new Function() { + + @Override + public Org apply(Reference in) { + return api.getOrgApi().get(in.getHref()); } - }, executor, null, logger, "organizations for names"); + }); } } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/href/NetworkURNToAdminHref.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/href/NetworkURNToAdminHref.java new file mode 100644 index 0000000000..bc5309c47b --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/href/NetworkURNToAdminHref.java @@ -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 resolveEntityCache) { + super(resolveEntityCache); + } + + @Override + protected String type() { + return VCloudDirectorMediaType.ADMIN_NETWORK; + } + +} \ No newline at end of file diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/href/NetworkURNToHref.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/href/NetworkURNToHref.java new file mode 100644 index 0000000000..076056f9fb --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/href/NetworkURNToHref.java @@ -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 resolveEntityCache) { + super(resolveEntityCache); + } + + @Override + protected String type() { + return VCloudDirectorMediaType.NETWORK; + } + +} \ No newline at end of file diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/href/TaskURNToHref.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/href/TaskURNToHref.java new file mode 100644 index 0000000000..5d28e2e7e4 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/href/TaskURNToHref.java @@ -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 resolveEntityCache) { + super(resolveEntityCache); + } + + @Override + protected String type() { + return VCloudDirectorMediaType.TASK; + } + +} \ No newline at end of file diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/href/TasksListURNToHref.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/href/TasksListURNToHref.java new file mode 100644 index 0000000000..5af7295b34 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/href/TasksListURNToHref.java @@ -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 resolveEntityCache) { + super(resolveEntityCache); + } + + @Override + protected String type() { + return VCloudDirectorMediaType.TASKS_LIST; + } + +} \ No newline at end of file diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/href/UserURNToHref.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/href/UserURNToHref.java new file mode 100644 index 0000000000..cf830fb245 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/href/UserURNToHref.java @@ -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 resolveEntityCache) { + super(resolveEntityCache); + } + + @Override + protected String type() { + return VCloudDirectorMediaType.USER; + } + +} \ No newline at end of file diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/predicates/EntityPredicates.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/predicates/EntityPredicates.java index bdd71dc257..aedf38101b 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/predicates/EntityPredicates.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/predicates/EntityPredicates.java @@ -30,9 +30,32 @@ 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 Predicate idEquals(final String id) { + checkNotNull(id, "id must be defined"); + + return new Predicate() { + @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. diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/predicates/LinkPredicates.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/predicates/LinkPredicates.java index 91187b49ca..a2af20f301 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/predicates/LinkPredicates.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/predicates/LinkPredicates.java @@ -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 relEquals(final String rel) { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/predicates/TaskStatusEquals.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/predicates/TaskStatusEquals.java index 2cd130426c..15cf4423f1 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/predicates/TaskStatusEquals.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/predicates/TaskStatusEquals.java @@ -67,7 +67,7 @@ public class TaskStatusEquals implements Predicate { 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; diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/predicates/TaskSuccess.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/predicates/TaskSuccess.java index 6456529781..e1059c53ac 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/predicates/TaskSuccess.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/predicates/TaskSuccess.java @@ -58,7 +58,7 @@ public class TaskSuccess implements Predicate { 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; diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/user/VCloudDirectorApi.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/user/VCloudDirectorApi.java index 5f5683b19e..cdbe8995cc 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/user/VCloudDirectorApi.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/user/VCloudDirectorApi.java @@ -54,7 +54,7 @@ public interface VCloudDirectorApi { * GET /entity/{id} * */ - Entity resolveEntity(String id); + Entity resolveEntity(String urn); /** * @return the current login session diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/HttpClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/HttpClientLiveTest.java index 64aad25a2f..427db4a991 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/HttpClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/HttpClientLiveTest.java @@ -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" }) diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorApiLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorApiLiveTest.java index dae7130131..b2e86fdf5c 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorApiLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorApiLiveTest.java @@ -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); } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorLiveTestConstants.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorLiveTestConstants.java index c1ee58df0e..f6f2ec040c 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorLiveTestConstants.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorLiveTestConstants.java @@ -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"; diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java index 6d4bcb35bc..fa1e6d1bc4 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java @@ -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); diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogApiExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogApiExpectTest.java index 699353937d..763593a51b 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogApiExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogApiExpectTest.java @@ -388,7 +388,7 @@ public class CatalogApiExpectTest extends VCloudDirectorApiExpectTest { VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, deleteItemMetadataEntry, deleteItemMetadataEntryResponse); assertEquals(api.getCatalogApi().getItemMetadataApi().deleteEntry(itemHref, "KEY"), deleteEntryTask()); } - + public static final Catalog catalog() { return Catalog.builder() .name("QunyingTestCatalog") diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogApiLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogApiLiveTest.java index 78147d8079..e5f5b9a7f4 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogApiLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogApiLiveTest.java @@ -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); diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaApiExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaApiExpectTest.java index a902e102ac..7b4edb5a36 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaApiExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaApiExpectTest.java @@ -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) diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaApiLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaApiLiveTest.java index efd405d670..4cdeb3b960 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaApiLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaApiLiveTest.java @@ -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.emptySet()).build(), String.format(GETTER_RETURNS_SAME_OBJ, diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkApiExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkApiExpectTest.java index 439d3bd3ec..b26d47a744 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkApiExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkApiExpectTest.java @@ -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. @@ -55,37 +63,40 @@ import com.google.common.collect.ImmutableSet; */ @Test(groups = { "unit", "user" }, singleThreaded = true, testName = "NetworkApiExpectTest") public class NetworkApiExpectTest extends VCloudDirectorAdminApiExpectTest { - - @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.toSubType(api.getNetworkApi().getNetwork(networkUri)), expected); + 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 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"); - - 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()); + @Test + public void testGetNetworkHrefInvalidId() { + + VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, + 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.") .majorErrorCode(400) @@ -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,91 +114,125 @@ 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"); - - 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() - .type("application/vnd.vmware.vcloud.metadata+xml") - .href(URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c/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")) - .build()) - .entries(ImmutableSet.of(MetadataEntry.builder().entry("key", "value").build())) - .build(); - - assertEquals(api.getNetworkApi().getMetadataApi().get(networkUri), expected); + public void testGetNetworkUrn() { + VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, resolveNetwork, resolveNetworkResponse, get, getResponse); + assertEquals(api.getNetworkApi().get(networkUrn), network()); } - @Test - public void testGetMetadataValue() { - URI networkUri = URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c"); - - 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() - .href(URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c/metadata/key")) - .link(Link.builder() - .rel("up") - .type("application/vnd.vmware.vcloud.metadata+xml") - .href(URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c/metadata")) - .build()) - .value("value") - .build(); - assertEquals(api.getNetworkApi().getMetadataApi().getValue(networkUri, "KEY"), expected); + 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(endpoint + "/network/" + network + "/metadata")) + .link(Link.builder() + .rel("up") + .type("application/vnd.vmware.vcloud.network+xml") + .href(networkHref) + .build()) + .entries(ImmutableSet.of(metadataEntry())) + .build(); } - public static OrgNetwork orgNetwork() { + 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 testGetNetworkMetadataEntryHref() { + VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, getMetadataValue, getMetadataValueResponse); + assertEquals(api.getNetworkApi().getMetadataApi().getValue(networkHref, "KEY"), metadataValue()); + } + + 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") + .type("application/vnd.vmware.vcloud.metadata+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c/metadata")) + .build()) + .value("value") + .build(); + } + + + public static OrgNetwork network() { return OrgNetwork.builder() .name("ilsolation01-Jclouds") .id("urn:vcloud:network:f3ba8256-6f48-4512-aad6-600e85b4dc38") diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkApiLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkApiLiveTest.java index bffe9f019d..d8c738ec31 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkApiLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkApiLiveTest.java @@ -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); diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgApiExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgApiExpectTest.java index 5924582355..98f2a29b91 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgApiExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgApiExpectTest.java @@ -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,130 +78,110 @@ public class OrgApiExpectTest extends VCloudDirectorAdminApiExpectTest { .build()) .build(); - assertEquals(api.getOrgApi().getOrgList(), expected); - } - - @Test - public void testGetOrgFromOrgListReference() { - VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, - getStandardRequest("GET", "/org/"), - getStandardPayloadResponse("/org/orglist.xml", VCloudDirectorMediaType.ORG_LIST)); - - 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") - .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"); - } - } - - @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)); - } - - @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)); + assertEquals(api.getOrgApi().list(), expected); } - @Test - public void testGetOrgMetadata() { - URI orgUri = URI.create(endpoint + "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"); - - 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() - .type("application/vnd.vmware.vcloud.metadata+xml") - .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/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")) - .build()) - .entries(ImmutableSet.of(metadataEntry())) + static String org = "6f312e42-cd2b-488d-a2bb-97519cd57ed0"; + static String orgUrn = "urn:vcloud:org:" + org; + static URI orgHref = URI.create(endpoint + "/org/" + org); + + HttpRequest get = HttpRequest.builder() + .method("GET") + .endpoint(orgHref) + .addHeader("Accept", "*/*") + .addHeader("x-vcloud-authorization", token) + .addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token) .build(); - - assertEquals(api.getOrgApi().getMetadataApi().get(orgUri), expected); + + HttpResponse getResponse = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResourceWithContentType("/org/org.xml", ORG + ";version=1.5")) + .build(); + + @Test + 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 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(); + public void testGetOrgUrn() { + VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, resolveOrg, resolveOrgResponse, get, getResponse); + assertEquals(api.getOrgApi().get(orgUrn), org()); + } + - assertEquals(api.getOrgApi().getMetadataApi().getValue(orgUri, "KEY"), expected); + 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 testGetOrgMetadataHref() { + VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, getMetadata, getMetadataResponse); + assertEquals(api.getOrgApi().getMetadataApi().get(orgHref), metadata()); } + static Metadata metadata() { + return Metadata.builder() + .type("application/vnd.vmware.vcloud.metadata+xml") + .href(URI.create(endpoint + "/org/" + org + "/metadata")) + .link(Link.builder() + .rel("up") + .type("application/vnd.vmware.vcloud.org+xml") + .href(orgHref) + .build()) + .entries(ImmutableSet.of(metadataEntry())) + .build(); + } + + 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 testGetOrgMetadataEntryHref() { + VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, getMetadataValue, getMetadataValueResponse); + assertEquals(api.getOrgApi().getMetadataApi().getValue(orgHref, "KEY"), metadataValue()); + } + public static Org org() { return Org.builder() .name("JClouds") diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgApiLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgApiLiveTest.java index 0457062c58..9e037bf76d 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgApiLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgApiLiveTest.java @@ -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,8 +116,10 @@ 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); if (adminContext != null) { @@ -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); - } } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryApiExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryApiExpectTest.java index dad3778421..782be36006 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryApiExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryApiExpectTest.java @@ -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(); diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskApiExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskApiExpectTest.java index 26e31436f7..a0091c8414 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskApiExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskApiExpectTest.java @@ -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,183 +43,140 @@ import org.testng.annotations.Test; */ @Test(groups = { "unit", "user" }, singleThreaded = true, testName = "TaskApiExpectTest") public class TaskApiExpectTest extends VCloudDirectorAdminApiExpectTest { - - @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(); - - 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") + 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(); + .addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token) + .build(); - HttpResponse orgResponse = HttpResponse.builder() + HttpResponse getTasksListResponse = HttpResponse.builder() .statusCode(200) - .payload(payloadFromResourceWithContentType("/org/org.xml", VCloudDirectorMediaType.TASKS_LIST + ";version=1.5")) + .payload(payloadFromResourceWithContentType("/task/tasksList.xml", TASKS_LIST + ";version=1.5")) .build(); - - VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse, orgRequest, orgResponse); - - TasksList expected = 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(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(); - - 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"); - } + public void testGetTasksListHref() { + VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, getTasksList, getTasksListResponse); + assertEquals(api.getTaskApi().getTasksList(tasksListHref), tasksList()); } - - @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() - .method("GET") - .endpoint(endpoint + "/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b") - .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")) - .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); - } - - @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 static Task taskOne() { - return Task.builder() - .type("application/vnd.vmware.vcloud.task+xml") - .name("task") - .id("urn:vcloud:task:5fcd2af3-d0ec-45ce-9451-8c585a2c766b") - .href(URI.create("https://vcloudbeta.bluelock.com/api/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b")) - .status("success") - .operation("Created Catalog QunyingTestCatalog(7212e451-76e1-4631-b2de-ba1dfd8080e4)") - .operationName("catalogCreateCatalog") - .startTime(dateService.iso8601DateParse("2012-02-07T00:16:28.450-05:00")) - .endTime(dateService.iso8601DateParse("2012-02-07T00:16:28.867-05:00")) - .expiryTime(dateService.iso8601DateParse("2012-05-07T00:16:28.450-04:00")) - .owner(Reference.builder() - .type("application/vnd.vmware.vcloud.catalog+xml") - .name("QunyingTestCatalog") - .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) - .build()) - .user(Reference.builder() - .type("application/vnd.vmware.admin.user+xml") - .name("JClouds") - .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) - .build()) - .org(Reference.builder() - .type("application/vnd.vmware.vcloud.org+xml") - .name("JClouds") - .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) - .build()) - .build(); + + 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(task()) + .task(taskTwo()) + .build(); } + static String task = "5fcd2af3-d0ec-45ce-9451-8c585a2c766b"; + static String taskUrn = "urn:vcloud:task:" + task; + static URI taskHref = URI.create(endpoint + "/task/" + task); + + HttpRequest get = HttpRequest.builder() + .method("GET") + .endpoint(taskHref) + .addHeader("Accept", "*/*") + .addHeader("x-vcloud-authorization", token) + .addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token) + .build(); + + HttpResponse getResponse = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResourceWithContentType("/task/task.xml", TASK + ";version=1.5")) + .build(); + + @Test + public void testGetTaskHref() { + VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, get, getResponse); + assertEquals(api.getTaskApi().get(taskHref), task()); + } + + 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") + .id("urn:vcloud:task:5fcd2af3-d0ec-45ce-9451-8c585a2c766b") + .href(URI.create("https://vcloudbeta.bluelock.com/api/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b")) + .status("success") + .operation("Created Catalog QunyingTestCatalog(7212e451-76e1-4631-b2de-ba1dfd8080e4)") + .operationName("catalogCreateCatalog") + .startTime(dateService.iso8601DateParse("2012-02-07T00:16:28.450-05:00")) + .endTime(dateService.iso8601DateParse("2012-02-07T00:16:28.867-05:00")) + .expiryTime(dateService.iso8601DateParse("2012-05-07T00:16:28.450-04:00")) + .owner(Reference.builder() + .type("application/vnd.vmware.vcloud.catalog+xml") + .name("QunyingTestCatalog") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) + .build()) + .user(Reference.builder() + .type("application/vnd.vmware.admin.user+xml") + .name("JClouds") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .build()) + .org(Reference.builder() + .type("application/vnd.vmware.vcloud.org+xml") + .name("JClouds") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .build()) + .build(); + } + + 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") diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskApiLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskApiLiveTest.java index d5d4828812..8f8db6c9d7 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskApiLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskApiLiveTest.java @@ -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)); } } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppApiLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppApiLiveTest.java index a43374373a..a36f32d147 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppApiLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppApiLiveTest.java @@ -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); diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppNetworksLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppNetworksLiveTest.java index 69df8f3556..04f8c6e26c 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppNetworksLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppNetworksLiveTest.java @@ -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 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 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 networks = vdc.getAvailableNetworks(); - - // Look up the network in the Vdc with the id configured for the tests - Optional parentNetwork = Iterables.tryFind(networks, new Predicate() { - @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 retrieveAllFirewallRules(NetworkFeatures networkFeatures) { Set firewallRules = Sets.newLinkedHashSet(); for (NetworkServiceType networkServiceType : networkFeatures.getNetworkServices()) { diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VdcApiExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VdcApiExpectTest.java index 8500b641df..f5b76c52c2 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VdcApiExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VdcApiExpectTest.java @@ -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) diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VdcApiLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VdcApiLiveTest.java index f0570561a1..60b282974b 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VdcApiLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VdcApiLiveTest.java @@ -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() { @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() diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VmApiLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VmApiLiveTest.java index b38a67496e..516bc43ff2 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VmApiLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VmApiLiveTest.java @@ -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()); } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminCatalogApiExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminCatalogApiExpectTest.java index a1924c5376..e38f8a307f 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminCatalogApiExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminCatalogApiExpectTest.java @@ -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 @@ -307,6 +307,8 @@ public class AdminCatalogApiExpectTest extends VCloudDirectorAdminApiExpectTest resolveCatalogResponse, deleteCatalog, deleteCatalogResponse); api.getCatalogApi().delete(catalogUrn); } + + //TODO: tests for access control! public static final AdminCatalog createCatalogInOrgSource() { return AdminCatalog.builder() diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminCatalogApiLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminCatalogApiLiveTest.java index 2489a0ea0d..ce924cf36b 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminCatalogApiLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminCatalogApiLiveTest.java @@ -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. 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() : "")); } + + } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminNetworkApiExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminNetworkApiExpectTest.java index a030f087af..e5f0d03fee 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminNetworkApiExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminNetworkApiExpectTest.java @@ -18,130 +18,234 @@ */ 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 { + + 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); - Reference networkRef = Reference.builder() - .href(URI.create(endpoint+"/admin/network/b466c0c5-8a5c-4335-b703-a2e2e6b5f3e1")) - .build(); + 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 testGetNetworkHref() { + VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, get, getResponse); + assertEquals(api.getNetworkApi().get(networkAdminHref), network()); + } + + 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() + .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 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 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(); - OrgNetwork expected = orgNetwork(); + HttpResponse updateResponse = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResourceWithContentType("/network/admin/updateNetworkTask.xml", TASK)) + .build(); - assertEquals(api.getNetworkApi().getNetwork(networkRef.getHref()), expected); + @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") - .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() - .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() - .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")) + @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")) + .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")) .build()) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.vcloud.metadata+xml") + .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() - - .build(); + .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(); } public final Task updateNetworkTask() { diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminNetworkApiLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminNetworkApiLiveTest.java index eebbaf4c4a..4708ed3635 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminNetworkApiLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminNetworkApiLiveTest.java @@ -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.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.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.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.toSubType(network)); // TODO: other assertions about the reset? that network is deployed when task is complete, for example diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminOrgApiExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminOrgApiExpectTest.java index 4032e6e999..372aac4907 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminOrgApiExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminOrgApiExpectTest.java @@ -39,234 +39,250 @@ 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 */ @Test(groups = { "unit", "user" }, singleThreaded = true, testName = "AdminOrgApiExpectTest") 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() - .httpRequestBuilder().build(), - new VcloudHttpResponsePrimer() - .xmlFilePayload("/org/admin/org.xml", - VCloudDirectorMediaType.ADMIN_ORG) - .httpResponseBuilder().build()); + 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) + .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() - .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() - .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() - .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() - .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() - .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() - .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() - .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() - .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() - .rel("remove") - .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) - .build()) - .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")) - .build()) - .description("") - .fullName("JClouds") - .isEnabled(true) - .settings(settings()) - .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() - .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() - .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() - .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() - .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() - .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() - .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() - .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() - .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() - .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() - .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() - .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(); + 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() + .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() + .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() + .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() + .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() + .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() + .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() + .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() + .rel("remove") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .build()) + .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")) + .build()) + .description("") + .fullName("JClouds") + .isEnabled(true) + .settings(settings()) + .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() + .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() + .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() + .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() + .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() + .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() + .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() + .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() + .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() + .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() + .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() + .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(); } - + @Test(enabled = false) public void testGetSettings() { - VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, - new VcloudHttpRequestPrimer() - .apiCommand("GET", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/") - .acceptAnyMedia() - .httpRequestBuilder().build(), - new VcloudHttpResponsePrimer() - .xmlFilePayload("/org/admin/settings.xml", - VCloudDirectorMediaType.ORG_SETTINGS) - .httpResponseBuilder().build()); + VCloudDirectorAdminApi api = requestsSendResponses( + loginRequest, + sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("GET", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/") + .acceptAnyMedia().httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/org/admin/settings.xml", VCloudDirectorMediaType.ORG_SETTINGS) + .httpResponseBuilder().build()); OrgSettings expected = settings(); assertEquals(api.getOrgApi().getSettings(orgRef.getHref()), expected); } - + @Test(enabled = false) public void testUpdateSettings() { - 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(), - new VcloudHttpResponsePrimer() - .xmlFilePayload("/org/admin/updateSettings.xml", - VCloudDirectorMediaType.ORG_SETTINGS) - .httpResponseBuilder().build()); + 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(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/org/admin/updateSettings.xml", VCloudDirectorMediaType.ORG_SETTINGS) + .httpResponseBuilder().build()); OrgSettings expected = updateSettings(); assertEquals(api.getOrgApi().updateSettings(orgRef.getHref(), expected), expected); } - + @Test public void testGetEmailSettings() { - VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, - new VcloudHttpRequestPrimer() - .apiCommand("GET", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/email") - .acceptAnyMedia() - .httpRequestBuilder().build(), - new VcloudHttpResponsePrimer() - .xmlFilePayload("/org/admin/emailSettings.xml", - VCloudDirectorMediaType.ORG_GENERAL_SETTINGS) - .httpResponseBuilder().build()); + VCloudDirectorAdminApi api = requestsSendResponses( + loginRequest, + sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("GET", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/email") + .acceptAnyMedia().httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/org/admin/emailSettings.xml", VCloudDirectorMediaType.ORG_GENERAL_SETTINGS) + .httpResponseBuilder().build()); OrgEmailSettings expected = emailSettings(); assertEquals(api.getOrgApi().getEmailSettings(orgRef.getHref()), expected); } - + @Test public void testUpdateEmailSettings() { - 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(), - new VcloudHttpResponsePrimer() - .xmlFilePayload("/org/admin/updateEmailSettings.xml", - VCloudDirectorMediaType.ORG_EMAIL_SETTINGS) - .httpResponseBuilder().build()); + 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(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/org/admin/updateEmailSettings.xml", + VCloudDirectorMediaType.ORG_EMAIL_SETTINGS).httpResponseBuilder().build()); OrgEmailSettings expected = updateEmailSettings(); assertEquals(api.getOrgApi().updateEmailSettings(orgRef.getHref(), expected), expected); } - + @Test(enabled = false) public void testGetGeneralSettings() { - VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, - new VcloudHttpRequestPrimer() - .apiCommand("GET", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/general") - .acceptAnyMedia() - .httpRequestBuilder().build(), - new VcloudHttpResponsePrimer() - .xmlFilePayload("/org/admin/generalSettings.xml", - VCloudDirectorMediaType.ORG_GENERAL_SETTINGS) - .httpResponseBuilder().build()); + VCloudDirectorAdminApi api = requestsSendResponses( + loginRequest, + sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("GET", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/general") + .acceptAnyMedia().httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/org/admin/generalSettings.xml", VCloudDirectorMediaType.ORG_GENERAL_SETTINGS) + .httpResponseBuilder().build()); OrgGeneralSettings expected = generalSettings(); @@ -274,335 +290,329 @@ public class AdminOrgApiExpectTest extends VCloudDirectorAdminApiExpectTest { } public static final OrgGeneralSettings generalSettings() { - 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() - .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(); + 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() + .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(); } - + @Test(enabled = false) public void testUpdateGeneralSettings() { - 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(), - new VcloudHttpResponsePrimer() - .xmlFilePayload("/org/admin/updateGeneralSettings.xml", - VCloudDirectorMediaType.ORG_GENERAL_SETTINGS) - .httpResponseBuilder().build()); + 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(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/org/admin/updateGeneralSettings.xml", + VCloudDirectorMediaType.ORG_GENERAL_SETTINGS).httpResponseBuilder().build()); OrgGeneralSettings expected = updateGeneralSettings(); assertEquals(api.getOrgApi().updateGeneralSettings(orgRef.getHref(), expected), expected); } - + public static final OrgGeneralSettings updateGeneralSettings() { return generalSettings().toBuilder() - - .build(); + + .build(); } - + @Test public void testGetLdapSettings() { - VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, - new VcloudHttpRequestPrimer() - .apiCommand("GET", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/ldap") - .acceptAnyMedia() - .httpRequestBuilder().build(), - new VcloudHttpResponsePrimer() - .xmlFilePayload("/org/admin/ldapSettings.xml", - VCloudDirectorMediaType.ORG_LDAP_SETTINGS) - .httpResponseBuilder().build()); + VCloudDirectorAdminApi api = requestsSendResponses( + loginRequest, + sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("GET", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/ldap") + .acceptAnyMedia().httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/org/admin/ldapSettings.xml", VCloudDirectorMediaType.ORG_LDAP_SETTINGS) + .httpResponseBuilder().build()); OrgLdapSettings expected = ldapSettings(); assertEquals(api.getOrgApi().getLdapSettings(orgRef.getHref()), expected); } - + public static final OrgLdapSettings ldapSettings() { - 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(); + 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(); } - + @Test public void testGetPasswordPolicy() { - VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, - new VcloudHttpRequestPrimer() - .apiCommand("GET", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/passwordPolicy") - .acceptAnyMedia() - .httpRequestBuilder().build(), - new VcloudHttpResponsePrimer() - .xmlFilePayload("/org/admin/passwordPolicy.xml", - VCloudDirectorMediaType.ORG_PASSWORD_POLICY_SETTINGS) - .httpResponseBuilder().build()); + VCloudDirectorAdminApi api = requestsSendResponses( + loginRequest, + sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("GET", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/passwordPolicy") + .acceptAnyMedia().httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/org/admin/passwordPolicy.xml", + VCloudDirectorMediaType.ORG_PASSWORD_POLICY_SETTINGS).httpResponseBuilder().build()); OrgPasswordPolicySettings expected = passwordPolicy(); assertEquals(api.getOrgApi().getPasswordPolicy(orgRef.getHref()), expected); } - + public static final OrgPasswordPolicySettings passwordPolicy() { - return OrgPasswordPolicySettings.builder() - .type("application/vnd.vmware.admin.organizationPasswordPolicySettings+xml") - .link(Link.builder() - .rel("edit") + return OrgPasswordPolicySettings + .builder() .type("application/vnd.vmware.admin.organizationPasswordPolicySettings+xml") + .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")) - .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, - 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(), - new VcloudHttpResponsePrimer() - .xmlFilePayload("/org/admin/updatePasswordPolicy.xml", - VCloudDirectorMediaType.ORG_PASSWORD_POLICY_SETTINGS) - .httpResponseBuilder().build()); + 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(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/org/admin/updatePasswordPolicy.xml", + VCloudDirectorMediaType.ORG_PASSWORD_POLICY_SETTINGS).httpResponseBuilder().build()); OrgPasswordPolicySettings expected = updateOrgPasswordPolicy(); assertEquals(api.getOrgApi().updatePasswordPolicy(orgRef.getHref(), expected), expected); } - + 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, - new VcloudHttpRequestPrimer() - .apiCommand("GET", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/vAppLeaseSettings") - .acceptAnyMedia() - .httpRequestBuilder().build(), - new VcloudHttpResponsePrimer() - .xmlFilePayload("/org/admin/vAppLeaseSettings.xml", - VCloudDirectorMediaType.ORG_LEASE_SETTINGS) - .httpResponseBuilder().build()); + VCloudDirectorAdminApi api = requestsSendResponses( + loginRequest, + sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("GET", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/vAppLeaseSettings") + .acceptAnyMedia().httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/org/admin/vAppLeaseSettings.xml", VCloudDirectorMediaType.ORG_LEASE_SETTINGS) + .httpResponseBuilder().build()); OrgLeaseSettings expected = vAppLeaseSettings(); assertEquals(api.getOrgApi().getVAppLeaseSettings(orgRef.getHref()), expected); } - + public static final OrgLeaseSettings vAppLeaseSettings() { - 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() - .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(); + 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() + .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(); } - + @Test(enabled = false) public void testUpdateOrgVAppLeaseSettings() { - 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(), - new VcloudHttpResponsePrimer() - .xmlFilePayload("/org/admin/updateVAppLeaseSettings.xml", - VCloudDirectorMediaType.ORG_LEASE_SETTINGS) - .httpResponseBuilder().build()); + 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(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/org/admin/updateVAppLeaseSettings.xml", + VCloudDirectorMediaType.ORG_LEASE_SETTINGS).httpResponseBuilder().build()); OrgLeaseSettings expected = updateVAppLeaseSettings(); assertEquals(api.getOrgApi().updateVAppLeaseSettings(orgRef.getHref(), expected), expected); } - + public static final OrgLeaseSettings updateVAppLeaseSettings() { return vAppLeaseSettings().toBuilder() - - .build(); + + .build(); } - + @Test(enabled = false) public void testGetVAppTemplateLeaseSettings() { - VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, - new VcloudHttpRequestPrimer() - .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()); + VCloudDirectorAdminApi api = requestsSendResponses( + loginRequest, + sessionResponse, + new VcloudHttpRequestPrimer() + .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()); OrgVAppTemplateLeaseSettings expected = vAppTemplateLeaseSettings(); assertEquals(api.getOrgApi().getVAppTemplateLeaseSettings(orgRef.getHref()), expected); } - + public static final OrgVAppTemplateLeaseSettings vAppTemplateLeaseSettings() { - 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() - .rel("edit") + 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")) - .build()) - .deleteOnStorageLeaseExpiration(false) - .storageLeaseSeconds(0) - .build(); + .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(); } - + @Test(enabled = false) public void testUpdateOrgVAppTemplateLeaseSettings() { - VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, - new VcloudHttpRequestPrimer() - .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(), - new VcloudHttpResponsePrimer() - .xmlFilePayload("/org/admin/updateVAppLeaseSettings.xml", - VCloudDirectorMediaType.ORG_VAPP_TEMPLATE_LEASE_SETTINGS) - .httpResponseBuilder().build()); + VCloudDirectorAdminApi api = requestsSendResponses( + loginRequest, + sessionResponse, + new VcloudHttpRequestPrimer() + .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(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/org/admin/updateVAppLeaseSettings.xml", + VCloudDirectorMediaType.ORG_VAPP_TEMPLATE_LEASE_SETTINGS).httpResponseBuilder() + .build()); OrgVAppTemplateLeaseSettings expected = updateVAppTemplateLeaseSettings(); assertEquals(api.getOrgApi().updateVAppTemplateLeaseSettings(orgRef.getHref(), expected), expected); } - + public static final OrgVAppTemplateLeaseSettings updateVAppTemplateLeaseSettings() { return vAppTemplateLeaseSettings().toBuilder() - - .build(); + + .build(); } - + public static final OrgSettings settings() { - 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() - .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() - .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() - .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() - .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() - .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() - .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() - .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(); + 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() + .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() + .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() + .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() + .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() + .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() + .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() + .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(); } - + @Test public static final OrgSettings updateSettings() { - return settings().toBuilder() - .build(); + return settings().toBuilder().build(); } - + public static final OrgEmailSettings emailSettings() { - 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() - .rel("edit") + 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")) - .build()) - .isDefaultSmtpServer(true) - .isDefaultOrgEmail(true) - .fromEmailAddress("") - .defaultSubjectPrefix("") - .isAlertEmailToAllAdmins(true) - .smtpServerSettings(SmtpServerSettings.builder() - .useAuthentication(false) - .host("") - .username("") - .password("") - .build()) - .build(); + .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")) + .build()) + .isDefaultSmtpServer(true) + .isDefaultOrgEmail(true) + .fromEmailAddress("") + .defaultSubjectPrefix("") + .isAlertEmailToAllAdmins(true) + .smtpServerSettings( + SmtpServerSettings.builder().useAuthentication(false).host("").username("").password("") + .build()).build(); } - + @Test public static final OrgEmailSettings updateEmailSettings() { - 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(); + 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(); } - + } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminOrgApiLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminOrgApiLiveTest.java index 3cbc14fb2d..bb3ba2171b 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminOrgApiLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminOrgApiLiveTest.java @@ -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,16 +36,14 @@ 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 */ @Test(groups = { "live", "admin" }, singleThreaded = true, testName = "AdminOrgApiLiveTest") public class AdminOrgApiLiveTest extends BaseVCloudDirectorApiLiveTest { - + public static final String ORG = "admin org"; /* @@ -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,338 +67,278 @@ 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(); String oldFromEmailAddress = emailSettings.getFromEmailAddress(); String newFromEmailAddress = "test@test.com"; String oldDefaultSubjectPrefix = emailSettings.getDefaultSubjectPrefix(); - String newDefaultSubjectPrefix = "new"+oldDefaultSubjectPrefix; + String newDefaultSubjectPrefix = "new" + oldDefaultSubjectPrefix; boolean isAlertEmailToAllAdmins = emailSettings.isAlertEmailToAllAdmins(); SmtpServerSettings oldSmtpServerSettings = emailSettings.getSmtpServerSettings(); SmtpServerSettings newSmtpServerSettings = oldSmtpServerSettings.toBuilder() - .useAuthentication(!oldSmtpServerSettings.useAuthentication()) - .host("new"+oldSmtpServerSettings.getHost()) - .username("new"+oldSmtpServerSettings.getUsername()) - .password("new"+oldSmtpServerSettings.getPassword()) - .build(); - + .useAuthentication(!oldSmtpServerSettings.useAuthentication()) + .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(); - - emailSettings = orgApi.updateEmailSettings( - orgRef.getHref(), newEmailSettings); - - assertTrue(equal(emailSettings.isDefaultSmtpServer(), !isDefaultSmtpServer), - String.format(OBJ_FIELD_UPDATABLE, - "emailSettings", "isDefaultSmtpServer")); - assertTrue(equal(emailSettings.isDefaultOrgEmail(), !isDefaultOrgEmail), - String.format(OBJ_FIELD_UPDATABLE, - "emailSettings", "isDefaultOrgEmail")); - assertTrue(equal(emailSettings.getFromEmailAddress(), newFromEmailAddress), - String.format(OBJ_FIELD_UPDATABLE, - "emailSettings", "fromEmailAddress")); - assertTrue(equal(emailSettings.getDefaultSubjectPrefix(), newDefaultSubjectPrefix), - String.format(OBJ_FIELD_UPDATABLE, - "emailSettings", "defaultSubjectPrefix")); - assertTrue(equal(emailSettings.isAlertEmailToAllAdmins(), !isAlertEmailToAllAdmins), - String.format(OBJ_FIELD_UPDATABLE, - "emailSettings", "isAlertEmailToAllAdmins")); - assertTrue(equal(emailSettings.getSmtpServerSettings(), newSmtpServerSettings), - String.format(OBJ_FIELD_UPDATABLE, - "emailSettings", "smtpServerSettings")); - - //TODO negative tests? - + OrgEmailSettings newEmailSettings = emailSettings.toBuilder().isDefaultSmtpServer(!isDefaultSmtpServer) + .isDefaultOrgEmail(!isDefaultOrgEmail).fromEmailAddress(newFromEmailAddress) + .defaultSubjectPrefix(newDefaultSubjectPrefix).isAlertEmailToAllAdmins(!isAlertEmailToAllAdmins) + .smtpServerSettings(newSmtpServerSettings).build(); + + emailSettings = orgApi.updateEmailSettings(org.getId(), newEmailSettings); + + assertTrue(equal(emailSettings.isDefaultSmtpServer(), !isDefaultSmtpServer), + String.format(OBJ_FIELD_UPDATABLE, "emailSettings", "isDefaultSmtpServer")); + assertTrue(equal(emailSettings.isDefaultOrgEmail(), !isDefaultOrgEmail), + String.format(OBJ_FIELD_UPDATABLE, "emailSettings", "isDefaultOrgEmail")); + assertTrue(equal(emailSettings.getFromEmailAddress(), newFromEmailAddress), + String.format(OBJ_FIELD_UPDATABLE, "emailSettings", "fromEmailAddress")); + assertTrue(equal(emailSettings.getDefaultSubjectPrefix(), newDefaultSubjectPrefix), + String.format(OBJ_FIELD_UPDATABLE, "emailSettings", "defaultSubjectPrefix")); + assertTrue(equal(emailSettings.isAlertEmailToAllAdmins(), !isAlertEmailToAllAdmins), + String.format(OBJ_FIELD_UPDATABLE, "emailSettings", "isAlertEmailToAllAdmins")); + assertTrue(equal(emailSettings.getSmtpServerSettings(), newSmtpServerSettings), + 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 = orgApi.updateEmailSettings( - orgRef.getHref(), emailSettings); + emailSettings = emailSettings.toBuilder().isDefaultSmtpServer(isDefaultSmtpServer) + .isDefaultOrgEmail(isDefaultOrgEmail).fromEmailAddress(oldFromEmailAddress) + .defaultSubjectPrefix(oldDefaultSubjectPrefix).isAlertEmailToAllAdmins(isAlertEmailToAllAdmins) + .smtpServerSettings(oldSmtpServerSettings).build(); + + 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(); + // boolean canPublishCatalogs = generalSettings.canPublishCatalogs(); Integer deployedVMQuota = generalSettings.getDeployedVMQuota(); Integer storedVmQuota = generalSettings.getStoredVmQuota(); boolean useServerBootSequence = generalSettings.useServerBootSequence(); Integer delayAfterPowerOnSeconds = generalSettings.getDelayAfterPowerOnSeconds(); - + try { - OrgGeneralSettings newGeneralSettings = generalSettings.toBuilder() - //.canPublishCatalogs(!canPublishCatalogs) - .deployedVMQuota(deployedVMQuota+1) - .storedVmQuota(storedVmQuota+1) - .useServerBootSequence(!useServerBootSequence) - .delayAfterPowerOnSeconds(delayAfterPowerOnSeconds+1) - .build(); - - generalSettings = orgApi.updateGeneralSettings( - orgRef.getHref(), 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")); - assertTrue(equal(generalSettings.getStoredVmQuota(), storedVmQuota+1), - String.format(OBJ_FIELD_UPDATABLE, - "generalSettings", "storedVmQuota")); - assertTrue(equal(generalSettings.useServerBootSequence(), !useServerBootSequence), - String.format(OBJ_FIELD_UPDATABLE, - "generalSettings", "useServerBootSequence")); - assertTrue(equal(generalSettings.getDelayAfterPowerOnSeconds(), delayAfterPowerOnSeconds+1), - String.format(OBJ_FIELD_UPDATABLE, - "generalSettings", "delayAfterPowerOnSeconds")); - - //TODO negative tests? - + OrgGeneralSettings newGeneralSettings = generalSettings + .toBuilder() + // .canPublishCatalogs(!canPublishCatalogs) + .deployedVMQuota(deployedVMQuota + 1).storedVmQuota(storedVmQuota + 1) + .useServerBootSequence(!useServerBootSequence).delayAfterPowerOnSeconds(delayAfterPowerOnSeconds + 1) + .build(); + + 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")); + assertTrue(equal(generalSettings.getStoredVmQuota(), storedVmQuota + 1), + String.format(OBJ_FIELD_UPDATABLE, "generalSettings", "storedVmQuota")); + assertTrue(equal(generalSettings.useServerBootSequence(), !useServerBootSequence), + String.format(OBJ_FIELD_UPDATABLE, "generalSettings", "useServerBootSequence")); + assertTrue(equal(generalSettings.getDelayAfterPowerOnSeconds(), delayAfterPowerOnSeconds + 1), + String.format(OBJ_FIELD_UPDATABLE, "generalSettings", "delayAfterPowerOnSeconds")); + + // TODO negative tests? + Checks.checkGeneralSettings(generalSettings); } finally { - generalSettings = generalSettings.toBuilder() -// .canPublishCatalogs(canPublishCatalogs) - .deployedVMQuota(deployedVMQuota) - .storedVmQuota(storedVmQuota) - .useServerBootSequence(useServerBootSequence) - .delayAfterPowerOnSeconds(delayAfterPowerOnSeconds) - .build(); - - generalSettings = orgApi.updateGeneralSettings( - orgRef.getHref(), generalSettings); + generalSettings = generalSettings + .toBuilder() + // .canPublishCatalogs(canPublishCatalogs) + .deployedVMQuota(deployedVMQuota).storedVmQuota(storedVmQuota) + .useServerBootSequence(useServerBootSequence).delayAfterPowerOnSeconds(delayAfterPowerOnSeconds) + .build(); + + 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(); Integer accountLockoutIntervalMinutes = passwordPolicy.getAccountLockoutIntervalMinutes(); - + try { OrgPasswordPolicySettings newPasswordPolicy = passwordPolicy.toBuilder() - .accountLockoutEnabled(!accountLockoutEnabled) - .invalidLoginsBeforeLockout(invalidLoginsBeforeLockout+1) - .accountLockoutIntervalMinutes(accountLockoutIntervalMinutes+1) - .build(); - - passwordPolicy = orgApi.updatePasswordPolicy( - orgRef.getHref(), newPasswordPolicy); - - assertTrue(equal(passwordPolicy.isAccountLockoutEnabled(), !accountLockoutEnabled), - String.format(OBJ_FIELD_UPDATABLE, - "PasswordPolicySettings", "deleteOnStorageLeaseExpiration")); - assertTrue(equal(passwordPolicy.getInvalidLoginsBeforeLockout(), invalidLoginsBeforeLockout+1), - String.format(OBJ_FIELD_UPDATABLE, - "PasswordPolicySettings", "storageLeaseSeconds")); - assertTrue(equal(passwordPolicy.getAccountLockoutIntervalMinutes(), accountLockoutIntervalMinutes+1), - String.format(OBJ_FIELD_UPDATABLE, - "PasswordPolicySettings", "deploymentLeaseSeconds")); - - //TODO negative tests? - + .accountLockoutEnabled(!accountLockoutEnabled) + .invalidLoginsBeforeLockout(invalidLoginsBeforeLockout + 1) + .accountLockoutIntervalMinutes(accountLockoutIntervalMinutes + 1).build(); + + passwordPolicy = orgApi.updatePasswordPolicy(org.getId(), newPasswordPolicy); + + assertTrue(equal(passwordPolicy.isAccountLockoutEnabled(), !accountLockoutEnabled), + String.format(OBJ_FIELD_UPDATABLE, "PasswordPolicySettings", "deleteOnStorageLeaseExpiration")); + assertTrue(equal(passwordPolicy.getInvalidLoginsBeforeLockout(), invalidLoginsBeforeLockout + 1), + String.format(OBJ_FIELD_UPDATABLE, "PasswordPolicySettings", "storageLeaseSeconds")); + assertTrue(equal(passwordPolicy.getAccountLockoutIntervalMinutes(), accountLockoutIntervalMinutes + 1), + String.format(OBJ_FIELD_UPDATABLE, "PasswordPolicySettings", "deploymentLeaseSeconds")); + + // TODO negative tests? + Checks.checkPasswordPolicySettings(passwordPolicy); } finally { - passwordPolicy = passwordPolicy.toBuilder() - .accountLockoutEnabled(accountLockoutEnabled) - .invalidLoginsBeforeLockout(invalidLoginsBeforeLockout) - .accountLockoutIntervalMinutes(accountLockoutIntervalMinutes) - .build(); - - passwordPolicy = orgApi.updatePasswordPolicy( - orgRef.getHref(), passwordPolicy); + passwordPolicy = passwordPolicy.toBuilder().accountLockoutEnabled(accountLockoutEnabled) + .invalidLoginsBeforeLockout(invalidLoginsBeforeLockout) + .accountLockoutIntervalMinutes(accountLockoutIntervalMinutes).build(); + + 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(); Integer deploymentLeaseSeconds = vAppLeaseSettings.getDeploymentLeaseSeconds(); - + try { OrgLeaseSettings newVAppLeaseSettings = vAppLeaseSettings.toBuilder() - .deleteOnStorageLeaseExpiration(!deleteOnStorageLeaseExpiration) - .storageLeaseSeconds(storageLeaseSeconds+1) - .deploymentLeaseSeconds(deploymentLeaseSeconds+1) - .build(); - - vAppLeaseSettings = orgApi.updateVAppLeaseSettings( - orgRef.getHref(), newVAppLeaseSettings); - - assertTrue(equal(vAppLeaseSettings.deleteOnStorageLeaseExpiration(), !deleteOnStorageLeaseExpiration), - String.format(OBJ_FIELD_UPDATABLE, - "vAppLeaseSettings", "deleteOnStorageLeaseExpiration")); - assertTrue(equal(vAppLeaseSettings.getStorageLeaseSeconds(), storageLeaseSeconds+1), - String.format(OBJ_FIELD_UPDATABLE, - "vAppLeaseSettings", "storageLeaseSeconds")); - assertTrue(equal(vAppLeaseSettings.getDeploymentLeaseSeconds(), deploymentLeaseSeconds+1), - String.format(OBJ_FIELD_UPDATABLE, - "vAppLeaseSettings", "deploymentLeaseSeconds")); - - //TODO negative tests? - + .deleteOnStorageLeaseExpiration(!deleteOnStorageLeaseExpiration) + .storageLeaseSeconds(storageLeaseSeconds + 1).deploymentLeaseSeconds(deploymentLeaseSeconds + 1) + .build(); + + vAppLeaseSettings = orgApi.updateVAppLeaseSettings(org.getId(), newVAppLeaseSettings); + + assertTrue(equal(vAppLeaseSettings.deleteOnStorageLeaseExpiration(), !deleteOnStorageLeaseExpiration), + String.format(OBJ_FIELD_UPDATABLE, "vAppLeaseSettings", "deleteOnStorageLeaseExpiration")); + assertTrue(equal(vAppLeaseSettings.getStorageLeaseSeconds(), storageLeaseSeconds + 1), + String.format(OBJ_FIELD_UPDATABLE, "vAppLeaseSettings", "storageLeaseSeconds")); + assertTrue(equal(vAppLeaseSettings.getDeploymentLeaseSeconds(), deploymentLeaseSeconds + 1), + String.format(OBJ_FIELD_UPDATABLE, "vAppLeaseSettings", "deploymentLeaseSeconds")); + + // TODO negative tests? + Checks.checkVAppLeaseSettings(vAppLeaseSettings); } finally { vAppLeaseSettings = vAppLeaseSettings.toBuilder() - .deleteOnStorageLeaseExpiration(deleteOnStorageLeaseExpiration) - .storageLeaseSeconds(storageLeaseSeconds) - .deploymentLeaseSeconds(deploymentLeaseSeconds) - .build(); - - vAppLeaseSettings = orgApi.updateVAppLeaseSettings( - orgRef.getHref(), vAppLeaseSettings); + .deleteOnStorageLeaseExpiration(deleteOnStorageLeaseExpiration) + .storageLeaseSeconds(storageLeaseSeconds).deploymentLeaseSeconds(deploymentLeaseSeconds).build(); + + 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(); - + try { OrgVAppTemplateLeaseSettings newVAppTemplateLeaseSettings = vAppTemplateLeaseSettings.toBuilder() - .deleteOnStorageLeaseExpiration(!deleteOnStorageLeaseExpiration) - .storageLeaseSeconds(storageLeaseSeconds+1) - .build(); - - vAppTemplateLeaseSettings = orgApi.updateVAppTemplateLeaseSettings( - orgRef.getHref(), newVAppTemplateLeaseSettings); - - assertTrue(equal(vAppTemplateLeaseSettings.deleteOnStorageLeaseExpiration(), !deleteOnStorageLeaseExpiration), - String.format(OBJ_FIELD_UPDATABLE, - "vAppTemplateLeaseSettings", "deleteOnStorageLeaseExpiration")); - assertTrue(equal(vAppTemplateLeaseSettings.getStorageLeaseSeconds(), storageLeaseSeconds+1), - String.format(OBJ_FIELD_UPDATABLE, - "vAppTemplateLeaseSettings", "storageLeaseSeconds")); - - //TODO negative tests? - + .deleteOnStorageLeaseExpiration(!deleteOnStorageLeaseExpiration) + .storageLeaseSeconds(storageLeaseSeconds + 1).build(); + + vAppTemplateLeaseSettings = orgApi.updateVAppTemplateLeaseSettings(org.getId(), newVAppTemplateLeaseSettings); + + assertTrue(equal(vAppTemplateLeaseSettings.deleteOnStorageLeaseExpiration(), !deleteOnStorageLeaseExpiration), + String.format(OBJ_FIELD_UPDATABLE, "vAppTemplateLeaseSettings", "deleteOnStorageLeaseExpiration")); + assertTrue(equal(vAppTemplateLeaseSettings.getStorageLeaseSeconds(), storageLeaseSeconds + 1), + String.format(OBJ_FIELD_UPDATABLE, "vAppTemplateLeaseSettings", "storageLeaseSeconds")); + + // TODO negative tests? + Checks.checkVAppTemplateLeaseSettings(vAppTemplateLeaseSettings); } finally { vAppTemplateLeaseSettings = vAppTemplateLeaseSettings.toBuilder() - .deleteOnStorageLeaseExpiration(deleteOnStorageLeaseExpiration) - .storageLeaseSeconds(storageLeaseSeconds) - .build(); - - vAppTemplateLeaseSettings = orgApi.updateVAppTemplateLeaseSettings( - orgRef.getHref(), vAppTemplateLeaseSettings); + .deleteOnStorageLeaseExpiration(deleteOnStorageLeaseExpiration) + .storageLeaseSeconds(storageLeaseSeconds).build(); + + 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"; + 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(); - - OrgSettings modified = orgApi.updateSettings( - orgRef.getHref(), newSettings); - + .emailSettings(emailSettings.toBuilder().fromEmailAddress(newFromEmailAddress).build()).build(); + + OrgSettings modified = orgApi.updateSettings(org.getId(), newSettings); + Checks.checkOrgSettings(settings); - assertTrue(equal(modified.getEmailSettings().getFromEmailAddress(), newFromEmailAddress), - String.format(OBJ_FIELD_UPDATABLE, - "orgSettings", "emailSettings")); - + assertTrue(equal(modified.getEmailSettings().getFromEmailAddress(), newFromEmailAddress), + String.format(OBJ_FIELD_UPDATABLE, "orgSettings", "emailSettings")); + } catch (Exception e) { exception = e; } finally { try { - OrgSettings restorableSettings = OrgSettings.builder() - .emailSettings(emailSettings) - .build(); - - settings = orgApi.updateSettings( - orgRef.getHref(), restorableSettings); + OrgSettings restorableSettings = OrgSettings.builder().emailSettings(emailSettings).build(); + + settings = orgApi.updateSettings(org.getId(), restorableSettings); } catch (Exception e) { if (exception != null) { logger.warn(e, "Error resetting settings; rethrowing original test exception..."); diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminVdcApiLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminVdcApiLiveTest.java index f981cddbe5..cc24e15f12 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminVdcApiLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminVdcApiLiveTest.java @@ -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); } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/UserApiExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/UserApiExpectTest.java index 1eacc743b9..89d4e05254 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/UserApiExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/UserApiExpectTest.java @@ -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")) - .build(); + 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 Reference userRef = Reference.builder() - .href(URI.create(endpoint + "/admin/user/b37223f3-8792-477a-820f-334998f61cd6")) - .build(); + 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 HttpResponse createResponse = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResourceWithContentType("/user/createUser.xml", USER + ";version=1.5")) + .build(); + + @Test + public void testCreateUserHref() { + VCloudDirectorAdminApi api = requestsSendResponses(loginRequest, sessionResponse, create, createResponse); + assertEquals(api.getUserApi().createUserInOrg(createUserSource(), orgAdminHref), 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(); + + 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 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 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(); - User source = createUserSource(); - User expected = createUser(); + 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(); - assertEquals(api.getUserApi().createUser(orgRef.getHref(), source), expected); + 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()); - } } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/UserApiLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/UserApiLiveTest.java index a7f0982545..d198570318 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/UserApiLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/UserApiLiveTest.java @@ -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); } } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorApiLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorApiLiveTest.java index e883675432..4176d4fe69 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorApiLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorApiLiveTest.java @@ -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 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 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. nameEquals(session.getOrg())).getHref()); + org = context.getApi().getOrgApi().get( + find(context.getApi().getOrgApi().list(), + ReferencePredicates. nameEquals(session.get())).getHref()); + + if (any(Lists.newArrayList(vAppTemplateURI, networkUrn, vdcURI), Predicates.isNull())) { if (vdcURI == null) - vdcURI = Iterables.find(thisOrg.getLinks(), - ReferencePredicates. typeEquals(VCloudDirectorMediaType.VDC)).getHref(); + vdcURI = find(org.getLinks(), + ReferencePredicates. typeEquals(VDC)).getHref(); - if (networkURI == null) - networkURI = Iterables.find(thisOrg.getLinks(), - ReferencePredicates. typeEquals(VCloudDirectorMediaType.ORG_NETWORK)).getHref(); + if (networkUrn == null) { + network = context.getApi().getNetworkApi().get(find(org.getLinks(), + ReferencePredicates. typeEquals(ORG_NETWORK)).getHref()); + networkUrn = network.getId(); + } // FIXME the URI should be opaque - if (Strings.isNullOrEmpty(catalogUrn)) { - String uri = Iterables.find(thisOrg.getLinks(), - ReferencePredicates. typeEquals(VCloudDirectorMediaType.CATALOG)).getHref().toASCIIString(); - catalogUrn = Iterables.getLast(Splitter.on('/').split(uri)); + if (isNullOrEmpty(catalogUrn)) { + String uri = find(org.getLinks(), + ReferencePredicates. 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() { + + @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 networks = vdc.getAvailableNetworks(); // Look up the network in the Vdc with the id configured for the tests - Optional parentNetwork = Iterables.tryFind(networks, new Predicate() { + Optional parentNetwork = tryFind(networks, new Predicate() { @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 diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/VCloudDirectorTestSession.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/VCloudDirectorTestSession.java index df425316e2..1fb805772f 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/VCloudDirectorTestSession.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/VCloudDirectorTestSession.java @@ -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(); diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/login/SessionApiLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/login/SessionApiLiveTest.java index 04465c1c9e..ec6cbf44cb 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/login/SessionApiLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/login/SessionApiLiveTest.java @@ -72,7 +72,7 @@ public class SessionApiLiveTest extends BaseContextLiveTest 0); assertNotNull(sessionWithToken.getToken()); } diff --git a/labs/vcloud-director/src/test/resources/media/cloneMediaParams.xml b/labs/vcloud-director/src/test/resources/media/cloneMediaParams.xml index 4081d718b4..fa767b0aae 100644 --- a/labs/vcloud-director/src/test/resources/media/cloneMediaParams.xml +++ b/labs/vcloud-director/src/test/resources/media/cloneMediaParams.xml @@ -1,6 +1,6 @@ moved by testCloneMedia() - + false diff --git a/labs/vcloud-director/src/test/resources/network/admin/resetNetworkTask.xml b/labs/vcloud-director/src/test/resources/network/admin/resetNetworkTask.xml index e69de29bb2..16dbd18556 100644 --- a/labs/vcloud-director/src/test/resources/network/admin/resetNetworkTask.xml +++ b/labs/vcloud-director/src/test/resources/network/admin/resetNetworkTask.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/labs/vcloud-director/src/test/resources/network/admin/updateNetworkSource.xml b/labs/vcloud-director/src/test/resources/network/admin/updateNetworkSource.xml index 81d08a6175..41363dccdd 100644 --- a/labs/vcloud-director/src/test/resources/network/admin/updateNetworkSource.xml +++ b/labs/vcloud-director/src/test/resources/network/admin/updateNetworkSource.xml @@ -1,10 +1,7 @@ - - - - - - + + + @@ -35,6 +32,5 @@ - \ No newline at end of file