From e764785219d6f7757665165c45b4deffcc45f1ba Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Fri, 17 Feb 2012 01:07:57 +0000 Subject: [PATCH 01/13] Query client and domain objects --- .../v1_5/VCloudDirectorAsyncClient.java | 7 + .../director/v1_5/VCloudDirectorClient.java | 11 +- .../v1_5/VCloudDirectorMediaType.java | 4 +- .../VCloudDirectorRestClientModule.java | 7 +- .../director/v1_5/domain/EntityType.java | 8 +- .../director/v1_5/domain/ResourceEntity.java | 258 +++++ .../director/v1_5/domain/ResourceType.java | 1 - .../vcloud/director/v1_5/domain/User.java | 924 ++++++++++++++++++ .../v1_5/domain/query/ContainerType.java | 238 +++++ .../query/QueryResultCatalogRecord.java | 406 ++++++++ .../query/QueryResultNetworkRecord.java | 358 +++++++ .../domain/query/QueryResultRecordType.java | 238 +++++ .../v1_5/domain/query/QueryResultRecords.java | 212 ++++ .../v1_5/domain/vapp/AbstractVAppType.java | 177 ++++ .../director/v1_5/domain/vapp/VApp.java | 279 ++++++ .../v1_5/features/QueryAsyncClient.java | 76 ++ .../director/v1_5/features/QueryClient.java | 62 ++ .../v1_5/features/CatalogClientLiveTest.java | 65 +- .../v1_5/features/QueryClientExpectTest.java | 52 + .../v1_5/features/QueryClientLiveTest.java | 67 ++ .../BaseVCloudDirectorClientLiveTest.java | 1 + .../src/test/resources/query/allCatalogs.xml | 8 + 22 files changed, 3403 insertions(+), 56 deletions(-) create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceEntity.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/User.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/ContainerType.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultCatalogRecord.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultNetworkRecord.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultRecordType.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultRecords.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/vapp/AbstractVAppType.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/vapp/VApp.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryAsyncClient.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryClient.java create mode 100644 labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientExpectTest.java create mode 100644 labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientLiveTest.java create mode 100644 labs/vcloud-director/src/test/resources/query/allCatalogs.xml diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorAsyncClient.java index d52451b1b9..2b445387b9 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorAsyncClient.java @@ -23,6 +23,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Session; import org.jclouds.vcloud.director.v1_5.features.CatalogAsyncClient; import org.jclouds.vcloud.director.v1_5.features.NetworkAsyncClient; import org.jclouds.vcloud.director.v1_5.features.OrgAsyncClient; +import org.jclouds.vcloud.director.v1_5.features.QueryAsyncClient; import org.jclouds.vcloud.director.v1_5.features.TaskAsyncClient; import com.google.inject.Provides; @@ -42,6 +43,12 @@ public interface VCloudDirectorAsyncClient { @Provides Session getCurrentSession(); + /** + * @return asynchronous access to query features + */ + @Delegate + QueryAsyncClient getQueryClient(); + /** * @return asynchronous access to {@link Org} features */ diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java index 096e0737c5..b64c125f65 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java @@ -27,13 +27,13 @@ import org.jclouds.vcloud.director.v1_5.features.CatalogClient; import org.jclouds.vcloud.director.v1_5.features.MediaClient; import org.jclouds.vcloud.director.v1_5.features.NetworkClient; import org.jclouds.vcloud.director.v1_5.features.OrgClient; +import org.jclouds.vcloud.director.v1_5.features.QueryClient; import org.jclouds.vcloud.director.v1_5.features.TaskClient; import com.google.inject.Provides; /** * Provides synchronous access to VCloudDirector. - *

* * @see VCloudDirectorAsyncClient * @author Adrian Cole @@ -41,12 +41,17 @@ import com.google.inject.Provides; @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) public interface VCloudDirectorClient { /** - * * @return the current login session */ @Provides Session getCurrentSession(); - + + /** + * @return asynchronous access to query features + */ + @Delegate + QueryClient getQueryClient(); + /** * @return synchronous access to {@link Org} features */ diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java index eae847ebd3..909d347cb6 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java @@ -73,10 +73,12 @@ public class VCloudDirectorMediaType { public static final String ADMIN_USER = "application/vnd.vmware.admin.user+xml"; + public static final String QUERY_RESULT_RECORDS = "application/vnd.vmware.vcloud.query.records+xml"; + public static final List ALL = Arrays.asList( SESSION, ERROR, ORG_LIST, METADATA, METADATA_ENTRY, METADATA_VALUE, ORG, TASKS_LIST, TASK, ORG_NETWORK, CATALOG, CATALOG_ITEM, CATALOG_ITEMS, CATALOGS_LIST, PROPERTY, - MEDIA, OWNER, VDC, ADMIN_USER + MEDIA, OWNER, VDC, ADMIN_USER, QUERY_RESULT_RECORDS ); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java index 104fb3f359..da1ea4dd89 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java @@ -17,8 +17,8 @@ */ package org.jclouds.vcloud.director.v1_5.config; -import static com.google.common.base.Throwables.propagate; -import static org.jclouds.rest.config.BinderUtils.bindClientAndAsyncClient; +import static com.google.common.base.Throwables.*; +import static org.jclouds.rest.config.BinderUtils.*; import java.net.URI; import java.util.Map; @@ -50,6 +50,8 @@ import org.jclouds.vcloud.director.v1_5.features.NetworkAsyncClient; import org.jclouds.vcloud.director.v1_5.features.NetworkClient; import org.jclouds.vcloud.director.v1_5.features.OrgAsyncClient; import org.jclouds.vcloud.director.v1_5.features.OrgClient; +import org.jclouds.vcloud.director.v1_5.features.QueryAsyncClient; +import org.jclouds.vcloud.director.v1_5.features.QueryClient; import org.jclouds.vcloud.director.v1_5.features.TaskAsyncClient; import org.jclouds.vcloud.director.v1_5.features.TaskClient; import org.jclouds.vcloud.director.v1_5.functions.LoginUserInOrgWithPassword; @@ -82,6 +84,7 @@ public class VCloudDirectorRestClientModule extends RestClientModule> extends ResourceType { } /** - * @see ReferenceType#getHref() + * @see ResourceType#getHref() */ @Override public Builder href(URI href) { @@ -114,7 +114,7 @@ public class EntityType> extends ResourceType { } /** - * @see ReferenceType#getType() + * @see ResourceType#getType() */ @Override public Builder type(String type) { @@ -123,7 +123,7 @@ public class EntityType> extends ResourceType { } /** - * @see ReferenceType#getLinks() + * @see ResourceType#getLinks() */ @Override public Builder links(Set links) { @@ -132,7 +132,7 @@ public class EntityType> extends ResourceType { } /** - * @see ReferenceType#getLinks() + * @see ResourceType#getLinks() */ @Override public Builder link(Link link) { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceEntity.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceEntity.java new file mode 100644 index 0000000000..5d339e20ab --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceEntity.java @@ -0,0 +1,258 @@ +/** + * 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.domain; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlSeeAlso; +import javax.xml.bind.annotation.XmlType; + + +/** + * + * Base type that represents a resource entity such as a vApp + * template or virtual media. + * + * + *

Java class for ResourceEntity complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="ResourceEntity">
+ *   <complexContent>
+ *     <extension base="{http://www.vmware.com/vcloud/v1.5}EntityType">
+ *       <sequence>
+ *         <element name="Files" type="{http://www.vmware.com/vcloud/v1.5}FilesListType" minOccurs="0"/>
+ *       </sequence>
+ *       <attribute name="status" type="{http://www.w3.org/2001/XMLSchema}int" />
+ *       <anyAttribute processContents='lax' namespace='##other'/>
+ *     </extension>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "ResourceEntity", propOrder = { + "files" +}) +@XmlSeeAlso({ + MediaType.class, + VAppTemplateType.class, + AbstractVAppType.class, + NetworkPoolType.class +}) +public class ResourceEntity + extends EntityType + +{ + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromResourceEntity(this); + } + + public static class Builder extends EntityType.Builder { + + private FilesList files; + private Integer status; + + /** + * @see ResourceEntity#getFiles() + */ + public Builder files(FilesList files) { + this.files = files; + return this; + } + + /** + * @see ResourceEntity#getStatus() + */ + public Builder status(Integer status) { + this.status = status; + return this; + } + + + public ResourceEntity build() { + ResourceEntity resourceEntity = new ResourceEntity(); + resourceEntity.setFiles(files); + resourceEntity.setStatus(status); + return resourceEntity; + } + + + /** + * @see EntityType#getId() + */ + @Override + public Builder id(String id) { + this.id = id; + return this; + } + + /** + * @see EntityType#getTasksInProgress() + */ + @Override + public Builder tasksInProgress(TasksInProgress tasksInProgress) { + this.tasksInProgress = tasksInProgress; + return this; + } + + /** + * @see ReferenceType#getHref() + */ + @Override + public Builder href(URI href) { + this.href = href; + return this; + } + + /** + * @see ReferenceType#getType() + */ + @Override + public Builder type(String type) { + this.type = type; + return this; + } + + /** + * @see ReferenceType#getLinks() + */ + @Override + public Builder links(Set links) { + this.links = Sets.newLinkedHashSet(checkNotNull(links, "links")); + return this; + } + + /** + * @see ReferenceType#getLinks() + */ + @Override + public Builder link(Link link) { + this.links.add(checkNotNull(link, "link")); + return this; + } + + + @Override + public Builder fromEntityType(EntityType in) { + return Builder.class.cast(super.fromEntityType(in)); + } + public Builder fromResourceEntity(ResourceEntity in) { + return fromEntityType(in) + .files(in.getFiles()) + .status(in.getStatus()); + } + } + + private ResourceEntity() { + // For JAXB and builder use + } + + + + @XmlElement(name = "Files") + protected FilesList files; + @XmlAttribute + protected Integer status; + + /** + * Gets the value of the files property. + * + * @return + * possible object is + * {@link FilesList } + * + */ + public FilesList getFiles() { + return files; + } + + /** + * Sets the value of the files property. + * + * @param value + * allowed object is + * {@link FilesList } + * + */ + public void setFiles(FilesList value) { + this.files = value; + } + + /** + * Gets the value of the status property. + * + * @return + * possible object is + * {@link Integer } + * + */ + public Integer getStatus() { + return status; + } + + /** + * Sets the value of the status property. + * + * @param value + * allowed object is + * {@link Integer } + * + */ + public void setStatus(Integer value) { + this.status = value; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + ResourceEntity that = ResourceEntity.class.cast(o); + return equal(files, that.files) && + equal(status, that.status); + } + + @Override + public int hashCode() { + return Objects.hashCode(files, + status); + } + + @Override + public String toString() { + return Objects.toStringHelper("") + .add("files", files) + .add("status", status).toString(); + } + +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceType.java index abeb7bf3b4..4dfaef9d07 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceType.java @@ -32,7 +32,6 @@ import javax.xml.bind.annotation.XmlElement; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; -import com.google.common.collect.Iterables; import com.google.common.collect.Sets; /** diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/User.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/User.java new file mode 100644 index 0000000000..332841b59c --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/User.java @@ -0,0 +1,924 @@ +/** + * 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.domain; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlType; + + +/** + * + * Represents users in the vCloud system. + * + * + *

Java class for User complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="User">
+ *   <complexContent>
+ *     <extension base="{http://www.vmware.com/vcloud/v1.5}EntityType">
+ *       <sequence>
+ *         <element name="FullName" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
+ *         <element name="EmailAddress" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
+ *         <element name="Telephone" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
+ *         <element name="IsEnabled" type="{http://www.w3.org/2001/XMLSchema}boolean" minOccurs="0"/>
+ *         <element name="IsLocked" type="{http://www.w3.org/2001/XMLSchema}boolean" minOccurs="0"/>
+ *         <element name="IM" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
+ *         <element name="NameInSource" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
+ *         <element name="IsAlertEnabled" type="{http://www.w3.org/2001/XMLSchema}boolean" minOccurs="0"/>
+ *         <element name="AlertEmailPrefix" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
+ *         <element name="AlertEmail" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
+ *         <element name="IsExternal" type="{http://www.w3.org/2001/XMLSchema}boolean" minOccurs="0"/>
+ *         <element name="IsDefaultCached" type="{http://www.w3.org/2001/XMLSchema}boolean" minOccurs="0"/>
+ *         <element name="IsGroupRole" type="{http://www.w3.org/2001/XMLSchema}boolean" minOccurs="0"/>
+ *         <element name="StoredVmQuota" type="{http://www.w3.org/2001/XMLSchema}int" minOccurs="0"/>
+ *         <element name="DeployedVmQuota" type="{http://www.w3.org/2001/XMLSchema}int" minOccurs="0"/>
+ *         <element name="Role" type="{http://www.vmware.com/vcloud/v1.5}ReferenceType" minOccurs="0"/>
+ *         <element name="Password" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
+ *         <element name="GroupReferences" type="{http://www.vmware.com/vcloud/v1.5}GroupsListType" minOccurs="0"/>
+ *       </sequence>
+ *       <anyAttribute processContents='lax' namespace='##other'/>
+ *     </extension>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "User", propOrder = { + "fullName", + "emailAddress", + "telephone", + "isEnabled", + "isLocked", + "im", + "nameInSource", + "isAlertEnabled", + "alertEmailPrefix", + "alertEmail", + "isExternal", + "isDefaultCached", + "isGroupRole", + "storedVmQuota", + "deployedVmQuota", + "role", + "password", + "groupReferences" +}) +public class User + extends EntityType + +{ + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromUser(this); + } + + public static class Builder extends EntityType.Builder { + + private String fullName; + private String emailAddress; + private String telephone; + private Boolean isEnabled; + private Boolean isLocked; + private String im; + private String nameInSource; + private Boolean isAlertEnabled; + private String alertEmailPrefix; + private String alertEmail; + private Boolean isExternal; + private Boolean isDefaultCached; + private Boolean isGroupRole; + private Integer storedVmQuota; + private Integer deployedVmQuota; + private Reference role; + private String password; + private GroupsList groupReferences; + + /** + * @see User#getFullName() + */ + public Builder fullName(String fullName) { + this.fullName = fullName; + return this; + } + + /** + * @see User#getEmailAddress() + */ + public Builder emailAddress(String emailAddress) { + this.emailAddress = emailAddress; + return this; + } + + /** + * @see User#getTelephone() + */ + public Builder telephone(String telephone) { + this.telephone = telephone; + return this; + } + + /** + * @see User#getIsEnabled() + */ + public Builder isEnabled(Boolean isEnabled) { + this.isEnabled = isEnabled; + return this; + } + + /** + * @see User#getIsLocked() + */ + public Builder isLocked(Boolean isLocked) { + this.isLocked = isLocked; + return this; + } + + /** + * @see User#getIm() + */ + public Builder im(String im) { + this.im = im; + return this; + } + + /** + * @see User#getNameInSource() + */ + public Builder nameInSource(String nameInSource) { + this.nameInSource = nameInSource; + return this; + } + + /** + * @see User#getIsAlertEnabled() + */ + public Builder isAlertEnabled(Boolean isAlertEnabled) { + this.isAlertEnabled = isAlertEnabled; + return this; + } + + /** + * @see User#getAlertEmailPrefix() + */ + public Builder alertEmailPrefix(String alertEmailPrefix) { + this.alertEmailPrefix = alertEmailPrefix; + return this; + } + + /** + * @see User#getAlertEmail() + */ + public Builder alertEmail(String alertEmail) { + this.alertEmail = alertEmail; + return this; + } + + /** + * @see User#getIsExternal() + */ + public Builder isExternal(Boolean isExternal) { + this.isExternal = isExternal; + return this; + } + + /** + * @see User#getIsDefaultCached() + */ + public Builder isDefaultCached(Boolean isDefaultCached) { + this.isDefaultCached = isDefaultCached; + return this; + } + + /** + * @see User#getIsGroupRole() + */ + public Builder isGroupRole(Boolean isGroupRole) { + this.isGroupRole = isGroupRole; + return this; + } + + /** + * @see User#getStoredVmQuota() + */ + public Builder storedVmQuota(Integer storedVmQuota) { + this.storedVmQuota = storedVmQuota; + return this; + } + + /** + * @see User#getDeployedVmQuota() + */ + public Builder deployedVmQuota(Integer deployedVmQuota) { + this.deployedVmQuota = deployedVmQuota; + return this; + } + + /** + * @see User#getRole() + */ + public Builder role(Reference role) { + this.role = role; + return this; + } + + /** + * @see User#getPassword() + */ + public Builder password(String password) { + this.password = password; + return this; + } + + /** + * @see User#getGroupReferences() + */ + public Builder groupReferences(GroupsList groupReferences) { + this.groupReferences = groupReferences; + return this; + } + + + public User build() { + User user = new User(im); + user.setFullName(fullName); + user.setEmailAddress(emailAddress); + user.setTelephone(telephone); + user.setIsEnabled(isEnabled); + user.setIsLocked(isLocked); + user.setNameInSource(nameInSource); + user.setIsAlertEnabled(isAlertEnabled); + user.setAlertEmailPrefix(alertEmailPrefix); + user.setAlertEmail(alertEmail); + user.setIsExternal(isExternal); + user.setIsDefaultCached(isDefaultCached); + user.setIsGroupRole(isGroupRole); + user.setStoredVmQuota(storedVmQuota); + user.setDeployedVmQuota(deployedVmQuota); + user.setRole(role); + user.setPassword(password); + user.setGroupReferences(groupReferences); + return user; + } + + + /** + * @see EntityType#getId() + */ + @Override + public Builder id(String id) { + this.id = id; + return this; + } + + /** + * @see EntityType#getTasksInProgress() + */ + @Override + public Builder tasksInProgress(TasksInProgress tasksInProgress) { + this.tasksInProgress = tasksInProgress; + return this; + } + + /** + * @see ReferenceType#getHref() + */ + @Override + public Builder href(URI href) { + this.href = href; + return this; + } + + /** + * @see ReferenceType#getType() + */ + @Override + public Builder type(String type) { + this.type = type; + return this; + } + + /** + * @see ReferenceType#getLinks() + */ + @Override + public Builder links(Set links) { + this.links = Sets.newLinkedHashSet(checkNotNull(links, "links")); + return this; + } + + /** + * @see ReferenceType#getLinks() + */ + @Override + public Builder link(Link link) { + this.links.add(checkNotNull(link, "link")); + return this; + } + + + @Override + public Builder fromEntityType(EntityType in) { + return Builder.class.cast(super.fromEntityType(in)); + } + public Builder fromUser(User in) { + return fromEntityType(in) + .fullName(in.getFullName()) + .emailAddress(in.getEmailAddress()) + .telephone(in.getTelephone()) + .isEnabled(in.getIsEnabled()) + .isLocked(in.getIsLocked()) + .im(in.getIm()) + .nameInSource(in.getNameInSource()) + .isAlertEnabled(in.getIsAlertEnabled()) + .alertEmailPrefix(in.getAlertEmailPrefix()) + .alertEmail(in.getAlertEmail()) + .isExternal(in.getIsExternal()) + .isDefaultCached(in.getIsDefaultCached()) + .isGroupRole(in.getIsGroupRole()) + .storedVmQuota(in.getStoredVmQuota()) + .deployedVmQuota(in.getDeployedVmQuota()) + .role(in.getRole()) + .password(in.getPassword()) + .groupReferences(in.getGroupReferences()); + } + } + + private User() { + // For JAXB and builder use + } + + private User(String im) { + this.im = im; + } + + + @XmlElement(name = "FullName") + protected String fullName; + @XmlElement(name = "EmailAddress") + protected String emailAddress; + @XmlElement(name = "Telephone") + protected String telephone; + @XmlElement(name = "IsEnabled") + protected Boolean isEnabled; + @XmlElement(name = "IsLocked") + protected Boolean isLocked; + @XmlElement(name = "IM") + protected String im; + @XmlElement(name = "NameInSource") + protected String nameInSource; + @XmlElement(name = "IsAlertEnabled") + protected Boolean isAlertEnabled; + @XmlElement(name = "AlertEmailPrefix") + protected String alertEmailPrefix; + @XmlElement(name = "AlertEmail") + protected String alertEmail; + @XmlElement(name = "IsExternal") + protected Boolean isExternal; + @XmlElement(name = "IsDefaultCached") + protected Boolean isDefaultCached; + @XmlElement(name = "IsGroupRole") + protected Boolean isGroupRole; + @XmlElement(name = "StoredVmQuota") + protected Integer storedVmQuota; + @XmlElement(name = "DeployedVmQuota") + protected Integer deployedVmQuota; + @XmlElement(name = "Role") + protected Reference role; + @XmlElement(name = "Password") + protected String password; + @XmlElement(name = "GroupReferences") + protected GroupsList groupReferences; + + /** + * Gets the value of the fullName property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getFullName() { + return fullName; + } + + /** + * Sets the value of the fullName property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setFullName(String value) { + this.fullName = value; + } + + /** + * Gets the value of the emailAddress property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getEmailAddress() { + return emailAddress; + } + + /** + * Sets the value of the emailAddress property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setEmailAddress(String value) { + this.emailAddress = value; + } + + /** + * Gets the value of the telephone property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getTelephone() { + return telephone; + } + + /** + * Sets the value of the telephone property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setTelephone(String value) { + this.telephone = value; + } + + /** + * Gets the value of the isEnabled property. + * + * @return + * possible object is + * {@link Boolean } + * + */ + public Boolean isIsEnabled() { + return isEnabled; + } + + /** + * Sets the value of the isEnabled property. + * + * @param value + * allowed object is + * {@link Boolean } + * + */ + public void setIsEnabled(Boolean value) { + this.isEnabled = value; + } + + /** + * Gets the value of the isLocked property. + * + * @return + * possible object is + * {@link Boolean } + * + */ + public Boolean isIsLocked() { + return isLocked; + } + + /** + * Sets the value of the isLocked property. + * + * @param value + * allowed object is + * {@link Boolean } + * + */ + public void setIsLocked(Boolean value) { + this.isLocked = value; + } + + /** + * Gets the value of the im property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getIM() { + return im; + } + + /** + * Sets the value of the im property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setIM(String value) { + this.im = value; + } + + /** + * Gets the value of the nameInSource property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getNameInSource() { + return nameInSource; + } + + /** + * Sets the value of the nameInSource property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setNameInSource(String value) { + this.nameInSource = value; + } + + /** + * Gets the value of the isAlertEnabled property. + * + * @return + * possible object is + * {@link Boolean } + * + */ + public Boolean isIsAlertEnabled() { + return isAlertEnabled; + } + + /** + * Sets the value of the isAlertEnabled property. + * + * @param value + * allowed object is + * {@link Boolean } + * + */ + public void setIsAlertEnabled(Boolean value) { + this.isAlertEnabled = value; + } + + /** + * Gets the value of the alertEmailPrefix property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getAlertEmailPrefix() { + return alertEmailPrefix; + } + + /** + * Sets the value of the alertEmailPrefix property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setAlertEmailPrefix(String value) { + this.alertEmailPrefix = value; + } + + /** + * Gets the value of the alertEmail property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getAlertEmail() { + return alertEmail; + } + + /** + * Sets the value of the alertEmail property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setAlertEmail(String value) { + this.alertEmail = value; + } + + /** + * Gets the value of the isExternal property. + * + * @return + * possible object is + * {@link Boolean } + * + */ + public Boolean isIsExternal() { + return isExternal; + } + + /** + * Sets the value of the isExternal property. + * + * @param value + * allowed object is + * {@link Boolean } + * + */ + public void setIsExternal(Boolean value) { + this.isExternal = value; + } + + /** + * Gets the value of the isDefaultCached property. + * + * @return + * possible object is + * {@link Boolean } + * + */ + public Boolean isIsDefaultCached() { + return isDefaultCached; + } + + /** + * Sets the value of the isDefaultCached property. + * + * @param value + * allowed object is + * {@link Boolean } + * + */ + public void setIsDefaultCached(Boolean value) { + this.isDefaultCached = value; + } + + /** + * Gets the value of the isGroupRole property. + * + * @return + * possible object is + * {@link Boolean } + * + */ + public Boolean isIsGroupRole() { + return isGroupRole; + } + + /** + * Sets the value of the isGroupRole property. + * + * @param value + * allowed object is + * {@link Boolean } + * + */ + public void setIsGroupRole(Boolean value) { + this.isGroupRole = value; + } + + /** + * Gets the value of the storedVmQuota property. + * + * @return + * possible object is + * {@link Integer } + * + */ + public Integer getStoredVmQuota() { + return storedVmQuota; + } + + /** + * Sets the value of the storedVmQuota property. + * + * @param value + * allowed object is + * {@link Integer } + * + */ + public void setStoredVmQuota(Integer value) { + this.storedVmQuota = value; + } + + /** + * Gets the value of the deployedVmQuota property. + * + * @return + * possible object is + * {@link Integer } + * + */ + public Integer getDeployedVmQuota() { + return deployedVmQuota; + } + + /** + * Sets the value of the deployedVmQuota property. + * + * @param value + * allowed object is + * {@link Integer } + * + */ + public void setDeployedVmQuota(Integer value) { + this.deployedVmQuota = value; + } + + /** + * Gets the value of the role property. + * + * @return + * possible object is + * {@link Reference } + * + */ + public Reference getRole() { + return role; + } + + /** + * Sets the value of the role property. + * + * @param value + * allowed object is + * {@link Reference } + * + */ + public void setRole(Reference value) { + this.role = value; + } + + /** + * Gets the value of the password property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getPassword() { + return password; + } + + /** + * Sets the value of the password property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setPassword(String value) { + this.password = value; + } + + /** + * Gets the value of the groupReferences property. + * + * @return + * possible object is + * {@link GroupsList } + * + */ + public GroupsList getGroupReferences() { + return groupReferences; + } + + /** + * Sets the value of the groupReferences property. + * + * @param value + * allowed object is + * {@link GroupsList } + * + */ + public void setGroupReferences(GroupsList value) { + this.groupReferences = value; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + User that = User.class.cast(o); + return equal(fullName, that.fullName) && + equal(emailAddress, that.emailAddress) && + equal(telephone, that.telephone) && + equal(isEnabled, that.isEnabled) && + equal(isLocked, that.isLocked) && + equal(im, that.im) && + equal(nameInSource, that.nameInSource) && + equal(isAlertEnabled, that.isAlertEnabled) && + equal(alertEmailPrefix, that.alertEmailPrefix) && + equal(alertEmail, that.alertEmail) && + equal(isExternal, that.isExternal) && + equal(isDefaultCached, that.isDefaultCached) && + equal(isGroupRole, that.isGroupRole) && + equal(storedVmQuota, that.storedVmQuota) && + equal(deployedVmQuota, that.deployedVmQuota) && + equal(role, that.role) && + equal(password, that.password) && + equal(groupReferences, that.groupReferences); + } + + @Override + public int hashCode() { + return Objects.hashCode(fullName, + emailAddress, + telephone, + isEnabled, + isLocked, + im, + nameInSource, + isAlertEnabled, + alertEmailPrefix, + alertEmail, + isExternal, + isDefaultCached, + isGroupRole, + storedVmQuota, + deployedVmQuota, + role, + password, + groupReferences); + } + + @Override + public String toString() { + return Objects.toStringHelper("") + .add("fullName", fullName) + .add("emailAddress", emailAddress) + .add("telephone", telephone) + .add("isEnabled", isEnabled) + .add("isLocked", isLocked) + .add("im", im) + .add("nameInSource", nameInSource) + .add("isAlertEnabled", isAlertEnabled) + .add("alertEmailPrefix", alertEmailPrefix) + .add("alertEmail", alertEmail) + .add("isExternal", isExternal) + .add("isDefaultCached", isDefaultCached) + .add("isGroupRole", isGroupRole) + .add("storedVmQuota", storedVmQuota) + .add("deployedVmQuota", deployedVmQuota) + .add("role", role) + .add("password", password) + .add("groupReferences", groupReferences).toString(); + } + +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/ContainerType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/ContainerType.java new file mode 100644 index 0000000000..21d64907c7 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/ContainerType.java @@ -0,0 +1,238 @@ +/** + * 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.domain.query; + +import static com.google.common.base.Objects.*; +import static com.google.common.base.Preconditions.*; + +import java.net.URI; +import java.util.Set; + +import javax.xml.bind.annotation.XmlAttribute; + +import org.jclouds.vcloud.director.v1_5.domain.Link; +import org.jclouds.vcloud.director.v1_5.domain.ResourceType; + +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.Sets; + +/** + * Container for query result sets. + * + *
+ * <complexType name="Container" />
+ * 
+ * + * @author grkvlt@apache.org + */ +public class ContainerType> extends ResourceType { + + public static > Builder builder() { + return new Builder(); + } + + @Override + public Builder toBuilder() { + return new Builder().fromContainerType(this); + } + + public static class Builder> extends ResourceType.Builder { + + protected String name; + protected Integer page; + protected Integer pageSize; + protected Long total; + + /** + * @see Container#getName() + */ + public Builder name(String name) { + this.name = name; + return this; + } + + /** + * @see Container#getPage() + */ + public Builder page(Integer page) { + this.page = page; + return this; + } + + /** + * @see Container#getPageSize() + */ + public Builder pageSize(Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + /** + * @see Container#getTotal() + */ + public Builder total(Long total) { + this.total = total; + return this; + } + + @Override + public ContainerType build() { + ContainerType container = new ContainerType(href); + container.setName(name); + container.setPage(page); + container.setPageSize(pageSize); + container.setTotal(total); + container.setType(type); + container.setLinks(links); + return container; + } + + /** + * @see ResourceType#getHref() + */ + @Override + public Builder href(URI href) { + super.href(href); + return this; + } + + /** + * @see ResourceType#getType() + */ + @Override + public Builder type(String type) { + super.type(type); + return this; + } + + /** + * @see ResourceType#getLinks() + */ + @Override + public Builder links(Set links) { + super.links(Sets.newLinkedHashSet(checkNotNull(links, "links"))); + return this; + } + + /** + * @see ResourceType#getLinks() + */ + @Override + public Builder link(Link link) { + super.link(link); + return this; + } + + @Override + public Builder fromResourceType(ResourceType in) { + return Builder.class.cast(super.fromResourceType(in)); + } + + public Builder fromContainerType(ContainerType in) { + return fromResourceType(in).name(in.getName()).page(in.getPage()).pageSize(in.getPageSize()).total(in.getTotal()); + } + } + + protected ContainerType() { + // For JAXB and builder use + } + + protected ContainerType(URI href) { + super(href); + } + + + @XmlAttribute + protected String name; + @XmlAttribute + protected Integer page; + @XmlAttribute + protected Integer pageSize; + @XmlAttribute + protected Long total; + + /** + * Query name that generated this result set. + */ + public String getName() { + return name; + } + + public void setName(String value) { + this.name = value; + } + + /** + * Page of the result set that this container holds. The first page is page number 1. + */ + public Integer getPage() { + return page; + } + + public void setPage(Integer value) { + this.page = value; + } + + /** + * Page size, as a number of records or references. + */ + public Integer getPageSize() { + return pageSize; + } + + public void setPageSize(Integer value) { + this.pageSize = value; + } + + /** + * Total number of records or references in the container. + */ + public Long getTotal() { + return total; + } + + public void setTotal(Long value) { + this.total = value; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + ContainerType that = ContainerType.class.cast(o); + return super.equals(that) && + equal(this.name, that.name) && equal(this.page, that.page) && + equal(this.pageSize, that.pageSize) && equal(this.total, that.total); + } + + @Override + public int hashCode() { + return super.hashCode() + Objects.hashCode(name, page, pageSize, total); + } + + @Override + public ToStringHelper string() { + return super.string().add("name", name).add("page", page).add("pageSize", pageSize).add("total", total); + } + +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultCatalogRecord.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultCatalogRecord.java new file mode 100644 index 0000000000..5e9ad67287 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultCatalogRecord.java @@ -0,0 +1,406 @@ +/** + * 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.domain.query; + +import static com.google.common.base.Objects.*; +import static com.google.common.base.Preconditions.*; + +import java.net.URI; +import java.util.Date; +import java.util.Set; + +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlSchemaType; + +import org.jclouds.vcloud.director.v1_5.domain.Link; + +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.Sets; + +/** + * Represents the results from a Catalog vCloud query as a record. + * + *
+ * <complexType name="QueryResultCatalogRecord" />
+ * 
+ * + * @author grkvlt@apache.org + */ +public class QueryResultCatalogRecord extends QueryResultRecordType { + + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + @Override + public Builder toBuilder() { + return new Builder().fromQueryResultCatalogRecord(this); + } + + public static class Builder extends QueryResultRecordType.Builder { + + private String name; + private Boolean isPublished; + private Boolean isShared; + private Date creationDate; + private String orgName; + private String ownerName; + private Integer numberOfVAppTemplates; + private Integer numberOfMedia; + private String owner; + + /** + * @see QueryResultCatalogRecord#getName() + */ + public Builder name(String name) { + this.name = name; + return this; + } + + /** + * @see QueryResultCatalogRecord#getIsPublished() + */ + public Builder isPublished(Boolean isPublished) { + this.isPublished = isPublished; + return this; + } + + /** + * @see QueryResultCatalogRecord#getIsPublished() + */ + public Builder published() { + this.isPublished = Boolean.TRUE; + return this; + } + + /** + * @see QueryResultCatalogRecord#getIsPublished() + */ + public Builder notPublished() { + this.isPublished = Boolean.FALSE; + return this; + } + + /** + * @see QueryResultCatalogRecord#getIsShared() + */ + public Builder isShared(Boolean isShared) { + this.isShared = isShared; + return this; + } + + /** + * @see QueryResultCatalogRecord#getIsShared() + */ + public Builder shared() { + this.isShared = Boolean.TRUE; + return this; + } + + /** + * @see QueryResultCatalogRecord#getIsShared() + */ + public Builder notShared() { + this.isShared = Boolean.FALSE; + return this; + } + + /** + * @see QueryResultCatalogRecord#getCreationDate() + */ + public Builder creationDate(Date creationDate) { + this.creationDate = creationDate; + return this; + } + + /** + * @see QueryResultCatalogRecord#getOrgName() + */ + public Builder orgName(String orgName) { + this.orgName = orgName; + return this; + } + + /** + * @see QueryResultCatalogRecord#getOwnerName() + */ + public Builder ownerName(String ownerName) { + this.ownerName = ownerName; + return this; + } + + /** + * @see QueryResultCatalogRecord#getNumberOfVAppTemplates() + */ + public Builder numberOfVAppTemplates(Integer numberOfVAppTemplates) { + this.numberOfVAppTemplates = numberOfVAppTemplates; + return this; + } + + /** + * @see QueryResultCatalogRecord#getNumberOfMedia() + */ + public Builder numberOfMedia(Integer numberOfMedia) { + this.numberOfMedia = numberOfMedia; + return this; + } + + /** + * @see QueryResultCatalogRecord#getOwner() + */ + public Builder owner(String owner) { + this.owner = owner; + return this; + } + + @Override + public QueryResultCatalogRecord build() { + QueryResultCatalogRecord queryResultCatalogRecord = new QueryResultCatalogRecord(href); + queryResultCatalogRecord.setName(name); + queryResultCatalogRecord.setIsPublished(isPublished); + queryResultCatalogRecord.setIsShared(isShared); + queryResultCatalogRecord.setCreationDate(creationDate); + queryResultCatalogRecord.setOrgName(orgName); + queryResultCatalogRecord.setOwnerName(ownerName); + queryResultCatalogRecord.setNumberOfVAppTemplates(numberOfVAppTemplates); + queryResultCatalogRecord.setNumberOfMedia(numberOfMedia); + queryResultCatalogRecord.setOwner(owner); + queryResultCatalogRecord.setId(id); + queryResultCatalogRecord.setType(type); + queryResultCatalogRecord.setLinks(links); + return queryResultCatalogRecord; + } + + /** + * @see QueryResultRecordType#getHref() + */ + @Override + public Builder href(URI href) { + this.href = href; + return this; + } + + /** + * @see QueryResultRecordType#getId() + */ + @Override + public Builder id(String id) { + this.id = id; + return this; + } + + /** + * @see QueryResultRecordType#getType() + */ + @Override + public Builder type(String type) { + this.type = type; + return this; + } + + /** + * @see QueryResultRecordType#getLinks() + */ + @Override + public Builder links(Set links) { + this.links = Sets.newLinkedHashSet(checkNotNull(links, "links")); + return this; + } + + /** + * @see QueryResultRecordType#getLinks() + */ + @Override + public Builder link(Link link) { + this.links.add(checkNotNull(link, "link")); + return this; + } + + @Override + public Builder fromQueryResultRecordType(QueryResultRecordType in) { + return Builder.class.cast(super.fromQueryResultRecordType(in)); + } + + public Builder fromQueryResultCatalogRecord(QueryResultCatalogRecord in) { + return fromQueryResultRecordType(in).name(in.getName()).isPublished(in.isPublished()).isShared(in.isShared()).creationDate(in.getCreationDate()).orgName(in.getOrgName()).ownerName( + in.getOwnerName()).numberOfVAppTemplates(in.getNumberOfVAppTemplates()).numberOfMedia(in.getNumberOfMedia()).owner(in.getOwner()); + } + } + + private QueryResultCatalogRecord() { + // For JAXB and builder use + } + + private QueryResultCatalogRecord(URI href) { + super(href); + } + + @XmlAttribute + protected String name; + @XmlAttribute + protected Boolean isPublished; + @XmlAttribute + protected Boolean isShared; + @XmlAttribute + @XmlSchemaType(name = "dateTime") + protected Date creationDate; + @XmlAttribute + protected String orgName; + @XmlAttribute + protected String ownerName; + @XmlAttribute + protected Integer numberOfVAppTemplates; + @XmlAttribute + protected Integer numberOfMedia; + @XmlAttribute + protected String owner; + + /** + * Gets the value of the name property. + */ + public String getName() { + return name; + } + + public void setName(String value) { + this.name = value; + } + + public Boolean isPublished() { + return isPublished; + } + + /** + * Sets the value of the isPublished property. + */ + public void setIsPublished(Boolean value) { + this.isPublished = value; + } + + public Boolean isShared() { + return isShared; + } + + /** + * Sets the value of the isShared property. + */ + public void setIsShared(Boolean value) { + this.isShared = value; + } + + /** + * Gets the value of the creationDate property. + */ + public Date getCreationDate() { + return creationDate; + } + + public void setCreationDate(Date value) { + this.creationDate = value; + } + + /** + * Gets the value of the orgName property. + */ + public String getOrgName() { + return orgName; + } + + public void setOrgName(String value) { + this.orgName = value; + } + + /** + * Gets the value of the ownerName property. + */ + public String getOwnerName() { + return ownerName; + } + + public void setOwnerName(String value) { + this.ownerName = value; + } + + /** + * Gets the value of the numberOfVAppTemplates property. + */ + public Integer getNumberOfVAppTemplates() { + return numberOfVAppTemplates; + } + + public void setNumberOfVAppTemplates(Integer value) { + this.numberOfVAppTemplates = value; + } + + /** + * Gets the value of the numberOfMedia property. + */ + public Integer getNumberOfMedia() { + return numberOfMedia; + } + + public void setNumberOfMedia(Integer value) { + this.numberOfMedia = value; + } + + /** + * Gets the value of the owner property. + */ + public String getOwner() { + return owner; + } + + public void setOwner(String value) { + this.owner = value; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + QueryResultCatalogRecord that = QueryResultCatalogRecord.class.cast(o); + return super.equals(that) && + equal(this.name, that.name) && equal(this.isPublished, that.isPublished) && + equal(this.isShared, that.isShared) && equal(this.creationDate, that.creationDate) && + equal(this.orgName, that.orgName) && equal(this.ownerName, that.ownerName) && + equal(this.numberOfVAppTemplates, that.numberOfVAppTemplates) && + equal(this.numberOfMedia, that.numberOfMedia) && equal(this.owner, that.owner); + } + + @Override + public int hashCode() { + return super.hashCode() + Objects.hashCode(name, isPublished, isShared, creationDate, + orgName, ownerName, numberOfVAppTemplates, numberOfMedia, owner); + } + + @Override + public ToStringHelper string() { + return super.string() + .add("name", name).add("isPublished", isPublished).add("isShared", isShared) + .add("creationDate", creationDate).add("orgName", orgName).add("ownerName", ownerName) + .add("numberOfVAppTemplates", numberOfVAppTemplates).add("numberOfMedia", numberOfMedia) + .add("owner", owner); + } + +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultNetworkRecord.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultNetworkRecord.java new file mode 100644 index 0000000000..953cf3b952 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultNetworkRecord.java @@ -0,0 +1,358 @@ +/** + * 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.domain.query; + +import static com.google.common.base.Objects.*; +import static com.google.common.base.Preconditions.*; + +import java.net.URI; +import java.util.Set; + +import javax.xml.bind.annotation.XmlAttribute; + +import org.jclouds.vcloud.director.v1_5.domain.Link; +import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecordType.Builder; + +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.Sets; + +/** + * Represents the results from a Network vCloud query as a record. + * + *
+ * <complexType name="QueryResultNetworkRecord" />
+ * 
+ * + * @author grkvlt@apache.org + */ +public class QueryResultNetworkRecord extends QueryResultRecordType { + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + @Override + public Builder toBuilder() { + return new Builder().fromQueryResultNetworkRecord(this); + } + + public static class Builder extends QueryResultRecordType.Builder { + + private String name; + private String ipScopeId; + private String gateway; + private String netmask; + private String dns1; + private String dns2; + private String dnsSuffix; + private Boolean isBusy; + + /** + * @see QueryResultNetworkRecord#getName() + */ + public Builder name(String name) { + this.name = name; + return this; + } + + /** + * @see QueryResultNetworkRecord#getIpScopeId() + */ + public Builder ipScopeId(String ipScopeId) { + this.ipScopeId = ipScopeId; + return this; + } + + /** + * @see QueryResultNetworkRecord#getGateway() + */ + public Builder gateway(String gateway) { + this.gateway = gateway; + return this; + } + + /** + * @see QueryResultNetworkRecord#getNetmask() + */ + public Builder netmask(String netmask) { + this.netmask = netmask; + return this; + } + + /** + * @see QueryResultNetworkRecord#getDns1() + */ + public Builder dns1(String dns1) { + this.dns1 = dns1; + return this; + } + + /** + * @see QueryResultNetworkRecord#getDns2() + */ + public Builder dns2(String dns2) { + this.dns2 = dns2; + return this; + } + + /** + * @see QueryResultNetworkRecord#getDnsSuffix() + */ + public Builder dnsSuffix(String dnsSuffix) { + this.dnsSuffix = dnsSuffix; + return this; + } + + /** + * @see QueryResultNetworkRecord#isBusy() + */ + public Builder isBusy(Boolean isBusy) { + this.isBusy = isBusy; + return this; + } + + /** + * @see QueryResultNetworkRecord#isBusy() + */ + public Builder busy() { + this.isBusy = Boolean.TRUE; + return this; + } + + /** + * @see QueryResultNetworkRecord#isBusy() + */ + public Builder notBusy() { + this.isBusy = Boolean.FALSE; + return this; + } + + @Override + public QueryResultNetworkRecord build() { + QueryResultNetworkRecord queryResultNetworkRecord = new QueryResultNetworkRecord(href); + queryResultNetworkRecord.setName(name); + queryResultNetworkRecord.setIpScopeId(ipScopeId); + queryResultNetworkRecord.setGateway(gateway); + queryResultNetworkRecord.setNetmask(netmask); + queryResultNetworkRecord.setDns1(dns1); + queryResultNetworkRecord.setDns2(dns2); + queryResultNetworkRecord.setDnsSuffix(dnsSuffix); + queryResultNetworkRecord.setIsBusy(isBusy); + queryResultNetworkRecord.setId(id); + queryResultNetworkRecord.setType(type); + queryResultNetworkRecord.setLinks(links); + return queryResultNetworkRecord; + } + + /** + * @see QueryResultRecordType#getHref() + */ + @Override + public Builder href(URI href) { + this.href = href; + return this; + } + + /** + * @see QueryResultRecordType#getId() + */ + @Override + public Builder id(String id) { + this.id = id; + return this; + } + + /** + * @see QueryResultRecordType#getType() + */ + @Override + public Builder type(String type) { + this.type = type; + return this; + } + + /** + * @see QueryResultRecordType#getLinks() + */ + @Override + public Builder links(Set links) { + this.links = Sets.newLinkedHashSet(checkNotNull(links, "links")); + return this; + } + + /** + * @see QueryResultRecordType#getLinks() + */ + @Override + public Builder link(Link link) { + this.links.add(checkNotNull(link, "link")); + return this; + } + + @Override + public Builder fromQueryResultRecordType(QueryResultRecordType in) { + return Builder.class.cast(super.fromQueryResultRecordType(in)); + } + + public Builder fromQueryResultNetworkRecord(QueryResultNetworkRecord in) { + return fromQueryResultRecordType(in) + .name(in.getName()).ipScopeId(in.getIpScopeId()).gateway(in.getGateway()) + .netmask(in.getNetmask()).dns1(in.getDns1()).dns2(in.getDns2()) + .dnsSuffix(in.getDnsSuffix()).isBusy(in.isBusy()); + } + } + + private QueryResultNetworkRecord() { + // For JAXB and builder use + } + + private QueryResultNetworkRecord(URI href) { + super(href); + } + + @XmlAttribute + protected String name; + @XmlAttribute + protected String ipScopeId; + @XmlAttribute + protected String gateway; + @XmlAttribute + protected String netmask; + @XmlAttribute + protected String dns1; + @XmlAttribute + protected String dns2; + @XmlAttribute + protected String dnsSuffix; + @XmlAttribute + protected Boolean isBusy; + + /** + * name. + */ + public String getName() { + return name; + } + + public void setName(String value) { + this.name = value; + } + + /** + * IP scope object of this network. + */ + public String getIpScopeId() { + return ipScopeId; + } + + public void setIpScopeId(String value) { + this.ipScopeId = value; + } + + /** + * Gateway for the network. + */ + public String getGateway() { + return gateway; + } + + public void setGateway(String value) { + this.gateway = value; + } + + /** + * Netmask for the network. + */ + public String getNetmask() { + return netmask; + } + + public void setNetmask(String value) { + this.netmask = value; + } + + /** + * Primary DNS for the network. + */ + public String getDns1() { + return dns1; + } + + public void setDns1(String value) { + this.dns1 = value; + } + + /** + * Secondary DNS for the network. + */ + public String getDns2() { + return dns2; + } + + public void setDns2(String value) { + this.dns2 = value; + } + + /** + * DNS suffix for the network. + */ + public String getDnsSuffix() { + return dnsSuffix; + } + + public void setDnsSuffix(String value) { + this.dnsSuffix = value; + } + + /** + * Shows whether it is busy. + */ + public Boolean isBusy() { + return isBusy; + } + + public void setIsBusy(Boolean value) { + this.isBusy = value; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + QueryResultNetworkRecord that = QueryResultNetworkRecord.class.cast(o); + return super.equals(that) && equal(name, that.name) && equal(ipScopeId, that.ipScopeId) && equal(gateway, that.gateway) && equal(netmask, that.netmask) && equal(dns1, that.dns1) + && equal(dns2, that.dns2) && equal(dnsSuffix, that.dnsSuffix) && equal(isBusy, that.isBusy); + } + + @Override + public int hashCode() { + return Objects.hashCode(name, ipScopeId, gateway, netmask, dns1, dns2, dnsSuffix, isBusy); + } + + @Override + public ToStringHelper string() { + return string().add("name", name).add("ipScopeId", ipScopeId).add("gateway", gateway).add("netmask", netmask).add("dns1", dns1).add("dns2", dns2).add("dnsSuffix", dnsSuffix).add("isBusy", + isBusy); + } + +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultRecordType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultRecordType.java new file mode 100644 index 0000000000..4c21115c69 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultRecordType.java @@ -0,0 +1,238 @@ +/** + * 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.domain.query; + +import static com.google.common.base.Objects.*; +import static com.google.common.base.Preconditions.*; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; + +import java.net.URI; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAnyAttribute; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlSchemaType; +import javax.xml.namespace.QName; + +import org.jclouds.vcloud.director.v1_5.domain.Link; + +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.Sets; + +/** + * Base type for query result Records. Subtypes define more specific elements. + * + *
+ * <complexType name="QueryResultRecordType" />
+ * 
+ * + * @author grkvlt@apache.org + */ +@XmlAccessorType(XmlAccessType.FIELD) +public class QueryResultRecordType> { + + public static > Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromQueryResultRecordType(this); + } + + public static class Builder> { + + protected URI href; + protected String id; + protected String type; + protected Set links = Sets.newLinkedHashSet(); + + /** + * @see QueryResultRecordType#getHref() + */ + public Builder href(URI href) { + this.href = href; + return this; + } + + /** + * @see QueryResultRecordType#getId() + */ + public Builder id(String id) { + this.id = id; + return this; + } + + /** + * @see QueryResultRecordType#getType() + */ + public Builder type(String type) { + this.type = type; + return this; + } + + /** + * @see QueryResultRecordType#getLinks() + */ + public Builder links(Set links) { + this.links = Sets.newLinkedHashSet(checkNotNull(links, "links")); + return this; + } + + /** + * @see QueryResultRecordType#getLinks() + */ + public Builder link(Link link) { + this.links.add(checkNotNull(link, "link")); + return this; + } + + public QueryResultRecordType build() { + QueryResultRecordType record = new QueryResultRecordType(href); + record.setId(id); + record.setType(type); + record.setLinks(links); + return record; + } + + public Builder fromQueryResultRecordType(QueryResultRecordType in) { + return href(in.getHref()).id(in.getId()).type(in.getType()); + } + } + + @XmlElement(namespace = VCLOUD_1_5_NS, name = "Link") + private Set links = Sets.newLinkedHashSet(); + @XmlAttribute + @XmlSchemaType(name = "anyURI") + private URI href; + @XmlAttribute + private String id; + @XmlAttribute + private String type; + @XmlAnyAttribute + // XXX not sure about this + private Map otherAttributes = new HashMap(); + + public QueryResultRecordType(URI href) { + this.href = href; + } + + public QueryResultRecordType() { + // For JAXB + } + + /** + * Set of optional links to an entity or operation associated with this object. + */ + public Set getLinks() { + return links; + } + + public void setLinks(Set links) { + this.links = Sets.newLinkedHashSet(checkNotNull(links, "links")); + } + + public void addLink(Link link) { + this.links.add(checkNotNull(link, "link")); + } + + /** + * Contains the URI to the entity. An object reference, expressed in URL format. Because this URL includes the object identifier + * portion of the id attribute value, it uniquely identifies the object, persists for the life of the object, and is never + * reused. The value of the href attribute is a reference to a view of the object, and can be used to access a representation of + * the object that is valid in a particular context. Although URLs have a well-known syntax and a well-understood interpretation, + * a client 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; + } + + public void setHref(URI href) { + this.href = 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; + } + + public void setId(String id) { + this.id = id; + } + + /** + * Contains the type 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 getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + // XXX not sure about this + + /** + * Gets a map that contains attributes that aren't bound to any typed property on this class. + */ + public Map getOtherAttributes() { + return otherAttributes; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + QueryResultRecordType that = QueryResultRecordType.class.cast(o); + return equal(this.href, that.href) && equal(this.id, that.id) && + equal(this.type, that.type) && equal(this.links, that.links); + } + + @Override + public int hashCode() { + return Objects.hashCode(href, id, type, links); + } + + @Override + public String toString() { + return string().toString(); + } + + protected ToStringHelper string() { + return Objects.toStringHelper("").add("href", href).add("id", id) + .add("type", type).add("links", links); + } +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultRecords.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultRecords.java new file mode 100644 index 0000000000..33cdd6fcc7 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultRecords.java @@ -0,0 +1,212 @@ +/** + * 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.domain.query; + +import static com.google.common.base.Objects.*; +import static com.google.common.base.Preconditions.*; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; + +import java.net.URI; +import java.util.List; +import java.util.Set; + +import javax.xml.bind.annotation.XmlElementRef; + +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.query.ContainerType.Builder; + +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; + +/** + * Represents the results from a vCloud query as records. + * + *
+ * <complexType name="QueryResultRecords" />
+ * 
+ * + * @author grkvlt@apache.org + */ +public class QueryResultRecords extends ContainerType { + + public static final String MEDIA_TYPE = VCloudDirectorMediaType.QUERY_RESULT_RECORDS; + + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + @Override + public Builder toBuilder() { + return new Builder().fromQueryResultRecords(this); + } + + public static class Builder extends ContainerType.Builder { + + private List> records = Lists.newArrayList(); + + /** + * @see QueryResultRecords#getRecords() + */ + public Builder records(List> records) { + this.records = records; + return this; + } + + /** + * @see QueryResultRecords#getRecords() + */ + public Builder record(QueryResultRecordType record) { + this.records.add(record); + return this; + } + + @Override + public QueryResultRecords build() { + QueryResultRecords queryResultRecords = new QueryResultRecords(href); + queryResultRecords.setRecords(records); + queryResultRecords.setName(name); + queryResultRecords.setPage(page); + queryResultRecords.setPageSize(pageSize); + queryResultRecords.setTotal(total); + queryResultRecords.setType(type); + queryResultRecords.setLinks(links); + return queryResultRecords; + } + + /** + * @see Container#getName() + */ + @Override + public Builder name(String name) { + this.name = name; + return this; + } + + /** + * @see Container#getPage() + */ + @Override + public Builder page(Integer page) { + this.page = page; + return this; + } + + /** + * @see Container#getPageSize() + */ + @Override + public Builder pageSize(Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + /** + * @see ResourceType#getHref() + */ + @Override + public Builder href(URI href) { + super.href(href); + return this; + } + + /** + * @see ResourceType#getType() + */ + @Override + public Builder type(String type) { + super.type(type); + return this; + } + + /** + * @see ResourceType#getLinks() + */ + @Override + public Builder links(Set links) { + super.links(Sets.newLinkedHashSet(checkNotNull(links, "links"))); + return this; + } + + /** + * @see ResourceType#getLinks() + */ + @Override + public Builder link(Link link) { + super.link(link); + return this; + } + + @Override + public Builder fromContainerType(ContainerType in) { + return Builder.class.cast(super.fromContainerType(in)); + } + + public Builder fromQueryResultRecords(QueryResultRecords in) { + return fromContainerType(in).records(in.getRecords()); + } + } + + private QueryResultRecords() { + // For JAXB and builder use + } + + @XmlElementRef(name = "Record", namespace = VCLOUD_1_5_NS) + protected List> records; + + /** + * Set of records representing query results. + */ + public List> getRecords() { + return records; + } + + public void setRecords(List> links) { + this.records = Lists.newArrayList(checkNotNull(links, "links")); + } + + public void addRecords(QueryResultRecordType record) { + this.records.add(checkNotNull(record, "record")); + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + QueryResultRecords that = QueryResultRecords.class.cast(o); + return super.equals(that) && equal(this.records, that.records); + } + + @Override + public int hashCode() { + return super.hashCode() + Objects.hashCode(records); + } + + @Override + public ToStringHelper string() { + return super.string().add("records", records); + } + +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/vapp/AbstractVAppType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/vapp/AbstractVAppType.java new file mode 100644 index 0000000000..1b353bc825 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/vapp/AbstractVAppType.java @@ -0,0 +1,177 @@ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2012.02.08 at 02:47:44 PM GMT +// + + +package org.jclouds.vcloud.director.v1_5.domain.vapp; + +import java.util.ArrayList; +import java.util.List; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementRef; +import javax.xml.bind.annotation.XmlSeeAlso; +import javax.xml.bind.annotation.XmlType; +import com.vmware.vcloud.api.rest.schema.ovf.AnnotationSectionType; +import com.vmware.vcloud.api.rest.schema.ovf.DeploymentOptionSectionType; +import com.vmware.vcloud.api.rest.schema.ovf.DiskSectionType; +import com.vmware.vcloud.api.rest.schema.ovf.EulaSectionType; +import com.vmware.vcloud.api.rest.schema.ovf.InstallSectionType; +import com.vmware.vcloud.api.rest.schema.ovf.NetworkSectionType; +import com.vmware.vcloud.api.rest.schema.ovf.OperatingSystemSectionType; +import com.vmware.vcloud.api.rest.schema.ovf.ProductSectionType; +import com.vmware.vcloud.api.rest.schema.ovf.ResourceAllocationSectionType; +import com.vmware.vcloud.api.rest.schema.ovf.SectionType; +import com.vmware.vcloud.api.rest.schema.ovf.StartupSectionType; +import com.vmware.vcloud.api.rest.schema.ovf.VirtualHardwareSectionType; + + +/** + * + * Represents a base type for VAppType and VmType. + * + * + *

Java class for AbstractVAppType complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="AbstractVAppType">
+ *   <complexContent>
+ *     <extension base="{http://www.vmware.com/vcloud/v1.5}ResourceEntityType">
+ *       <sequence>
+ *         <element name="VAppParent" type="{http://www.vmware.com/vcloud/v1.5}ReferenceType" minOccurs="0"/>
+ *         <element ref="{http://schemas.dmtf.org/ovf/envelope/1}Section" maxOccurs="unbounded" minOccurs="0"/>
+ *       </sequence>
+ *       <attribute name="deployed" type="{http://www.w3.org/2001/XMLSchema}boolean" />
+ *       <anyAttribute processContents='lax' namespace='##other'/>
+ *     </extension>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "AbstractVAppType", propOrder = { + "vAppParent", + "section" +}) +@XmlSeeAlso({ + VmType.class, + VAppType.class +}) +public abstract class AbstractVAppType + extends ResourceEntityType +{ + + @XmlElement(name = "VAppParent") + protected ReferenceType vAppParent; + @XmlElementRef(name = "Section", namespace = "http://schemas.dmtf.org/ovf/envelope/1", type = JAXBElement.class) + protected List> section; + @XmlAttribute + protected Boolean deployed; + + /** + * Gets the value of the vAppParent property. + * + * @return + * possible object is + * {@link ReferenceType } + * + */ + public ReferenceType getVAppParent() { + return vAppParent; + } + + /** + * Sets the value of the vAppParent property. + * + * @param value + * allowed object is + * {@link ReferenceType } + * + */ + public void setVAppParent(ReferenceType value) { + this.vAppParent = value; + } + + /** + * + * Specific ovf:Section with additional information for the vApp. + * Gets the value of the section property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the section property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getSection().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link JAXBElement }{@code <}{@link SectionType }{@code >} + * {@link JAXBElement }{@code <}{@link VirtualHardwareSectionType }{@code >} + * {@link JAXBElement }{@code <}{@link LeaseSettingsSectionType }{@code >} + * {@link JAXBElement }{@code <}{@link EulaSectionType }{@code >} + * {@link JAXBElement }{@code <}{@link RuntimeInfoSectionType }{@code >} + * {@link JAXBElement }{@code <}{@link AnnotationSectionType }{@code >} + * {@link JAXBElement }{@code <}{@link DeploymentOptionSectionType }{@code >} + * {@link JAXBElement }{@code <}{@link StartupSectionType }{@code >} + * {@link JAXBElement }{@code <}{@link ResourceAllocationSectionType }{@code >} + * {@link JAXBElement }{@code <}{@link NetworkConnectionSectionType }{@code >} + * {@link JAXBElement }{@code <}{@link CustomizationSectionType }{@code >} + * {@link JAXBElement }{@code <}{@link ProductSectionType }{@code >} + * {@link JAXBElement }{@code <}{@link GuestCustomizationSectionType }{@code >} + * {@link JAXBElement }{@code <}{@link OperatingSystemSectionType }{@code >} + * {@link JAXBElement }{@code <}{@link NetworkConfigSectionType }{@code >} + * {@link JAXBElement }{@code <}{@link NetworkSectionType }{@code >} + * {@link JAXBElement }{@code <}{@link DiskSectionType }{@code >} + * {@link JAXBElement }{@code <}{@link InstallSectionType }{@code >} + * + * + */ + public List> getSection() { + if (section == null) { + section = new ArrayList>(); + } + return this.section; + } + + /** + * Gets the value of the deployed property. + * + * @return + * possible object is + * {@link Boolean } + * + */ + public Boolean isDeployed() { + return deployed; + } + + /** + * Sets the value of the deployed property. + * + * @param value + * allowed object is + * {@link Boolean } + * + */ + public void setDeployed(Boolean value) { + this.deployed = value; + } + +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/vapp/VApp.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/vapp/VApp.java new file mode 100644 index 0000000000..78654802ca --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/vapp/VApp.java @@ -0,0 +1,279 @@ +/** + * 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.domain.vapp; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlType; + + +/** + * + * Represents a vApp. + * + * + *

Java class for VApp complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="VApp">
+ *   <complexContent>
+ *     <extension base="{http://www.vmware.com/vcloud/v1.5}AbstractVApp">
+ *       <sequence>
+ *         <element name="Owner" type="{http://www.vmware.com/vcloud/v1.5}OwnerType" minOccurs="0"/>
+ *         <element name="InMaintenanceMode" type="{http://www.w3.org/2001/XMLSchema}boolean" minOccurs="0"/>
+ *         <element name="Children" type="{http://www.vmware.com/vcloud/v1.5}VAppChildrenType" minOccurs="0"/>
+ *       </sequence>
+ *       <attribute name="ovfDescriptorUploaded" type="{http://www.w3.org/2001/XMLSchema}boolean" />
+ *       <anyAttribute processContents='lax' namespace='##other'/>
+ *     </extension>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "VApp", propOrder = { + "owner", + "inMaintenanceMode", + "children" +}) +public class VApp + extends AbstractVAppType + +{ + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromVApp(this); + } + + public static class Builder extends AbstractVAppType.Builder { + + private Owner owner; + private Boolean inMaintenanceMode; + private VAppChildren children; + private Boolean ovfDescriptorUploaded; + + /** + * @see VApp#getOwner() + */ + public Builder owner(Owner owner) { + this.owner = owner; + return this; + } + + /** + * @see VApp#getInMaintenanceMode() + */ + public Builder inMaintenanceMode(Boolean inMaintenanceMode) { + this.inMaintenanceMode = inMaintenanceMode; + return this; + } + + /** + * @see VApp#getChildren() + */ + public Builder children(VAppChildren children) { + this.children = children; + return this; + } + + /** + * @see VApp#getOvfDescriptorUploaded() + */ + public Builder ovfDescriptorUploaded(Boolean ovfDescriptorUploaded) { + this.ovfDescriptorUploaded = ovfDescriptorUploaded; + return this; + } + + + public VApp build() { + VApp vApp = new VApp(); + vApp.setOwner(owner); + vApp.setInMaintenanceMode(inMaintenanceMode); + vApp.setChildren(children); + vApp.setOvfDescriptorUploaded(ovfDescriptorUploaded); + return vApp; + } + + + @Override + public Builder fromAbstractVAppType(AbstractVAppType in) { + return Builder.class.cast(super.fromAbstractVAppType(in)); + } + public Builder fromVApp(VApp in) { + return fromAbstractVAppType(in) + .owner(in.getOwner()) + .inMaintenanceMode(in.getInMaintenanceMode()) + .children(in.getChildren()) + .ovfDescriptorUploaded(in.getOvfDescriptorUploaded()); + } + } + + private VApp() { + // For JAXB and builder use + } + + + + @XmlElement(name = "Owner") + protected Owner owner; + @XmlElement(name = "InMaintenanceMode") + protected Boolean inMaintenanceMode; + @XmlElement(name = "Children") + protected VAppChildren children; + @XmlAttribute + protected Boolean ovfDescriptorUploaded; + + /** + * Gets the value of the owner property. + * + * @return + * possible object is + * {@link Owner } + * + */ + public Owner getOwner() { + return owner; + } + + /** + * Sets the value of the owner property. + * + * @param value + * allowed object is + * {@link Owner } + * + */ + public void setOwner(Owner value) { + this.owner = value; + } + + /** + * Gets the value of the inMaintenanceMode property. + * + * @return + * possible object is + * {@link Boolean } + * + */ + public Boolean isInMaintenanceMode() { + return inMaintenanceMode; + } + + /** + * Sets the value of the inMaintenanceMode property. + * + * @param value + * allowed object is + * {@link Boolean } + * + */ + public void setInMaintenanceMode(Boolean value) { + this.inMaintenanceMode = value; + } + + /** + * Gets the value of the children property. + * + * @return + * possible object is + * {@link VAppChildren } + * + */ + public VAppChildren getChildren() { + return children; + } + + /** + * Sets the value of the children property. + * + * @param value + * allowed object is + * {@link VAppChildren } + * + */ + public void setChildren(VAppChildren value) { + this.children = value; + } + + /** + * Gets the value of the ovfDescriptorUploaded property. + * + * @return + * possible object is + * {@link Boolean } + * + */ + public Boolean isOvfDescriptorUploaded() { + return ovfDescriptorUploaded; + } + + /** + * Sets the value of the ovfDescriptorUploaded property. + * + * @param value + * allowed object is + * {@link Boolean } + * + */ + public void setOvfDescriptorUploaded(Boolean value) { + this.ovfDescriptorUploaded = value; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + VApp that = VApp.class.cast(o); + return equal(owner, that.owner) && + equal(inMaintenanceMode, that.inMaintenanceMode) && + equal(children, that.children) && + equal(ovfDescriptorUploaded, that.ovfDescriptorUploaded); + } + + @Override + public int hashCode() { + return Objects.hashCode(owner, + inMaintenanceMode, + children, + ovfDescriptorUploaded); + } + + @Override + public String toString() { + return Objects.toStringHelper("") + .add("owner", owner) + .add("inMaintenanceMode", inMaintenanceMode) + .add("children", children) + .add("ovfDescriptorUploaded", ovfDescriptorUploaded).toString(); + } + +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryAsyncClient.java new file mode 100644 index 0000000000..be09637d06 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryAsyncClient.java @@ -0,0 +1,76 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.vcloud.director.v1_5.features; + +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; + +import 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.vcloud.director.v1_5.domain.ReferenceType; +import org.jclouds.vcloud.director.v1_5.domain.Task; +import org.jclouds.vcloud.director.v1_5.domain.TasksList; +import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; +import org.jclouds.vcloud.director.v1_5.functions.OrgReferenceToTaskListEndpoint; +import org.jclouds.vcloud.director.v1_5.functions.ReferenceToEndpoint; +import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx; + +import com.google.common.util.concurrent.ListenableFuture; + +/** + * @see TaskClient + * @author grkvlt@apache.org + */ +@RequestFilters(AddVCloudAuthorizationToRequest.class) +public interface QueryAsyncClient { + + /** + * @see TaskClient#getTaskList(ReferenceType) + */ + @GET + @Consumes + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture getTaskList(@EndpointParam(parser = OrgReferenceToTaskListEndpoint.class) ReferenceType orgRef); + + /** + * @see TaskClient#getTask(URI) + */ + @GET + @Consumes + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture getTask(@EndpointParam URI taskUri); + + /** + * @see TaskClient#cancelTask(URI) + */ + @POST + @Path("/action/cancel") + @Consumes + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture cancelTask(@EndpointParam URI taskUri); +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryClient.java new file mode 100644 index 0000000000..188f5b7f7e --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryClient.java @@ -0,0 +1,62 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.vcloud.director.v1_5.features; + +import java.net.URI; +import java.util.concurrent.TimeUnit; + +import org.jclouds.concurrent.Timeout; +import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; +import org.jclouds.vcloud.director.v1_5.domain.Task; +import org.jclouds.vcloud.director.v1_5.domain.TasksList; + +/** + * Provides synchronous access to The REST API query interface. + * + * @see TaskAsyncClient + * @author grkvlt@apache.org + */ +@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) +public interface QueryClient { + + /** + * REST API General queries handler. + * + *
+    * GET /query/
+    * 
+ */ + ContainerType query(String queryParams); + + /** + * Retrieves a list of Catalogs by using REST API general QueryHandler. + * + * If filter is provided it will be applied to the corresponding result set. + * Format determines the elements representation - references or records. + * Default format is references. + * + *
+    * GET /catalogs/query/
+    * 
+ * + * @param orgId the unique id for the organization + * @return a list of tasks + */ + ContainerType catalogsQuery(ReferenceType orgRef); +} diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java index ba26090415..819d5861c7 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java @@ -33,55 +33,30 @@ import org.testng.annotations.Test; import com.google.common.collect.Iterables; /** -* Tests live behavior of {@link taskClient}. -* -* @author grkvlt@apache.task -*/ -@Test(groups = { "live", "apitests" }, testName = "TaskClientLiveTest") + * Tests live behavior of {@link CatalogClient}. + * + * @author grkvlt@apache.org + */ +@Test(groups = { "live", "apitests" }, testName = "CatalogClientLiveTest") public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest { + /* + * Convenience references to API clients. + */ + + private final CatalogClient catalogClient = context.getApi().getCatalogClient(); + private final QueryClient queryClient = context.getApi().getQueryClient(); + /* * Shared state between dependant tests. */ - - private OrgList orgList; - private Reference orgRef; - private TasksList taskList; - private Task task; - private URI taskUri; - - @Test(testName = "GET /tasksList/{id}") + + private Reference catalogRef; + private Catalog catalog; + + @Test(testName = "GET /catalog/{id}") public void testGetTaskList() { - orgList = context.getApi().getOrgClient().getOrgList(); - orgRef = Iterables.getFirst(orgList.getOrgs(), null); - - // Call the method being tested - taskList = context.getApi().getTaskClient().getTaskList(orgRef); - - // NOTE The environment MUST have ... - - // Check required elements and attributes - assertFalse(Iterables.isEmpty(taskList.getTasks()), "There must always be Task elements in the TaskList"); - - for (Task task : taskList.getTasks()) { - checkTask(task); - } + catalogRef = null; + catalog = catalogClient.getCatalog(catalogRef); } - - @Test(testName = "GET /task/{id}", dependsOnMethods = { "testGetTaskList" }) - public void testGetTask() { - taskUri = Iterables.getFirst(taskList.getTasks(), null).getHref(); - - // Call the method being tested - task = context.getApi().getTaskClient().getTask(taskUri); - - // Check required elements and attributes - checkTask(task); - } - - @Test(testName = "GET /task/{id}/metadata/", dependsOnMethods = { "testGetTask" }) - public void testCancelTask() { - // Call the method being tested - context.getApi().getTaskClient().cancelTask(taskUri); - } -} \ No newline at end of file +} diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientExpectTest.java new file mode 100644 index 0000000000..5bba119b06 --- /dev/null +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientExpectTest.java @@ -0,0 +1,52 @@ +/* + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.vcloud.director.v1_5.features; + +import static org.testng.Assert.*; + +import java.net.URI; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; +import org.jclouds.vcloud.director.v1_5.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; +import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMultimap; + +/** + * Test the {@link TaskClient} by observing its side effects. + * + * @author grkvlt@apache.org + */ +@Test(groups = "unit", singleThreaded = true, testName = "QueryClientExpectTest") +public class QueryClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { + + @Test + public void testQueryCatalogNoParam() { + assertTrue(true); + } +} + \ No newline at end of file diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientLiveTest.java new file mode 100644 index 0000000000..f90f927e2a --- /dev/null +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientLiveTest.java @@ -0,0 +1,67 @@ +/* + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.vcloud.director.v1_5.features; + +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.*; +import static org.jclouds.vcloud.director.v1_5.domain.Checks.*; +import static org.testng.Assert.*; + +import java.net.URI; + +import org.jclouds.vcloud.director.v1_5.domain.Metadata; +import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; +import org.jclouds.vcloud.director.v1_5.domain.OrgList; +import org.jclouds.vcloud.director.v1_5.domain.Reference; +import org.jclouds.vcloud.director.v1_5.domain.Task; +import org.jclouds.vcloud.director.v1_5.domain.TasksList; +import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest; +import org.testng.annotations.Test; + +import com.google.common.collect.Iterables; + +/** +* Tests live behavior of {@link QueryClient}. +* +* @author grkvlt@apache.org +*/ +@Test(groups = { "live", "apitests" }, testName = "QueryClientLiveTest") +public class QueryClientLiveTest extends BaseVCloudDirectorClientLiveTest { + + /* + * Convenience references to API clients. + */ + + private final CatalogClient catalogClient = context.getApi().getCatalogClient(); + private final QueryClient queryClient = context.getApi().getQueryClient(); + + /* + * Shared state between dependant tests. + */ + + private OrgList orgList; + private Reference orgRef; + private TasksList taskList; + private Task task; + private URI taskUri; + + @Test(testName = "GET /catalogs/query/") + public void testQueryCatalogNoParam() { + assertTrue(true); + } +} \ No newline at end of file diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java index 5bd2cb9c4b..249f9707ad 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java @@ -62,3 +62,4 @@ public class BaseVCloudDirectorClientLiveTest extends BaseVersionedServiceLiveTe } } + diff --git a/labs/vcloud-director/src/test/resources/query/allCatalogs.xml b/labs/vcloud-director/src/test/resources/query/allCatalogs.xml new file mode 100644 index 0000000000..da801692f3 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/query/allCatalogs.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file From 97f4d097783f145d2c957f6e9972b8b5d9c1c8d5 Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Fri, 17 Feb 2012 01:14:27 +0000 Subject: [PATCH 02/13] Updates to query client and more domain objects and tests --- .../v1_5/VCloudDirectorMediaType.java | 15 +- .../v1_5/domain/CatalogReference.java | 97 ++++ .../vcloud/director/v1_5/domain/Link.java | 10 +- .../director/v1_5/domain/ResourceEntity.java | 34 +- .../vcloud/director/v1_5/domain/User.java | 47 +- .../v1_5/domain/query/CatalogReferences.java | 152 ++++++ .../director/v1_5/domain/query/QueryList.java | 98 ++++ .../query/QueryResultCatalogRecord.java | 13 +- .../domain/query/QueryResultRecordType.java | 5 + .../v1_5/domain/query/QueryResultRecords.java | 79 ++-- .../domain/query/QueryResultReferences.java | 215 +++++++++ .../v1_5/domain/vapp/AbstractVAppType.java | 254 +++++----- .../director/v1_5/domain/vapp/VApp.java | 438 +++++++++--------- .../v1_5/features/QueryAsyncClient.java | 62 ++- .../director/v1_5/features/QueryClient.java | 26 +- .../v1_5/features/QueryClientExpectTest.java | 83 +++- 16 files changed, 1160 insertions(+), 468 deletions(-) create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogReference.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/CatalogReferences.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryList.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultReferences.java diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java index 909d347cb6..d4d7386d81 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java @@ -75,10 +75,15 @@ public class VCloudDirectorMediaType { public static final String QUERY_RESULT_RECORDS = "application/vnd.vmware.vcloud.query.records+xml"; + public static final String QUERY_RESULT_REFERENCES = "application/vnd.vmware.vcloud.query.references+xml"; + + public static final String QUERY_RESULT_ID_RECORDS = "application/vnd.vmware.vcloud.query.idrecords+xml"; + public static final List ALL = Arrays.asList( - SESSION, ERROR, ORG_LIST, METADATA, METADATA_ENTRY, - METADATA_VALUE, ORG, TASKS_LIST, TASK, ORG_NETWORK, - CATALOG, CATALOG_ITEM, CATALOG_ITEMS, CATALOGS_LIST, PROPERTY, - MEDIA, OWNER, VDC, ADMIN_USER, QUERY_RESULT_RECORDS - ); + SESSION, ERROR, ORG_LIST, METADATA, METADATA_ENTRY, + METADATA_VALUE, ORG, TASKS_LIST, TASK, ORG_NETWORK, + CATALOG, CATALOG_ITEM, CATALOG_ITEMS, CATALOGS_LIST, PROPERTY, + MEDIA, OWNER, VDC, ADMIN_USER, QUERY_RESULT_RECORDS, + QUERY_RESULT_REFERENCES, QUERY_RESULT_ID_RECORDS + ); } 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 new file mode 100644 index 0000000000..bb7ec86e9d --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogReference.java @@ -0,0 +1,97 @@ +package org.jclouds.vcloud.director.v1_5.domain; + +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; + +import java.net.URI; + +import javax.xml.bind.annotation.XmlRootElement; + + +@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "catalogReference") +public class CatalogReference extends ReferenceType { + + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + @Override + public Builder toBuilder() { + return new Builder().fromCatalogReference(this); + } + + public static class Builder extends ReferenceType.Builder { + + @Override + public CatalogReference build() { + CatalogReference reference = new CatalogReference(href); + reference.setId(id); + reference.setName(name); + reference.setType(type); + return reference; + } + + /** + * @see ReferenceType#getHref() + */ + @Override + public Builder href(URI href) { + this.href = href; + return this; + } + + /** + * @see ReferenceType#getId() + */ + @Override + public Builder id(String id) { + this.id = id; + return this; + } + + /** + * @see ReferenceType#getType() + */ + @Override + public Builder type(String type) { + this.type = type; + return this; + } + + /** + * @see ReferenceType#getName() + */ + @Override + public Builder name(String name) { + this.name = name; + return this; + } + + @Override + protected Builder fromReferenceType(ReferenceType in) { + return Builder.class.cast(super.fromReferenceType(in)); + } + + protected Builder fromCatalogReference(CatalogReference in) { + return fromReferenceType(in); + } + } + + protected CatalogReference(URI href) { + super(href); + } + + protected CatalogReference() { + // For JAXB + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Reference that = Reference.class.cast(o); + return super.equals(that); + } +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Link.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Link.java index c56c8ed202..61c52d73b7 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Link.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Link.java @@ -51,9 +51,15 @@ public class Link extends ReferenceType { public static final String REMOVE = "remove"; public static final String CATALOG_ITEM = "catalogItem"; public static final String TASK_CANCEL = "task:cancel"; + public static final String ALTERNATE = "alternate"; + public static final String NEXT_PAGE = "nextPage"; + public static final String PREVIOUS_PAGE = "previousPage"; + public static final String LAST_PAGE = "lastPage"; + public static final String FIRST_PAGE = "firstPage"; public static final List ALL = Arrays.asList( - UP, DOWN, EDIT, DELETE, ADD, REMOVE, CATALOG_ITEM, TASK_CANCEL + UP, DOWN, EDIT, DELETE, ADD, REMOVE, CATALOG_ITEM, TASK_CANCEL, + ALTERNATE, NEXT_PAGE, PREVIOUS_PAGE, LAST_PAGE, FIRST_PAGE ); } @@ -193,4 +199,4 @@ public class Link extends ReferenceType { public ToStringHelper string() { return super.string().add("rel", rel); } -} \ No newline at end of file +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceEntity.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceEntity.java index 5d339e20ab..934f955c39 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceEntity.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceEntity.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -16,16 +16,22 @@ * specific language governing permissions and limitations * under the License. */ - package org.jclouds.vcloud.director.v1_5.domain; +import static com.google.common.base.Objects.*; +import static com.google.common.base.Preconditions.*; + +import java.net.URI; +import java.util.Set; + import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlSeeAlso; import javax.xml.bind.annotation.XmlType; +import com.google.common.base.Objects; +import com.google.common.collect.Sets; /** * @@ -57,16 +63,8 @@ import javax.xml.bind.annotation.XmlType; @XmlType(name = "ResourceEntity", propOrder = { "files" }) -@XmlSeeAlso({ - MediaType.class, - VAppTemplateType.class, - AbstractVAppType.class, - NetworkPoolType.class -}) -public class ResourceEntity - extends EntityType +public class ResourceEntity extends EntityType { -{ @SuppressWarnings("unchecked") public static Builder builder() { return new Builder(); @@ -78,13 +76,13 @@ public class ResourceEntity public static class Builder extends EntityType.Builder { - private FilesList files; + private Object /* FilesList */ files; private Integer status; /** * @see ResourceEntity#getFiles() */ - public Builder files(FilesList files) { + public Builder files(Object /* FilesList */ files) { this.files = files; return this; } @@ -172,14 +170,14 @@ public class ResourceEntity } } - private ResourceEntity() { + protected ResourceEntity() { // For JAXB and builder use } @XmlElement(name = "Files") - protected FilesList files; + protected Object /* FilesList */ files; @XmlAttribute protected Integer status; @@ -191,7 +189,7 @@ public class ResourceEntity * {@link FilesList } * */ - public FilesList getFiles() { + public Object /* FilesList */ getFiles() { return files; } @@ -203,7 +201,7 @@ public class ResourceEntity * {@link FilesList } * */ - public void setFiles(FilesList value) { + public void setFiles(Object /* FilesList */ value) { this.files = value; } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/User.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/User.java index 332841b59c..95ea0c61a8 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/User.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/User.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -16,14 +16,21 @@ * specific language governing permissions and limitations * under the License. */ - package org.jclouds.vcloud.director.v1_5.domain; +import static com.google.common.base.Objects.*; +import static com.google.common.base.Preconditions.*; + +import java.net.URI; +import java.util.Set; + import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlType; +import com.google.common.base.Objects; +import com.google.common.collect.Sets; /** * @@ -119,7 +126,7 @@ public class User private Integer deployedVmQuota; private Reference role; private String password; - private GroupsList groupReferences; + private Object /* GroupsList */ groupReferences; /** * @see User#getFullName() @@ -260,7 +267,7 @@ public class User /** * @see User#getGroupReferences() */ - public Builder groupReferences(GroupsList groupReferences) { + public Builder groupReferences(Object /* GroupsList */ groupReferences) { this.groupReferences = groupReferences; return this; } @@ -353,16 +360,16 @@ public class User .fullName(in.getFullName()) .emailAddress(in.getEmailAddress()) .telephone(in.getTelephone()) - .isEnabled(in.getIsEnabled()) - .isLocked(in.getIsLocked()) - .im(in.getIm()) + .isEnabled(in.isEnabled()) + .isLocked(in.isLocked()) + .im(in.getIM()) .nameInSource(in.getNameInSource()) - .isAlertEnabled(in.getIsAlertEnabled()) + .isAlertEnabled(in.isAlertEnabled()) .alertEmailPrefix(in.getAlertEmailPrefix()) .alertEmail(in.getAlertEmail()) - .isExternal(in.getIsExternal()) - .isDefaultCached(in.getIsDefaultCached()) - .isGroupRole(in.getIsGroupRole()) + .isExternal(in.isExternal()) + .isDefaultCached(in.isDefaultCached()) + .isGroupRole(in.isGroupRole()) .storedVmQuota(in.getStoredVmQuota()) .deployedVmQuota(in.getDeployedVmQuota()) .role(in.getRole()) @@ -415,7 +422,7 @@ public class User @XmlElement(name = "Password") protected String password; @XmlElement(name = "GroupReferences") - protected GroupsList groupReferences; + protected Object /* GroupsList */ groupReferences; /** * Gets the value of the fullName property. @@ -497,7 +504,7 @@ public class User * {@link Boolean } * */ - public Boolean isIsEnabled() { + public Boolean isEnabled() { return isEnabled; } @@ -521,7 +528,7 @@ public class User * {@link Boolean } * */ - public Boolean isIsLocked() { + public Boolean isLocked() { return isLocked; } @@ -593,7 +600,7 @@ public class User * {@link Boolean } * */ - public Boolean isIsAlertEnabled() { + public Boolean isAlertEnabled() { return isAlertEnabled; } @@ -665,7 +672,7 @@ public class User * {@link Boolean } * */ - public Boolean isIsExternal() { + public Boolean isExternal() { return isExternal; } @@ -689,7 +696,7 @@ public class User * {@link Boolean } * */ - public Boolean isIsDefaultCached() { + public Boolean isDefaultCached() { return isDefaultCached; } @@ -713,7 +720,7 @@ public class User * {@link Boolean } * */ - public Boolean isIsGroupRole() { + public Boolean isGroupRole() { return isGroupRole; } @@ -833,7 +840,7 @@ public class User * {@link GroupsList } * */ - public GroupsList getGroupReferences() { + public Object /* GroupsList */ getGroupReferences() { return groupReferences; } @@ -845,7 +852,7 @@ public class User * {@link GroupsList } * */ - public void setGroupReferences(GroupsList value) { + public void setGroupReferences(Object /* GroupsList */ value) { this.groupReferences = value; } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/CatalogReferences.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/CatalogReferences.java new file mode 100644 index 0000000000..df3782c805 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/CatalogReferences.java @@ -0,0 +1,152 @@ +/** + * 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.domain.query; + +import static com.google.common.base.Preconditions.*; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; + +import java.net.URI; +import java.util.Set; + +import javax.xml.bind.annotation.XmlRootElement; + +import org.jclouds.vcloud.director.v1_5.domain.CatalogReference; +import org.jclouds.vcloud.director.v1_5.domain.Link; + +import com.google.common.collect.Sets; + +/** + * Represents the results from a vCloud query as references. + * + *
+ * <complexType name="QueryResultReferences" />
+ * 
+ * + * @author grkvlt@apache.org + */ +@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "CatalogReferences") +public class CatalogReferences extends QueryResultReferences { + + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + @Override + public Builder toBuilder() { + return new Builder().fromQueryResultReferences(this); + } + + public static class Builder extends QueryResultReferences.Builder { + + @Override + public CatalogReferences build() { + CatalogReferences queryResultReferences = new CatalogReferences(href); + queryResultReferences.setReferences(references); + queryResultReferences.setName(name); + queryResultReferences.setPage(page); + queryResultReferences.setPageSize(pageSize); + queryResultReferences.setTotal(total); + queryResultReferences.setType(type); + queryResultReferences.setLinks(links); + return queryResultReferences; + } + + /** + * @see Container#getName() + */ + @Override + public Builder name(String name) { + this.name = name; + return this; + } + + /** + * @see Container#getPage() + */ + @Override + public Builder page(Integer page) { + this.page = page; + return this; + } + + /** + * @see Container#getPageSize() + */ + @Override + public Builder pageSize(Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + /** + * @see ResourceType#getHref() + */ + @Override + public Builder href(URI href) { + super.href(href); + return this; + } + + /** + * @see ResourceType#getType() + */ + @Override + public Builder type(String type) { + super.type(type); + return this; + } + + /** + * @see ResourceType#getLinks() + */ + @Override + public Builder links(Set links) { + super.links(Sets.newLinkedHashSet(checkNotNull(links, "links"))); + return this; + } + + /** + * @see ResourceType#getLinks() + */ + @Override + public Builder link(Link link) { + super.link(link); + return this; + } + + @Override + public Builder fromQueryResultReferences(QueryResultReferences in) { + return Builder.class.cast(super.fromContainerType(in)); + } + + public Builder fromCatalogReferences(CatalogReferences in) { + return Builder.class.cast(fromQueryResultReferences(in).references(in.getReferences())); + } + } + + protected CatalogReferences() { + // For JAXB and builder use + } + + protected CatalogReferences(URI href) { + super(href); + } +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryList.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryList.java new file mode 100644 index 0000000000..b40238e019 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryList.java @@ -0,0 +1,98 @@ +/* + * 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.domain.query; + +import javax.xml.bind.annotation.XmlType; + +import com.google.common.base.Objects.ToStringHelper; + +/** + * + * Container for the list of typed queries available to the + * requesting user. + * + * + *

Java class for QueryList complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="QueryList">
+ *   <complexContent>
+ *     <extension base="{http://www.vmware.com/vcloud/v1.5}ContainerType">
+ *       <anyAttribute processContents='lax' namespace='##other'/>
+ *     </extension>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlType(name = "QueryList") +public class QueryList extends ContainerType { + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromQueryList(this); + } + + public static class Builder extends ContainerType.Builder { + + public QueryList build() { + QueryList queryList = new QueryList(); + return queryList; + } + + @Override + public Builder fromContainerType(ContainerType in) { + return Builder.class.cast(super.fromContainerType(in)); + } + public Builder fromQueryList(QueryList in) { + return fromContainerType(in); + } + } + + private QueryList() { + // For JAXB and builder use + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + QueryList that = QueryList.class.cast(o); + return super.equals(that) ; + } + + @Override + public int hashCode() { + return super.hashCode(); + } + + @Override + public ToStringHelper string() { + return super.string(); + } + +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultCatalogRecord.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultCatalogRecord.java index 5e9ad67287..225c762f2a 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultCatalogRecord.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultCatalogRecord.java @@ -21,12 +21,14 @@ package org.jclouds.vcloud.director.v1_5.domain.query; import static com.google.common.base.Objects.*; import static com.google.common.base.Preconditions.*; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; import java.net.URI; import java.util.Date; import java.util.Set; import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlSchemaType; import org.jclouds.vcloud.director.v1_5.domain.Link; @@ -44,6 +46,7 @@ import com.google.common.collect.Sets; * * @author grkvlt@apache.org */ +@XmlRootElement(name = "CatalogRecord", namespace = VCLOUD_1_5_NS) public class QueryResultCatalogRecord extends QueryResultRecordType { @SuppressWarnings("unchecked") @@ -66,7 +69,7 @@ public class QueryResultCatalogRecord extends QueryResultRecordType> { public static > Builder builder() { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultRecords.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultRecords.java index 33cdd6fcc7..fdbf3e6d13 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultRecords.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultRecords.java @@ -28,10 +28,10 @@ import java.util.List; import java.util.Set; import javax.xml.bind.annotation.XmlElementRef; +import javax.xml.bind.annotation.XmlRootElement; 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.query.ContainerType.Builder; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; @@ -47,28 +47,28 @@ import com.google.common.collect.Sets; * * @author grkvlt@apache.org */ -public class QueryResultRecords extends ContainerType { +@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "QueryResultRecords") +public class QueryResultRecords> extends ContainerType> { public static final String MEDIA_TYPE = VCloudDirectorMediaType.QUERY_RESULT_RECORDS; - @SuppressWarnings("unchecked") - public static Builder builder() { - return new Builder(); + public static > Builder builder() { + return new Builder(); } @Override - public Builder toBuilder() { - return new Builder().fromQueryResultRecords(this); + public Builder toBuilder() { + return new Builder().fromQueryResultRecords(this); } - public static class Builder extends ContainerType.Builder { + public static class Builder> extends ContainerType.Builder> { - private List> records = Lists.newArrayList(); + private List records = Lists.newArrayList(); /** * @see QueryResultRecords#getRecords() */ - public Builder records(List> records) { + public Builder records(List records) { this.records = records; return this; } @@ -76,14 +76,14 @@ public class QueryResultRecords extends ContainerType { /** * @see QueryResultRecords#getRecords() */ - public Builder record(QueryResultRecordType record) { + public Builder record(T record) { this.records.add(record); return this; } @Override - public QueryResultRecords build() { - QueryResultRecords queryResultRecords = new QueryResultRecords(href); + public QueryResultRecords build() { + QueryResultRecords queryResultRecords = new QueryResultRecords(href); queryResultRecords.setRecords(records); queryResultRecords.setName(name); queryResultRecords.setPage(page); @@ -95,37 +95,46 @@ public class QueryResultRecords extends ContainerType { } /** - * @see Container#getName() + * @see ContainerType#getName() */ @Override - public Builder name(String name) { + public Builder name(String name) { this.name = name; return this; } /** - * @see Container#getPage() + * @see ContainerType#getPage() */ @Override - public Builder page(Integer page) { + public Builder page(Integer page) { this.page = page; return this; } /** - * @see Container#getPageSize() + * @see ContainerType#getPageSize() */ @Override - public Builder pageSize(Integer pageSize) { + public Builder pageSize(Integer pageSize) { this.pageSize = pageSize; return this; } + /** + * @see ContainerType#getTotal() + */ + @Override + public Builder total(Long total) { + this.total = total; + return this; + } + /** * @see ResourceType#getHref() */ @Override - public Builder href(URI href) { + public Builder href(URI href) { super.href(href); return this; } @@ -134,7 +143,7 @@ public class QueryResultRecords extends ContainerType { * @see ResourceType#getType() */ @Override - public Builder type(String type) { + public Builder type(String type) { super.type(type); return this; } @@ -143,7 +152,7 @@ public class QueryResultRecords extends ContainerType { * @see ResourceType#getLinks() */ @Override - public Builder links(Set links) { + public Builder links(Set links) { super.links(Sets.newLinkedHashSet(checkNotNull(links, "links"))); return this; } @@ -152,40 +161,44 @@ public class QueryResultRecords extends ContainerType { * @see ResourceType#getLinks() */ @Override - public Builder link(Link link) { + public Builder link(Link link) { super.link(link); return this; } @Override - public Builder fromContainerType(ContainerType in) { + public Builder fromContainerType(ContainerType> in) { return Builder.class.cast(super.fromContainerType(in)); } - public Builder fromQueryResultRecords(QueryResultRecords in) { + public Builder fromQueryResultRecords(QueryResultRecords in) { return fromContainerType(in).records(in.getRecords()); } } - private QueryResultRecords() { + protected QueryResultRecords() { // For JAXB and builder use } - @XmlElementRef(name = "Record", namespace = VCLOUD_1_5_NS) - protected List> records; + protected QueryResultRecords(URI href) { + super(href); + } + + @XmlElementRef + protected List records; /** * Set of records representing query results. */ - public List> getRecords() { + public List getRecords() { return records; } - public void setRecords(List> links) { - this.records = Lists.newArrayList(checkNotNull(links, "links")); + public void setRecords(List records) { + this.records = Lists.newArrayList(checkNotNull(records, "records")); } - public void addRecords(QueryResultRecordType record) { + public void addRecords(T record) { this.records.add(checkNotNull(record, "record")); } @@ -195,7 +208,7 @@ public class QueryResultRecords extends ContainerType { return true; if (o == null || getClass() != o.getClass()) return false; - QueryResultRecords that = QueryResultRecords.class.cast(o); + QueryResultRecords that = QueryResultRecords.class.cast(o); return super.equals(that) && equal(this.records, that.records); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultReferences.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultReferences.java new file mode 100644 index 0000000000..af482325ea --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultReferences.java @@ -0,0 +1,215 @@ +/** + * 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.domain.query; + +import static com.google.common.base.Objects.*; +import static com.google.common.base.Preconditions.*; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; + +import java.net.URI; +import java.util.List; +import java.util.Set; + +import javax.xml.bind.annotation.XmlElementRef; + +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.ReferenceType; + +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; + +/** + * Represents the results from a vCloud query as references. + * + *
+ * <complexType name="QueryResultReferences" />
+ * 
+ * + * @author grkvlt@apache.org + */ +public class QueryResultReferences> extends ContainerType> { + + public static final String MEDIA_TYPE = VCloudDirectorMediaType.QUERY_RESULT_REFERENCES; + + public static > Builder builder() { + return new Builder(); + } + + @Override + public Builder toBuilder() { + return new Builder().fromQueryResultReferences(this); + } + + public static class Builder> extends ContainerType.Builder> { + + protected List references = Lists.newArrayList(); + + /** + * @see QueryResultReferences#getReferences() + */ + public Builder references(List references) { + this.references = references; + return this; + } + + /** + * @see QueryResultReferences#getReferences() + */ + public Builder reference(T reference) { + this.references.add(reference); + return this; + } + + @Override + public QueryResultReferences build() { + QueryResultReferences queryResultReferences = new QueryResultReferences(href); + queryResultReferences.setReferences(references); + queryResultReferences.setName(name); + queryResultReferences.setPage(page); + queryResultReferences.setPageSize(pageSize); + queryResultReferences.setTotal(total); + queryResultReferences.setType(type); + queryResultReferences.setLinks(links); + return queryResultReferences; + } + + /** + * @see Container#getName() + */ + @Override + public Builder name(String name) { + this.name = name; + return this; + } + + /** + * @see Container#getPage() + */ + @Override + public Builder page(Integer page) { + this.page = page; + return this; + } + + /** + * @see Container#getPageSize() + */ + @Override + public Builder pageSize(Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + /** + * @see ResourceType#getHref() + */ + @Override + public Builder href(URI href) { + super.href(href); + return this; + } + + /** + * @see ResourceType#getType() + */ + @Override + public Builder type(String type) { + super.type(type); + return this; + } + + /** + * @see ResourceType#getLinks() + */ + @Override + public Builder links(Set links) { + super.links(Sets.newLinkedHashSet(checkNotNull(links, "links"))); + return this; + } + + /** + * @see ResourceType#getLinks() + */ + @Override + public Builder link(Link link) { + super.link(link); + return this; + } + + @Override + public Builder fromContainerType(ContainerType> in) { + return Builder.class.cast(super.fromContainerType(in)); + } + + public Builder fromQueryResultReferences(QueryResultReferences in) { + return fromContainerType(in).references(in.getReferences()); + } + } + + protected QueryResultReferences() { + // For JAXB and builder use + } + + protected QueryResultReferences(URI href) { + super(href); + } + + @XmlElementRef(name = "Reference", namespace = VCLOUD_1_5_NS) + protected List references; + + /** + * Set of references representing query results. + */ + public List getReferences() { + return references; + } + + public void setReferences(List references) { + this.references = Lists.newArrayList(checkNotNull(references, "references")); + } + + public void addReference(T reference) { + this.references.add(checkNotNull(reference, "reference")); + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + QueryResultReferences that = QueryResultReferences.class.cast(o); + return super.equals(that) && equal(this.references, that.references); + } + + @Override + public int hashCode() { + return super.hashCode() + Objects.hashCode(references); + } + + @Override + public ToStringHelper string() { + return super.string().add("references", references); + } + +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/vapp/AbstractVAppType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/vapp/AbstractVAppType.java index 1b353bc825..eba27db878 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/vapp/AbstractVAppType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/vapp/AbstractVAppType.java @@ -1,15 +1,26 @@ -// -// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 -// See http://java.sun.com/xml/jaxb -// Any modifications to this file will be lost upon recompilation of the source schema. -// Generated on: 2012.02.08 at 02:47:44 PM GMT -// - - +/* + * 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.domain.vapp; import java.util.ArrayList; import java.util.List; + import javax.xml.bind.JAXBElement; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -18,18 +29,9 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementRef; import javax.xml.bind.annotation.XmlSeeAlso; import javax.xml.bind.annotation.XmlType; -import com.vmware.vcloud.api.rest.schema.ovf.AnnotationSectionType; -import com.vmware.vcloud.api.rest.schema.ovf.DeploymentOptionSectionType; -import com.vmware.vcloud.api.rest.schema.ovf.DiskSectionType; -import com.vmware.vcloud.api.rest.schema.ovf.EulaSectionType; -import com.vmware.vcloud.api.rest.schema.ovf.InstallSectionType; -import com.vmware.vcloud.api.rest.schema.ovf.NetworkSectionType; -import com.vmware.vcloud.api.rest.schema.ovf.OperatingSystemSectionType; -import com.vmware.vcloud.api.rest.schema.ovf.ProductSectionType; -import com.vmware.vcloud.api.rest.schema.ovf.ResourceAllocationSectionType; -import com.vmware.vcloud.api.rest.schema.ovf.SectionType; -import com.vmware.vcloud.api.rest.schema.ovf.StartupSectionType; -import com.vmware.vcloud.api.rest.schema.ovf.VirtualHardwareSectionType; + +import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; +import org.jclouds.vcloud.director.v1_5.domain.ResourceEntity; /** @@ -63,115 +65,109 @@ import com.vmware.vcloud.api.rest.schema.ovf.VirtualHardwareSectionType; "vAppParent", "section" }) -@XmlSeeAlso({ - VmType.class, - VAppType.class -}) -public abstract class AbstractVAppType - extends ResourceEntityType -{ +public abstract class AbstractVAppType extends ResourceEntity { - @XmlElement(name = "VAppParent") - protected ReferenceType vAppParent; - @XmlElementRef(name = "Section", namespace = "http://schemas.dmtf.org/ovf/envelope/1", type = JAXBElement.class) - protected List> section; - @XmlAttribute - protected Boolean deployed; - - /** - * Gets the value of the vAppParent property. - * - * @return - * possible object is - * {@link ReferenceType } - * - */ - public ReferenceType getVAppParent() { - return vAppParent; - } - - /** - * Sets the value of the vAppParent property. - * - * @param value - * allowed object is - * {@link ReferenceType } - * - */ - public void setVAppParent(ReferenceType value) { - this.vAppParent = value; - } - - /** - * - * Specific ovf:Section with additional information for the vApp. - * Gets the value of the section property. - * - *

- * This accessor method returns a reference to the live list, - * not a snapshot. Therefore any modification you make to the - * returned list will be present inside the JAXB object. - * This is why there is not a set method for the section property. - * - *

- * For example, to add a new item, do as follows: - *

-     *    getSection().add(newItem);
-     * 
- * - * - *

- * Objects of the following type(s) are allowed in the list - * {@link JAXBElement }{@code <}{@link SectionType }{@code >} - * {@link JAXBElement }{@code <}{@link VirtualHardwareSectionType }{@code >} - * {@link JAXBElement }{@code <}{@link LeaseSettingsSectionType }{@code >} - * {@link JAXBElement }{@code <}{@link EulaSectionType }{@code >} - * {@link JAXBElement }{@code <}{@link RuntimeInfoSectionType }{@code >} - * {@link JAXBElement }{@code <}{@link AnnotationSectionType }{@code >} - * {@link JAXBElement }{@code <}{@link DeploymentOptionSectionType }{@code >} - * {@link JAXBElement }{@code <}{@link StartupSectionType }{@code >} - * {@link JAXBElement }{@code <}{@link ResourceAllocationSectionType }{@code >} - * {@link JAXBElement }{@code <}{@link NetworkConnectionSectionType }{@code >} - * {@link JAXBElement }{@code <}{@link CustomizationSectionType }{@code >} - * {@link JAXBElement }{@code <}{@link ProductSectionType }{@code >} - * {@link JAXBElement }{@code <}{@link GuestCustomizationSectionType }{@code >} - * {@link JAXBElement }{@code <}{@link OperatingSystemSectionType }{@code >} - * {@link JAXBElement }{@code <}{@link NetworkConfigSectionType }{@code >} - * {@link JAXBElement }{@code <}{@link NetworkSectionType }{@code >} - * {@link JAXBElement }{@code <}{@link DiskSectionType }{@code >} - * {@link JAXBElement }{@code <}{@link InstallSectionType }{@code >} - * - * - */ - public List> getSection() { - if (section == null) { - section = new ArrayList>(); - } - return this.section; - } - - /** - * Gets the value of the deployed property. - * - * @return - * possible object is - * {@link Boolean } - * - */ - public Boolean isDeployed() { - return deployed; - } - - /** - * Sets the value of the deployed property. - * - * @param value - * allowed object is - * {@link Boolean } - * - */ - public void setDeployed(Boolean value) { - this.deployed = value; - } +// @XmlElement(name = "VAppParent") +// protected ReferenceType vAppParent; +// @XmlElementRef(name = "Section", namespace = "http://schemas.dmtf.org/ovf/envelope/1", type = JAXBElement.class) +// protected List> section; +// @XmlAttribute +// protected Boolean deployed; +// +// /** +// * Gets the value of the vAppParent property. +// * +// * @return +// * possible object is +// * {@link ReferenceType } +// * +// */ +// public ReferenceType getVAppParent() { +// return vAppParent; +// } +// +// /** +// * Sets the value of the vAppParent property. +// * +// * @param value +// * allowed object is +// * {@link ReferenceType } +// * +// */ +// public void setVAppParent(ReferenceType value) { +// this.vAppParent = value; +// } +// +// /** +// * +// * Specific ovf:Section with additional information for the vApp. +// * Gets the value of the section property. +// * +// *

+// * This accessor method returns a reference to the live list, +// * not a snapshot. Therefore any modification you make to the +// * returned list will be present inside the JAXB object. +// * This is why there is not a set method for the section property. +// * +// *

+// * For example, to add a new item, do as follows: +// *

+//     *    getSection().add(newItem);
+//     * 
+// * +// * +// *

+// * Objects of the following type(s) are allowed in the list +// * {@link JAXBElement }{@code <}{@link SectionType }{@code >} +// * {@link JAXBElement }{@code <}{@link VirtualHardwareSectionType }{@code >} +// * {@link JAXBElement }{@code <}{@link LeaseSettingsSectionType }{@code >} +// * {@link JAXBElement }{@code <}{@link EulaSectionType }{@code >} +// * {@link JAXBElement }{@code <}{@link RuntimeInfoSectionType }{@code >} +// * {@link JAXBElement }{@code <}{@link AnnotationSectionType }{@code >} +// * {@link JAXBElement }{@code <}{@link DeploymentOptionSectionType }{@code >} +// * {@link JAXBElement }{@code <}{@link StartupSectionType }{@code >} +// * {@link JAXBElement }{@code <}{@link ResourceAllocationSectionType }{@code >} +// * {@link JAXBElement }{@code <}{@link NetworkConnectionSectionType }{@code >} +// * {@link JAXBElement }{@code <}{@link CustomizationSectionType }{@code >} +// * {@link JAXBElement }{@code <}{@link ProductSectionType }{@code >} +// * {@link JAXBElement }{@code <}{@link GuestCustomizationSectionType }{@code >} +// * {@link JAXBElement }{@code <}{@link OperatingSystemSectionType }{@code >} +// * {@link JAXBElement }{@code <}{@link NetworkConfigSectionType }{@code >} +// * {@link JAXBElement }{@code <}{@link NetworkSectionType }{@code >} +// * {@link JAXBElement }{@code <}{@link DiskSectionType }{@code >} +// * {@link JAXBElement }{@code <}{@link InstallSectionType }{@code >} +// * +// * +// */ +// public List> getSection() { +// if (section == null) { +// section = new ArrayList>(); +// } +// return this.section; +// } +// +// /** +// * Gets the value of the deployed property. +// * +// * @return +// * possible object is +// * {@link Boolean } +// * +// */ +// public Boolean isDeployed() { +// return deployed; +// } +// +// /** +// * Sets the value of the deployed property. +// * +// * @param value +// * allowed object is +// * {@link Boolean } +// * +// */ +// public void setDeployed(Boolean value) { +// this.deployed = value; +// } } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/vapp/VApp.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/vapp/VApp.java index 78654802ca..5e02670dd5 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/vapp/VApp.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/vapp/VApp.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -16,15 +16,19 @@ * specific language governing permissions and limitations * under the License. */ - package org.jclouds.vcloud.director.v1_5.domain.vapp; +import static com.google.common.base.Objects.*; + import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlType; +import org.jclouds.vcloud.director.v1_5.domain.Owner; + +import com.google.common.base.Objects; /** * @@ -59,221 +63,219 @@ import javax.xml.bind.annotation.XmlType; "inMaintenanceMode", "children" }) -public class VApp - extends AbstractVAppType - -{ - @SuppressWarnings("unchecked") - public static Builder builder() { - return new Builder(); - } - - public Builder toBuilder() { - return new Builder().fromVApp(this); - } - - public static class Builder extends AbstractVAppType.Builder { - - private Owner owner; - private Boolean inMaintenanceMode; - private VAppChildren children; - private Boolean ovfDescriptorUploaded; - - /** - * @see VApp#getOwner() - */ - public Builder owner(Owner owner) { - this.owner = owner; - return this; - } - - /** - * @see VApp#getInMaintenanceMode() - */ - public Builder inMaintenanceMode(Boolean inMaintenanceMode) { - this.inMaintenanceMode = inMaintenanceMode; - return this; - } - - /** - * @see VApp#getChildren() - */ - public Builder children(VAppChildren children) { - this.children = children; - return this; - } - - /** - * @see VApp#getOvfDescriptorUploaded() - */ - public Builder ovfDescriptorUploaded(Boolean ovfDescriptorUploaded) { - this.ovfDescriptorUploaded = ovfDescriptorUploaded; - return this; - } - - - public VApp build() { - VApp vApp = new VApp(); - vApp.setOwner(owner); - vApp.setInMaintenanceMode(inMaintenanceMode); - vApp.setChildren(children); - vApp.setOvfDescriptorUploaded(ovfDescriptorUploaded); - return vApp; - } - - - @Override - public Builder fromAbstractVAppType(AbstractVAppType in) { - return Builder.class.cast(super.fromAbstractVAppType(in)); - } - public Builder fromVApp(VApp in) { - return fromAbstractVAppType(in) - .owner(in.getOwner()) - .inMaintenanceMode(in.getInMaintenanceMode()) - .children(in.getChildren()) - .ovfDescriptorUploaded(in.getOvfDescriptorUploaded()); - } - } - - private VApp() { - // For JAXB and builder use - } - - - - @XmlElement(name = "Owner") - protected Owner owner; - @XmlElement(name = "InMaintenanceMode") - protected Boolean inMaintenanceMode; - @XmlElement(name = "Children") - protected VAppChildren children; - @XmlAttribute - protected Boolean ovfDescriptorUploaded; - - /** - * Gets the value of the owner property. - * - * @return - * possible object is - * {@link Owner } - * - */ - public Owner getOwner() { - return owner; - } - - /** - * Sets the value of the owner property. - * - * @param value - * allowed object is - * {@link Owner } - * - */ - public void setOwner(Owner value) { - this.owner = value; - } - - /** - * Gets the value of the inMaintenanceMode property. - * - * @return - * possible object is - * {@link Boolean } - * - */ - public Boolean isInMaintenanceMode() { - return inMaintenanceMode; - } - - /** - * Sets the value of the inMaintenanceMode property. - * - * @param value - * allowed object is - * {@link Boolean } - * - */ - public void setInMaintenanceMode(Boolean value) { - this.inMaintenanceMode = value; - } - - /** - * Gets the value of the children property. - * - * @return - * possible object is - * {@link VAppChildren } - * - */ - public VAppChildren getChildren() { - return children; - } - - /** - * Sets the value of the children property. - * - * @param value - * allowed object is - * {@link VAppChildren } - * - */ - public void setChildren(VAppChildren value) { - this.children = value; - } - - /** - * Gets the value of the ovfDescriptorUploaded property. - * - * @return - * possible object is - * {@link Boolean } - * - */ - public Boolean isOvfDescriptorUploaded() { - return ovfDescriptorUploaded; - } - - /** - * Sets the value of the ovfDescriptorUploaded property. - * - * @param value - * allowed object is - * {@link Boolean } - * - */ - public void setOvfDescriptorUploaded(Boolean value) { - this.ovfDescriptorUploaded = value; - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - VApp that = VApp.class.cast(o); - return equal(owner, that.owner) && - equal(inMaintenanceMode, that.inMaintenanceMode) && - equal(children, that.children) && - equal(ovfDescriptorUploaded, that.ovfDescriptorUploaded); - } - - @Override - public int hashCode() { - return Objects.hashCode(owner, - inMaintenanceMode, - children, - ovfDescriptorUploaded); - } - - @Override - public String toString() { - return Objects.toStringHelper("") - .add("owner", owner) - .add("inMaintenanceMode", inMaintenanceMode) - .add("children", children) - .add("ovfDescriptorUploaded", ovfDescriptorUploaded).toString(); - } +public class VApp extends AbstractVAppType { +// +// @SuppressWarnings("unchecked") +// public static Builder builder() { +// return new Builder(); +// } +// +// public Builder toBuilder() { +// return new Builder().fromVApp(this); +// } +// +// public static class Builder extends AbstractVAppType.Builder { +// +// private Owner owner; +// private Boolean inMaintenanceMode; +// private VAppChildren children; +// private Boolean ovfDescriptorUploaded; +// +// /** +// * @see VApp#getOwner() +// */ +// public Builder owner(Owner owner) { +// this.owner = owner; +// return this; +// } +// +// /** +// * @see VApp#getInMaintenanceMode() +// */ +// public Builder inMaintenanceMode(Boolean inMaintenanceMode) { +// this.inMaintenanceMode = inMaintenanceMode; +// return this; +// } +// +// /** +// * @see VApp#getChildren() +// */ +// public Builder children(VAppChildren children) { +// this.children = children; +// return this; +// } +// +// /** +// * @see VApp#getOvfDescriptorUploaded() +// */ +// public Builder ovfDescriptorUploaded(Boolean ovfDescriptorUploaded) { +// this.ovfDescriptorUploaded = ovfDescriptorUploaded; +// return this; +// } +// +// +// public VApp build() { +// VApp vApp = new VApp(); +// vApp.setOwner(owner); +// vApp.setInMaintenanceMode(inMaintenanceMode); +// vApp.setChildren(children); +// vApp.setOvfDescriptorUploaded(ovfDescriptorUploaded); +// return vApp; +// } +// +// +// @Override +// public Builder fromAbstractVAppType(AbstractVAppType in) { +// return Builder.class.cast(super.fromAbstractVAppType(in)); +// } +// public Builder fromVApp(VApp in) { +// return fromAbstractVAppType(in) +// .owner(in.getOwner()) +// .inMaintenanceMode(in.getInMaintenanceMode()) +// .children(in.getChildren()) +// .ovfDescriptorUploaded(in.getOvfDescriptorUploaded()); +// } +// } +// +// private VApp() { +// // For JAXB and builder use +// } +// +// +// +// @XmlElement(name = "Owner") +// protected Owner owner; +// @XmlElement(name = "InMaintenanceMode") +// protected Boolean inMaintenanceMode; +// @XmlElement(name = "Children") +// protected VAppChildren children; +// @XmlAttribute +// protected Boolean ovfDescriptorUploaded; +// +// /** +// * Gets the value of the owner property. +// * +// * @return +// * possible object is +// * {@link Owner } +// * +// */ +// public Owner getOwner() { +// return owner; +// } +// +// /** +// * Sets the value of the owner property. +// * +// * @param value +// * allowed object is +// * {@link Owner } +// * +// */ +// public void setOwner(Owner value) { +// this.owner = value; +// } +// +// /** +// * Gets the value of the inMaintenanceMode property. +// * +// * @return +// * possible object is +// * {@link Boolean } +// * +// */ +// public Boolean isInMaintenanceMode() { +// return inMaintenanceMode; +// } +// +// /** +// * Sets the value of the inMaintenanceMode property. +// * +// * @param value +// * allowed object is +// * {@link Boolean } +// * +// */ +// public void setInMaintenanceMode(Boolean value) { +// this.inMaintenanceMode = value; +// } +// +// /** +// * Gets the value of the children property. +// * +// * @return +// * possible object is +// * {@link VAppChildren } +// * +// */ +// public VAppChildren getChildren() { +// return children; +// } +// +// /** +// * Sets the value of the children property. +// * +// * @param value +// * allowed object is +// * {@link VAppChildren } +// * +// */ +// public void setChildren(VAppChildren value) { +// this.children = value; +// } +// +// /** +// * Gets the value of the ovfDescriptorUploaded property. +// * +// * @return +// * possible object is +// * {@link Boolean } +// * +// */ +// public Boolean isOvfDescriptorUploaded() { +// return ovfDescriptorUploaded; +// } +// +// /** +// * Sets the value of the ovfDescriptorUploaded property. +// * +// * @param value +// * allowed object is +// * {@link Boolean } +// * +// */ +// public void setOvfDescriptorUploaded(Boolean value) { +// this.ovfDescriptorUploaded = value; +// } +// +// @Override +// public boolean equals(Object o) { +// if (this == o) +// return true; +// if (o == null || getClass() != o.getClass()) +// return false; +// VApp that = VApp.class.cast(o); +// return equal(owner, that.owner) && +// equal(inMaintenanceMode, that.inMaintenanceMode) && +// equal(children, that.children) && +// equal(ovfDescriptorUploaded, that.ovfDescriptorUploaded); +// } +// +// @Override +// public int hashCode() { +// return Objects.hashCode(owner, +// inMaintenanceMode, +// children, +// ovfDescriptorUploaded); +// } +// +// @Override +// public String toString() { +// return Objects.toStringHelper("") +// .add("owner", owner) +// .add("inMaintenanceMode", inMaintenanceMode) +// .add("children", children) +// .add("ovfDescriptorUploaded", ovfDescriptorUploaded).toString(); +// } } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryAsyncClient.java index be09637d06..8b99bf4701 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryAsyncClient.java @@ -18,59 +18,81 @@ */ package org.jclouds.vcloud.director.v1_5.features; -import java.net.URI; - import javax.ws.rs.Consumes; +import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; -import javax.ws.rs.POST; import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; -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.vcloud.director.v1_5.domain.ReferenceType; -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.query.CatalogReferences; +import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecords; import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; -import org.jclouds.vcloud.director.v1_5.functions.OrgReferenceToTaskListEndpoint; -import org.jclouds.vcloud.director.v1_5.functions.ReferenceToEndpoint; import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx; import com.google.common.util.concurrent.ListenableFuture; /** - * @see TaskClient + * @see QueryClient * @author grkvlt@apache.org */ @RequestFilters(AddVCloudAuthorizationToRequest.class) public interface QueryAsyncClient { /** - * @see TaskClient#getTaskList(ReferenceType) + * REST API General queries handler. */ @GET + @Path("/query") @Consumes @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture getTaskList(@EndpointParam(parser = OrgReferenceToTaskListEndpoint.class) ReferenceType orgRef); + ListenableFuture query(@QueryParam("type") String type, @QueryParam("filter") String filter); + + @GET + @Path("/query") + @Consumes + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture query(@QueryParam("page") Integer page, @QueryParam("pageSize") Integer pageSize, + @QueryParam("format") String format, @QueryParam("type") String type, @QueryParam("filter") String filter); /** - * @see TaskClient#getTask(URI) + * Retrieves a list of Catalogs by using REST API general QueryHandler. */ @GET + @Path("/catalogs/query") @Consumes @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture getTask(@EndpointParam URI taskUri); + ListenableFuture catalogsQuery(@QueryParam("filter") String filter); - /** - * @see TaskClient#cancelTask(URI) - */ - @POST - @Path("/action/cancel") + @GET + @Path("/catalogs/query") @Consumes @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture cancelTask(@EndpointParam URI taskUri); + ListenableFuture catalogsQuery(@QueryParam("page") Integer page, @QueryParam("pageSize") Integer pageSize, + @QueryParam("format") String format, @QueryParam("filter") String filter); + + @GET + @Path("/catalogs/query") + @Consumes + @DefaultValue("references") + @QueryParam("format") + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture catalogReferencesQuery(@QueryParam("filter") String filter); + + @GET + @Path("/catalogs/query") + @Consumes + @DefaultValue("references") + @QueryParam("format") + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture catalogReferencesQuery(@QueryParam("page") Integer page, @QueryParam("pageSize") Integer pageSize, + @QueryParam("filter") String filter); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryClient.java index 188f5b7f7e..39bca1b3f0 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryClient.java @@ -18,13 +18,11 @@ */ package org.jclouds.vcloud.director.v1_5.features; -import java.net.URI; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; -import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; -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.query.CatalogReferences; +import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecords; /** * Provides synchronous access to The REST API query interface. @@ -39,10 +37,12 @@ public interface QueryClient { * REST API General queries handler. * *

-    * GET /query/
+    * GET /query
     * 
*/ - ContainerType query(String queryParams); + QueryResultRecords query(String type, String filter); + + QueryResultRecords query(Integer page, Integer pageSize, String format, String type, String filter); /** * Retrieves a list of Catalogs by using REST API general QueryHandler. @@ -52,11 +52,15 @@ public interface QueryClient { * Default format is references. * *
-    * GET /catalogs/query/
+    * GET /catalogs/query
     * 
- * - * @param orgId the unique id for the organization - * @return a list of tasks */ - ContainerType catalogsQuery(ReferenceType orgRef); + QueryResultRecords catalogsQuery(String filter); + + QueryResultRecords catalogsQuery(Integer page, Integer pageSize, String format, String filter); + + CatalogReferences catalogReferencesQuery(String filter); + + CatalogReferences catalogReferencesQuery(Integer page, Integer pageSize, String filter); + } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientExpectTest.java index 5bba119b06..50f1b0cf8c 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientExpectTest.java @@ -25,12 +25,10 @@ import java.net.URI; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; -import org.jclouds.vcloud.director.v1_5.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; +import org.jclouds.vcloud.director.v1_5.domain.Link; +import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultCatalogRecord; +import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecords; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; import org.testng.annotations.Test; @@ -46,7 +44,78 @@ public class QueryClientExpectTest extends BaseVCloudDirectorRestClientExpectTes @Test public void testQueryCatalogNoParam() { - assertTrue(true); + HttpRequest queryRequest = HttpRequest.builder() + .method("GET") + .endpoint(URI.create(endpoint + "/catalogs/query?filter=")) + .headers(ImmutableMultimap. builder() + .put("Accept", "*/*") + .put("x-vcloud-authorization", token) + .build()) + .build(); + + HttpResponse queryResponse= HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResourceWithContentType("/query/allCatalogs.xml", VCloudDirectorMediaType.QUERY_RESULT_RECORDS + ";version=1.5")) + .build(); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, queryRequest, queryResponse); + + QueryResultRecords expected = QueryResultRecords.builder() + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalogs/query?page=1&pageSize=25&format=records")) + .type("application/vnd.vmware.vcloud.query.records+xml") + .name("catalog") + .page(1) + .pageSize(25) + .total(3L) + .link(Link.builder() + .rel("alternate") + .type("application/vnd.vmware.vcloud.query.references+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalogs/query?page=1&pageSize=25&format=references")) + .build()) + .link(Link.builder() + .rel("alternate") + .type("application/vnd.vmware.vcloud.query.idrecords+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalogs/query?page=1&pageSize=25&format=idrecords")) + .build()) + .record(QueryResultCatalogRecord.builder() + .ownerName("qunying.huang@enstratus.com") + .owner(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/967d317c-4273-4a95-b8a4-bf63b78e9c69")) + .orgName("JClouds") + .numberOfVAppTemplates(0) + .numberOfMedia(0) + .name("QunyingTestCatalog") + .shared() + .notPublished() + .creationDate(dateService.iso8601DateParse("2012-02-07T00:16:28.323-05:00")) + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) + .build()) + .record(QueryResultCatalogRecord.builder() + .ownerName("system") + .owner(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/0ebf2453-5e95-48ab-b223-02671965ee91")) + .orgName("Bluelock") + .numberOfVAppTemplates(0) + .numberOfMedia(0) + .name("Public") + .notShared() + .published() + .creationDate(dateService.iso8601DateParse("2011-09-28T13:45:44.207-04:00")) + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c")) + .build()) + .record(QueryResultCatalogRecord.builder() + .ownerName("adk@cloudsoftcorp.com") + .owner(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/e9eb1b29-0404-4c5e-8ef7-e584acc51da9")) + .orgName("JClouds") + .numberOfVAppTemplates(0) + .numberOfMedia(0) + .name("test") + .shared() + .notPublished() + .creationDate(dateService.iso8601DateParse("2012-02-09T12:32:17.723-05:00")) + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/b7289d54-4ca4-497f-9a93-2d4afc97e3da")) + .build()) + .build(); + + assertEquals(client.getQueryClient().catalogsQuery(""), expected); } } - \ No newline at end of file + From 973ef7e1672b16a2c1cf84ba06eacaef3049f673 Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Fri, 17 Feb 2012 01:40:29 +0000 Subject: [PATCH 03/13] Query and catalog expect and live testing along with Checks and other cliemt and domain object fixes --- .../v1_5/domain/CatalogReference.java | 5 +- .../director/v1_5/domain/Reference.java | 4 +- .../v1_5/domain/query/CatalogReferences.java | 32 +++- .../v1_5/domain/query/ContainerType.java | 1 + .../domain/query/QueryResultRecordType.java | 5 +- .../domain/query/QueryResultReferences.java | 17 +- .../v1_5/features/QueryAsyncClient.java | 43 ++++- .../director/v1_5/features/QueryClient.java | 11 +- .../vcloud/director/v1_5/domain/Checks.java | 53 +++++- .../v1_5/features/CatalogClientLiveTest.java | 161 ++++++++++++++++-- .../v1_5/features/NetworkClientLiveTest.java | 27 ++- .../v1_5/features/OrgClientLiveTest.java | 8 +- .../v1_5/features/QueryClientExpectTest.java | 72 +++++++- .../v1_5/features/QueryClientLiveTest.java | 17 +- .../v1_5/features/TaskClientLiveTest.java | 12 +- .../BaseVCloudDirectorClientLiveTest.java | 1 - .../resources/query/allCatalogReferences.xml | 9 + .../src/test/resources/query/queryList.xml | 58 +++++++ 18 files changed, 470 insertions(+), 66 deletions(-) create mode 100644 labs/vcloud-director/src/test/resources/query/allCatalogReferences.xml create mode 100644 labs/vcloud-director/src/test/resources/query/queryList.xml 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 bb7ec86e9d..b7b74ac855 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 @@ -6,8 +6,7 @@ import java.net.URI; import javax.xml.bind.annotation.XmlRootElement; - -@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "catalogReference") +@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "CatalogReference") public class CatalogReference extends ReferenceType { @SuppressWarnings("unchecked") @@ -91,7 +90,7 @@ public class CatalogReference extends ReferenceType { return true; if (o == null || getClass() != o.getClass()) return false; - Reference that = Reference.class.cast(o); + CatalogReference that = CatalogReference.class.cast(o); return super.equals(that); } } 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 33ecf0c234..1e3af67113 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 @@ -85,11 +85,11 @@ public class Reference extends ReferenceType { } @Override - protected Builder fromReferenceType(ReferenceType in) { + public Builder fromReferenceType(ReferenceType in) { return Builder.class.cast(super.fromReferenceType(in)); } - protected Builder fromReference(Reference in) { + public Builder fromReference(Reference in) { return fromReferenceType(in); } } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/CatalogReferences.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/CatalogReferences.java index df3782c805..27f6f05c0a 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/CatalogReferences.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/CatalogReferences.java @@ -23,6 +23,7 @@ import static com.google.common.base.Preconditions.*; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; import java.net.URI; +import java.util.List; import java.util.Set; import javax.xml.bind.annotation.XmlRootElement; @@ -69,6 +70,24 @@ public class CatalogReferences extends QueryResultReferences { return queryResultReferences; } + /** + * @see QueryResultReferences#getReferences() + */ + @Override + public Builder references(List references) { + this.references = references; + return this; + } + + /** + * @see QueryResultReferences#getReferences() + */ + @Override + public Builder reference(CatalogReference reference) { + this.references.add(reference); + return this; + } + /** * @see Container#getName() */ @@ -96,6 +115,15 @@ public class CatalogReferences extends QueryResultReferences { return this; } + /** + * @see Container#getTotal() + */ + @Override + public Builder total(Long total) { + this.total = total; + return this; + } + /** * @see ResourceType#getHref() */ @@ -134,11 +162,11 @@ public class CatalogReferences extends QueryResultReferences { @Override public Builder fromQueryResultReferences(QueryResultReferences in) { - return Builder.class.cast(super.fromContainerType(in)); + return Builder.class.cast(super.fromQueryResultReferences(in)); } public Builder fromCatalogReferences(CatalogReferences in) { - return Builder.class.cast(fromQueryResultReferences(in).references(in.getReferences())); + return fromQueryResultReferences(in); } } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/ContainerType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/ContainerType.java index 21d64907c7..0602dea39b 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/ContainerType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/ContainerType.java @@ -26,6 +26,7 @@ import java.net.URI; import java.util.Set; import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlType; import org.jclouds.vcloud.director.v1_5.domain.Link; import org.jclouds.vcloud.director.v1_5.domain.ResourceType; diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultRecordType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultRecordType.java index c2d0537704..4648ee0047 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultRecordType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultRecordType.java @@ -52,10 +52,7 @@ import com.google.common.collect.Sets; * @author grkvlt@apache.org */ @XmlAccessorType(XmlAccessType.FIELD) -@XmlSeeAlso({ - QueryResultCatalogRecord.class, - QueryResultNetworkRecord.class, -}) +@XmlSeeAlso({ QueryResultCatalogRecord.class, QueryResultNetworkRecord.class }) public class QueryResultRecordType> { public static > Builder builder() { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultReferences.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultReferences.java index af482325ea..869378bc1c 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultReferences.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultReferences.java @@ -21,15 +21,16 @@ package org.jclouds.vcloud.director.v1_5.domain.query; import static com.google.common.base.Objects.*; import static com.google.common.base.Preconditions.*; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; import java.net.URI; import java.util.List; import java.util.Set; import javax.xml.bind.annotation.XmlElementRef; +import javax.xml.bind.annotation.XmlElementRefs; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.jclouds.vcloud.director.v1_5.domain.CatalogReference; import org.jclouds.vcloud.director.v1_5.domain.Link; import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; @@ -120,6 +121,15 @@ public class QueryResultReferences> extends Container return this; } + /** + * @see Container#getTotal() + */ + @Override + public Builder total(Long total) { + this.total = total; + return this; + } + /** * @see ResourceType#getHref() */ @@ -174,7 +184,10 @@ public class QueryResultReferences> extends Container super(href); } - @XmlElementRef(name = "Reference", namespace = VCLOUD_1_5_NS) + // NOTE add other types as they are used. probably not the best way to do this. + @XmlElementRefs({ + @XmlElementRef(type = CatalogReference.class) + }) protected List references; /** diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryAsyncClient.java index 8b99bf4701..cebd6eac94 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryAsyncClient.java @@ -19,15 +19,17 @@ package org.jclouds.vcloud.director.v1_5.features; import javax.ws.rs.Consumes; -import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.QueryParam; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.JAXBResponseParser; +import org.jclouds.rest.annotations.QueryParams; import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.SkipEncoding; import org.jclouds.vcloud.director.v1_5.domain.query.CatalogReferences; +import org.jclouds.vcloud.director.v1_5.domain.query.QueryList; import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecords; import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx; @@ -39,11 +41,27 @@ import com.google.common.util.concurrent.ListenableFuture; * @author grkvlt@apache.org */ @RequestFilters(AddVCloudAuthorizationToRequest.class) +@SkipEncoding({ '=' }) +@SuppressWarnings("rawtypes") public interface QueryAsyncClient { /** * REST API General queries handler. */ + @GET + @Path("/query") + @Consumes + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture queryList(); + + @GET + @Path("/query") + @Consumes + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture queryAll(@QueryParam("type") String type); + @GET @Path("/query") @Consumes @@ -62,6 +80,13 @@ public interface QueryAsyncClient { /** * Retrieves a list of Catalogs by using REST API general QueryHandler. */ + @GET + @Path("/catalogs/query") + @Consumes + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture catalogsQueryAll(); + @GET @Path("/catalogs/query") @Consumes @@ -75,13 +100,20 @@ public interface QueryAsyncClient { @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture catalogsQuery(@QueryParam("page") Integer page, @QueryParam("pageSize") Integer pageSize, - @QueryParam("format") String format, @QueryParam("filter") String filter); + @QueryParam("filter") String filter); @GET @Path("/catalogs/query") @Consumes - @DefaultValue("references") - @QueryParam("format") + @QueryParams(keys = { "format" }, values = { "references" }) + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture catalogReferencesQueryAll(); + + @GET + @Path("/catalogs/query") + @Consumes + @QueryParams(keys = { "format" }, values = { "references" }) @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture catalogReferencesQuery(@QueryParam("filter") String filter); @@ -89,8 +121,7 @@ public interface QueryAsyncClient { @GET @Path("/catalogs/query") @Consumes - @DefaultValue("references") - @QueryParam("format") + @QueryParams(keys = { "format" }, values = { "references" }) @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture catalogReferencesQuery(@QueryParam("page") Integer page, @QueryParam("pageSize") Integer pageSize, diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryClient.java index 39bca1b3f0..9df4ffa54a 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/QueryClient.java @@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; import org.jclouds.vcloud.director.v1_5.domain.query.CatalogReferences; +import org.jclouds.vcloud.director.v1_5.domain.query.QueryList; import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecords; /** @@ -40,6 +41,10 @@ public interface QueryClient { * GET /query * */ + QueryList queryList(); + + QueryResultRecords queryAll(String type); + QueryResultRecords query(String type, String filter); QueryResultRecords query(Integer page, Integer pageSize, String format, String type, String filter); @@ -55,9 +60,13 @@ public interface QueryClient { * GET /catalogs/query * */ + QueryResultRecords catalogsQueryAll(); + QueryResultRecords catalogsQuery(String filter); - QueryResultRecords catalogsQuery(Integer page, Integer pageSize, String format, String filter); + QueryResultRecords catalogsQuery(Integer page, Integer pageSize, String filter); + + CatalogReferences catalogReferencesQueryAll(); CatalogReferences catalogReferencesQuery(String filter); 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 7f39cd9484..f3d4084264 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 @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -121,9 +121,9 @@ public class Checks { public static void checkLink(Link link) { // Check required fields assertNotNull(link.getRel(), "The Rel attribute of a Link must be set"); - assertTrue(Link.Rel.ALL.contains(link.getRel()), - String.format("The Rel attribute (%s) of a Link must be one of the allowed list - %s", - link.getRel(), Iterables.toString(Link.Rel.ALL))); + // XXX choose one + assertTrue(Link.Rel.ALL.contains(link.getRel()), String.format("The Rel attribute of a Link must be from the allowed list: %s", Iterables.toString(Link.Rel.ALL))); + assertTrue(Link.Rel.ALL.contains(link.getRel()), String.format("The Rel attribute of a Link cannot be '%s'", link.getRel())); // Check parent type checkReferenceType(link); @@ -132,9 +132,9 @@ public class Checks { public static void checkTask(Task task) { // Check required fields assertNotNull(task.getStatus(), "The Status attribute of a Task must be set"); - assertTrue(Task.Status.ALL.contains(task.getStatus().toString()), - String.format("The Status of a Task (%s) must be one of the allowed list - %s", - task.getStatus().toString(), Iterables.toString(Task.Status.ALL))); + // XXX choose one + assertTrue(Task.Status.ALL.contains(task.getStatus()), String.format("The Status of a Task must be from the allowed list: %s", Iterables.toString(Task.Status.ALL))); + assertTrue(Task.Status.ALL.contains(task.getStatus()), String.format("The Status of a Task cannot be '%s'", task.getStatus())); // Check optional fields // NOTE operation cannot be checked @@ -174,6 +174,24 @@ public class Checks { checkEntityType(file); } + public static void checkMetadata(Metadata metadata) { + Set metadataEntries = metadata.getMetadataEntries(); + if (metadataEntries != null && !metadataEntries.isEmpty()) { + for (MetadataEntry metadataEntry : metadataEntries) checkMetadataEntry(metadataEntry); + } + + // Check parent type + checkResourceType(metadata); + } + + public static void checkMetadataEntry(MetadataEntry metadataEntry) {+ // Check required fields + assertNotNull(metadataEntry.getKey(), "The Key attribute of a MetadataEntry must be set"); + assertNotNull(metadataEntry.getValue(), "The Value attribute of a MetadataEntry must be set"); + + // Check parent type + checkResourceType(metadataEntry); + } + public static void checkProgress(Integer progress) { assertTrue(progress >= 0 && progress <= 100, "The Progress attribute must be between 0 and 100"); } @@ -188,6 +206,27 @@ public class Checks { // NOTE stackTrace cannot be checked } + public static void checkCatalog(Catalog catalog) { + // Check optional elements/attributes + Entity owner = catalog.getOwner(); + if (owner != null) checkEntityType(owner); + CatalogItems catalogItems = catalog.getCatalogItems(); + if (catalogItems != null) { + for (Reference catalogItemReference : catalogItems.getCatalogItems()) { + checkReferenceType(catalogItemReference); + } + } + // NOTE isPublished cannot be checked + + // Check parent type + checkEntityType(catalog); + } + + public static void checkCatalogItem(CatalogItem catalogItem) { + // Check parent type + checkEntityType(catalogItem); + } + public static void checkImageType(String imageType) { assertTrue(Media.ImageType.ALL.contains(imageType), "The Image type of a Media must be one of the allowed list"); diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java index 819d5861c7..3a19a91f3c 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java @@ -18,18 +18,26 @@ */ package org.jclouds.vcloud.director.v1_5.features; -import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkTask; -import static org.testng.Assert.assertFalse; +import static org.jclouds.vcloud.director.v1_5.domain.Checks.*; +import static org.testng.Assert.*; -import java.net.URI; - -import org.jclouds.vcloud.director.v1_5.domain.OrgList; +import org.jclouds.predicates.RetryablePredicate; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorException; +import org.jclouds.vcloud.director.v1_5.domain.Catalog; +import org.jclouds.vcloud.director.v1_5.domain.CatalogItem; +import org.jclouds.vcloud.director.v1_5.domain.Metadata; +import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; +import org.jclouds.vcloud.director.v1_5.domain.MetadataValue; import org.jclouds.vcloud.director.v1_5.domain.Reference; +import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; 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.query.CatalogReferences; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest; +import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; import com.google.common.collect.Iterables; /** @@ -40,23 +48,146 @@ import com.google.common.collect.Iterables; @Test(groups = { "live", "apitests" }, testName = "CatalogClientLiveTest") public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest { + private static final String CATALOG_NAME = "QunyingTestCatalog"; // TODO add as test configuration property + /* * Convenience references to API clients. */ - - private final CatalogClient catalogClient = context.getApi().getCatalogClient(); - private final QueryClient queryClient = context.getApi().getQueryClient(); - + + private CatalogClient catalogClient; + private QueryClient queryClient; + /* * Shared state between dependant tests. */ - - private Reference catalogRef; + + private ReferenceType catalogRef; + private ReferenceType catalogItemRef; + private ReferenceType newCatalogItemRef; private Catalog catalog; - + private CatalogItem catalogItem; + private CatalogItem newCatalogItem; + private Metadata catalogMetadata; + + @BeforeGroups(groups = { "live" }) + public void setupClients() { + catalogClient = context.getApi().getCatalogClient(); + queryClient = context.getApi().getQueryClient(); + } + @Test(testName = "GET /catalog/{id}") - public void testGetTaskList() { - catalogRef = null; + public void testGetCatalog() { + CatalogReferences catalogReferences = queryClient.catalogReferencesQuery(String.format("name==%s", CATALOG_NAME)); + assertEquals(Iterables.size(catalogReferences.getReferences()), 1, String.format("The %s Catalog must exist", CATALOG_NAME)); + catalogRef = Iterables.getOnlyElement(catalogReferences.getReferences()); catalog = catalogClient.getCatalog(catalogRef); } + + @Test(testName = "GET /catalogItem/{id}", dependsOnMethods = { "testGetCatalog" }) + public void testGetCatalogItem() { + assertFalse(Iterables.isEmpty(catalog.getCatalogItems().getCatalogItems())); + catalogItemRef = Iterables.get(catalog.getCatalogItems().getCatalogItems(), 0); + catalogItem = catalogClient.getCatalogItem(catalogItemRef); + checkCatalogItem(catalogItem); + } + + // NOTE for this test to work, we need to be able to upload a new vAppTemplate to a vDC first + // NOTE we could do this with a test environment property -Dtest.vcloud-director.vappTemplateId=vapptemplate-abcd + @Test(testName = "POST /catalog/{id}/catalogItems", dependsOnMethods = { "testGetCatalogItem" }, enabled = false) + public void testAddCatalogItem() { + CatalogItem editedCatalogItem = CatalogItem.builder() + .name("newitem") + .description("New Item") + // XXX org.jclouds.vcloud.director.v1_5.VCloudDirectorException: Error: The VCD entity image already exists. + // .entity(Reference.builder().href(catalogItem.getEntity().getHref()).build()) + // XXX org.jclouds.vcloud.director.v1_5.VCloudDirectorException: Error: The VCD entity ubuntu10 already exists. + // .entity(Reference.builder().href(URI.create(endpoint + "/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9")).build()) + .build(); + newCatalogItem = catalogClient.addCatalogItem(catalogRef, editedCatalogItem); + checkCatalogItem(newCatalogItem); + assertEquals(newCatalogItem.getName(), "newitem"); + } + + @Test(testName = "PUT /catalogItem/{id}", dependsOnMethods = { "testAddCatalogItem" }, enabled = false) + public void testUpdateCatalogItem() { + Catalog catalog = catalogClient.getCatalog(catalogRef); + newCatalogItemRef = Iterables.find(catalog.getCatalogItems().getCatalogItems(), new Predicate() { + @Override + public boolean apply(Reference input) { + return input.getHref().equals(newCatalogItem.getHref()); + } + }); + CatalogItem updatedCatalogItem = CatalogItem.builder().fromCatalogItem(catalogItem).name("UPDATEDNAME").build(); + newCatalogItem = catalogClient.updateCatalogItem(catalogRef, updatedCatalogItem); + checkCatalogItem(newCatalogItem); + assertEquals(newCatalogItem.getName(), "UPDATEDNAME"); + } + + @Test(testName = "DELETE /catalogItem/{id}", dependsOnMethods = { "testUpdateCatalogItem" }, enabled = false) + public void testDeleteCatalogItem() { + catalogClient.deleteCatalogItem(newCatalogItemRef); + try { + catalogClient.getCatalogItem(newCatalogItemRef); + fail("The CatalogItem should have been deleted"); + } catch (VCloudDirectorException vcde) { + checkError(vcde.getError()); + assertEquals(vcde.getError().getMajorErrorCode(), Integer.valueOf(403), "The majorErrorCode should be 403 since the item has been deleted"); + } + } + + // NOTE for this test to work, we need to be able to create metadata on a Catalog, specifically { "KEY", "VALUE" } + @Test(testName = "GET /catalog/{id}/metadata", dependsOnMethods = { "testGetCatalog" }, enabled = false) + public void testGetCatalogMetadata() { + catalogMetadata = catalogClient.getCatalogMetadata(catalogRef); + checkMetadata(catalogMetadata); + } + + // NOTE for this test to work, we need to be able to create metadata on a Catalog, specifically { "KEY", "VALUE" } + @Test(testName = "GET /catalog/{id}/metadata/{key}", dependsOnMethods = { "testGetCatalogMetadata" }, enabled = false) + public void testGetCatalogMetadataEntry() { + MetadataEntry existingMetadataEntry = Iterables.find(catalogMetadata.getMetadataEntries(), new Predicate() { + @Override + public boolean apply(MetadataEntry input) { + return input.getKey().equals("KEY"); + } + }); + MetadataEntry metadataEntry = catalogClient.getCatalogMetadataEntry(catalogRef, "KEY"); + assertEquals(existingMetadataEntry.getValue(), metadataEntry.getValue()); + checkMetadataEntry(metadataEntry); + } + + @Test(testName = "POST /catalogItem/{id}/metadata", dependsOnMethods = { "testGetCatalogItem" }) + public void testMergeCatalogItemMetadata() { + Metadata newMetadata = Metadata.builder() + .entry(MetadataEntry.builder().entry("KEY", "VALUE").build()) + .build(); + + Task task = catalogClient.mergeCatalogItemMetadata(catalogItemRef, newMetadata); + // TODO wait until task no longer running... + } + + @Test(testName = "GET /catalogItem/{id}/metadata", dependsOnMethods = { "testMergeCatalogItemMetadata" }) + public void testGetCatalogItemMetadata() { + Metadata metadata = catalogClient.getCatalogItemMetadata(catalogItemRef); + } + + // XXX org.jclouds.vcloud.director.v1_5.VCloudDirectorException: Error: The access to the resource metadata_item with id KEY is forbidden + @Test(testName = "GET /catalog/{id}/metadata/{key}", dependsOnMethods = { "testMergeCatalogItemMetadata" }, enabled = false) + public void testGetCatalogItemMetadataEntry() { + MetadataEntry metadataEntry = catalogClient.getCatalogItemMetadataEntry(catalogItemRef, "KEY"); + } + + @Test(testName = "PUT /catalog/{id}/metadata/{key}", dependsOnMethods = { "testMergeCatalogItemMetadata" }) + public void testSetCatalogItemMetadataEntry() { + MetadataValue newMetadataValue = MetadataValue.builder().value("NEW").build(); + + Task task = catalogClient.setCatalogItemMetadataEntry(catalogItemRef, "KEY", newMetadataValue); + // TODO wait until task no longer running... + } + + @Test(testName = "DELETE /catalog/{id}/metadata/{key}", dependsOnMethods = { "testMergeCatalogItemMetadata" }) + public void testDeleteCatalogItemMetadataEntry() { + Task task = catalogClient.deleteCatalogItemMetadataEntry(catalogItemRef, "KEY"); + // TODO wait until task no longer running... + } } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientLiveTest.java index 8a4392d78b..5173dee544 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientLiveTest.java @@ -18,8 +18,7 @@ */ package org.jclouds.vcloud.director.v1_5.features; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.fail; +import static org.testng.Assert.*; import java.net.URI; @@ -30,15 +29,27 @@ import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; import org.jclouds.vcloud.director.v1_5.domain.OrgNetwork; import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest; +import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; /** - * Tests behavior of {@code NetworkClient} + * Tests behavior of {@link NetworkClient} * * @author danikov */ @Test(groups = { "live", "apitests" }, testName = "NetworkClientLiveTest") public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest { + + /* + * Convenience references to API clients. + */ + + private NetworkClient networkClient; + + @BeforeGroups(groups = { "live" }) + public void setupClients() { + networkClient = context.getApi().getNetworkClient(); + } // @Before populate String networkId = "55a677cf-ab3f-48ae-b880-fab90421980c"; @@ -49,7 +60,7 @@ public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest { Reference networkRef = Reference.builder() .href(URI.create(endpoint + "/network/"+networkId)).build(); - OrgNetwork network = context.getApi().getNetworkClient().getNetwork(networkRef); + OrgNetwork network = networkClient.getNetwork(networkRef); //TODO assert network is valid } @@ -66,7 +77,7 @@ public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest { .build(); try { - context.getApi().getNetworkClient().getNetwork(networkRef); + networkClient.getNetwork(networkRef); fail("Should give HTTP 400 error"); } catch (VCloudDirectorException vde) { assertEquals(vde.getError(), expected); @@ -87,7 +98,7 @@ public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest { .build(); try { - context.getApi().getNetworkClient().getNetwork(networkRef); + networkClient.getNetwork(networkRef); fail("Should give HTTP 403 error"); } catch (VCloudDirectorException vde) { assertEquals(vde.getError(), expected); @@ -108,7 +119,7 @@ public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest { .build(); try { - context.getApi().getNetworkClient().getNetwork(networkRef); + networkClient.getNetwork(networkRef); fail("Should give HTTP 403 error"); } catch (VCloudDirectorException vde) { assertEquals(vde.getError(), expected); @@ -137,7 +148,7 @@ public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest { Reference networkRef = Reference.builder() .href(URI.create(endpoint + "/network/"+networkId)).build(); - MetadataEntry expected = context.getApi().getNetworkClient().getMetadataEntry(networkRef, metadataKey); + MetadataEntry expected = networkClient.getMetadataEntry(networkRef, metadataKey); // assert metadataEntry is valid } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientLiveTest.java index 5d493ea9fc..7973a175ae 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientLiveTest.java @@ -29,6 +29,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Org; import org.jclouds.vcloud.director.v1_5.domain.OrgList; import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest; +import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; import com.google.common.collect.Iterables; @@ -45,7 +46,12 @@ public class OrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { * Convenience references to API clients. */ - private final OrgClient orgClient = context.getApi().getOrgClient(); + private OrgClient orgClient; + + @BeforeGroups(groups = { "live" }) + public void setupClients() { + orgClient = context.getApi().getOrgClient(); + } /* * Shared state between dependant tests. diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientExpectTest.java index 50f1b0cf8c..790fc7ce08 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientExpectTest.java @@ -26,7 +26,9 @@ import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.jclouds.vcloud.director.v1_5.domain.CatalogReference; import org.jclouds.vcloud.director.v1_5.domain.Link; +import org.jclouds.vcloud.director.v1_5.domain.query.CatalogReferences; import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultCatalogRecord; import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecords; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; @@ -43,10 +45,10 @@ import com.google.common.collect.ImmutableMultimap; public class QueryClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { @Test - public void testQueryCatalogNoParam() { + public void testQueryAllCatalogs() { HttpRequest queryRequest = HttpRequest.builder() .method("GET") - .endpoint(URI.create(endpoint + "/catalogs/query?filter=")) + .endpoint(URI.create(endpoint + "/catalogs/query")) .headers(ImmutableMultimap. builder() .put("Accept", "*/*") .put("x-vcloud-authorization", token) @@ -115,7 +117,71 @@ public class QueryClientExpectTest extends BaseVCloudDirectorRestClientExpectTes .build()) .build(); - assertEquals(client.getQueryClient().catalogsQuery(""), expected); + assertEquals(client.getQueryClient().catalogsQueryAll(), expected); + } + + @Test + public void testQueryAllCatalogReferences() { + HttpRequest queryRequest = HttpRequest.builder() + .method("GET") + .endpoint(URI.create(endpoint + "/catalogs/query?format=references")) + .headers(ImmutableMultimap. builder() + .put("Accept", "*/*") + .put("x-vcloud-authorization", token) + .build()) + .build(); + + HttpResponse queryResponse= HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResourceWithContentType("/query/allCatalogReferences.xml", VCloudDirectorMediaType.QUERY_RESULT_RECORDS + ";version=1.5")) + .build(); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, queryRequest, queryResponse); + + CatalogReferences expected = CatalogReferences.builder() + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalogs/query?page=1&pageSize=25&format=references")) + .type("application/vnd.vmware.vcloud.query.references+xml") + .name("catalog") + .page(1) + .pageSize(25) + .total(4L) + .link(Link.builder() + .rel("alternate") + .type("application/vnd.vmware.vcloud.query.records+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalogs/query?page=1&pageSize=25&format=records")) + .build()) + .link(Link.builder() + .rel("alternate") + .type("application/vnd.vmware.vcloud.query.idrecords+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalogs/query?page=1&pageSize=25&format=idrecords")) + .build()) + .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(); + + assertEquals(client.getQueryClient().catalogReferencesQueryAll(), expected); } } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientLiveTest.java index f90f927e2a..68a4a5e9a9 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientLiveTest.java @@ -18,23 +18,18 @@ */ package org.jclouds.vcloud.director.v1_5.features; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.*; -import static org.jclouds.vcloud.director.v1_5.domain.Checks.*; import static org.testng.Assert.*; import java.net.URI; -import org.jclouds.vcloud.director.v1_5.domain.Metadata; -import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; import org.jclouds.vcloud.director.v1_5.domain.OrgList; import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.domain.TasksList; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest; +import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; -import com.google.common.collect.Iterables; - /** * Tests live behavior of {@link QueryClient}. * @@ -47,8 +42,14 @@ public class QueryClientLiveTest extends BaseVCloudDirectorClientLiveTest { * Convenience references to API clients. */ - private final CatalogClient catalogClient = context.getApi().getCatalogClient(); - private final QueryClient queryClient = context.getApi().getQueryClient(); + private CatalogClient catalogClient; + private QueryClient queryClient; + + @BeforeGroups(groups = { "live" }) + public void setupClients() { + catalogClient = context.getApi().getCatalogClient(); + queryClient = context.getApi().getQueryClient(); + } /* * Shared state between dependant tests. diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientLiveTest.java index 622020fb27..7959c075d2 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientLiveTest.java @@ -18,7 +18,6 @@ */ package org.jclouds.vcloud.director.v1_5.features; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.*; import static org.jclouds.vcloud.director.v1_5.domain.Checks.*; import static org.testng.Assert.*; @@ -29,6 +28,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.domain.TasksList; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest; +import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; import com.google.common.collect.Iterables; @@ -45,8 +45,14 @@ public class TaskClientLiveTest extends BaseVCloudDirectorClientLiveTest { * Convenience references to API clients. */ - private final OrgClient orgClient = context.getApi().getOrgClient(); - private final TaskClient taskClient = context.getApi().getTaskClient(); + private OrgClient orgClient; + private TaskClient taskClient; + + @BeforeGroups(groups = { "live" }) + public void setupClients() { + orgClient = context.getApi().getOrgClient(); + taskClient = context.getApi().getTaskClient(); + } /* * Shared state between dependant tests. diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java index 249f9707ad..5bd2cb9c4b 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java @@ -62,4 +62,3 @@ public class BaseVCloudDirectorClientLiveTest extends BaseVersionedServiceLiveTe } } - diff --git a/labs/vcloud-director/src/test/resources/query/allCatalogReferences.xml b/labs/vcloud-director/src/test/resources/query/allCatalogReferences.xml new file mode 100644 index 0000000000..1f1cd5da90 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/query/allCatalogReferences.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/labs/vcloud-director/src/test/resources/query/queryList.xml b/labs/vcloud-director/src/test/resources/query/queryList.xml new file mode 100644 index 0000000000..7d3c2f01c9 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/query/queryList.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From d8390da9b4eeeed871d92fcaf1cd5248be4861df Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Mon, 20 Feb 2012 11:38:48 +0000 Subject: [PATCH 04/13] Updates and fixes for existing clients, domain objects and tests, including: - Changed MetadataEntry to MetadataValue where required - Added more standardised assertion/error check messages - Completed CatalogClientLiveTest --- .../vcloud/director/v1_5/domain/Link.java | 4 +- .../domain/query/QueryResultReferences.java | 2 +- .../v1_5/features/CatalogAsyncClient.java | 9 +- .../director/v1_5/features/CatalogClient.java | 13 +- .../v1_5/features/OrgAsyncClient.java | 4 +- .../director/v1_5/features/OrgClient.java | 6 +- .../v1_5/VCloudDirectorLiveTestConstants.java | 18 ++- .../vcloud/director/v1_5/domain/Checks.java | 65 ++++---- .../features/CatalogClientExpectTest.java | 40 ++++- .../v1_5/features/CatalogClientLiveTest.java | 139 +++++++++++++----- .../v1_5/features/OrgClientExpectTest.java | 37 +++-- .../v1_5/features/OrgClientLiveTest.java | 46 ++---- .../v1_5/features/TaskClientLiveTest.java | 3 +- ...Entry.xml => catalogItemMetadataValue.xml} | 5 +- ...dataEntry.xml => catalogMetadataValue.xml} | 5 +- ...MetadataEntry.xml => orgMetadataValue.xml} | 5 +- 16 files changed, 258 insertions(+), 143 deletions(-) rename labs/vcloud-director/src/test/resources/catalog/{catalogItemMetadataEntry.xml => catalogItemMetadataValue.xml} (83%) rename labs/vcloud-director/src/test/resources/catalog/{catalogMetadataEntry.xml => catalogMetadataValue.xml} (83%) rename labs/vcloud-director/src/test/resources/org/{orgMetadataEntry.xml => orgMetadataValue.xml} (82%) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Link.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Link.java index 61c52d73b7..6e130f9e81 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Link.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Link.java @@ -46,8 +46,8 @@ public class Link extends ReferenceType { public static final String UP = "up"; public static final String DOWN = "down"; public static final String EDIT = "edit"; - public static final String DELETE = "delete"; public static final String ADD = "add"; + public static final String DELETE = "delete"; public static final String REMOVE = "remove"; public static final String CATALOG_ITEM = "catalogItem"; public static final String TASK_CANCEL = "task:cancel"; @@ -58,7 +58,7 @@ public class Link extends ReferenceType { public static final String FIRST_PAGE = "firstPage"; public static final List ALL = Arrays.asList( - UP, DOWN, EDIT, DELETE, ADD, REMOVE, CATALOG_ITEM, TASK_CANCEL, + UP, DOWN, EDIT, ADD, DELETE, REMOVE, CATALOG_ITEM, TASK_CANCEL, ALTERNATE, NEXT_PAGE, PREVIOUS_PAGE, LAST_PAGE, FIRST_PAGE ); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultReferences.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultReferences.java index 869378bc1c..979d90b537 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultReferences.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/query/QueryResultReferences.java @@ -188,7 +188,7 @@ public class QueryResultReferences> extends Container @XmlElementRefs({ @XmlElementRef(type = CatalogReference.class) }) - protected List references; + protected List references = Lists.newArrayList(); /** * Set of references representing query results. diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/CatalogAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/CatalogAsyncClient.java index b250c47b05..62675b5064 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/CatalogAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/CatalogAsyncClient.java @@ -37,7 +37,6 @@ import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; import org.jclouds.vcloud.director.v1_5.domain.Catalog; import org.jclouds.vcloud.director.v1_5.domain.CatalogItem; import org.jclouds.vcloud.director.v1_5.domain.Metadata; -import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; import org.jclouds.vcloud.director.v1_5.domain.MetadataValue; import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; import org.jclouds.vcloud.director.v1_5.domain.Task; @@ -93,7 +92,7 @@ public interface CatalogAsyncClient { @Consumes @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture getCatalogMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType catalogRef, + ListenableFuture getCatalogMetadataValue(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType catalogRef, @PathParam("key") String key); /** @@ -155,7 +154,7 @@ public interface CatalogAsyncClient { @Consumes @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture getCatalogItemMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType catalogItemRef, + ListenableFuture getCatalogItemMetadataValue(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType catalogItemRef, @PathParam("key") String key); /** @@ -167,7 +166,7 @@ public interface CatalogAsyncClient { @Produces(VCloudDirectorMediaType.METADATA_VALUE) @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture setCatalogItemMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType catalogItemRef, + ListenableFuture setCatalogItemMetadataValue(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType catalogItemRef, @PathParam("key") String key, @BinderParam(BindToXMLPayload.class) MetadataValue metadataValue); /** @@ -178,6 +177,6 @@ public interface CatalogAsyncClient { @Consumes @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture deleteCatalogItemMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType catalogItemRef, + ListenableFuture deleteCatalogItemMetadataValue(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType catalogItemRef, @PathParam("key") String key); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/CatalogClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/CatalogClient.java index 981286730f..81e64e4dd5 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/CatalogClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/CatalogClient.java @@ -24,7 +24,6 @@ import org.jclouds.concurrent.Timeout; import org.jclouds.vcloud.director.v1_5.domain.Catalog; import org.jclouds.vcloud.director.v1_5.domain.CatalogItem; import org.jclouds.vcloud.director.v1_5.domain.Metadata; -import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; import org.jclouds.vcloud.director.v1_5.domain.MetadataValue; import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; import org.jclouds.vcloud.director.v1_5.domain.Task; @@ -84,9 +83,9 @@ public interface CatalogClient { * * @param catalogRef the reference for the catalog * @param key the metadata entry key - * @return the catalog metadata entry + * @return the catalog metadata value */ - MetadataEntry getCatalogMetadataEntry(ReferenceType catalogRef, String key); + MetadataValue getCatalogMetadataValue(ReferenceType catalogRef, String key); /** * Retrieves a catalog item. @@ -158,9 +157,9 @@ public interface CatalogClient { * * @param catalogItemRef the reference for the catalog item * @param key the metadata entry key - * @return the catalog item metadata entry + * @return the catalog item metadata value */ - MetadataEntry getCatalogItemMetadataEntry(ReferenceType catalogItemRef, String key); + MetadataValue getCatalogItemMetadataValue(ReferenceType catalogItemRef, String key); /** * Sets the metadata for the particular key for the catalog item to the value provided. @@ -174,7 +173,7 @@ public interface CatalogClient { * @param value the metadata value * @return a task for the set operation */ - Task setCatalogItemMetadataEntry(ReferenceType catalogItemRef, String key, MetadataValue value); + Task setCatalogItemMetadataValue(ReferenceType catalogItemRef, String key, MetadataValue value); /** * Deletes the metadata for the particular key for the catalog item. @@ -187,5 +186,5 @@ public interface CatalogClient { * @param key the metadata entry key * @return a task for the delete operation */ - Task deleteCatalogItemMetadataEntry(ReferenceType catalogItemRef, String key); + Task deleteCatalogItemMetadataValue(ReferenceType catalogItemRef, String key); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgAsyncClient.java index 9fda1f293a..4f608da006 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgAsyncClient.java @@ -28,7 +28,7 @@ import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.JAXBResponseParser; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.vcloud.director.v1_5.domain.Metadata; -import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; +import org.jclouds.vcloud.director.v1_5.domain.MetadataValue; import org.jclouds.vcloud.director.v1_5.domain.Org; import org.jclouds.vcloud.director.v1_5.domain.OrgList; import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; @@ -81,6 +81,6 @@ public interface OrgAsyncClient { @Consumes @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture getOrgMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType orgRef, + ListenableFuture getOrgMetadataValue(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType orgRef, @PathParam("key") String key); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgClient.java index 96125cca70..63fa69d4b9 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgClient.java @@ -22,7 +22,7 @@ import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; import org.jclouds.vcloud.director.v1_5.domain.Metadata; -import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; +import org.jclouds.vcloud.director.v1_5.domain.MetadataValue; import org.jclouds.vcloud.director.v1_5.domain.Org; import org.jclouds.vcloud.director.v1_5.domain.OrgList; import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; @@ -58,7 +58,6 @@ public interface OrgClient { * @return the org or null if not found */ Org getOrg(ReferenceType orgRef); - // FIXME throws exception on not found currently /** * Retrieves an list of the organization's metadata @@ -80,6 +79,5 @@ public interface OrgClient { * * @return the metadata entry or null if not found */ - MetadataEntry getOrgMetadataEntry(ReferenceType orgRef, String key); - // FIXME throws exception on not found currently + MetadataValue getOrgMetadataValue(ReferenceType orgRef, String key); } 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 c58b863299..54ddd6156d 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 @@ -38,6 +38,22 @@ public class VCloudDirectorLiveTestConstants { public static final String TASK_COMPLETE_TIMELY = "Task %s should complete in a timely fashion"; @Deprecated - public static final String FIELD_NOT_NULL_FMT = "The %s field of the %s must not be null"; + public static final String NOT_NULL_OBJECT_FMT = "The %s field of the %s must not be null"; + + public static final String NOT_EMPTY_OBJECT_FMT = "One or more %s fields of the %s must be present"; + + public static final String REQUIRED_VALUE_OBJECT_FMT = "The %s field of the %s must not be '%s'"; + + public static final String REQUIRED_VALUE_FMT = "The %s field must not be '%s'"; + + public static final String MUST_BE_WELL_FORMED_FMT = "The %s field must be well formed: '%s'"; + + public static final String MUST_EXIST_FMT = "The '%s' %s must exist"; + + public static final String MUST_CONTAIN_FMT = "The %s field must contain '%s': '%s'"; + + public static final String CONDITION_FMT = "The %s field must be %s: '%s'"; + + public static final String CORRECT_VALUE_OBJECT_FMT = "The %s field of the %s must be '%s': '%s'"; } 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 f3d4084264..0c805c55b1 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 @@ -18,6 +18,8 @@ */ package org.jclouds.vcloud.director.v1_5.domain; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.*; +import static org.jclouds.vcloud.director.v1_5.domain.Checks.*; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; @@ -51,7 +53,7 @@ public class Checks { public static void checkEntityType(EntityType entity) { // Check required fields - assertNotNull(entity.getName(), "The Name attribute of an EntityType must be set"); + assertNotNull(entity.getName(), String.format(NOT_NULL_OBJECT_FMT, "Name", "EntityType")); // Check optional fields // NOTE description cannot be checked @@ -66,7 +68,7 @@ public class Checks { public static void checkReferenceType(ReferenceType reference) { // Check required fields - assertNotNull(reference.getHref(), "The Href attribute of a ReferenceType must be set"); + assertNotNull(reference.getHref(), String.format(NOT_NULL_OBJECT_FMT, "Href", "ReferenceType")); // Check optional fields String id = reference.getId(); @@ -90,21 +92,18 @@ public class Checks { public static void checkId(String id) { Iterable parts = Splitter.on(':').split(id); - assertEquals(Iterables.size(parts), 4, "The Id must be well formed"); - assertEquals(Iterables.get(parts, 0), "urn", "The Id must start with 'urn'"); - assertEquals(Iterables.get(parts, 1), "vcloud", "The Id must include 'vcloud'"); + assertEquals(Iterables.size(parts), 4, String.format(MUST_BE_WELL_FORMED_FMT, "Id", id)); + assertEquals(Iterables.get(parts, 0), "urn", String.format(MUST_CONTAIN_FMT, "Id", "urn", id)); + assertEquals(Iterables.get(parts, 1), "vcloud", String.format(MUST_CONTAIN_FMT, "Id", "vcloud", id)); try { - UUID uuid = UUID.fromString(Iterables.get(parts, 3)); - assertNotNull(uuid, "The UUID part of an Id must be well formed"); + UUID.fromString(Iterables.get(parts, 3)); } catch (IllegalArgumentException iae) { - fail("The UUID part of an Id must be well formed"); + fail(String.format(MUST_BE_WELL_FORMED_FMT, "Id", id)); } } public static void checkType(String type) { - assertTrue(VCloudDirectorMediaType.ALL.contains(type), - String.format("The Type (%s) must be a valid media type - %s", type, - Iterables.toString(VCloudDirectorMediaType.ALL))); + assertTrue(VCloudDirectorMediaType.ALL.contains(type), String.format(REQUIRED_VALUE_FMT, "Type", type, Iterables.toString(VCloudDirectorMediaType.ALL))); } // NOTE this does not currently check anything @@ -120,10 +119,8 @@ public class Checks { public static void checkLink(Link link) { // Check required fields - assertNotNull(link.getRel(), "The Rel attribute of a Link must be set"); - // XXX choose one - assertTrue(Link.Rel.ALL.contains(link.getRel()), String.format("The Rel attribute of a Link must be from the allowed list: %s", Iterables.toString(Link.Rel.ALL))); - assertTrue(Link.Rel.ALL.contains(link.getRel()), String.format("The Rel attribute of a Link cannot be '%s'", link.getRel())); + assertNotNull(link.getRel(), String.format(NOT_NULL_OBJECT_FMT, "Rel", "Link")); + assertTrue(Link.Rel.ALL.contains(link.getRel()), String.format(REQUIRED_VALUE_OBJECT_FMT, "Rel", "Link", link.getRel(), Iterables.toString(Link.Rel.ALL))); // Check parent type checkReferenceType(link); @@ -131,10 +128,8 @@ public class Checks { public static void checkTask(Task task) { // Check required fields - assertNotNull(task.getStatus(), "The Status attribute of a Task must be set"); - // XXX choose one - assertTrue(Task.Status.ALL.contains(task.getStatus()), String.format("The Status of a Task must be from the allowed list: %s", Iterables.toString(Task.Status.ALL))); - assertTrue(Task.Status.ALL.contains(task.getStatus()), String.format("The Status of a Task cannot be '%s'", task.getStatus())); + assertNotNull(task.getStatus(), String.format(NOT_NULL_OBJECT_FMT, "Status", "Task")); + assertTrue(Task.Status.ALL.contains(task.getStatus()), String.format(REQUIRED_VALUE_OBJECT_FMT, "Status", "Task", task.getStatus(), Iterables.toString(Link.Rel.ALL))); // Check optional fields // NOTE operation cannot be checked @@ -177,7 +172,9 @@ public class Checks { public static void checkMetadata(Metadata metadata) { Set metadataEntries = metadata.getMetadataEntries(); if (metadataEntries != null && !metadataEntries.isEmpty()) { - for (MetadataEntry metadataEntry : metadataEntries) checkMetadataEntry(metadataEntry); + for (MetadataEntry metadataEntry : metadataEntries) { + checkMetadataEntry(metadataEntry); + } } // Check parent type @@ -185,27 +182,43 @@ public class Checks { } public static void checkMetadataEntry(MetadataEntry metadataEntry) {+ // Check required fields - assertNotNull(metadataEntry.getKey(), "The Key attribute of a MetadataEntry must be set"); - assertNotNull(metadataEntry.getValue(), "The Value attribute of a MetadataEntry must be set"); + assertNotNull(metadataEntry.getKey(), String.format(NOT_NULL_OBJECT_FMT, "Key", "MetadataEntry")); + assertNotNull(metadataEntry.getValue(), String.format(NOT_NULL_OBJECT_FMT, "Value", "MetadataEntry")); // Check parent type checkResourceType(metadataEntry); } + public static void checkMetadataValue(MetadataValue metadataValue) { + // Check required elements and attributes + assertNotNull(metadataValue.getValue(), String.format(NOT_NULL_OBJECT_FMT, "Value", "MetadataValue")); + + // Check parent type + checkResourceType(metadataValue); + } + public static void checkProgress(Integer progress) { - assertTrue(progress >= 0 && progress <= 100, "The Progress attribute must be between 0 and 100"); + assertTrue(progress >= 0 && progress <= 100, String.format(CONDITION_FMT, "Progress", "between 0 and 100", Integer.toString(progress))); } public static void checkError(Error error) { // Check required fields - assertNotNull(error.getMessage(), "The Message attribute of an Error must be set"); - assertNotNull(error.getMajorErrorCode(), "The MajorErrorCode attribute of an Error must be set"); - assertNotNull(error.getMinorErrorCode(), "The MinorErrorCode attribute of an Error must be set"); + assertNotNull(error.getMessage(), String.format(NOT_NULL_OBJECT_FMT, "Message", "Error")); + assertNotNull(error.getMajorErrorCode(), String.format(NOT_NULL_OBJECT_FMT, "MajorErrorCode", "Error")); + assertNotNull(error.getMinorErrorCode(), String.format(NOT_NULL_OBJECT_FMT, "MinorErrorCode", "Error")); // NOTE vendorSpecificErrorCode cannot be checked // NOTE stackTrace cannot be checked } + public static void checkOrg(Org org) { + // Check required elements and attributes + assertNotNull(org.getFullName(), String.format(NOT_NULL_OBJECT_FMT, "FullName", "Org")); + + // Check parent type + checkEntityType(org); + } + public static void checkCatalog(Catalog catalog) { // Check optional elements/attributes Entity owner = catalog.getOwner(); diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientExpectTest.java index 9bf2121484..afeff912ac 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientExpectTest.java @@ -165,7 +165,7 @@ public class CatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectT HttpResponse catalogResponse = HttpResponse.builder() .statusCode(200) - .payload(payloadFromResourceWithContentType("/catalog/catalogMetadataEntry.xml", VCloudDirectorMediaType.METADATA_ENTRY)) + .payload(payloadFromResourceWithContentType("/catalog/catalogMetadataValue.xml", VCloudDirectorMediaType.METADATA_VALUE)) .build(); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, catalogRequest, catalogResponse); @@ -176,9 +176,9 @@ public class CatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectT .href(URI.create(endpoint + "/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) .build(); - MetadataEntry expected = metadataEntry(); + MetadataValue expected = metadataValue(); - assertEquals(client.getCatalogClient().getCatalogMetadataEntry(catalogRef, "KEY"), expected); + assertEquals(client.getCatalogClient().getCatalogMetadataValue(catalogRef, "KEY"), expected); } @Test @@ -349,7 +349,7 @@ public class CatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectT HttpResponse catalogItemResponse = HttpResponse.builder() .statusCode(200) - .payload(payloadFromResourceWithContentType("/catalog/catalogItemMetadataEntry.xml", VCloudDirectorMediaType.METADATA_ENTRY + ";version=1.5")) + .payload(payloadFromResourceWithContentType("/catalog/catalogItemMetadataValue.xml", VCloudDirectorMediaType.METADATA_VALUE + ";version=1.5")) .build(); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse); @@ -360,9 +360,9 @@ public class CatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectT .href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df")) .build(); - MetadataEntry expected = itemMetadataEntry(); + MetadataValue expected = itemMetadataValue(); - assertEquals(client.getCatalogClient().getCatalogItemMetadataEntry(catalogItemReference, "KEY"), expected); + assertEquals(client.getCatalogClient().getCatalogItemMetadataValue(catalogItemReference, "KEY"), expected); } @Test @@ -394,7 +394,7 @@ public class CatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectT Task expected = setMetadataValueTask(); - assertEquals(client.getCatalogClient().setCatalogItemMetadataEntry(catalogItemReference, "KEY", value), expected); + assertEquals(client.getCatalogClient().setCatalogItemMetadataValue(catalogItemReference, "KEY", value), expected); } @Test @@ -423,7 +423,7 @@ public class CatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectT Task expected = deleteMetadataEntryTask(); - assertEquals(client.getCatalogClient().deleteCatalogItemMetadataEntry(catalogItemReference, "KEY"), expected); + assertEquals(client.getCatalogClient().deleteCatalogItemMetadataValue(catalogItemReference, "KEY"), expected); } public static final Catalog catalog() { @@ -524,6 +524,30 @@ public class CatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectT .entry("KEY", "VALUE") .build(); } + + public static MetadataValue metadataValue() { + return MetadataValue.builder() + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/metadata/KEY")) + .link(Link.builder() + .rel("up") + .type("application/vnd.vmware.vcloud.metadata+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/metadata")) + .build()) + .value("VALUE") + .build(); + } + + public static MetadataValue itemMetadataValue() { + return MetadataValue.builder() + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df/metadata/KEY")) + .link(Link.builder() + .rel("up") + .type("application/vnd.vmware.vcloud.metadata+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df/metadata")) + .build()) + .value("VALUE") + .build(); + } public static CatalogItem catalogItem() { return CatalogItem.builder() diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java index 3a19a91f3c..ed8e3d73a8 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java @@ -18,13 +18,14 @@ */ package org.jclouds.vcloud.director.v1_5.features; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.*; import static org.jclouds.vcloud.director.v1_5.domain.Checks.*; import static org.testng.Assert.*; -import org.jclouds.predicates.RetryablePredicate; import org.jclouds.vcloud.director.v1_5.VCloudDirectorException; import org.jclouds.vcloud.director.v1_5.domain.Catalog; import org.jclouds.vcloud.director.v1_5.domain.CatalogItem; +import org.jclouds.vcloud.director.v1_5.domain.Error; import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; import org.jclouds.vcloud.director.v1_5.domain.MetadataValue; @@ -37,7 +38,6 @@ import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; import com.google.common.base.Predicate; -import com.google.common.base.Predicates; import com.google.common.collect.Iterables; /** @@ -45,11 +45,9 @@ import com.google.common.collect.Iterables; * * @author grkvlt@apache.org */ -@Test(groups = { "live", "apitests" }, testName = "CatalogClientLiveTest") +@Test(groups = { "live", "apitests" }, testName = "CatalogClientLiveTest", singleThreaded = true) public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest { - private static final String CATALOG_NAME = "QunyingTestCatalog"; // TODO add as test configuration property - /* * Convenience references to API clients. */ @@ -74,11 +72,12 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest { catalogClient = context.getApi().getCatalogClient(); queryClient = context.getApi().getQueryClient(); } + private Metadata catalogItemMetadata; @Test(testName = "GET /catalog/{id}") public void testGetCatalog() { - CatalogReferences catalogReferences = queryClient.catalogReferencesQuery(String.format("name==%s", CATALOG_NAME)); - assertEquals(Iterables.size(catalogReferences.getReferences()), 1, String.format("The %s Catalog must exist", CATALOG_NAME)); + CatalogReferences catalogReferences = queryClient.catalogReferencesQuery(String.format("name==%s", catalogName)); + assertEquals(Iterables.size(catalogReferences.getReferences()), 1, String.format(MUST_EXIST_FMT, catalogName, "Catalog")); catalogRef = Iterables.getOnlyElement(catalogReferences.getReferences()); catalog = catalogClient.getCatalog(catalogRef); } @@ -93,7 +92,7 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest { // NOTE for this test to work, we need to be able to upload a new vAppTemplate to a vDC first // NOTE we could do this with a test environment property -Dtest.vcloud-director.vappTemplateId=vapptemplate-abcd - @Test(testName = "POST /catalog/{id}/catalogItems", dependsOnMethods = { "testGetCatalogItem" }, enabled = false) + @Test(testName = "POST /catalog/{id}/catalogItems", dependsOnMethods = { "testGetCatalog" }, enabled = false) public void testAddCatalogItem() { CatalogItem editedCatalogItem = CatalogItem.builder() .name("newitem") @@ -123,7 +122,7 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest { assertEquals(newCatalogItem.getName(), "UPDATEDNAME"); } - @Test(testName = "DELETE /catalogItem/{id}", dependsOnMethods = { "testUpdateCatalogItem" }, enabled = false) + @Test(testName = "DELETE /catalogItem/{id}", dependsOnMethods = { "testAddCatalogItem" }, enabled = false) public void testDeleteCatalogItem() { catalogClient.deleteCatalogItem(newCatalogItemRef); try { @@ -131,6 +130,7 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest { fail("The CatalogItem should have been deleted"); } catch (VCloudDirectorException vcde) { checkError(vcde.getError()); + // XXX assertEquals(vcde.getError().getMajorErrorCode(), Integer.valueOf(403), "The majorErrorCode should be 403 since the item has been deleted"); } } @@ -144,50 +144,123 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest { // NOTE for this test to work, we need to be able to create metadata on a Catalog, specifically { "KEY", "VALUE" } @Test(testName = "GET /catalog/{id}/metadata/{key}", dependsOnMethods = { "testGetCatalogMetadata" }, enabled = false) - public void testGetCatalogMetadataEntry() { + public void testGetCatalogMetadataValue() { MetadataEntry existingMetadataEntry = Iterables.find(catalogMetadata.getMetadataEntries(), new Predicate() { @Override public boolean apply(MetadataEntry input) { return input.getKey().equals("KEY"); } }); - MetadataEntry metadataEntry = catalogClient.getCatalogMetadataEntry(catalogRef, "KEY"); - assertEquals(existingMetadataEntry.getValue(), metadataEntry.getValue()); - checkMetadataEntry(metadataEntry); + MetadataValue metadataValue = catalogClient.getCatalogMetadataValue(catalogRef, "KEY"); + // XXX + assertEquals(metadataValue.getValue(), existingMetadataEntry.getValue(), + "The MetadataValue for KEY should have the same Value as the existing MetadataEntry"); + checkMetadataValue(metadataValue); } - @Test(testName = "POST /catalogItem/{id}/metadata", dependsOnMethods = { "testGetCatalogItem" }) + @Test(testName = "GET /catalogItem/{id}/metadata", dependsOnMethods = { "testGetCatalogItem" }) + public void testGetCatalogItemMetadata() { + resetCatalogItemMetadata(catalogItemRef); + catalogItemMetadata = catalogClient.getCatalogItemMetadata(catalogItemRef); + // XXX + assertEquals(catalogItemMetadata.getMetadataEntries().size(), 1, "There should be a single MetadataEntry"); + checkMetadata(catalogItemMetadata); + } + + @Test(testName = "POST /catalogItem/{id}/metadata", dependsOnMethods = { "testGetCatalogItemMetadata" }) public void testMergeCatalogItemMetadata() { Metadata newMetadata = Metadata.builder() - .entry(MetadataEntry.builder().entry("KEY", "VALUE").build()) + .entry(MetadataEntry.builder().entry("KEY", "MARMALADE").build()) + .entry(MetadataEntry.builder().entry("VEGIMITE", "VALUE").build()) .build(); - Task task = catalogClient.mergeCatalogItemMetadata(catalogItemRef, newMetadata); - // TODO wait until task no longer running... - } - - @Test(testName = "GET /catalogItem/{id}/metadata", dependsOnMethods = { "testMergeCatalogItemMetadata" }) - public void testGetCatalogItemMetadata() { - Metadata metadata = catalogClient.getCatalogItemMetadata(catalogItemRef); + Task mergeCatalogItemMetadata = catalogClient.mergeCatalogItemMetadata(catalogItemRef, newMetadata); + checkTask(mergeCatalogItemMetadata); + // TODO requires code from dan to be merged +// assertTrue(taskTester.apply(mergeCatalogItemMetadata.getHref()), +// String.format(TASK_COMPLETE_TIMELY, "mergeCatalogItemMetadata")); + + Metadata mergedCatalogItemMetadata = catalogClient.getCatalogItemMetadata(catalogItemRef); + // XXX + assertEquals(mergedCatalogItemMetadata.getMetadataEntries().size(), catalogItemMetadata.getMetadataEntries().size() + 1, + "Should have added another MetadataEntry to the CatalogItem"); + + MetadataValue keyMetadataValue = catalogClient.getCatalogItemMetadataValue(catalogItemRef, "KEY"); + // XXX + assertEquals(keyMetadataValue.getValue(), "MARMALADE", "The Value of the MetadataValue for KEY should have changed"); + checkMetadataValue(keyMetadataValue); + + MetadataValue newKeyMetadataValue = catalogClient.getCatalogItemMetadataValue(catalogItemRef, "VEGIMITE"); + // XXX + assertEquals(newKeyMetadataValue.getValue(), "VALUE", "The Value of the MetadataValue for NEW_KEY should have been set"); + checkMetadataValue(newKeyMetadataValue); } + // TODO escalate // XXX org.jclouds.vcloud.director.v1_5.VCloudDirectorException: Error: The access to the resource metadata_item with id KEY is forbidden - @Test(testName = "GET /catalog/{id}/metadata/{key}", dependsOnMethods = { "testMergeCatalogItemMetadata" }, enabled = false) - public void testGetCatalogItemMetadataEntry() { - MetadataEntry metadataEntry = catalogClient.getCatalogItemMetadataEntry(catalogItemRef, "KEY"); + @Test(testName = "GET /catalog/{id}/metadata/{key}", dependsOnMethods = { "testGetCatalogItemMetadata" }) + public void testGetCatalogItemMetadataValue() { + MetadataEntry existingMetadataEntry = Iterables.find(catalogItemMetadata.getMetadataEntries(), new Predicate() { + @Override + public boolean apply(MetadataEntry input) { + return input.getKey().equals("KEY"); + } + }); + MetadataValue metadataValue = catalogClient.getCatalogItemMetadataValue(catalogItemRef, "KEY"); + assertEquals(existingMetadataEntry.getValue(), metadataValue.getValue()); + checkMetadataValue(metadataValue); } - @Test(testName = "PUT /catalog/{id}/metadata/{key}", dependsOnMethods = { "testMergeCatalogItemMetadata" }) - public void testSetCatalogItemMetadataEntry() { + @Test(testName = "PUT /catalog/{id}/metadata/{key}", dependsOnMethods = { "testGetCatalogItemMetadataValue" }) + public void testSetCatalogItemMetadataValue() { MetadataValue newMetadataValue = MetadataValue.builder().value("NEW").build(); - Task task = catalogClient.setCatalogItemMetadataEntry(catalogItemRef, "KEY", newMetadataValue); - // TODO wait until task no longer running... + Task setCatalogItemMetadataValue = catalogClient.setCatalogItemMetadataValue(catalogItemRef, "KEY", newMetadataValue); + checkTask(setCatalogItemMetadataValue); + // TODO requires code from dan to be merged +// assertTrue(taskTester.apply(setCatalogItemMetadataValue.getHref()), +// String.format(TASK_COMPLETE_TIMELY, "setCatalogItemMetadataValue")); + + MetadataValue updatedMetadataValue = catalogClient.getCatalogItemMetadataValue(catalogItemRef, "KEY"); + assertEquals(updatedMetadataValue.getValue(), newMetadataValue.getValue(), + String.format(CORRECT_VALUE_OBJECT_FMT, "Value", "MetadataValue", newMetadataValue.getValue(), updatedMetadataValue.getValue())); + checkMetadataValue(updatedMetadataValue); } - @Test(testName = "DELETE /catalog/{id}/metadata/{key}", dependsOnMethods = { "testMergeCatalogItemMetadata" }) - public void testDeleteCatalogItemMetadataEntry() { - Task task = catalogClient.deleteCatalogItemMetadataEntry(catalogItemRef, "KEY"); - // TODO wait until task no longer running... + @Test(testName = "DELETE /catalog/{id}/metadata/{key}", dependsOnMethods = { "testSetCatalogItemMetadataValue" }) + public void testDeleteCatalogItemMetadataValue() { + Task deleteCatalogItemMetadataValue = catalogClient.deleteCatalogItemMetadataValue(catalogItemRef, "KEY"); + checkTask(deleteCatalogItemMetadataValue); + // TODO requires code from dan to be merged +// assertTrue(taskTester.apply(deleteCatalogItemMetadataValue.getHref()), +// String.format(TASK_COMPLETE_TIMELY, "deleteCatalogItemMetadataValue")); + try { + catalogClient.getCatalogItemMetadataValue(catalogItemRef, "KEY"); + fail("The CatalogItem MetadataValue for KEY should have been deleted"); + } catch (VCloudDirectorException vcde) { + Error error = vcde.getError(); + checkError(error); + Integer majorErrorCode = error.getMajorErrorCode(); + assertEquals(majorErrorCode, Integer.valueOf(403), + String.format(CORRECT_VALUE_OBJECT_FMT, "MajorErrorCode", "Error", "403",Integer.toString(majorErrorCode))); + } + } + + private void deleteAllCatalogItemMetadata(ReferenceType catalogItemRef) { + Metadata currentMetadata = catalogClient.getCatalogItemMetadata(catalogItemRef); + for (MetadataEntry currentMetadataEntry : currentMetadata.getMetadataEntries()) { + catalogClient.deleteCatalogItemMetadataValue(catalogItemRef, currentMetadataEntry.getKey()); + } + Metadata emptyMetadata = catalogClient.getCatalogItemMetadata(catalogItemRef); + assertTrue(emptyMetadata.getMetadataEntries().isEmpty(), "The catalogItem Metadata should be empty"); + } + + private void resetCatalogItemMetadata(ReferenceType catalogItemRef) { + deleteAllCatalogItemMetadata(catalogItemRef); + Metadata newMetadata = Metadata.builder().entry(MetadataEntry.builder().entry("KEY", "VALUE").build()).build(); + Task mergeCatalogItemMetadata = catalogClient.mergeCatalogItemMetadata(catalogItemRef, newMetadata); + // TODO requires code from dan to be merged +// assertTrue(taskTester.apply(mergeCatalogItemMetadata.getHref()), +// String.format(TASK_COMPLETE_TIMELY, "mergeCatalogItemMetadata")); } } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientExpectTest.java index 541a37134e..514ad64b88 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientExpectTest.java @@ -29,6 +29,7 @@ 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; import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; +import org.jclouds.vcloud.director.v1_5.domain.MetadataValue; import org.jclouds.vcloud.director.v1_5.domain.Org; import org.jclouds.vcloud.director.v1_5.domain.OrgList; import org.jclouds.vcloud.director.v1_5.domain.Reference; @@ -197,18 +198,18 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest } @Test - public void testGetOrgMetadataEntry() { + public void testGetOrgMetadataValue() { URI orgUri = URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, getStandardRequest("GET", "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata/KEY"), - getStandardPayloadResponse("/org/orgMetadataEntry.xml", VCloudDirectorMediaType.METADATA_ENTRY)); + getStandardPayloadResponse("/org/orgMetadataValue.xml", VCloudDirectorMediaType.METADATA_VALUE)); - MetadataEntry expected = metadataEntry(); + MetadataValue expected = metadataValue(); Reference orgRef = Reference.builder().href(orgUri).build(); - assertEquals(client.getOrgClient().getOrgMetadataEntry(orgRef, "KEY"), expected); + assertEquals(client.getOrgClient().getOrgMetadataValue(orgRef, "KEY"), expected); } public static Org org() { @@ -263,13 +264,25 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest public static MetadataEntry metadataEntry() { return MetadataEntry.builder() - .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata/KEY")) - .link(Link.builder() - .rel("up") - .type("application/vnd.vmware.vcloud.metadata+xml") - .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata")) - .build()) - .entry("KEY", "VALUE") - .build(); + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata/KEY")) + .link(Link.builder() + .rel("up") + .type("application/vnd.vmware.vcloud.metadata+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata")) + .build()) + .entry("KEY", "VALUE") + .build(); + } + + public static MetadataValue metadataValue() { + return MetadataValue.builder() + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata/KEY")) + .link(Link.builder() + .rel("up") + .type("application/vnd.vmware.vcloud.metadata+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata")) + .build()) + .value("VALUE") + .build(); } } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientLiveTest.java index 7973a175ae..67a480a51e 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientLiveTest.java @@ -24,7 +24,7 @@ import static org.testng.Assert.*; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; import org.jclouds.vcloud.director.v1_5.domain.Metadata; -import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; +import org.jclouds.vcloud.director.v1_5.domain.MetadataValue; import org.jclouds.vcloud.director.v1_5.domain.Org; import org.jclouds.vcloud.director.v1_5.domain.OrgList; import org.jclouds.vcloud.director.v1_5.domain.Reference; @@ -68,11 +68,11 @@ public class OrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { // NOTE The environment MUST have at least one organisation configured - // Check required elements and attributes - assertFalse(Iterables.isEmpty(orgList.getOrgs()), "There must always be Org elements in the OrgList"); + // Check test requirements + assertFalse(Iterables.isEmpty(orgList.getOrgs()), String.format(NOT_EMPTY_OBJECT_FMT, "Org", "OrgList")); for (Reference orgRef : orgList.getOrgs()) { - assertEquals(orgRef.getType(), VCloudDirectorMediaType.ORG, "The Refernce must be to an Org type"); + assertEquals(orgRef.getType(), VCloudDirectorMediaType.ORG, String.format(CONDITION_FMT, "Reference.Type", VCloudDirectorMediaType.ORG, orgRef.getType())); checkReferenceType(orgRef); } } @@ -84,11 +84,7 @@ public class OrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { // Call the method being tested org = orgClient.getOrg(orgRef); - // Check required elements and attributes - assertNotNull(org.getFullName(), String.format(FIELD_NOT_NULL_FMT, "FullName", "Org")); - - // Check parent type - checkEntityType(org); + checkOrg(org); } @Test(testName = "GET /org/{id}/metadata/", dependsOnMethods = { "testGetOrg" }) @@ -98,36 +94,22 @@ public class OrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { // NOTE The environment MUST have at one metadata entry for the first organisation configured - // Check required elements and attributes - assertFalse(Iterables.isEmpty(metadata.getMetadataEntries()), "There must always be MetadataEntry elements in the Org"); + checkMetadata(metadata); - // Check parent type - checkResourceType(metadata); - - for (MetadataEntry entry : metadata.getMetadataEntries()) { - // Check required elements and attributes - assertNotNull(entry.getKey(), String.format(FIELD_NOT_NULL_FMT, "Key", "MetadataEntry")); - assertNotNull(entry.getValue(), String.format(FIELD_NOT_NULL_FMT, "Value", "MetadataEntry")); - - // Check parent type - checkResourceType(entry); - } + // Check requirements for this test + assertFalse(Iterables.isEmpty(metadata.getMetadataEntries()), String.format(NOT_EMPTY_OBJECT_FMT, "MetadataEntry", "Org")); } @Test(testName = "GET /org/{id}/metadata/{key}", dependsOnMethods = { "testGetOrgMetadata" }) - public void testGetOrgMetadataEntry() { + public void testGetOrgMetadataValue() { // Call the method being tested - MetadataEntry entry = orgClient.getOrgMetadataEntry(orgRef, "KEY"); + MetadataValue value = orgClient.getOrgMetadataValue(orgRef, "KEY"); // NOTE The environment MUST have configured the metadata entry as '{ key="KEY", value="VALUE" )' - // Check required elements and attributes - assertNotNull(entry.getKey(), String.format(FIELD_NOT_NULL_FMT, "Key", "MetadataEntry")); - assertEquals(entry.getKey(), "KEY", "The Key field must have the value \"KEY\""); - assertNotNull(entry.getValue(), String.format(FIELD_NOT_NULL_FMT, "Value", "MetadataEntry")); - assertEquals(entry.getValue(), "VALUE", "The Value field must have the value \"VALUE\""); - - // Check parent type - checkResourceType(entry); + String expected = "VALUE"; + + checkMetadataValue(value); + assertEquals(value.getValue(), expected, String.format(CORRECT_VALUE_OBJECT_FMT, "Value", "MetadataValue", expected, value.getValue())); } } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientLiveTest.java index 7959c075d2..28bd663ae9 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientLiveTest.java @@ -18,6 +18,7 @@ */ package org.jclouds.vcloud.director.v1_5.features; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.*; import static org.jclouds.vcloud.director.v1_5.domain.Checks.*; import static org.testng.Assert.*; @@ -75,7 +76,7 @@ public class TaskClientLiveTest extends BaseVCloudDirectorClientLiveTest { // NOTE The environment MUST have ... // Check required elements and attributes - assertFalse(Iterables.isEmpty(taskList.getTasks()), "There must always be Task elements in the TaskList"); + assertFalse(Iterables.isEmpty(taskList.getTasks()), String.format(NOT_EMPTY_OBJECT_FMT, "Task", "TaskList")); for (Task task : taskList.getTasks()) { checkTask(task); diff --git a/labs/vcloud-director/src/test/resources/catalog/catalogItemMetadataEntry.xml b/labs/vcloud-director/src/test/resources/catalog/catalogItemMetadataValue.xml similarity index 83% rename from labs/vcloud-director/src/test/resources/catalog/catalogItemMetadataEntry.xml rename to labs/vcloud-director/src/test/resources/catalog/catalogItemMetadataValue.xml index 23cef493a4..3c623ae8dd 100644 --- a/labs/vcloud-director/src/test/resources/catalog/catalogItemMetadataEntry.xml +++ b/labs/vcloud-director/src/test/resources/catalog/catalogItemMetadataValue.xml @@ -1,6 +1,5 @@ - + - KEY VALUE - + diff --git a/labs/vcloud-director/src/test/resources/catalog/catalogMetadataEntry.xml b/labs/vcloud-director/src/test/resources/catalog/catalogMetadataValue.xml similarity index 83% rename from labs/vcloud-director/src/test/resources/catalog/catalogMetadataEntry.xml rename to labs/vcloud-director/src/test/resources/catalog/catalogMetadataValue.xml index 345afec682..6f7e44604c 100644 --- a/labs/vcloud-director/src/test/resources/catalog/catalogMetadataEntry.xml +++ b/labs/vcloud-director/src/test/resources/catalog/catalogMetadataValue.xml @@ -1,6 +1,5 @@ - + - KEY VALUE - + diff --git a/labs/vcloud-director/src/test/resources/org/orgMetadataEntry.xml b/labs/vcloud-director/src/test/resources/org/orgMetadataValue.xml similarity index 82% rename from labs/vcloud-director/src/test/resources/org/orgMetadataEntry.xml rename to labs/vcloud-director/src/test/resources/org/orgMetadataValue.xml index 8cb2bd63c9..5ee3e5f704 100644 --- a/labs/vcloud-director/src/test/resources/org/orgMetadataEntry.xml +++ b/labs/vcloud-director/src/test/resources/org/orgMetadataValue.xml @@ -1,6 +1,5 @@ - + - KEY VALUE - + From 473126e7ec088abcf7c27476d58b4c8e7ee06131 Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Mon, 20 Feb 2012 11:47:35 +0000 Subject: [PATCH 05/13] Add numeric ids to Check error messages --- .../v1_5/VCloudDirectorLiveTestConstants.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) 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 54ddd6156d..dbf530b03a 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 @@ -23,6 +23,8 @@ package org.jclouds.vcloud.director.v1_5; */ public class VCloudDirectorLiveTestConstants { + /* danikov */ + public static final String REF_REQ_LIVE = "%s reference required to perform live tests"; public static final String OBJ_REQ_LIVE = "%s instance required to perform live tests"; public static final String OBJ_FIELD_REQ_LIVE = "%s must have a non-null \"%s\" to perform live tests"; @@ -37,23 +39,24 @@ public class VCloudDirectorLiveTestConstants { public static final String OBJ_DEL = "%s (%s) should have been deleted"; public static final String TASK_COMPLETE_TIMELY = "Task %s should complete in a timely fashion"; - @Deprecated - public static final String NOT_NULL_OBJECT_FMT = "The %s field of the %s must not be null"; + /* grkvlt */ + + public static final String NOT_NULL_OBJECT_FMT = "ERR-01: The %s field of the %s must not be null"; - public static final String NOT_EMPTY_OBJECT_FMT = "One or more %s fields of the %s must be present"; + public static final String NOT_EMPTY_OBJECT_FMT = "ERR-02: One or more %s fields of the %s must be present"; - public static final String REQUIRED_VALUE_OBJECT_FMT = "The %s field of the %s must not be '%s'"; + public static final String REQUIRED_VALUE_OBJECT_FMT = "ERR-03: The %s field of the %s must not be '%s'; allowed values: %s"; - public static final String REQUIRED_VALUE_FMT = "The %s field must not be '%s'"; + public static final String REQUIRED_VALUE_FMT = "ERR-04: The %s field must not be '%sr'; allowed values: %s"; - public static final String MUST_BE_WELL_FORMED_FMT = "The %s field must be well formed: '%s'"; + public static final String MUST_BE_WELL_FORMED_FMT = "ERR-05: The %s field must be well formed: '%s'"; - public static final String MUST_EXIST_FMT = "The '%s' %s must exist"; + public static final String MUST_EXIST_FMT = "ERR-06: The '%s' %s must exist"; - public static final String MUST_CONTAIN_FMT = "The %s field must contain '%s': '%s'"; + public static final String MUST_CONTAIN_FMT = "ERR-07: The %s field must contain '%s': '%s'"; - public static final String CONDITION_FMT = "The %s field must be %s: '%s'"; + public static final String CONDITION_FMT = "ERR-08: The %s field must be %s: '%s'"; - public static final String CORRECT_VALUE_OBJECT_FMT = "The %s field of the %s must be '%s': '%s'"; + public static final String CORRECT_VALUE_OBJECT_FMT = "ERR-09: The %s field of the %s must be '%s': '%s'"; } From 4e6bb27e9d8a2ef1b93b854e1762aa614c8d8dab Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Fri, 17 Feb 2012 19:21:41 +0000 Subject: [PATCH 06/13] Finishing up live tests for Catalog and Query, and general tifying of domain objects and constants --- .../v1_5/VCloudDirectorConstants.java | 26 ++ .../v1_5/VCloudDirectorException.java | 13 +- .../v1_5/VCloudDirectorMediaType.java | 10 +- .../v1_5/VCloudDirectorPropertiesBuilder.java | 19 +- .../VCloudDirectorRestClientModule.java | 5 + .../vcloud/director/v1_5/domain/Link.java | 11 +- .../vcloud/director/v1_5/domain/Media.java | 179 ++++-------- .../director/v1_5/domain/ResourceEntity.java | 256 ------------------ .../v1_5/domain/ResourceEntityType.java | 142 +++------- .../vcloud/director/v1_5/domain/Task.java | 15 +- .../domain/TaskInErrorStateException.java | 41 --- .../director/v1_5/domain/TaskStatus.java | 73 ----- .../v1_5/domain/vapp/AbstractVAppType.java | 47 +--- .../director/v1_5/domain/vapp/VApp.java | 42 +-- .../director/v1_5/predicates/TaskSuccess.java | 47 ++-- ...CloudDirectorClientExperimentLiveTest.java | 2 +- .../v1_5/VCloudDirectorLiveTestConstants.java | 2 +- .../vcloud/director/v1_5/domain/Checks.java | 2 +- .../v1_5/features/CatalogClientLiveTest.java | 20 +- .../v1_5/features/NetworkClientLiveTest.java | 6 +- .../v1_5/features/OrgClientLiveTest.java | 6 +- .../v1_5/features/QueryClientLiveTest.java | 35 +-- .../v1_5/features/TaskClientLiveTest.java | 6 +- .../BaseVCloudDirectorClientLiveTest.java | 15 +- 24 files changed, 259 insertions(+), 761 deletions(-) delete mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceEntity.java delete mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TaskInErrorStateException.java delete mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TaskStatus.java diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorConstants.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorConstants.java index c094600788..cffe572f65 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorConstants.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorConstants.java @@ -28,4 +28,30 @@ public class VCloudDirectorConstants { /** The XML namespace used by the clients. */ public static final String VCLOUD_1_5_NS = "http://www.vmware.com/vcloud/v1.5"; + /** The property used to configure the timeout for task completion. */ + public static final String PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED = "jclouds.vcloud-director.timeout.task-complete"; + + public static final String PROPERTY_VCLOUD_VERSION_SCHEMA = "jclouds.vcloud.version.schema"; + + /** Name of the default org that your vApp will join, if an org isn't explicitly specified. */ + public static final String PROPERTY_VCLOUD_DEFAULT_ORG = "jclouds.vcloud.defaults.org"; + + /** Name of the default catalog to query, if it isn't explicitly specified. */ + public static final String PROPERTY_VCLOUD_DEFAULT_CATALOG = "jclouds.vcloud.defaults.catalog"; + + /** Name of the VDC that your vApp will join, if a vDC isn't explicitly specified. */ + public static final String PROPERTY_VCLOUD_DEFAULT_VDC = "jclouds.vcloud.defaults.vdc"; + + /** Name of the default network, in the default VDC that your vApp will join. */ + public static final String PROPERTY_VCLOUD_DEFAULT_NETWORK = "jclouds.vcloud.defaults.network"; + + /** TODO javadoc */ + // public static final String PROPERTY_VCLOUD_DEFAULT_FENCEMODE = "jclouds.vcloud.defaults.fencemode"; + + /** TODO javadoc */ + public static final String PROPERTY_VCLOUD_XML_NAMESPACE = "jclouds.vcloud.xml.ns"; + + /** TODO javadoc */ + public static final String PROPERTY_VCLOUD_XML_SCHEMA = "jclouds.vcloud.xml.schema"; + } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorException.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorException.java index 620128e13a..f325032393 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorException.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorException.java @@ -27,22 +27,33 @@ import org.jclouds.vcloud.director.v1_5.domain.Task; public class VCloudDirectorException extends RuntimeException { /** The serialVersionUID. */ - private static final long serialVersionUID = -3200853408568729058L; + private static final long serialVersionUID = -5292516858598372960L; private final Error error; + private final Task task; public VCloudDirectorException(Error error) { super("Error: " + error.getMessage()); this.error = error; + this.task = null; } public VCloudDirectorException(Task task) { super("Task error: " + task.getError().getMessage()); this.error = task.getError(); + this.task = task; } public Error getError() { return error; } + public boolean hasTask() { + return task != null; + } + + public Task getTask() { + return task; + } + } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java index d4d7386d81..43756144b4 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java @@ -78,12 +78,20 @@ public class VCloudDirectorMediaType { public static final String QUERY_RESULT_REFERENCES = "application/vnd.vmware.vcloud.query.references+xml"; public static final String QUERY_RESULT_ID_RECORDS = "application/vnd.vmware.vcloud.query.idrecords+xml"; + + public static final String CONTROL_ACCESS = "application/vnd.vmware.vcloud.controlAccess+xml"; + /** + * All acceptable media types. + * + * This list must be updated whenever a new media type constant is added. + */ public static final List ALL = Arrays.asList( SESSION, ERROR, ORG_LIST, METADATA, METADATA_ENTRY, METADATA_VALUE, ORG, TASKS_LIST, TASK, ORG_NETWORK, CATALOG, CATALOG_ITEM, CATALOG_ITEMS, CATALOGS_LIST, PROPERTY, MEDIA, OWNER, VDC, ADMIN_USER, QUERY_RESULT_RECORDS, - QUERY_RESULT_REFERENCES, QUERY_RESULT_ID_RECORDS + QUERY_RESULT_REFERENCES, QUERY_RESULT_ID_RECORDS, + CONTROL_ACCESS ); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorPropertiesBuilder.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorPropertiesBuilder.java index 0e0b74745a..446e921835 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorPropertiesBuilder.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorPropertiesBuilder.java @@ -18,9 +18,8 @@ */ package org.jclouds.vcloud.director.v1_5; -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; +import static org.jclouds.Constants.*; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; import java.util.Properties; @@ -37,8 +36,20 @@ public class VCloudDirectorPropertiesBuilder extends PropertiesBuilder { protected Properties defaultProperties() { Properties properties = super.defaultProperties(); properties.setProperty(PROPERTY_ENDPOINT, "https://vcloudbeta.bluelock.com/api"); - properties.setProperty(PROPERTY_SESSION_INTERVAL, 30*60 + ""); + properties.setProperty(PROPERTY_SESSION_INTERVAL, Integer.toString(30 * 60)); properties.setProperty(PROPERTY_API_VERSION, "1.5"); + + properties.setProperty(PROPERTY_VCLOUD_XML_NAMESPACE, + String.format("http://www.vmware.com/vcloud/v${%s}", PROPERTY_VCLOUD_VERSION_SCHEMA)); + properties.setProperty(PROPERTY_SESSION_INTERVAL, Integer.toString(8 * 60)); + properties.setProperty(PROPERTY_VCLOUD_XML_SCHEMA, "https://vcloudbeta.bluelock.com/api/v1.5/schema/master.xsd"); + properties.setProperty("jclouds.dns_name_length_min", "1"); + properties.setProperty("jclouds.dns_name_length_max", "80"); + + // TODO integrate these with the {@link ComputeTimeouts} instead of having a single timeout for everything. + properties.setProperty(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED, Long.toString(1200l * 1000l)); + properties.setProperty(PROPERTY_SESSION_INTERVAL, Integer.toString(300)); + return properties; } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java index da1ea4dd89..0fde279933 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java @@ -19,6 +19,7 @@ package org.jclouds.vcloud.director.v1_5.config; import static com.google.common.base.Throwables.*; import static org.jclouds.rest.config.BinderUtils.*; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; import java.net.URI; import java.util.Map; @@ -35,6 +36,7 @@ import org.jclouds.http.annotation.ClientError; import org.jclouds.http.annotation.Redirection; import org.jclouds.http.annotation.ServerError; import org.jclouds.location.Provider; +import org.jclouds.predicates.RetryablePredicate; import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.config.RestClientModule; import org.jclouds.vcloud.director.v1_5.VCloudDirectorAsyncClient; @@ -59,14 +61,17 @@ import org.jclouds.vcloud.director.v1_5.handlers.InvalidateSessionAndRetryOn401A import org.jclouds.vcloud.director.v1_5.handlers.VCloudDirectorErrorHandler; import org.jclouds.vcloud.director.v1_5.login.SessionAsyncClient; import org.jclouds.vcloud.director.v1_5.login.SessionClient; +import org.jclouds.vcloud.director.v1_5.predicates.TaskSuccess; import com.google.common.base.Function; +import com.google.common.base.Predicate; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableMap; +import com.google.inject.Injector; import com.google.inject.Provides; import com.google.inject.Singleton; import com.google.inject.name.Named; diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Link.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Link.java index 6e130f9e81..ebdd25a00f 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Link.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Link.java @@ -56,10 +56,17 @@ public class Link extends ReferenceType { public static final String PREVIOUS_PAGE = "previousPage"; public static final String LAST_PAGE = "lastPage"; public static final String FIRST_PAGE = "firstPage"; + public static final String CONTROL_ACCESS = "controlAccess"; - public static final List ALL = Arrays.asList( + /** + * All acceptable {@link Link#getRel()} values. + * + * This list must be updated whenever a new relationship is added. + */ + public static final List ALL = Arrays.asList( UP, DOWN, EDIT, ADD, DELETE, REMOVE, CATALOG_ITEM, TASK_CANCEL, - ALTERNATE, NEXT_PAGE, PREVIOUS_PAGE, LAST_PAGE, FIRST_PAGE + ALTERNATE, NEXT_PAGE, PREVIOUS_PAGE, LAST_PAGE, FIRST_PAGE, + CONTROL_ACCESS ); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Media.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Media.java index 5a26d952ef..d0d74894d7 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Media.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Media.java @@ -16,80 +16,51 @@ * specific language governing permissions and limitations * under the License. */ - package org.jclouds.vcloud.director.v1_5.domain; -import static com.google.common.base.Objects.equal; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.VCLOUD_1_5_NS; +import static com.google.common.base.Objects.*; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; import java.net.URI; import java.util.Arrays; import java.util.List; import java.util.Set; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; import com.google.common.base.Objects; - /** - * - * Represents a media. - * - * - *

Java class for Media complex type. - * - *

The following schema fragment specifies the expected content contained within this class. + * Represents a media. * *

- * <complexType name="Media">
- *   <complexContent>
- *     <extension base="{http://www.vmware.com/vcloud/v1.5}ResourceEntityType">
- *       <sequence>
- *         <element name="Owner" type="{http://www.vmware.com/vcloud/v1.5}OwnerType" minOccurs="0"/>
- *       </sequence>
- *       <attribute name="imageType" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
- *       <attribute name="size" use="required" type="{http://www.w3.org/2001/XMLSchema}long" />
- *       <anyAttribute processContents='lax' namespace='##other'/>
- *     </extension>
- *   </complexContent>
- * </complexType>
+ * <complexType name="Media" />
  * 
- * - * */ -@XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement(namespace = VCLOUD_1_5_NS, name = "Media") -@XmlType(propOrder = {"owner"}) -public class Media - extends ResourceEntityType +public class Media extends ResourceEntityType { -{ public static final class ImageType { public static final String ISO = "iso"; public static final String FLOPPY = "floppy"; - public static final List ALL = Arrays.asList( - ISO, FLOPPY - ); + public static final List ALL = Arrays.asList(ISO, FLOPPY); } - + @SuppressWarnings("unchecked") public static Builder builder() { return new Builder(); } + @Override public Builder toBuilder() { return new Builder().fromMedia(this); } public static class Builder extends ResourceEntityType.Builder { - + private Owner owner; private String imageType; private long size; @@ -118,7 +89,7 @@ public class Media return this; } - + @Override public Media build() { Media media = new Media(); media.setOwner(owner); @@ -126,10 +97,11 @@ public class Media media.setSize(size); return media; } - + /** * @see ResourceEntityType#getFiles() */ + @Override public Builder files(FilesList files) { super.files(files); return this; @@ -138,11 +110,12 @@ public class Media /** * @see ResourceEntityType#getStatus() */ + @Override public Builder status(Integer status) { super.status(status); return this; } - + /** * @see EntityType#getName() */ @@ -215,16 +188,13 @@ public class Media return this; } - @Override public Builder fromResourceEntityType(ResourceEntityType in) { - return Builder.class.cast(super.fromResourceEntityType(in)); + return Builder.class.cast(super.fromResourceEntityType(in)); } + public Builder fromMedia(Media in) { - return fromResourceEntityType(in) - .owner(in.getOwner()) - .imageType(in.getImageType()) - .size(in.getSize()); + return fromResourceEntityType(in).owner(in.getOwner()).imageType(in.getImageType()).size(in.getSize()); } } @@ -232,102 +202,65 @@ public class Media super(); } - @XmlElement(namespace = VCLOUD_1_5_NS, name = "Owner") - protected Owner owner; - @XmlAttribute(required = true) - protected String imageType; - @XmlAttribute(required = true) - protected long size; + @XmlElement(namespace = VCLOUD_1_5_NS, name = "Owner") + protected Owner owner; + @XmlAttribute(required = true) + protected String imageType; + @XmlAttribute(required = true) + protected long size; - /** - * Gets the value of the owner property. - * - * @return - * possible object is - * {@link Owner } - * - */ - public Owner getOwner() { - return owner; - } + /** + * Gets the value of the owner property. + */ + public Owner getOwner() { + return owner; + } - /** - * Sets the value of the owner property. - * - * @param value - * allowed object is - * {@link Owner } - * - */ - public void setOwner(Owner value) { - this.owner = value; - } + public void setOwner(Owner value) { + this.owner = value; + } - /** - * Gets the value of the imageType property. - * - * @return - * possible object is - * {@link String } - * - */ - public String getImageType() { - return imageType; - } + /** + * Gets the value of the imageType property. + */ + public String getImageType() { + return imageType; + } - /** - * Sets the value of the imageType property. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setImageType(String value) { - this.imageType = value; - } + public void setImageType(String value) { + this.imageType = value; + } - /** - * Gets the value of the size property. - * - */ - public long getSize() { - return size; - } + /** + * Gets the value of the size property. + */ + public long getSize() { + return size; + } - /** - * Sets the value of the size property. - * - */ - public void setSize(long value) { - this.size = value; - } + public void setSize(long value) { + this.size = value; + } @Override public boolean equals(Object o) { if (this == o) - return true; + return true; if (o == null || getClass() != o.getClass()) return false; Media that = Media.class.cast(o); - return equal(owner, that.owner) && - equal(imageType, that.imageType) && - equal(size, that.size); + return super.equals(that) && + equal(this.owner, that.owner) && equal(this.imageType, that.imageType) && equal(this.size, that.size); } @Override public int hashCode() { - return Objects.hashCode(owner, - imageType, - size); + return super.hashCode() + Objects.hashCode(owner, imageType, size); } @Override - public String toString() { - return Objects.toStringHelper("") - .add("owner", owner) - .add("imageType", imageType) - .add("size", size).toString(); + public ToStringHelper string() { + return super.string().add("owner", owner).add("imageType", imageType).add("size", size); } } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceEntity.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceEntity.java deleted file mode 100644 index 934f955c39..0000000000 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceEntity.java +++ /dev/null @@ -1,256 +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.domain; - -import static com.google.common.base.Objects.*; -import static com.google.common.base.Preconditions.*; - -import java.net.URI; -import java.util.Set; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlType; - -import com.google.common.base.Objects; -import com.google.common.collect.Sets; - -/** - * - * Base type that represents a resource entity such as a vApp - * template or virtual media. - * - * - *

Java class for ResourceEntity complex type. - * - *

The following schema fragment specifies the expected content contained within this class. - * - *

- * <complexType name="ResourceEntity">
- *   <complexContent>
- *     <extension base="{http://www.vmware.com/vcloud/v1.5}EntityType">
- *       <sequence>
- *         <element name="Files" type="{http://www.vmware.com/vcloud/v1.5}FilesListType" minOccurs="0"/>
- *       </sequence>
- *       <attribute name="status" type="{http://www.w3.org/2001/XMLSchema}int" />
- *       <anyAttribute processContents='lax' namespace='##other'/>
- *     </extension>
- *   </complexContent>
- * </complexType>
- * 
- * - * - */ -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "ResourceEntity", propOrder = { - "files" -}) -public class ResourceEntity extends EntityType { - - @SuppressWarnings("unchecked") - public static Builder builder() { - return new Builder(); - } - - public Builder toBuilder() { - return new Builder().fromResourceEntity(this); - } - - public static class Builder extends EntityType.Builder { - - private Object /* FilesList */ files; - private Integer status; - - /** - * @see ResourceEntity#getFiles() - */ - public Builder files(Object /* FilesList */ files) { - this.files = files; - return this; - } - - /** - * @see ResourceEntity#getStatus() - */ - public Builder status(Integer status) { - this.status = status; - return this; - } - - - public ResourceEntity build() { - ResourceEntity resourceEntity = new ResourceEntity(); - resourceEntity.setFiles(files); - resourceEntity.setStatus(status); - return resourceEntity; - } - - - /** - * @see EntityType#getId() - */ - @Override - public Builder id(String id) { - this.id = id; - return this; - } - - /** - * @see EntityType#getTasksInProgress() - */ - @Override - public Builder tasksInProgress(TasksInProgress tasksInProgress) { - this.tasksInProgress = tasksInProgress; - return this; - } - - /** - * @see ReferenceType#getHref() - */ - @Override - public Builder href(URI href) { - this.href = href; - return this; - } - - /** - * @see ReferenceType#getType() - */ - @Override - public Builder type(String type) { - this.type = type; - return this; - } - - /** - * @see ReferenceType#getLinks() - */ - @Override - public Builder links(Set links) { - this.links = Sets.newLinkedHashSet(checkNotNull(links, "links")); - return this; - } - - /** - * @see ReferenceType#getLinks() - */ - @Override - public Builder link(Link link) { - this.links.add(checkNotNull(link, "link")); - return this; - } - - - @Override - public Builder fromEntityType(EntityType in) { - return Builder.class.cast(super.fromEntityType(in)); - } - public Builder fromResourceEntity(ResourceEntity in) { - return fromEntityType(in) - .files(in.getFiles()) - .status(in.getStatus()); - } - } - - protected ResourceEntity() { - // For JAXB and builder use - } - - - - @XmlElement(name = "Files") - protected Object /* FilesList */ files; - @XmlAttribute - protected Integer status; - - /** - * Gets the value of the files property. - * - * @return - * possible object is - * {@link FilesList } - * - */ - public Object /* FilesList */ getFiles() { - return files; - } - - /** - * Sets the value of the files property. - * - * @param value - * allowed object is - * {@link FilesList } - * - */ - public void setFiles(Object /* FilesList */ value) { - this.files = value; - } - - /** - * Gets the value of the status property. - * - * @return - * possible object is - * {@link Integer } - * - */ - public Integer getStatus() { - return status; - } - - /** - * Sets the value of the status property. - * - * @param value - * allowed object is - * {@link Integer } - * - */ - public void setStatus(Integer value) { - this.status = value; - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - ResourceEntity that = ResourceEntity.class.cast(o); - return equal(files, that.files) && - equal(status, that.status); - } - - @Override - public int hashCode() { - return Objects.hashCode(files, - status); - } - - @Override - public String toString() { - return Objects.toStringHelper("") - .add("files", files) - .add("status", status).toString(); - } - -} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceEntityType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceEntityType.java index 56c9ac6ea0..53b9a64a82 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceEntityType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceEntityType.java @@ -19,58 +19,28 @@ package org.jclouds.vcloud.director.v1_5.domain; -import static com.google.common.base.Objects.equal; -import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Objects.*; +import static com.google.common.base.Preconditions.*; import java.net.URI; import java.util.Set; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlType; import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.Sets; - /** - * - * Base type that represents a resource entity such as a vApp - * template or virtual media. - * - * - *

Java class for ResourceEntity complex type. - * - *

The following schema fragment specifies the expected content contained within this class. + * Base type that represents a resource entity such as a vApp template or virtual media. * *

- * <complexType name="ResourceEntity">
- *   <complexContent>
- *     <extension base="{http://www.vmware.com/vcloud/v1.5}EntityType">
- *       <sequence>
- *         <element name="Files" type="{http://www.vmware.com/vcloud/v1.5}FilesListType" minOccurs="0"/>
- *       </sequence>
- *       <attribute name="status" type="{http://www.w3.org/2001/XMLSchema}int" />
- *       <anyAttribute processContents='lax' namespace='##other'/>
- *     </extension>
- *   </complexContent>
- * </complexType>
+ * <complexType name="ResourceEntity" >
  * 
* - * + * @author danikov */ -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "ResourceEntity", propOrder = { - "files" -}) -//@XmlSeeAlso({ -// MediaType.class, -// VAppTemplateType.class, -// AbstractVAppType.class, -// NetworkPoolType.class -//}) public class ResourceEntityType> extends EntityType { public static > Builder builder() { @@ -83,7 +53,7 @@ public class ResourceEntityType> extends EntityT } public static class Builder> extends EntityType.Builder { - + private FilesList files; private Integer status; @@ -103,7 +73,7 @@ public class ResourceEntityType> extends EntityT return this; } - + @Override public ResourceEntityType build() { ResourceEntityType resourceEntity = new ResourceEntityType(); resourceEntity.setFiles(files); @@ -111,7 +81,6 @@ public class ResourceEntityType> extends EntityT return resourceEntity; } - /** * @see EntityType#getId() */ @@ -165,101 +134,66 @@ public class ResourceEntityType> extends EntityT this.links.add(checkNotNull(link, "link")); return this; } - - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") + @Override public Builder fromResourceType(ResourceType in) { return Builder.class.cast(super.fromResourceType(in)); } public Builder fromResourceEntityType(ResourceEntityType in) { - return fromResourceType(in) - .files(in.getFiles()) - .status(in.getStatus()); + return fromResourceType(in).files(in.getFiles()).status(in.getStatus()); } } public ResourceEntityType() { + // for JAXB } - @XmlElement(name = "Files") - protected FilesList files; - @XmlAttribute - protected Integer status; + @XmlElement(name = "Files") + protected FilesList files; + @XmlAttribute + protected Integer status; - /** - * Gets the value of the files property. - * - * @return - * possible object is - * {@link FilesList } - * - */ - public FilesList getFiles() { - return files; - } + /** + * Gets the value of the files property. + */ + public FilesList getFiles() { + return files; + } - /** - * Sets the value of the files property. - * - * @param value - * allowed object is - * {@link FilesList } - * - */ - public void setFiles(FilesList value) { - this.files = value; - } + public void setFiles(FilesList value) { + this.files = value; + } - /** - * Gets the value of the status property. - * - * @return - * possible object is - * {@link Integer } - * - */ - public Integer getStatus() { - return status; - } + /** + * Gets the value of the status property. + */ + public Integer getStatus() { + return status; + } - /** - * Sets the value of the status property. - * - * @param value - * allowed object is - * {@link Integer } - * - */ - public void setStatus(Integer value) { - this.status = value; - } + public void setStatus(Integer value) { + this.status = value; + } @Override public boolean equals(Object o) { if (this == o) - return true; + return true; if (o == null || getClass() != o.getClass()) return false; ResourceEntityType that = ResourceEntityType.class.cast(o); - return equal(files, that.files) && - equal(status, that.status); + return super.equals(that) && equal(this.files, that.files) && equal(this.status, that.status); } @Override public int hashCode() { - return Objects.hashCode(files, - status); + return super.hashCode() + Objects.hashCode(files, status); } @Override - public String toString() { - return Objects.toStringHelper("") - .add("files", files) - .add("status", status).toString(); + public ToStringHelper string() { + return super.string().add("files", files).add("status", status); } } 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 8c270c8441..78d52f5be9 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 @@ -147,13 +147,6 @@ public class Task extends EntityType { this.status = status; return this; } - - /** - * @see Task#getStatus() - */ - public Builder status(TaskStatus status) { - return this.status(status.toString()); - } /** * @see Task#getOperation() @@ -418,14 +411,10 @@ public class Task extends EntityType { *
  • aborted - The task was aborted by an administrative action. * */ - public TaskStatus getStatus() { - return TaskStatus.fromValue(status); + public String getStatus() { + return status; } - public void setStatus(TaskStatus status) { - this.setStatus(status.toString()); - } - public void setStatus(String status) { this.status = status; } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TaskInErrorStateException.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TaskInErrorStateException.java deleted file mode 100644 index 5b8fe5a272..0000000000 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TaskInErrorStateException.java +++ /dev/null @@ -1,41 +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.domain; - -/** - * - * @author Adrian Cole - * - */ -public class TaskInErrorStateException extends RuntimeException { - - private static final long serialVersionUID = 1L; - - private final Task task; - - public TaskInErrorStateException(Task task) { - super("error on task: " + task + " error: " + task.getError()); - this.task = task; - } - - public Task getTask() { - return task; - } - -} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TaskStatus.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TaskStatus.java deleted file mode 100644 index ebef2f5218..0000000000 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/TaskStatus.java +++ /dev/null @@ -1,73 +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.domain; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * @author Adrian Cole - */ -public enum TaskStatus { - /** - * The task has completed and returned a value indicating success. - */ - SUCCESS, - /** - * The task is running. - */ - RUNNING, - - /** - * The task has been queued for execution. - */ - QUEUED, - /** - * The task has completed and returned a value indicating an error. - */ - ERROR, - /** - * not an official status, temporarily in. - */ - CANCELLED, UNRECOGNIZED; - public String value() { - return name().toLowerCase(); - } - - @Override - public String toString() { - return value(); - } - - public static TaskStatus fromValue(String status) { - if ("CANCELED".equals(status.toUpperCase())) { - // TODO: ecloud hack - status = "CANCELLED"; - } else if ("FAILED".equals(status.toUpperCase())) { - status = "ERROR"; - } else if ("COMPLETED".equals(status.toUpperCase())) { - status = "SUCCESS"; - } - try { - return valueOf(checkNotNull(status, "status").toUpperCase()); - } catch (IllegalArgumentException e) { - return UNRECOGNIZED; - } - } - -} \ No newline at end of file diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/vapp/AbstractVAppType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/vapp/AbstractVAppType.java index eba27db878..bfe81d4b1b 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/vapp/AbstractVAppType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/vapp/AbstractVAppType.java @@ -18,54 +18,19 @@ */ package org.jclouds.vcloud.director.v1_5.domain.vapp; -import java.util.ArrayList; -import java.util.List; - -import javax.xml.bind.JAXBElement; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElementRef; -import javax.xml.bind.annotation.XmlSeeAlso; -import javax.xml.bind.annotation.XmlType; - -import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; -import org.jclouds.vcloud.director.v1_5.domain.ResourceEntity; +import org.jclouds.vcloud.director.v1_5.domain.ResourceEntityType; /** - * - * Represents a base type for VAppType and VmType. - * - * - *

    Java class for AbstractVAppType complex type. - * - *

    The following schema fragment specifies the expected content contained within this class. - * + * Represents a base type for VAppType and VmType. + * *

    - * <complexType name="AbstractVAppType">
    - *   <complexContent>
    - *     <extension base="{http://www.vmware.com/vcloud/v1.5}ResourceEntityType">
    - *       <sequence>
    - *         <element name="VAppParent" type="{http://www.vmware.com/vcloud/v1.5}ReferenceType" minOccurs="0"/>
    - *         <element ref="{http://schemas.dmtf.org/ovf/envelope/1}Section" maxOccurs="unbounded" minOccurs="0"/>
    - *       </sequence>
    - *       <attribute name="deployed" type="{http://www.w3.org/2001/XMLSchema}boolean" />
    - *       <anyAttribute processContents='lax' namespace='##other'/>
    - *     </extension>
    - *   </complexContent>
    - * </complexType>
    + * <complexType name="AbstractVAppType" >
      * 
    * - * + * @author grkvlt@apache.org */ -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "AbstractVAppType", propOrder = { - "vAppParent", - "section" -}) -public abstract class AbstractVAppType extends ResourceEntity { +public abstract class AbstractVAppType extends ResourceEntityType { // @XmlElement(name = "VAppParent") // protected ReferenceType vAppParent; diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/vapp/VApp.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/vapp/VApp.java index 5e02670dd5..5eead42ddc 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/vapp/VApp.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/vapp/VApp.java @@ -18,51 +18,15 @@ */ package org.jclouds.vcloud.director.v1_5.domain.vapp; -import static com.google.common.base.Objects.*; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlType; - -import org.jclouds.vcloud.director.v1_5.domain.Owner; - -import com.google.common.base.Objects; - /** - * - * Represents a vApp. - * - * - *

    Java class for VApp complex type. - * - *

    The following schema fragment specifies the expected content contained within this class. + * Represents a vApp. * *

    - * <complexType name="VApp">
    - *   <complexContent>
    - *     <extension base="{http://www.vmware.com/vcloud/v1.5}AbstractVApp">
    - *       <sequence>
    - *         <element name="Owner" type="{http://www.vmware.com/vcloud/v1.5}OwnerType" minOccurs="0"/>
    - *         <element name="InMaintenanceMode" type="{http://www.w3.org/2001/XMLSchema}boolean" minOccurs="0"/>
    - *         <element name="Children" type="{http://www.vmware.com/vcloud/v1.5}VAppChildrenType" minOccurs="0"/>
    - *       </sequence>
    - *       <attribute name="ovfDescriptorUploaded" type="{http://www.w3.org/2001/XMLSchema}boolean" />
    - *       <anyAttribute processContents='lax' namespace='##other'/>
    - *     </extension>
    - *   </complexContent>
    - * </complexType>
    + * <complexType name="VApp" />
      * 
    * - * + * @author grkvlt@apache.org */ -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "VApp", propOrder = { - "owner", - "inMaintenanceMode", - "children" -}) public class VApp extends AbstractVAppType { // // @SuppressWarnings("unchecked") 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 df0015def3..dec785759c 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 @@ -18,53 +18,64 @@ */ package org.jclouds.vcloud.director.v1_5.predicates; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; + import java.net.URI; import javax.annotation.Resource; +import javax.inject.Named; import javax.inject.Singleton; import org.jclouds.logging.Logger; +import org.jclouds.predicates.RetryablePredicate; import org.jclouds.rest.RestContext; import org.jclouds.vcloud.director.v1_5.VCloudDirectorAsyncClient; import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorException; import org.jclouds.vcloud.director.v1_5.domain.Task; -import org.jclouds.vcloud.director.v1_5.domain.TaskInErrorStateException; -import org.jclouds.vcloud.director.v1_5.domain.TaskStatus; import org.jclouds.vcloud.director.v1_5.features.TaskClient; import com.google.common.base.Predicate; import com.google.inject.Inject; /** + * Keeps testing {@link Task} to see if it has succeeded before a time limit has elapsed. * - * Tests to see if a task succeeds. - * - * @author Adrian Cole + * @author grkvlt@apache.org */ @Singleton public class TaskSuccess implements Predicate { private final TaskClient taskClient; + private final RetryablePredicate retry; + private final Predicate checkSuccess = new Predicate() { + @Override + public boolean apply(URI taskUri) { + logger.trace("looking for status on task %s", taskUri); + + Task task = taskClient.getTask(taskUri); + // perhaps task isn't available, yet + if (task == null) return false; + logger.trace("%s: looking for status %s: currently: %s", task, Task.Status.SUCCESS, task.getStatus()); + if (task.getStatus().equals(Task.Status.ERROR)) + throw new VCloudDirectorException(task); + return task.getStatus().equals(Task.Status.SUCCESS); + } + }; @Resource protected Logger logger = Logger.NULL; @Inject - public TaskSuccess(RestContext context) { + public TaskSuccess(RestContext context, + @Named(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED) long maxWait) { this.taskClient = context.getApi().getTaskClient(); + this.retry = new RetryablePredicate(checkSuccess, maxWait); } - public boolean apply(URI taskUri) { - logger.trace("looking for status on task %s", taskUri); - - Task task = taskClient.getTask(taskUri); - // perhaps task isn't available, yet - if (task == null) - return false; - logger.trace("%s: looking for status %s: currently: %s", task, TaskStatus.SUCCESS, task.getStatus()); - if (task.getStatus() == TaskStatus.ERROR) - throw new TaskInErrorStateException(task); - return task.getStatus() == TaskStatus.SUCCESS; + /** @see Predicate#apply(Object) */ + @Override + public boolean apply(URI input) { + return retry.apply(input); } - } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClientExperimentLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClientExperimentLiveTest.java index b3bce348ab..de9d0afdaf 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClientExperimentLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClientExperimentLiveTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.vcloud.director.v1_5; -import static org.testng.Assert.assertEquals; +import static org.testng.Assert.*; import org.jclouds.vcloud.director.v1_5.domain.Session; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest; 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 dbf530b03a..dc7c3d91c1 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 @@ -47,7 +47,7 @@ public class VCloudDirectorLiveTestConstants { public static final String REQUIRED_VALUE_OBJECT_FMT = "ERR-03: The %s field of the %s must not be '%s'; allowed values: %s"; - public static final String REQUIRED_VALUE_FMT = "ERR-04: The %s field must not be '%sr'; allowed values: %s"; + public static final String REQUIRED_VALUE_FMT = "ERR-04: The %s field must not be '%s'; allowed values: %s"; public static final String MUST_BE_WELL_FORMED_FMT = "ERR-05: The %s field must be well formed: '%s'"; 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 0c805c55b1..ee86ff8926 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 @@ -129,7 +129,7 @@ public class Checks { public static void checkTask(Task task) { // Check required fields assertNotNull(task.getStatus(), String.format(NOT_NULL_OBJECT_FMT, "Status", "Task")); - assertTrue(Task.Status.ALL.contains(task.getStatus()), String.format(REQUIRED_VALUE_OBJECT_FMT, "Status", "Task", task.getStatus(), Iterables.toString(Link.Rel.ALL))); + assertTrue(Task.Status.ALL.contains(task.getStatus()), String.format(REQUIRED_VALUE_OBJECT_FMT, "Status", "Task", task.getStatus(), Iterables.toString(Task.Status.ALL))); // Check optional fields // NOTE operation cannot be checked diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java index ed8e3d73a8..7edb69a6a0 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java @@ -34,7 +34,7 @@ import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.domain.query.CatalogReferences; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.base.Predicate; @@ -54,6 +54,7 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest { private CatalogClient catalogClient; private QueryClient queryClient; + private MediaClient mediaClient; /* * Shared state between dependant tests. @@ -67,11 +68,13 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest { private CatalogItem newCatalogItem; private Metadata catalogMetadata; - @BeforeGroups(groups = { "live" }) - public void setupClients() { + @BeforeClass(inheritGroups = true) + public void setupRequiredClients() { catalogClient = context.getApi().getCatalogClient(); queryClient = context.getApi().getQueryClient(); + mediaClient = context.getApi().getMediaClient(); } + private Metadata catalogItemMetadata; @Test(testName = "GET /catalog/{id}") @@ -152,9 +155,8 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest { } }); MetadataValue metadataValue = catalogClient.getCatalogMetadataValue(catalogRef, "KEY"); - // XXX assertEquals(metadataValue.getValue(), existingMetadataEntry.getValue(), - "The MetadataValue for KEY should have the same Value as the existing MetadataEntry"); + String.format(CORRECT_VALUE_OBJECT_FMT, "Value", "MetadataValue", existingMetadataEntry.getValue(), metadataValue.getValue())); checkMetadataValue(metadataValue); } @@ -162,8 +164,7 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest { public void testGetCatalogItemMetadata() { resetCatalogItemMetadata(catalogItemRef); catalogItemMetadata = catalogClient.getCatalogItemMetadata(catalogItemRef); - // XXX - assertEquals(catalogItemMetadata.getMetadataEntries().size(), 1, "There should be a single MetadataEntry"); + assertEquals(catalogItemMetadata.getMetadataEntries().size(), 1, String.format(MUST_EXIST_FMT, "MetadataEntry", "CatalogItem")); checkMetadata(catalogItemMetadata); } @@ -176,9 +177,8 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest { Task mergeCatalogItemMetadata = catalogClient.mergeCatalogItemMetadata(catalogItemRef, newMetadata); checkTask(mergeCatalogItemMetadata); - // TODO requires code from dan to be merged -// assertTrue(taskTester.apply(mergeCatalogItemMetadata.getHref()), -// String.format(TASK_COMPLETE_TIMELY, "mergeCatalogItemMetadata")); + assertTrue(successTester.apply(mergeCatalogItemMetadata.getHref()), + String.format(TASK_COMPLETE_TIMELY, "mergeCatalogItemMetadata")); Metadata mergedCatalogItemMetadata = catalogClient.getCatalogItemMetadata(catalogItemRef); // XXX diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientLiveTest.java index 5173dee544..2c3e38afb9 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientLiveTest.java @@ -29,7 +29,7 @@ import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; import org.jclouds.vcloud.director.v1_5.domain.OrgNetwork; import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; /** @@ -46,8 +46,8 @@ public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest { private NetworkClient networkClient; - @BeforeGroups(groups = { "live" }) - public void setupClients() { + @BeforeClass(inheritGroups = true) + public void setupRequiredClients() { networkClient = context.getApi().getNetworkClient(); } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientLiveTest.java index 67a480a51e..8bd51f5289 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientLiveTest.java @@ -29,7 +29,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Org; import org.jclouds.vcloud.director.v1_5.domain.OrgList; import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.collect.Iterables; @@ -48,8 +48,8 @@ public class OrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { private OrgClient orgClient; - @BeforeGroups(groups = { "live" }) - public void setupClients() { + @BeforeClass(inheritGroups = true) + public void setupRequiredClients() { orgClient = context.getApi().getOrgClient(); } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientLiveTest.java index 68a4a5e9a9..4b8c77a5cf 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientLiveTest.java @@ -18,16 +18,13 @@ */ package org.jclouds.vcloud.director.v1_5.features; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.*; import static org.testng.Assert.*; -import java.net.URI; - -import org.jclouds.vcloud.director.v1_5.domain.OrgList; -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.query.CatalogReferences; +import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecords; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; /** @@ -45,8 +42,8 @@ public class QueryClientLiveTest extends BaseVCloudDirectorClientLiveTest { private CatalogClient catalogClient; private QueryClient queryClient; - @BeforeGroups(groups = { "live" }) - public void setupClients() { + @BeforeClass(inheritGroups = true) + public void setupRequiredClients() { catalogClient = context.getApi().getCatalogClient(); queryClient = context.getApi().getQueryClient(); } @@ -55,14 +52,18 @@ public class QueryClientLiveTest extends BaseVCloudDirectorClientLiveTest { * Shared state between dependant tests. */ - private OrgList orgList; - private Reference orgRef; - private TasksList taskList; - private Task task; - private URI taskUri; + private QueryResultRecords catalogRecords; + private CatalogReferences catalogReferences; - @Test(testName = "GET /catalogs/query/") - public void testQueryCatalogNoParam() { - assertTrue(true); + @Test(testName = "GET /catalogs/query") + public void testQueryAllCatalogs() { + catalogRecords = queryClient.catalogsQueryAll(); + assertFalse(catalogRecords.getRecords().isEmpty(), String.format(NOT_EMPTY_OBJECT_FMT, "CatalogRecord", "QueryResultRecords")); + } + + @Test(testName = "GET /catalogs/query?format=references", dependsOnMethods = { "testQueryAllCatalogs" }) + public void testQueryAllCatalogReferences() { + catalogReferences = queryClient.catalogReferencesQueryAll(); + assertFalse(catalogReferences.getReferences().isEmpty(), String.format(NOT_EMPTY_OBJECT_FMT, "CatalogReference", "CatalogReferences")); } } \ No newline at end of file diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientLiveTest.java index 28bd663ae9..13e465ffb2 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientLiveTest.java @@ -29,7 +29,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.domain.TasksList; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.collect.Iterables; @@ -49,8 +49,8 @@ public class TaskClientLiveTest extends BaseVCloudDirectorClientLiveTest { private OrgClient orgClient; private TaskClient taskClient; - @BeforeGroups(groups = { "live" }) - public void setupClients() { + @BeforeClass(inheritGroups = true) + public void setupRequiredClients() { orgClient = context.getApi().getOrgClient(); taskClient = context.getApi().getTaskClient(); } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java index 5bd2cb9c4b..6910dba4c3 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java @@ -27,8 +27,8 @@ import org.jclouds.rest.RestContextFactory; import org.jclouds.sshj.config.SshjSshClientModule; import org.jclouds.vcloud.director.v1_5.VCloudDirectorAsyncClient; import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; -import org.testng.annotations.AfterGroups; -import org.testng.annotations.BeforeGroups; +import org.jclouds.vcloud.director.v1_5.predicates.TaskSuccess; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; @@ -41,21 +41,24 @@ import com.google.inject.Module; */ @Test(groups = "live") public class BaseVCloudDirectorClientLiveTest extends BaseVersionedServiceLiveTest { - public BaseVCloudDirectorClientLiveTest() { + + protected BaseVCloudDirectorClientLiveTest() { provider = "vcloud-director"; } + + protected TaskSuccess successTester; protected RestContext context; - @BeforeGroups(groups = { "live" }) - public void setupClient() { + @BeforeClass(groups = { "live" }) + public void setupContext() { setupCredentials(); Properties overrides = setupProperties(); context = new RestContextFactory().createContext(provider, identity, credential, ImmutableSet. of(new Log4JLoggingModule(), new SshjSshClientModule()), overrides); + successTester = new TaskSuccess(context, 1000L); } - @AfterGroups(groups = "live") protected void tearDown() { if (context != null) context.close(); From e7416e8709ba90fc700c9d9cb0122c0098ae5a1f Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Mon, 20 Feb 2012 12:34:09 +0000 Subject: [PATCH 07/13] maybe --- .../v1_5/internal/BaseVCloudDirectorClientLiveTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java index 6910dba4c3..b9775478c8 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java @@ -20,6 +20,8 @@ package org.jclouds.vcloud.director.v1_5.internal; import java.util.Properties; +import javax.inject.Inject; + import org.jclouds.compute.BaseVersionedServiceLiveTest; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.rest.RestContext; @@ -46,6 +48,7 @@ public class BaseVCloudDirectorClientLiveTest extends BaseVersionedServiceLiveTe provider = "vcloud-director"; } + @Inject protected TaskSuccess successTester; protected RestContext context; @@ -56,7 +59,7 @@ public class BaseVCloudDirectorClientLiveTest extends BaseVersionedServiceLiveTe Properties overrides = setupProperties(); context = new RestContextFactory().createContext(provider, identity, credential, ImmutableSet. of(new Log4JLoggingModule(), new SshjSshClientModule()), overrides); - successTester = new TaskSuccess(context, 1000L); + successTester = new TaskSuccess(context, 1000L); // NOTE is this required? } protected void tearDown() { From 29f26df1378f74ad0a1e3e3466139f9ae10cb2a5 Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Mon, 20 Feb 2012 13:18:11 +0000 Subject: [PATCH 08/13] default properties or something --- .../director/v1_5/VCloudDirectorConstants.java | 8 +++++++- .../v1_5/VCloudDirectorPropertiesBuilder.java | 12 ++++++++---- .../vcloud/director/v1_5/predicates/TaskSuccess.java | 2 +- .../v1_5/features/CatalogClientLiveTest.java | 1 + .../internal/BaseVCloudDirectorClientLiveTest.java | 2 +- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorConstants.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorConstants.java index cffe572f65..1bcf131fc7 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorConstants.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorConstants.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -54,4 +54,10 @@ public class VCloudDirectorConstants { /** TODO javadoc */ public static final String PROPERTY_VCLOUD_XML_SCHEMA = "jclouds.vcloud.xml.schema"; + /** TODO javadoc */ + public static final String PROPERTY_VCLOUD_DNS_NAME_LEN_MIN = "jclouds.dns_name_length_min"; + + /** TODO javadoc */ + public static final String PROPERTY_VCLOUD_DNS_NAME_LEN_MAX = "jclouds.dns_name_length_max"; + } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorPropertiesBuilder.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorPropertiesBuilder.java index 446e921835..47af70592d 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorPropertiesBuilder.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorPropertiesBuilder.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -42,14 +42,18 @@ public class VCloudDirectorPropertiesBuilder extends PropertiesBuilder { properties.setProperty(PROPERTY_VCLOUD_XML_NAMESPACE, String.format("http://www.vmware.com/vcloud/v${%s}", PROPERTY_VCLOUD_VERSION_SCHEMA)); properties.setProperty(PROPERTY_SESSION_INTERVAL, Integer.toString(8 * 60)); - properties.setProperty(PROPERTY_VCLOUD_XML_SCHEMA, "https://vcloudbeta.bluelock.com/api/v1.5/schema/master.xsd"); - properties.setProperty("jclouds.dns_name_length_min", "1"); - properties.setProperty("jclouds.dns_name_length_max", "80"); + properties.setProperty(PROPERTY_VCLOUD_XML_SCHEMA, PROPERTY_ENDPOINT + "/v1.5/schema/master.xsd"); + properties.setProperty(PROPERTY_VCLOUD_DNS_NAME_LEN_MIN, "1"); + properties.setProperty(PROPERTY_VCLOUD_DNS_NAME_LEN_MAX, "80"); // TODO integrate these with the {@link ComputeTimeouts} instead of having a single timeout for everything. properties.setProperty(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED, Long.toString(1200l * 1000l)); properties.setProperty(PROPERTY_SESSION_INTERVAL, Integer.toString(300)); + properties.setProperty(PROPERTY_VCLOUD_DEFAULT_CATALOG, "Public"); + properties.setProperty(PROPERTY_VCLOUD_DEFAULT_VDC, "FIXME"); + properties.setProperty(PROPERTY_VCLOUD_DEFAULT_NETWORK, "FIXME"); + return properties; } 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 dec785759c..5664853080 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 @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java index 7edb69a6a0..4c812a45bb 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java @@ -79,6 +79,7 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest { @Test(testName = "GET /catalog/{id}") public void testGetCatalog() { + // TODO use property from default property set CatalogReferences catalogReferences = queryClient.catalogReferencesQuery(String.format("name==%s", catalogName)); assertEquals(Iterables.size(catalogReferences.getReferences()), 1, String.format(MUST_EXIST_FMT, catalogName, "Catalog")); catalogRef = Iterables.getOnlyElement(catalogReferences.getReferences()); diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java index b9775478c8..f66f81bda0 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java @@ -59,7 +59,7 @@ public class BaseVCloudDirectorClientLiveTest extends BaseVersionedServiceLiveTe Properties overrides = setupProperties(); context = new RestContextFactory().createContext(provider, identity, credential, ImmutableSet. of(new Log4JLoggingModule(), new SshjSshClientModule()), overrides); - successTester = new TaskSuccess(context, 1000L); // NOTE is this required? +// successTester = new TaskSuccess(context, 1000L); // NOTE is this required? } protected void tearDown() { From 34459605fc34698480de90d629d0c1c4f88b1486 Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Tue, 21 Feb 2012 16:07:31 +0000 Subject: [PATCH 09/13] Large squashed commit with various changes: - Setup new test properties for catalog names and various ids as injectable - Make retryable TaskSuccess predicate injectable - Mark test classes as "user" - Various tidyup and code fixes as and when required --- .../compute/BaseVersionedServiceLiveTest.java | 5 +- .../jclouds/rest/BaseRestClientLiveTest.java | 1 - labs/vcloud-director/pom.xml | 10 ++++ .../v1_5/VCloudDirectorConstants.java | 28 +++++---- .../v1_5/VCloudDirectorPropertiesBuilder.java | 21 ++++--- .../VCloudDirectorRestClientModule.java | 10 ++-- .../director/v1_5/predicates/TaskSuccess.java | 49 ++++++--------- .../v1_5/VCloudDirectorClientExpectTest.java | 2 - .../vcloud/director/v1_5/domain/Checks.java | 3 +- .../features/CatalogClientExpectTest.java | 2 +- .../v1_5/features/CatalogClientLiveTest.java | 4 +- .../v1_5/features/MediaClientExpectTest.java | 2 +- .../v1_5/features/MediaClientLiveTest.java | 60 +++++++++---------- .../features/NetworkClientExpectTest.java | 2 +- .../v1_5/features/NetworkClientLiveTest.java | 55 +++++------------ .../v1_5/features/OrgClientExpectTest.java | 2 +- .../v1_5/features/OrgClientLiveTest.java | 2 +- .../v1_5/features/QueryClientExpectTest.java | 2 +- .../v1_5/features/QueryClientLiveTest.java | 2 +- .../v1_5/features/TaskClientExpectTest.java | 2 +- .../v1_5/features/TaskClientLiveTest.java | 2 +- .../BaseVCloudDirectorClientLiveTest.java | 55 ++++++++++++++--- ...aseVCloudDirectorRestClientExpectTest.java | 5 +- .../v1_5/login/SessionClientExpectTest.java | 2 +- .../v1_5/login/SessionClientLiveTest.java | 11 ++-- 25 files changed, 175 insertions(+), 164 deletions(-) diff --git a/compute/src/test/java/org/jclouds/compute/BaseVersionedServiceLiveTest.java b/compute/src/test/java/org/jclouds/compute/BaseVersionedServiceLiveTest.java index c02573e522..ea6e592dd8 100644 --- a/compute/src/test/java/org/jclouds/compute/BaseVersionedServiceLiveTest.java +++ b/compute/src/test/java/org/jclouds/compute/BaseVersionedServiceLiveTest.java @@ -29,7 +29,6 @@ import com.google.common.base.Splitter; import com.google.common.collect.Iterables; /** - * * @author Jason King */ public abstract class BaseVersionedServiceLiveTest extends BaseRestClientLiveTest { @@ -48,16 +47,18 @@ public abstract class BaseVersionedServiceLiveTest extends BaseRestClientLiveTes overrides.setProperty(provider + ".image.login-user", loginUser); if (authenticateSudo != null) overrides.setProperty(provider + ".image.authenticate-sudo", authenticateSudo); - return overrides; } + @Override @BeforeClass protected void setupCredentials() { super.setupCredentials(); + imageId = System.getProperty("test." + provider + ".image-id"); loginUser = System.getProperty("test." + provider + ".image.login-user"); authenticateSudo = System.getProperty("test." + provider + ".image.authenticate-sudo"); + if (loginUser != null){ Iterable userPass = Splitter.on(':').split(loginUser); Builder loginCredentialsBuilder = LoginCredentials.builder(); diff --git a/core/src/test/java/org/jclouds/rest/BaseRestClientLiveTest.java b/core/src/test/java/org/jclouds/rest/BaseRestClientLiveTest.java index c4a787d915..4df6e584b0 100644 --- a/core/src/test/java/org/jclouds/rest/BaseRestClientLiveTest.java +++ b/core/src/test/java/org/jclouds/rest/BaseRestClientLiveTest.java @@ -40,7 +40,6 @@ public abstract class BaseRestClientLiveTest { protected String apiVersion; protected String buildVersion; - protected Properties setupRestProperties() { return RestContextFactory.getPropertiesFromResource("/rest.properties"); } diff --git a/labs/vcloud-director/pom.xml b/labs/vcloud-director/pom.xml index a813091aa9..35619c5414 100644 --- a/labs/vcloud-director/pom.xml +++ b/labs/vcloud-director/pom.xml @@ -42,6 +42,11 @@ + Public + + + + @@ -109,6 +114,11 @@ ${test.vcloud-director.image-id} ${test.vcloud-director.image.login-user} ${test.vcloud-director.image.authenticate-sudo} + ${test.vcloud-director.catalog-name} + ${test.vcloud-director.media-id} + ${test.vcloud-director.vapptemplate-id} + ${test.vcloud-director.network-id} + ${test.vcloud-director.vdc-id} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorConstants.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorConstants.java index 1bcf131fc7..3bd358e433 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorConstants.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorConstants.java @@ -18,9 +18,10 @@ */ package org.jclouds.vcloud.director.v1_5; + /** * Constants used by VCloudDirector clients - * + * * @author grkvlt@apache.org */ public class VCloudDirectorConstants { @@ -29,35 +30,36 @@ public class VCloudDirectorConstants { public static final String VCLOUD_1_5_NS = "http://www.vmware.com/vcloud/v1.5"; /** The property used to configure the timeout for task completion. */ - public static final String PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED = "jclouds.vcloud-director.timeout.task-complete"; + public static final String PROPERTY_VCLOUD_DIRECTOR_TIMEOUT_TASK_COMPLETED = "jclouds.vcloud-director.timeout.task-complete"; - public static final String PROPERTY_VCLOUD_VERSION_SCHEMA = "jclouds.vcloud.version.schema"; + public static final String PROPERTY_VCLOUD_DIRECTOR_VERSION_SCHEMA = "jclouds.vcloud-director.version.schema"; /** Name of the default org that your vApp will join, if an org isn't explicitly specified. */ - public static final String PROPERTY_VCLOUD_DEFAULT_ORG = "jclouds.vcloud.defaults.org"; + public static final String PROPERTY_VCLOUD_DIRECTOR_DEFAULT_ORG = "jclouds.vcloud-director.defaults.org"; /** Name of the default catalog to query, if it isn't explicitly specified. */ - public static final String PROPERTY_VCLOUD_DEFAULT_CATALOG = "jclouds.vcloud.defaults.catalog"; + public static final String PROPERTY_VCLOUD_DIRECTOR_DEFAULT_CATALOG = "jclouds.vcloud-director.defaults.catalog"; /** Name of the VDC that your vApp will join, if a vDC isn't explicitly specified. */ - public static final String PROPERTY_VCLOUD_DEFAULT_VDC = "jclouds.vcloud.defaults.vdc"; + public static final String PROPERTY_VCLOUD_DIRECTOR_DEFAULT_VDC = "jclouds.vcloud-director.defaults.vdc"; /** Name of the default network, in the default VDC that your vApp will join. */ - public static final String PROPERTY_VCLOUD_DEFAULT_NETWORK = "jclouds.vcloud.defaults.network"; + public static final String PROPERTY_VCLOUD_DIRECTOR_DEFAULT_NETWORK = "jclouds.vcloud-director.defaults.network"; /** TODO javadoc */ - // public static final String PROPERTY_VCLOUD_DEFAULT_FENCEMODE = "jclouds.vcloud.defaults.fencemode"; + // public static final String PROPERTY_VCLOUD_DEFAULT_FENCEMODE = "jclouds.vcloud-director.defaults.fencemode"; /** TODO javadoc */ - public static final String PROPERTY_VCLOUD_XML_NAMESPACE = "jclouds.vcloud.xml.ns"; + public static final String PROPERTY_VCLOUD_DIRECTOR_XML_NAMESPACE = "jclouds.vcloud-director.xml.ns"; /** TODO javadoc */ - public static final String PROPERTY_VCLOUD_XML_SCHEMA = "jclouds.vcloud.xml.schema"; + public static final String PROPERTY_VCLOUD_DIRECTOR_XML_SCHEMA = "jclouds.vcloud-director.xml.schema"; + + // TODO put these somewhere else, maybe core? /** TODO javadoc */ - public static final String PROPERTY_VCLOUD_DNS_NAME_LEN_MIN = "jclouds.dns_name_length_min"; + public static final String PROPERTY_DNS_NAME_LEN_MIN = "jclouds.dns_name_length_min"; /** TODO javadoc */ - public static final String PROPERTY_VCLOUD_DNS_NAME_LEN_MAX = "jclouds.dns_name_length_max"; - + public static final String PROPERTY_NS_NAME_LEN_MAX = "jclouds.dns_name_length_max"; } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorPropertiesBuilder.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorPropertiesBuilder.java index 47af70592d..049e2cd3c3 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorPropertiesBuilder.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorPropertiesBuilder.java @@ -33,30 +33,29 @@ import org.jclouds.PropertiesBuilder; public class VCloudDirectorPropertiesBuilder extends PropertiesBuilder { @Override - protected Properties defaultProperties() { + public Properties defaultProperties() { Properties properties = super.defaultProperties(); + properties.setProperty(PROPERTY_ENDPOINT, "https://vcloudbeta.bluelock.com/api"); properties.setProperty(PROPERTY_SESSION_INTERVAL, Integer.toString(30 * 60)); properties.setProperty(PROPERTY_API_VERSION, "1.5"); - properties.setProperty(PROPERTY_VCLOUD_XML_NAMESPACE, - String.format("http://www.vmware.com/vcloud/v${%s}", PROPERTY_VCLOUD_VERSION_SCHEMA)); + properties.setProperty(PROPERTY_VCLOUD_DIRECTOR_XML_NAMESPACE, + String.format("http://www.vmware.com/vcloud/v${%s}", PROPERTY_VCLOUD_DIRECTOR_VERSION_SCHEMA)); properties.setProperty(PROPERTY_SESSION_INTERVAL, Integer.toString(8 * 60)); - properties.setProperty(PROPERTY_VCLOUD_XML_SCHEMA, PROPERTY_ENDPOINT + "/v1.5/schema/master.xsd"); - properties.setProperty(PROPERTY_VCLOUD_DNS_NAME_LEN_MIN, "1"); - properties.setProperty(PROPERTY_VCLOUD_DNS_NAME_LEN_MAX, "80"); + properties.setProperty(PROPERTY_VCLOUD_DIRECTOR_XML_SCHEMA, PROPERTY_ENDPOINT + "/v1.5/schema/master.xsd"); // TODO integrate these with the {@link ComputeTimeouts} instead of having a single timeout for everything. - properties.setProperty(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED, Long.toString(1200l * 1000l)); properties.setProperty(PROPERTY_SESSION_INTERVAL, Integer.toString(300)); - - properties.setProperty(PROPERTY_VCLOUD_DEFAULT_CATALOG, "Public"); - properties.setProperty(PROPERTY_VCLOUD_DEFAULT_VDC, "FIXME"); - properties.setProperty(PROPERTY_VCLOUD_DEFAULT_NETWORK, "FIXME"); + properties.setProperty(PROPERTY_VCLOUD_DIRECTOR_TIMEOUT_TASK_COMPLETED, Long.toString(1200l * 1000l)); return properties; } + public VCloudDirectorPropertiesBuilder() { + super(); + } + public VCloudDirectorPropertiesBuilder(Properties properties) { super(properties); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java index 0fde279933..98c18c8111 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java @@ -19,7 +19,6 @@ package org.jclouds.vcloud.director.v1_5.config; import static com.google.common.base.Throwables.*; import static org.jclouds.rest.config.BinderUtils.*; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*; import java.net.URI; import java.util.Map; @@ -36,7 +35,6 @@ import org.jclouds.http.annotation.ClientError; import org.jclouds.http.annotation.Redirection; import org.jclouds.http.annotation.ServerError; import org.jclouds.location.Provider; -import org.jclouds.predicates.RetryablePredicate; import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.config.RestClientModule; import org.jclouds.vcloud.director.v1_5.VCloudDirectorAsyncClient; @@ -61,17 +59,14 @@ import org.jclouds.vcloud.director.v1_5.handlers.InvalidateSessionAndRetryOn401A import org.jclouds.vcloud.director.v1_5.handlers.VCloudDirectorErrorHandler; import org.jclouds.vcloud.director.v1_5.login.SessionAsyncClient; import org.jclouds.vcloud.director.v1_5.login.SessionClient; -import org.jclouds.vcloud.director.v1_5.predicates.TaskSuccess; import com.google.common.base.Function; -import com.google.common.base.Predicate; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableMap; -import com.google.inject.Injector; import com.google.inject.Provides; import com.google.inject.Singleton; import com.google.inject.name.Named; @@ -100,10 +95,13 @@ public class VCloudDirectorRestClientModule extends RestClientModule { private final TaskClient taskClient; - private final RetryablePredicate retry; - private final Predicate checkSuccess = new Predicate() { - @Override - public boolean apply(URI taskUri) { - logger.trace("looking for status on task %s", taskUri); - - Task task = taskClient.getTask(taskUri); - // perhaps task isn't available, yet - if (task == null) return false; - logger.trace("%s: looking for status %s: currently: %s", task, Task.Status.SUCCESS, task.getStatus()); - if (task.getStatus().equals(Task.Status.ERROR)) - throw new VCloudDirectorException(task); - return task.getStatus().equals(Task.Status.SUCCESS); - } - }; @Resource protected Logger logger = Logger.NULL; @Inject - public TaskSuccess(RestContext context, - @Named(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED) long maxWait) { - this.taskClient = context.getApi().getTaskClient(); - this.retry = new RetryablePredicate(checkSuccess, maxWait); + public TaskSuccess(TaskClient taskClient) { + this.taskClient = taskClient; } /** @see Predicate#apply(Object) */ @Override - public boolean apply(URI input) { - return retry.apply(input); + public boolean apply(URI taskUri) { + logger.trace("looking for status on task %s", taskUri); + + Task task = taskClient.getTask(taskUri); + // perhaps task isn't available, yet + if (task == null) return false; + logger.trace("%s: looking for status %s: currently: %s", task, Task.Status.SUCCESS, task.getStatus()); + if (task.getStatus().equals(Task.Status.ERROR)) + throw new VCloudDirectorException(task); + return task.getStatus().equals(Task.Status.SUCCESS); + } + + @Override + public String toString() { + return "checkTaskSuccess()"; } } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClientExpectTest.java index 3aa3533b34..9306a3c754 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClientExpectTest.java @@ -35,7 +35,5 @@ public class VCloudDirectorClientExpectTest extends BaseVCloudDirectorRestClient VCloudDirectorClient clientWhenSessionsExist = requestSendsResponse(loginRequest, sessionResponse); assertEquals(clientWhenSessionsExist.getCurrentSession(), SessionClientExpectTest.SESSION); - } - } 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 ee86ff8926..eb837cb4e6 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 @@ -181,7 +181,8 @@ public class Checks { checkResourceType(metadata); } - public static void checkMetadataEntry(MetadataEntry metadataEntry) {+ // Check required fields + public static void checkMetadataEntry(MetadataEntry metadataEntry) { + // Check required fields assertNotNull(metadataEntry.getKey(), String.format(NOT_NULL_OBJECT_FMT, "Key", "MetadataEntry")); assertNotNull(metadataEntry.getValue(), String.format(NOT_NULL_OBJECT_FMT, "Value", "MetadataEntry")); diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientExpectTest.java index afeff912ac..22f7d99da3 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientExpectTest.java @@ -46,7 +46,7 @@ import com.google.common.collect.ImmutableSet; * * @author grkvlt@apache.org */ -@Test(groups = "unit", singleThreaded = true, testName = "CatalogClientExpectTest") +@Test(groups = { "unit", "user" }, singleThreaded = true, testName = "CatalogClientExpectTest") public class CatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { @Test diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java index 4c812a45bb..7dcca58682 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientLiveTest.java @@ -45,7 +45,7 @@ import com.google.common.collect.Iterables; * * @author grkvlt@apache.org */ -@Test(groups = { "live", "apitests" }, testName = "CatalogClientLiveTest", singleThreaded = true) +@Test(groups = { "live", "api", "user" }, singleThreaded = true, testName = "CatalogClientLiveTest") public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest { /* @@ -178,7 +178,7 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest { Task mergeCatalogItemMetadata = catalogClient.mergeCatalogItemMetadata(catalogItemRef, newMetadata); checkTask(mergeCatalogItemMetadata); - assertTrue(successTester.apply(mergeCatalogItemMetadata.getHref()), + assertTrue(retryTaskSuccess.apply(mergeCatalogItemMetadata.getHref()), String.format(TASK_COMPLETE_TIMELY, "mergeCatalogItemMetadata")); Metadata mergedCatalogItemMetadata = catalogClient.getCatalogItemMetadata(catalogItemRef); diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java index 43677c8291..e3c74afac4 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java @@ -43,7 +43,7 @@ import org.testng.annotations.Test; * * @author danikov */ -@Test(groups = "unit", singleThreaded = true, testName = "NetworkClientExpectTest") +@Test(groups = { "unit", "user" }, singleThreaded = true, testName = "NetworkClientExpectTest") public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { @Test diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientLiveTest.java index f2bb585c63..acfda6450a 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientLiveTest.java @@ -69,10 +69,9 @@ import com.google.common.collect.Iterables; * * @author danikov */ -@Test(groups = { "live", "apitests", "User" }, testName = "MediaClientLiveTest") +@Test(groups = { "live", "api", "user" }, singleThreaded = true, testName = "MediaClientLiveTest") public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { public static final String MEDIA = "media"; - public static Predicate taskTester; /* * Convenience references to API clients. @@ -99,7 +98,6 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { .id(mediaId) .build(); mediaClient = context.getApi().getMediaClient(); - taskTester = new RetryablePredicate(new TaskSuccess(context), 10, 1, TimeUnit.SECONDS); mediaClient.setMetadata(mediaRef, "key", MetadataValue.builder().value("value").build()); } @@ -127,11 +125,11 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { assertTrue(size >= 0, String.format(OBJ_FIELD_GTE_0, MEDIA, "size", size)); } - @Test(testName = "GET /media/{id}/owner", + @Test(testName = "GET /media/{id}/owner", dependsOnMethods = { "testWhenResponseIs2xxLoginReturnsValidMedia" }) public void testWhenResponseIs2xxLoginReturnsValidMediaOwner() { Owner directOwner = mediaClient.getOwner(mediaRef); - assertEquals(owner, directOwner, String.format(GETTER_RETURNS_SAME_OBJ, + assertEquals(owner, directOwner, String.format(GETTER_RETURNS_SAME_OBJ, "getOwner()", "owner", "media.getOwner()", owner.toString(), directOwner.toString())); // parent type @@ -142,7 +140,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { Checks.checkReferenceType(directOwner.getUser()); } - @Test(testName = "PUT /media/{id}", + @Test(testName = "PUT /media/{id}", dependsOnMethods = { "testWhenResponseIs2xxLoginReturnsValidMedia" }) public void testWhenResponseIs2xxLoginReturnsValidNetwork() { String oldName = media.getName(); @@ -154,11 +152,11 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { Task updateMedia = mediaClient.updateMedia(mediaRef, media); Checks.checkTask(updateMedia); - assertTrue(taskTester.apply(updateMedia.getHref()), String.format(TASK_COMPLETE_TIMELY, "updateMedia")); + assertTrue(retryTaskSuccess.apply(updateMedia.getHref()), String.format(TASK_COMPLETE_TIMELY, "updateMedia")); media = mediaClient.getMedia(mediaRef); assertTrue(equal(media.getName(), newName), String.format(OBJ_FIELD_UPDATABLE, MEDIA, "name")); - assertTrue(equal(media.getDescription(), newDescription), + assertTrue(equal(media.getDescription(), newDescription), String.format(OBJ_FIELD_UPDATABLE, MEDIA, "description")); //TODO negative tests? @@ -171,16 +169,16 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { updateMedia = mediaClient.updateMedia(mediaRef, media); Checks.checkTask(updateMedia); - assertTrue(taskTester.apply(updateMedia.getHref()), String.format(TASK_COMPLETE_TIMELY, "updateMedia")); + assertTrue(retryTaskSuccess.apply(updateMedia.getHref()), String.format(TASK_COMPLETE_TIMELY, "updateMedia")); media = mediaClient.getMedia(mediaRef); } - @Test(testName = "GET /media/{id}/metadata", + @Test(testName = "GET /media/{id}/metadata", dependsOnMethods = { "testWhenResponseIs2xxLoginReturnsValidMedia" }) public void testWhenResponseIs2xxLoginReturnsValidMetadata() { metadata = mediaClient.getMetadata(mediaRef); // required for testing - assertFalse(Iterables.isEmpty(metadata.getMetadataEntries()), + assertFalse(Iterables.isEmpty(metadata.getMetadataEntries()), String.format(OBJ_FIELD_REQ_LIVE, MEDIA, "metadata.entries")); // parent type @@ -188,9 +186,9 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { for (MetadataEntry entry : metadata.getMetadataEntries()) { // required elements and attributes - assertNotNull(entry.getKey(), + assertNotNull(entry.getKey(), String.format(OBJ_FIELD_ATTRB_REQ, MEDIA, "MetadataEntry", metadataValue, "key")); - assertNotNull(entry.getValue(), + assertNotNull(entry.getValue(), String.format(OBJ_FIELD_ATTRB_REQ, MEDIA, "MetadataEntry", metadataValue, "value")); // parent type @@ -198,7 +196,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { } } - @Test(testName = "POST /media/{id}/metadata", + @Test(testName = "POST /media/{id}/metadata", dependsOnMethods = { "testWhenResponseIs2xxLoginReturnsValidMetadata" }) public void testWhenResponseIs2xxLoginMergedMetadata() { // test new @@ -209,7 +207,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { Task mergeMetadata = mediaClient.mergeMetadata(mediaRef, inputMetadata); Checks.checkTask(mergeMetadata); - assertTrue(taskTester.apply(mergeMetadata.getHref()), String.format(TASK_COMPLETE_TIMELY, "mergeMetadata(new)")); + assertTrue(retryTaskSuccess.apply(mergeMetadata.getHref()), String.format(TASK_COMPLETE_TIMELY, "mergeMetadata(new)")); metadata = mediaClient.getMetadata(mediaRef); checkMetadataContainsEntries(metadata, inputEntries); @@ -223,7 +221,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { mergeMetadata = mediaClient.mergeMetadata(mediaRef, inputMetadata); Checks.checkTask(mergeMetadata); - assertTrue(taskTester.apply(mergeMetadata.getHref()), String.format(TASK_COMPLETE_TIMELY, "mergeMetadata(modify)")); + assertTrue(retryTaskSuccess.apply(mergeMetadata.getHref()), String.format(TASK_COMPLETE_TIMELY, "mergeMetadata(modify)")); metadata = mediaClient.getMetadata(mediaRef); checkMetadataContainsEntries(metadata, inputEntries); @@ -240,14 +238,14 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { } if (!found) { - String.format(OBJ_FIELD_CONTAINS, MEDIA, "metadata", - Iterables.toString(metadata.getMetadataEntries()), + String.format(OBJ_FIELD_CONTAINS, MEDIA, "metadata", + Iterables.toString(metadata.getMetadataEntries()), Iterables.toString(entries)); } } } - @Test(testName = "GET /media/{id}/metadata/{key}", + @Test(testName = "GET /media/{id}/metadata/{key}", dependsOnMethods = { "testWhenResponseIs2xxLoginMergedMetadata" }) public void testWhenResponseIs2xxLoginReturnsValidMetadataValue() { metadataValue = mediaClient.getMetadataValue(mediaRef, "key"); @@ -257,14 +255,14 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { // Check required elements and attributes String value = metadataValue.getValue(); - assertNotNull(value, - String.format(OBJ_FIELD_ATTRB_REQ, MEDIA, "MetadataEntry", + assertNotNull(value, + String.format(OBJ_FIELD_ATTRB_REQ, MEDIA, "MetadataEntry", metadataValue.toString(), metadataEntryValue.toString())); - assertEquals(value, metadataEntryValue, + assertEquals(value, metadataEntryValue, String.format(OBJ_FIELD_EQ, MEDIA, "metadataEntry.value", metadataEntryValue, value)); } - @Test(testName = "PUT /media/{id}/metadata/{key}", + @Test(testName = "PUT /media/{id}/metadata/{key}", dependsOnMethods = { "testWhenResponseIs2xxLoginReturnsValidMetadataValue" }) public void testWhenResponseIs2xxLoginUpdatesMetadataEntry() { metadataEntryValue = "newValue"; @@ -272,7 +270,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { Task setMetadataEntry = mediaClient.setMetadata(mediaRef, "key", newValue); Checks.checkTask(setMetadataEntry); - assertTrue(taskTester.apply(setMetadataEntry.getHref()), + assertTrue(retryTaskSuccess.apply(setMetadataEntry.getHref()), String.format(TASK_COMPLETE_TIMELY, "setMetadataEntry")); metadataValue = mediaClient.getMetadataValue(mediaRef, "key"); @@ -280,12 +278,12 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { testWhenResponseIs2xxLoginReturnsValidMetadataValue(); } - @Test(testName = "DELETE /media/{id}/metadata/{key}", + @Test(testName = "DELETE /media/{id}/metadata/{key}", dependsOnMethods = { "testWhenResponseIs2xxLoginUpdatesMetadataEntry" } ) public void testWhenResponseIs2xxLoginDeletesMetadataEntry() { Task deleteMetadataEntry = mediaClient.deleteMetadataEntry(mediaRef, "testKey"); Checks.checkTask(deleteMetadataEntry); - assertTrue(taskTester.apply(deleteMetadataEntry.getHref()), + assertTrue(retryTaskSuccess.apply(deleteMetadataEntry.getHref()), String.format(TASK_COMPLETE_TIMELY, "deleteMetadataEntry")); Error expected = Error.builder() @@ -305,8 +303,8 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { } if (metadataValue != null) { // guard against NPE on the .toStrings - assertNull(metadataValue, String.format(OBJ_FIELD_ATTRB_DEL, MEDIA, - "Metadata", metadataValue.toString(), + assertNull(metadataValue, String.format(OBJ_FIELD_ATTRB_DEL, MEDIA, + "Metadata", metadataValue.toString(), "metadataEntry", metadataValue.toString())); } @@ -314,18 +312,18 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { testWhenResponseIs2xxLoginReturnsValidMetadata(); testWhenResponseIs2xxLoginReturnsValidMedia(); } - @Test(testName = "DELETE /media/{id}", + @Test(testName = "DELETE /media/{id}", dependsOnMethods = { "testWhenResponseIs2xxLoginDeletesMetadataEntry" } ) public void testWhenResponseIs2xxLoginDeletesMedia() { Task deleteMedia = mediaClient.deleteMedia(mediaRef); Checks.checkTask(deleteMedia); - assertTrue(taskTester.apply(deleteMedia.getHref()), + assertTrue(retryTaskSuccess.apply(deleteMedia.getHref()), String.format(TASK_COMPLETE_TIMELY, "deleteMedia")); Error expected = Error.builder() .message(String.format( - "No access to entity \"(com.vmware.vcloud.entity.media:%s)\".", + "No access to entity \"(com.vmware.vcloud.entity.media:%s)\".", mediaRef.getId())) .majorErrorCode(403) .minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN") diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientExpectTest.java index 6b8c76d413..771ec92ba0 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientExpectTest.java @@ -48,7 +48,7 @@ import com.google.common.collect.ImmutableSet; * * @author danikov */ -@Test(groups = "unit", singleThreaded = true, testName = "NetworkClientExpectTest") +@Test(groups = { "unit", "user" }, singleThreaded = true, testName = "NetworkClientExpectTest") public class NetworkClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { @Test diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientLiveTest.java index 2c3e38afb9..e75fd7c47e 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientLiveTest.java @@ -19,6 +19,7 @@ package org.jclouds.vcloud.director.v1_5.features; import static org.testng.Assert.*; +import static org.jclouds.vcloud.director.v1_5.domain.Checks.*; import java.net.URI; @@ -37,7 +38,7 @@ import org.testng.annotations.Test; * * @author danikov */ -@Test(groups = { "live", "apitests" }, testName = "NetworkClientLiveTest") +@Test(groups = { "live", "api", "user" }, singleThreaded = true, testName = "NetworkClientLiveTest") public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest { /* @@ -51,27 +52,24 @@ public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest { networkClient = context.getApi().getNetworkClient(); } - // @Before populate - String networkId = "55a677cf-ab3f-48ae-b880-fab90421980c"; - String catalogId = "9e08c2f6-077a-42ce-bece-d5332e2ebb5c"; - @Test(testName = "GET /network/{id}") public void testWhenResponseIs2xxLoginReturnsValidNetwork() { Reference networkRef = Reference.builder() - .href(URI.create(endpoint + "/network/"+networkId)).build(); + .href(URI.create(endpoint + "/network/" + networkId)).build(); OrgNetwork network = networkClient.getNetwork(networkRef); - //TODO assert network is valid + // TODO change to checkOrgNetwork(...) + checkEntityType(network); } - @Test(testName = "GET /network/NOTAUUID", enabled=false) + @Test(testName = "GET /network/{id} - invalid") public void testWhenResponseIs400ForInvalidNetworkId() { Reference networkRef = Reference.builder() .href(URI.create(endpoint + "/network/NOTAUUID")).build(); Error expected = Error.builder() - .message("validation error : EntityRef has incorrect type, expected type is com.vmware.vcloud.entity.network.") + .message("validation error on field 'id': String value has invalid format or length") .majorErrorCode(400) .minorErrorCode("BAD_REQUEST") .build(); @@ -85,29 +83,8 @@ public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest { fail("Should have thrown a VCloudDirectorException"); } } - - @Test(testName = "GET /network/{catalog_id}", enabled=false) - public void testWhenResponseIs403ForCatalogIdUsedAsNetworkId() { - Reference networkRef = Reference.builder() - .href(URI.create(endpoint + "/network"+catalogId)).build(); - Error expected = Error.builder() - .message("This operation is denied.") - .majorErrorCode(403) - .minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN") - .build(); - - try { - networkClient.getNetwork(networkRef); - fail("Should give HTTP 403 error"); - } catch (VCloudDirectorException vde) { - assertEquals(vde.getError(), expected); - } catch (Exception e) { - fail("Should have thrown a VCloudDirectorException"); - } - } - - @Test(testName = "GET /network/{fake_id}") + @Test(testName = "GET /network/{id} - fake") public void testWhenResponseIs403ForFakeNetworkId() { Reference networkRef = Reference.builder() .href(URI.create(endpoint + "/network/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")).build(); @@ -133,11 +110,12 @@ public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest { Reference networkRef = Reference.builder() .href(URI.create(endpoint + "/network/"+networkId)).build(); - Metadata expected = context.getApi().getNetworkClient().getMetadata(networkRef); - - // assert metadata is valid - // assert has metadata in order to support subsequent test - // assign metadata key (todo- ordering) + Metadata metadata = context.getApi().getNetworkClient().getMetadata(networkRef); + + checkMetadata(metadata); + + // TODO assert has metadata in order to support subsequent test + // TODO assign metadata key (todo- ordering) } String metadataKey = "key"; @@ -148,9 +126,8 @@ public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest { Reference networkRef = Reference.builder() .href(URI.create(endpoint + "/network/"+networkId)).build(); - MetadataEntry expected = networkClient.getMetadataEntry(networkRef, metadataKey); + MetadataEntry metadataEntry = networkClient.getMetadataEntry(networkRef, metadataKey); - // assert metadataEntry is valid + checkMetadataEntry(metadataEntry); } - } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientExpectTest.java index 514ad64b88..b65c66f4dc 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientExpectTest.java @@ -44,7 +44,7 @@ import com.google.common.collect.Iterables; * * @author Adrian Cole */ -@Test(groups = "unit", singleThreaded = true, testName = "OrgClientExpectTest") +@Test(groups = { "unit", "user" }, singleThreaded = true, testName = "OrgClientExpectTest") public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { @Test diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientLiveTest.java index 8bd51f5289..2a243da968 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientLiveTest.java @@ -39,7 +39,7 @@ import com.google.common.collect.Iterables; * * @author grkvlt@apache.org */ -@Test(groups = { "live", "apitests" }, testName = "OrgClientLiveTest") +@Test(groups = { "live", "api", "user" }, singleThreaded = true, testName = "OrgClientLiveTest") public class OrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { /* diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientExpectTest.java index 790fc7ce08..a1c74cb413 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientExpectTest.java @@ -41,7 +41,7 @@ import com.google.common.collect.ImmutableMultimap; * * @author grkvlt@apache.org */ -@Test(groups = "unit", singleThreaded = true, testName = "QueryClientExpectTest") +@Test(groups = { "unit", "user" }, singleThreaded = true, testName = "QueryClientExpectTest") public class QueryClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { @Test diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientLiveTest.java index 4b8c77a5cf..268a99c725 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientLiveTest.java @@ -32,7 +32,7 @@ import org.testng.annotations.Test; * * @author grkvlt@apache.org */ -@Test(groups = { "live", "apitests" }, testName = "QueryClientLiveTest") +@Test(groups = { "live", "api", "user" }, singleThreaded = true, testName = "QueryClientLiveTest") public class QueryClientLiveTest extends BaseVCloudDirectorClientLiveTest { /* diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientExpectTest.java index 716ec3e286..1408e26083 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientExpectTest.java @@ -41,7 +41,7 @@ import com.google.common.collect.ImmutableMultimap; * * @author grkvlt@apache.org */ -@Test(groups = "unit", singleThreaded = true, testName = "TaskClientExpectTest") +@Test(groups = { "unit", "user" }, singleThreaded = true, testName = "TaskClientExpectTest") public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { @Test diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientLiveTest.java index 13e465ffb2..eebc3c1c7b 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientLiveTest.java @@ -39,7 +39,7 @@ import com.google.common.collect.Iterables; * * @author grkvlt@apache.org */ -@Test(groups = { "live", "apitests" }, testName = "TaskClientLiveTest") +@Test(groups = { "live", "api", "user" }, singleThreaded = true, testName = "TaskClientLiveTest") public class TaskClientLiveTest extends BaseVCloudDirectorClientLiveTest { /* diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java index f66f81bda0..79b0e0d79e 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java @@ -18,12 +18,14 @@ */ package org.jclouds.vcloud.director.v1_5.internal; -import java.util.Properties; +import static org.testng.Assert.*; -import javax.inject.Inject; +import java.net.URI; +import java.util.Properties; import org.jclouds.compute.BaseVersionedServiceLiveTest; import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.jclouds.predicates.RetryablePredicate; import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContextFactory; import org.jclouds.sshj.config.SshjSshClientModule; @@ -33,13 +35,17 @@ import org.jclouds.vcloud.director.v1_5.predicates.TaskSuccess; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import com.google.common.base.Predicate; import com.google.common.collect.ImmutableSet; +import com.google.inject.Guice; +import com.google.inject.Inject; import com.google.inject.Module; /** - * Tests behavior of {@code VCloudDirectorClient} + * Tests behavior of {@link VCloudDirectorClient} * * @author Adrian Cole + * @author grkvlt@apache.org */ @Test(groups = "live") public class BaseVCloudDirectorClientLiveTest extends BaseVersionedServiceLiveTest { @@ -48,8 +54,41 @@ public class BaseVCloudDirectorClientLiveTest extends BaseVersionedServiceLiveTe provider = "vcloud-director"; } - @Inject - protected TaskSuccess successTester; + protected String catalogName; + protected String mediaId; + protected String vAppTemplateId; + protected String networkId; + protected String vDCId; + + @Override + protected Properties setupProperties() { + Properties overrides= super.setupProperties(); + if (catalogName != null) + overrides.setProperty(provider + ".catalog-name", catalogName); + if (mediaId != null) + overrides.setProperty(provider + ".media-id", mediaId); + if (vAppTemplateId != null) + overrides.setProperty(provider + ".vapptemplate-id", vAppTemplateId); + if (networkId != null) + overrides.setProperty(provider + ".network-id", networkId); + if (vDCId != null) + overrides.setProperty(provider + ".vcd-id", vDCId); + return overrides; + } + + public Predicate retryTaskSuccess; + + @Override + @BeforeClass(groups = { "live" }) + protected void setupCredentials() { + super.setupCredentials(); + + catalogName = System.getProperty("test." + provider + ".catalog-name"); + mediaId = System.getProperty("test." + provider + ".media-id"); + vAppTemplateId = System.getProperty("test." + provider + ".vapptemplate-id"); + networkId = System.getProperty("test." + provider + ".network-id"); + vDCId = System.getProperty("test." + provider + ".vdc-id"); + } protected RestContext context; @@ -57,14 +96,16 @@ public class BaseVCloudDirectorClientLiveTest extends BaseVersionedServiceLiveTe public void setupContext() { setupCredentials(); Properties overrides = setupProperties(); + context = new RestContextFactory().createContext(provider, identity, credential, ImmutableSet. of(new Log4JLoggingModule(), new SshjSshClientModule()), overrides); -// successTester = new TaskSuccess(context, 1000L); // NOTE is this required? + + TaskSuccess taskSuccess = context.utils().injector().getInstance(TaskSuccess.class); + retryTaskSuccess = new RetryablePredicate(taskSuccess, 1000L); } protected void tearDown() { if (context != null) context.close(); } - } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java index 75c4a4ea49..4882d4b886 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java @@ -18,8 +18,8 @@ */ package org.jclouds.vcloud.director.v1_5.internal; -import static com.google.common.base.Preconditions.checkNotNull; -import static org.testng.Assert.assertNotNull; +import static com.google.common.base.Preconditions.*; +import static org.testng.Assert.*; import java.net.URI; @@ -29,6 +29,7 @@ import org.jclouds.http.HttpResponse; import org.jclouds.rest.BaseRestClientExpectTest; import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.jclouds.vcloud.director.v1_5.predicates.TaskSuccess; import org.testng.annotations.BeforeGroups; import com.google.common.collect.ImmutableMultimap; diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/login/SessionClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/login/SessionClientExpectTest.java index 89055a05f5..0c31ba2885 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/login/SessionClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/login/SessionClientExpectTest.java @@ -41,7 +41,7 @@ import com.google.common.collect.ImmutableMultimap; * @author Adrian Cole */ @Test(groups = "unit", testName = "SessionClientExpectTest") -// only needed as SessionClient is not(Link.builder().registered in(Link.builder().rest.properties +// only needed as SessionClient is not registered in rest.properties @RegisterContext(sync = SessionClient.class, async = SessionAsyncClient.class) public class SessionClientExpectTest extends BaseRestClientExpectTest { public static final String user = "adrian@jclouds.org"; diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/login/SessionClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/login/SessionClientLiveTest.java index 040a34f97a..8144418278 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/login/SessionClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/login/SessionClientLiveTest.java @@ -18,17 +18,14 @@ */ package org.jclouds.vcloud.director.v1_5.login; -import static org.jclouds.rest.RestContextFactory.contextSpec; -import static org.jclouds.rest.RestContextFactory.createContextBuilder; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; +import static org.jclouds.rest.RestContextFactory.*; +import static org.testng.Assert.*; import java.net.URI; import java.util.Properties; import org.jclouds.compute.BaseVersionedServiceLiveTest; -import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; +import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContextSpec; import org.jclouds.vcloud.director.v1_5.domain.SessionWithToken; @@ -61,7 +58,7 @@ public class SessionClientLiveTest extends BaseVersionedServiceLiveTest { apiVersion, buildVersion, "", identity, credential, SessionClient.class, SessionAsyncClient.class); context = createContextBuilder(contextSpec, overrides).withModules( - ImmutableSet. of(new SLF4JLoggingModule())).buildContext(); + ImmutableSet. of(new Log4JLoggingModule())).buildContext(); // session client isn't typically exposed to the user, as it is implicit client = context.utils().injector().getInstance(SessionClient.class); From be80a60b8873e3bc5809908facd138a52ab617f4 Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Tue, 21 Feb 2012 16:49:13 +0000 Subject: [PATCH 10/13] Add error century code of '8xx' for vCloud generated exception messages --- .../jclouds/vcloud/director/v1_5/VCloudDirectorException.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorException.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorException.java index f325032393..55a73625e0 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorException.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorException.java @@ -33,13 +33,13 @@ public class VCloudDirectorException extends RuntimeException { private final Task task; public VCloudDirectorException(Error error) { - super("Error: " + error.getMessage()); + super("ERR-801: Error: " + error.getMessage()); this.error = error; this.task = null; } public VCloudDirectorException(Task task) { - super("Task error: " + task.getError().getMessage()); + super("ERR-802: Task error: " + task.getError().getMessage()); this.error = task.getError(); this.task = task; } From 36ef6fb9d4851cbb8cb771047405ee182c544365 Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Tue, 21 Feb 2012 16:49:30 +0000 Subject: [PATCH 11/13] Fix network media type --- .../jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java index 43756144b4..01c4808467 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java @@ -51,7 +51,7 @@ public class VCloudDirectorMediaType { public static final String TASK = "application/vnd.vmware.vcloud.task+xml"; - public static final String NETWORK = "application/vnd.vmware.vcloud.entity.network+xml"; + public static final String NETWORK = "application/vnd.vmware.vcloud.network+xml"; public static final String ORG_NETWORK = "application/vnd.vmware.vcloud.orgNetwork+xml"; From 06ca9b1e3d8662164d834a788becfda0c770b39d Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Tue, 21 Feb 2012 16:49:56 +0000 Subject: [PATCH 12/13] Updated our error codes --- .../v1_5/VCloudDirectorLiveTestConstants.java | 70 +++++++++++-------- 1 file changed, 41 insertions(+), 29 deletions(-) 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 dc7c3d91c1..5420c9b670 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 @@ -23,40 +23,52 @@ package org.jclouds.vcloud.director.v1_5; */ public class VCloudDirectorLiveTestConstants { - /* danikov */ + /* Error codes from 100 to 199 reflect parsing and other errors in domain objects. */ - public static final String REF_REQ_LIVE = "%s reference required to perform live tests"; - public static final String OBJ_REQ_LIVE = "%s instance required to perform live tests"; - public static final String OBJ_FIELD_REQ_LIVE = "%s must have a non-null \"%s\" to perform live tests"; - public static final String OBJ_FIELD_REQ = "%s must always have a non-null field \"%s\""; - public static final String OBJ_FIELD_ATTRB_REQ = "%s %s (%s) must always have a non-null field \"%s\""; - public static final String OBJ_FIELD_EQ = "%s %s must have the value \"%s\" (%s)"; - public static final String OBJ_FIELD_CONTAINS = "%s %s must contain the values \"%s\" (%s)"; - public static final String OBJ_FIELD_GTE_0 = "%s field %s must be greater than to equal to 0 (%d)"; - public static final String GETTER_RETURNS_SAME_OBJ = "%s should return the same %s as %s (%s, %s)"; - public static final String OBJ_FIELD_UPDATABLE = "%s field %s should be updatable"; - public static final String OBJ_FIELD_ATTRB_DEL = "%s %s (%s) should have deleted field \"%s\" (%s)"; - public static final String OBJ_DEL = "%s (%s) should have been deleted"; - public static final String TASK_COMPLETE_TIMELY = "Task %s should complete in a timely fashion"; + public static final String OK = "ERR-100: ok"; + + public static final String REF_REQ_LIVE = "ERR-101: %s reference required to perform live tests"; + + public static final String OBJ_REQ_LIVE = "ERR-102: %s instance required to perform live tests"; + + public static final String OBJ_FIELD_REQ_LIVE = "ERR-103: %s must have a non-null \"%s\" to perform live tests"; + + public static final String OBJ_FIELD_REQ = "ERR-103: %s must always have a non-null field \"%s\""; + + public static final String OBJ_FIELD_ATTRB_REQ = "ERR-105: %s %s (%s) must always have a non-null field \"%s\""; + + public static final String OBJ_FIELD_EQ = "ERR-106: %s %s must have the value \"%s\" (%s)"; + + public static final String OBJ_FIELD_CONTAINS = "ERR-107: %s %s must contain the values \"%s\" (%s)"; + + public static final String OBJ_FIELD_GTE_0 = "ERR-108: %s field %s must be greater than to equal to 0 (%d)"; + + public static final String GETTER_RETURNS_SAME_OBJ = "ERR-109: %s should return the same %s as %s (%s, %s)"; + + public static final String OBJ_FIELD_UPDATABLE = "ERR-110: %s field %s should be updatable"; + + public static final String OBJ_FIELD_ATTRB_DEL = "ERR-111: %s %s (%s) should have deleted field \"%s\" (%s)"; + + public static final String OBJ_DEL = "ERR-112: %s (%s) should have been deleted"; + + public static final String TASK_COMPLETE_TIMELY = "ERR-113: Task %s should complete in a timely fashion"; + + public static final String NOT_NULL_OBJECT_FMT = "ERR-114: The %s field of the %s must not be null"; - /* grkvlt */ - - public static final String NOT_NULL_OBJECT_FMT = "ERR-01: The %s field of the %s must not be null"; + public static final String NOT_EMPTY_OBJECT_FMT = "ERR-115: One or more %s fields of the %s must be present"; - public static final String NOT_EMPTY_OBJECT_FMT = "ERR-02: One or more %s fields of the %s must be present"; + public static final String REQUIRED_VALUE_OBJECT_FMT = "ERR-116: The %s field of the %s must not be '%s'; allowed values: %s"; + + public static final String REQUIRED_VALUE_FMT = "ERR-117: The %s field must not be '%s'; allowed values: %s"; + + public static final String MUST_BE_WELL_FORMED_FMT = "ERR-118: The %s field must be well formed: '%s'"; + + public static final String MUST_EXIST_FMT = "ERR-119: The '%s' %s must exist"; - public static final String REQUIRED_VALUE_OBJECT_FMT = "ERR-03: The %s field of the %s must not be '%s'; allowed values: %s"; + public static final String MUST_CONTAIN_FMT = "ERR-120: The %s field must contain '%s': '%s'"; - public static final String REQUIRED_VALUE_FMT = "ERR-04: The %s field must not be '%s'; allowed values: %s"; + public static final String CONDITION_FMT = "ERR-121: The %s field must be %s: '%s'"; - public static final String MUST_BE_WELL_FORMED_FMT = "ERR-05: The %s field must be well formed: '%s'"; - - public static final String MUST_EXIST_FMT = "ERR-06: The '%s' %s must exist"; - - public static final String MUST_CONTAIN_FMT = "ERR-07: The %s field must contain '%s': '%s'"; - - public static final String CONDITION_FMT = "ERR-08: The %s field must be %s: '%s'"; - - public static final String CORRECT_VALUE_OBJECT_FMT = "ERR-09: The %s field of the %s must be '%s': '%s'"; + public static final String CORRECT_VALUE_OBJECT_FMT = "ERR-122: The %s field of the %s must be '%s': '%s'"; } From 5201207f1ca515a87564de23c64a9243ca9e576f Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Tue, 21 Feb 2012 17:14:26 +0000 Subject: [PATCH 13/13] Updates to tidy up and make sure everything is both internally and externally consistent --- .../director/v1_5/VCloudDirectorMediaType.java | 2 +- .../VCloudDirectorClientExperimentLiveTest.java | 8 ++++++++ .../v1_5/features/MediaClientExpectTest.java | 2 +- .../v1_5/features/MediaClientLiveTest.java | 17 ++++++++++++----- .../v1_5/features/NetworkClientLiveTest.java | 5 ++++- .../v1_5/features/OrgClientLiveTest.java | 1 + .../v1_5/features/QueryClientLiveTest.java | 1 + .../v1_5/features/TaskClientLiveTest.java | 1 + .../BaseVCloudDirectorClientLiveTest.java | 7 ++++++- 9 files changed, 35 insertions(+), 9 deletions(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java index 01c4808467..82282db00f 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java @@ -88,7 +88,7 @@ public class VCloudDirectorMediaType { */ public static final List ALL = Arrays.asList( SESSION, ERROR, ORG_LIST, METADATA, METADATA_ENTRY, - METADATA_VALUE, ORG, TASKS_LIST, TASK, ORG_NETWORK, + METADATA_VALUE, ORG, TASKS_LIST, TASK, NETWORK, ORG_NETWORK, CATALOG, CATALOG_ITEM, CATALOG_ITEMS, CATALOGS_LIST, PROPERTY, MEDIA, OWNER, VDC, ADMIN_USER, QUERY_RESULT_RECORDS, QUERY_RESULT_REFERENCES, QUERY_RESULT_ID_RECORDS, diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClientExperimentLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClientExperimentLiveTest.java index de9d0afdaf..101fdecb89 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClientExperimentLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClientExperimentLiveTest.java @@ -36,4 +36,12 @@ public class VCloudDirectorClientExperimentLiveTest extends BaseVCloudDirectorCl assertEquals(session.getHref().toASCIIString(), context.getEndpoint().toASCIIString() + "/session/"); } + /** + * No operation. + * + * @see BaseVCloudDirectorClientLiveTest#setupRequiredClients() + */ + @Override + public void setupRequiredClients() { } + } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java index e3c74afac4..230c04ed73 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java @@ -46,7 +46,7 @@ import org.testng.annotations.Test; @Test(groups = { "unit", "user" }, singleThreaded = true, testName = "NetworkClientExpectTest") public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { - @Test + @Test(enabled = false) public void testGetMedia() { URI mediaUri = URI.create(endpoint + "/media/794eb334-754e-4917-b5a0-5df85cbd61d1"); diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientLiveTest.java index acfda6450a..428fa35e3a 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientLiveTest.java @@ -57,6 +57,7 @@ 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.internal.BaseVCloudDirectorClientLiveTest; import org.jclouds.vcloud.director.v1_5.predicates.TaskSuccess; +import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; @@ -71,13 +72,21 @@ import com.google.common.collect.Iterables; */ @Test(groups = { "live", "api", "user" }, singleThreaded = true, testName = "MediaClientLiveTest") public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { + public static final String MEDIA = "media"; /* * Convenience references to API clients. */ + protected MediaClient mediaClient; + @BeforeClass(inheritGroups = true) + @Override + public void setupRequiredClients() { + mediaClient = context.getApi().getMediaClient(); + } + /* * Shared state between dependent tests. */ @@ -88,16 +97,14 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { private MetadataValue metadataValue; private String metadataEntryValue = "value"; - @BeforeGroups(groups = { "live" }, dependsOnMethods = { "setupClient" }) - public void before() { - String mediaId = "68dc01a4-6c76-4177-9f19-ec12bf94287c"; // TODO: inject + @BeforeGroups(groups = { "live" }) + public void createReferenceData() { mediaRef = Reference.builder() .type("application/vnd.vmware.vcloud.media+xml") .name("") - .href(URI.create(endpoint+"/media/"+mediaId)) + .href(URI.create(endpoint+"/media/" + mediaId)) .id(mediaId) .build(); - mediaClient = context.getApi().getMediaClient(); mediaClient.setMetadata(mediaRef, "key", MetadataValue.builder().value("value").build()); } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientLiveTest.java index e75fd7c47e..3a16992387 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientLiveTest.java @@ -41,13 +41,16 @@ import org.testng.annotations.Test; @Test(groups = { "live", "api", "user" }, singleThreaded = true, testName = "NetworkClientLiveTest") public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest { + public static final String NETWORK = "network"; + /* * Convenience references to API clients. */ - private NetworkClient networkClient; + protected NetworkClient networkClient; @BeforeClass(inheritGroups = true) + @Override public void setupRequiredClients() { networkClient = context.getApi().getNetworkClient(); } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientLiveTest.java index 2a243da968..90cb04c083 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientLiveTest.java @@ -49,6 +49,7 @@ public class OrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { private OrgClient orgClient; @BeforeClass(inheritGroups = true) + @Override public void setupRequiredClients() { orgClient = context.getApi().getOrgClient(); } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientLiveTest.java index 268a99c725..93b23be2b1 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientLiveTest.java @@ -43,6 +43,7 @@ public class QueryClientLiveTest extends BaseVCloudDirectorClientLiveTest { private QueryClient queryClient; @BeforeClass(inheritGroups = true) + @Override public void setupRequiredClients() { catalogClient = context.getApi().getCatalogClient(); queryClient = context.getApi().getQueryClient(); diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientLiveTest.java index eebc3c1c7b..8e3288b466 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientLiveTest.java @@ -50,6 +50,7 @@ public class TaskClientLiveTest extends BaseVCloudDirectorClientLiveTest { private TaskClient taskClient; @BeforeClass(inheritGroups = true) + @Override public void setupRequiredClients() { orgClient = context.getApi().getOrgClient(); taskClient = context.getApi().getTaskClient(); diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java index 79b0e0d79e..b68ee2c84f 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java @@ -48,7 +48,7 @@ import com.google.inject.Module; * @author grkvlt@apache.org */ @Test(groups = "live") -public class BaseVCloudDirectorClientLiveTest extends BaseVersionedServiceLiveTest { +public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServiceLiveTest { protected BaseVCloudDirectorClientLiveTest() { provider = "vcloud-director"; @@ -75,7 +75,12 @@ public class BaseVCloudDirectorClientLiveTest extends BaseVersionedServiceLiveTe overrides.setProperty(provider + ".vcd-id", vDCId); return overrides; } + + @BeforeClass(inheritGroups = true) + // NOTE Implement as required to populate xxxClient fields, or NOP + public abstract void setupRequiredClients(); + /** Injected by {@link #setupContext} */ public Predicate retryTaskSuccess; @Override