Issue 830: Use XmlWrapper for collections in Vdc

This commit is contained in:
Andrew Donald Kennedy 2012-03-21 22:15:29 +00:00
parent 25fac3b36e
commit 35391b876b
13 changed files with 91 additions and 483 deletions

View File

@ -1,139 +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.equal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
/**
* Represents a list of references to available networks.
* <p/>
* <p/>
* <p>Java class for AvailableNetworks complex type.
* <p/>
* <p>The following schema fragment specifies the expected content contained within this class.
* <p/>
* <pre>
* &lt;complexType name="AvailableNetworks">
* &lt;complexContent>
* &lt;extension base="{http://www.vmware.com/vcloud/v1.5}VCloudExtensibleType">
* &lt;sequence>
* &lt;element name="Network" type="{http://www.vmware.com/vcloud/v1.5}ReferenceType" maxOccurs="unbounded" minOccurs="0"/>
* &lt;/sequence>
* &lt;anyAttribute processContents='lax' namespace='##other'/>
* &lt;/extension>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*/
@XmlType(name = "AvailableNetworks", propOrder = {
"networks"
})
public class AvailableNetworks {
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return new Builder().fromAvailableNetworks(this);
}
public static class Builder {
private Set<Reference> networks = Sets.newLinkedHashSet();
/**
* @see AvailableNetworks#getNetworks()
*/
public Builder networks(Collection<Reference> networks) {
this.networks = Sets.newLinkedHashSet(checkNotNull(networks, "networks"));
return this;
}
/**
* @see AvailableNetworks#getNetworks()
*/
public Builder network(Reference network) {
networks.add(checkNotNull(network, "network"));
return this;
}
public AvailableNetworks build() {
AvailableNetworks availableNetworks = new AvailableNetworks(networks);
return availableNetworks;
}
public Builder fromAvailableNetworks(AvailableNetworks in) {
return networks(in.getNetworks());
}
}
@XmlElement(name = "Network")
protected Set<Reference> networks = Sets.newLinkedHashSet();
private AvailableNetworks(Set<Reference> networks) {
this.networks = ImmutableSet.copyOf(networks);
}
private AvailableNetworks() {
// For JAXB
}
/**
* Gets the value of the network property.
*/
public Set<Reference> getNetworks() {
return Collections.unmodifiableSet(this.networks);
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
AvailableNetworks that = AvailableNetworks.class.cast(o);
return equal(networks, that.networks);
}
@Override
public int hashCode() {
return Objects.hashCode(networks);
}
@Override
public String toString() {
return Objects.toStringHelper("")
.add("network", networks).toString();
}
}

View File

@ -20,11 +20,17 @@
package org.jclouds.vcloud.director.v1_5.domain; package org.jclouds.vcloud.director.v1_5.domain;
import static com.google.common.base.Objects.equal; import static com.google.common.base.Objects.equal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Set;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlType; import javax.xml.bind.annotation.XmlType;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
/** /**
@ -62,13 +68,21 @@ public class Capabilities {
public static class Builder { public static class Builder {
private SupportedHardwareVersions supportedHardwareVersions; private Set<String> supportedHardwareVersions = Sets.newLinkedHashSet();
/** /**
* @see Capabilities#getSupportedHardwareVersions() * @see Capabilities#getSupportedHardwareVersions()
*/ */
public Builder supportedHardwareVersions(SupportedHardwareVersions supportedHardwareVersions) { public Builder supportedHardwareVersions(Set<String> supportedHardwareVersions) {
this.supportedHardwareVersions = supportedHardwareVersions; this.supportedHardwareVersions = Sets.newLinkedHashSet(checkNotNull(supportedHardwareVersions, "supportedHardwareVersions"));
return this;
}
/**
* @see Capabilities#getSupportedHardwareVersions()
*/
public Builder supportedHardwareVersion(String supportedHardwareVersion) {
this.supportedHardwareVersions.add(checkNotNull(supportedHardwareVersion, "supportedHardwareVersion"));
return this; return this;
} }
@ -79,12 +93,12 @@ public class Capabilities {
public Builder fromCapabilities(Capabilities in) { public Builder fromCapabilities(Capabilities in) {
return supportedHardwareVersions(in.getSupportedHardwareVersions()); return supportedHardwareVersions(Sets.newLinkedHashSet(in.getSupportedHardwareVersions()));
} }
} }
private Capabilities(SupportedHardwareVersions supportedHardwareVersions) { private Capabilities(Set<String> supportedHardwareVersions) {
this.supportedHardwareVersions = supportedHardwareVersions; this.supportedHardwareVersions = supportedHardwareVersions == null ? Sets.<String>newLinkedHashSet() : ImmutableSet.copyOf(supportedHardwareVersions);
} }
private Capabilities() { private Capabilities() {
@ -92,16 +106,14 @@ public class Capabilities {
} }
@XmlElement(name = "SupportedHardwareVersions") @XmlElementWrapper(name = "SupportedHardwareVersions")
protected SupportedHardwareVersions supportedHardwareVersions; @XmlElement(name = "SupportedHardwareVersion")
protected Set<String> supportedHardwareVersions = Sets.newLinkedHashSet();
/** /**
* Gets the value of the supportedHardwareVersions property. * Gets the value of the supportedHardwareVersions property.
*
* @return possible object is
* {@link SupportedHardwareVersions }
*/ */
public SupportedHardwareVersions getSupportedHardwareVersions() { public Set<String> getSupportedHardwareVersions() {
return supportedHardwareVersions; return supportedHardwareVersions;
} }

View File

@ -31,6 +31,7 @@ import javax.xml.bind.annotation.XmlType;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
/** /**
* Basic entity type in the vCloud object model. * Basic entity type in the vCloud object model.
@ -104,7 +105,7 @@ public class EntityType extends ResourceType {
public B fromEntityType(EntityType in) { public B fromEntityType(EntityType in) {
return fromResourceType(in) return fromResourceType(in)
.description(in.getDescription()).tasks(in.getTasks()) .description(in.getDescription()).tasks(Sets.newLinkedHashSet(in.getTasks()))
.id(in.getId()).name(in.getName()); .id(in.getId()).name(in.getName());
} }
} }
@ -123,7 +124,7 @@ public class EntityType extends ResourceType {
super(builder); super(builder);
this.description = builder.description; this.description = builder.description;
// nullable so that jaxb wont persist empty collections // nullable so that jaxb wont persist empty collections
this.tasks = builder.tasks != null && builder.tasks.size() == 0 ? null : builder.tasks; this.tasks = builder.tasks == null || builder.tasks.isEmpty() ? null : ImmutableSet.copyOf(builder.tasks);
this.id = builder.id; this.id = builder.id;
this.name = builder.name; this.name = builder.name;
} }
@ -147,7 +148,7 @@ public class EntityType extends ResourceType {
* A list of queued, running, or recently completed tasks associated with this entity. * A list of queued, running, or recently completed tasks associated with this entity.
*/ */
public Set<Task> getTasks() { public Set<Task> getTasks() {
return tasks == null ? ImmutableSet.<Task>of() : Collections.unmodifiableSet(tasks); return tasks == null ? ImmutableSet.<Task>of() : ImmutableSet.copyOf(tasks);
} }
/** /**

View File

@ -1,126 +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.equal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Collections;
import java.util.Set;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
/**
* Represents a list of references to resource entities.
*
* <pre>
* &lt;complexType name="ResourceEntities" /&gt;
* </pre>
*
* @author grkvlt@apache.org
*/
@XmlType(name = "ResourceEntities")
public class ResourceEntities {
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return new Builder().fromResourceEntities(this);
}
public static class Builder {
private Set<Reference> resourceEntities = Sets.newLinkedHashSet();
/**
* @see ResourceEntities#getResourceEntities()
*/
public Builder resourceEntities(Set<Reference> resourceEntities) {
this.resourceEntities = ImmutableSet.copyOf(checkNotNull(resourceEntities, "resourceEntities"));
return this;
}
/**
* @see ResourceEntities#getResourceEntities()
*/
public Builder resourceEntity(Reference resourceEntity) {
resourceEntities.add(checkNotNull(resourceEntity, "resourceEntity"));
return this;
}
public ResourceEntities build() {
return new ResourceEntities(this.resourceEntities);
}
public Builder fromResourceEntities(ResourceEntities in) {
return resourceEntities(in.getResourceEntities());
}
}
private ResourceEntities() {
// for JAXB
}
private ResourceEntities(Set<Reference> resourceEntity) {
this.resourceEntities = ImmutableSet.copyOf(resourceEntity);
}
@XmlElement(name = "ResourceEntity")
private Set<Reference> resourceEntities = Sets.newLinkedHashSet();
/**
* Gets the value of the resourceEntity property.
*/
public Set<Reference> getResourceEntities() {
return Collections.unmodifiableSet(this.resourceEntities);
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
ResourceEntities that = ResourceEntities.class.cast(o);
return equal(resourceEntities, that.resourceEntities);
}
@Override
public int hashCode() {
return Objects.hashCode(resourceEntities);
}
@Override
public String toString() {
return Objects.toStringHelper("")
.add("resourceEntity", resourceEntities).toString();
}
}

View File

@ -1,140 +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.equal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Collections;
import java.util.Set;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
/**
* Represents a list of supported VM hardware versions.
* <p/>
* <p/>
* <p>Java class for SupportedHardwareVersions complex type.
* <p/>
* <p>The following schema fragment specifies the expected content contained within this class.
* <p/>
* <pre>
* &lt;complexType name="SupportedHardwareVersions">
* &lt;complexContent>
* &lt;extension base="{http://www.vmware.com/vcloud/v1.5}VCloudExtensibleType">
* &lt;sequence>
* &lt;element name="SupportedHardwareVersion" type="{http://www.vmware.com/vcloud/v1.5}SupportedHardwareVersionType" maxOccurs="unbounded" minOccurs="0"/>
* &lt;/sequence>
* &lt;anyAttribute processContents='lax' namespace='##other'/>
* &lt;/extension>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*/
@XmlType(name = "SupportedHardwareVersions", propOrder = {
"supportedHardwareVersions"
})
public class SupportedHardwareVersions {
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return new Builder().fromSupportedHardwareVersions(this);
}
public static class Builder {
private Set<String> supportedHardwareVersions = Sets.newLinkedHashSet();
/**
* @see SupportedHardwareVersions#getSupportedHardwareVersions()
*/
public Builder supportedHardwareVersions(Set<String> supportedHardwareVersions) {
this.supportedHardwareVersions = Sets.newLinkedHashSet(checkNotNull(supportedHardwareVersions, "supportedHardwareVersions"));
return this;
}
/**
* @see SupportedHardwareVersions#getSupportedHardwareVersions()
*/
public Builder supportedHardwareVersion(String supportedHardwareVersion) {
supportedHardwareVersions.add(checkNotNull(supportedHardwareVersion, "supportedHardwareVersion"));
return this;
}
public SupportedHardwareVersions build() {
SupportedHardwareVersions supportedHardwareVersions = new SupportedHardwareVersions(this.supportedHardwareVersions);
return supportedHardwareVersions;
}
public Builder fromSupportedHardwareVersions(SupportedHardwareVersions in) {
return supportedHardwareVersions(in.getSupportedHardwareVersions());
}
}
private SupportedHardwareVersions() {
// for JAXB
}
private SupportedHardwareVersions(Set<String> supportedHardwareVersions) {
this.supportedHardwareVersions = ImmutableSet.copyOf(supportedHardwareVersions);
}
@XmlElement(name = "SupportedHardwareVersion")
protected Set<String> supportedHardwareVersions = Sets.newLinkedHashSet();
/**
* Gets the value of the supportedHardwareVersion property.
*/
public Set<String> getSupportedHardwareVersions() {
return Collections.unmodifiableSet(supportedHardwareVersions);
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
SupportedHardwareVersions that = SupportedHardwareVersions.class.cast(o);
return equal(supportedHardwareVersions, that.supportedHardwareVersions);
}
@Override
public int hashCode() {
return Objects.hashCode(supportedHardwareVersions);
}
@Override
public String toString() {
return Objects.toStringHelper("")
.add("supportedHardwareVersion", supportedHardwareVersions).toString();
}
}

View File

@ -19,15 +19,21 @@
package org.jclouds.vcloud.director.v1_5.domain; package org.jclouds.vcloud.director.v1_5.domain;
import static com.google.common.base.Objects.equal; import static com.google.common.base.Objects.equal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Set;
import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso; import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.bind.annotation.XmlType; import javax.xml.bind.annotation.XmlType;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
/** /**
* Represents a virtual data center (vDC). * Represents a virtual data center (vDC).
@ -45,6 +51,7 @@ public class Vdc extends EntityType {
return new ConcreteBuilder(); return new ConcreteBuilder();
} }
@Override
public Builder<?> toBuilder() { public Builder<?> toBuilder() {
return builder().fromVdc(this); return builder().fromVdc(this);
} }
@ -56,8 +63,8 @@ public class Vdc extends EntityType {
private String allocationModel; private String allocationModel;
private CapacityWithUsage storageCapacity; private CapacityWithUsage storageCapacity;
private ComputeCapacity computeCapacity; private ComputeCapacity computeCapacity;
private ResourceEntities resourceEntities; private Set<Reference> resourceEntities = Sets.newLinkedHashSet();
private AvailableNetworks availableNetworks; private Set<Reference> availableNetworks = Sets.newLinkedHashSet();
private Capabilities capabilities; private Capabilities capabilities;
private Integer nicQuota; private Integer nicQuota;
private Integer networkQuota; private Integer networkQuota;
@ -92,16 +99,32 @@ public class Vdc extends EntityType {
/** /**
* @see Vdc#getResourceEntities() * @see Vdc#getResourceEntities()
*/ */
public B resourceEntities(ResourceEntities resourceEntities) { public B resourceEntities(Set<Reference> resourceEntities) {
this.resourceEntities = resourceEntities; this.resourceEntities = Sets.newLinkedHashSet(checkNotNull(resourceEntities, "resourceEntities"));
return self();
}
/**
* @see Vdc#getResourceEntities()
*/
public B resourceEntity(Reference resourceEntity) {
this.resourceEntities.add(checkNotNull(resourceEntity, "resourceEntity"));
return self(); return self();
} }
/** /**
* @see Vdc#getAvailableNetworks() * @see Vdc#getAvailableNetworks()
*/ */
public B availableNetworks(AvailableNetworks availableNetworks) { public B availableNetworks(Set<Reference> availableNetworks) {
this.availableNetworks = availableNetworks; this.availableNetworks = Sets.newLinkedHashSet(checkNotNull(availableNetworks, "availableNetworks"));
return self();
}
/**
* @see Vdc#getAvailableNetworks()
*/
public B network(Reference availableNetwork) {
this.availableNetworks.add(checkNotNull(availableNetwork, "availableNetwork"));;
return self(); return self();
} }
@ -163,8 +186,8 @@ public class Vdc extends EntityType {
.allocationModel(in.getAllocationModel()) .allocationModel(in.getAllocationModel())
.storageCapacity(in.getStorageCapacity()) .storageCapacity(in.getStorageCapacity())
.computeCapacity(in.getComputeCapacity()) .computeCapacity(in.getComputeCapacity())
.resourceEntities(in.getResourceEntities()) .resourceEntities(Sets.newLinkedHashSet(in.getResourceEntities()))
.availableNetworks(in.getAvailableNetworks()) .availableNetworks(Sets.newLinkedHashSet(in.getAvailableNetworks()))
.capabilities(in.getCapabilities()) .capabilities(in.getCapabilities())
.nicQuota(in.getNicQuota()) .nicQuota(in.getNicQuota())
.networkQuota(in.getNetworkQuota()) .networkQuota(in.getNetworkQuota())
@ -183,8 +206,8 @@ public class Vdc extends EntityType {
this.allocationModel = builder.allocationModel; this.allocationModel = builder.allocationModel;
this.storageCapacity = builder.storageCapacity; this.storageCapacity = builder.storageCapacity;
this.computeCapacity = builder.computeCapacity; this.computeCapacity = builder.computeCapacity;
this.resourceEntities = builder.resourceEntities; this.resourceEntities = builder.resourceEntities == null ? Sets.<Reference>newLinkedHashSet() : ImmutableSet.copyOf(builder.resourceEntities);
this.availableNetworks = builder.availableNetworks; this.availableNetworks = builder.availableNetworks == null ? Sets.<Reference>newLinkedHashSet() : ImmutableSet.copyOf(builder.availableNetworks);
this.capabilities = builder.capabilities; this.capabilities = builder.capabilities;
this.nicQuota = builder.nicQuota; this.nicQuota = builder.nicQuota;
this.networkQuota = builder.networkQuota; this.networkQuota = builder.networkQuota;
@ -199,10 +222,12 @@ public class Vdc extends EntityType {
private CapacityWithUsage storageCapacity; private CapacityWithUsage storageCapacity;
@XmlElement(name = "ComputeCapacity", required = true) @XmlElement(name = "ComputeCapacity", required = true)
private ComputeCapacity computeCapacity; private ComputeCapacity computeCapacity;
@XmlElement(name = "ResourceEntities") @XmlElementWrapper(name = "ResourceEntities")
private ResourceEntities resourceEntities; @XmlElement(name = "ResourceEntity")
@XmlElement(name = "AvailableNetworks") private Set<Reference> resourceEntities = Sets.newLinkedHashSet();
private AvailableNetworks availableNetworks; @XmlElementWrapper(name = "AvailableNetworks")
@XmlElement(name = "Network")
protected Set<Reference> availableNetworks = Sets.newLinkedHashSet();
@XmlElement(name = "Capabilities") @XmlElement(name = "Capabilities")
private Capabilities capabilities; private Capabilities capabilities;
@XmlElement(name = "NicQuota") @XmlElement(name = "NicQuota")
@ -240,14 +265,14 @@ public class Vdc extends EntityType {
/** /**
* Gets the value of the resourceEntities property. * Gets the value of the resourceEntities property.
*/ */
public ResourceEntities getResourceEntities() { public Set<Reference> getResourceEntities() {
return resourceEntities; return resourceEntities;
} }
/** /**
* Gets the value of the availableNetworks property. * Gets the value of the availableNetworks property.
*/ */
public AvailableNetworks getAvailableNetworks() { public Set<Reference> getAvailableNetworks() {
return availableNetworks; return availableNetworks;
} }

View File

@ -521,26 +521,9 @@ public class Checks {
} }
} }
public static void checkResourceEntities(ResourceEntities resourceEntities) {
for (Reference resourceEntity : resourceEntities.getResourceEntities()) {
checkReferenceType(resourceEntity);
}
}
public static void checkAvailableNetworks(AvailableNetworks availableNetworks) {
for (Reference network : availableNetworks.getNetworks()) {
checkReferenceType(network);
}
}
public static void checkCapabilities(Capabilities capabilities) { public static void checkCapabilities(Capabilities capabilities) {
// Check optional fields // Check optional fields
if (capabilities.getSupportedHardwareVersions() != null) { for (String supportedHardwareVersion : capabilities.getSupportedHardwareVersions()) {
checkSupportedHardwareVersions(capabilities.getSupportedHardwareVersions());
}
}
public static void checkSupportedHardwareVersions(SupportedHardwareVersions supportedHardwareVersions) {
for (String supportedHardwareVersion : supportedHardwareVersions.getSupportedHardwareVersions()) {
// NOTE supportedHardwareVersion cannot be checked? // NOTE supportedHardwareVersion cannot be checked?
} }
} }
@ -1469,11 +1452,11 @@ public class Checks {
// optional // optional
// NOTE isEnabled cannot be checked // NOTE isEnabled cannot be checked
if (vdc.getResourceEntities() != null) { for (Reference resourceEntity : vdc.getResourceEntities()) {
checkResourceEntities(vdc.getResourceEntities()); checkReferenceType(resourceEntity);
} }
if (vdc.getAvailableNetworks() != null) { for (Reference availableNetwork : vdc.getAvailableNetworks()) {
checkAvailableNetworks(vdc.getAvailableNetworks()); checkReferenceType(availableNetwork);
} }
if (vdc.getCapabilities() != null) { if (vdc.getCapabilities() != null) {
checkCapabilities(vdc.getCapabilities()); checkCapabilities(vdc.getCapabilities());

View File

@ -179,18 +179,17 @@ public abstract class AbstractVAppClientLiveTest extends BaseVCloudDirectorClien
@AfterClass(alwaysRun = true, description = "Cleans up the environment by deleting created VApps") @AfterClass(alwaysRun = true, description = "Cleans up the environment by deleting created VApps")
protected void cleanUp() { protected void cleanUp() {
// Find references in the Vdc with the VApp type and named 'test-vapp' or 'new-name' // Find references in the Vdc with the VApp type and in the list of instantiated VApp names
Iterable<Reference> vApps = Iterables.filter( Iterable<Reference> vApps = Iterables.filter(
vdc.getResourceEntities().getResourceEntities(), vdc.getResourceEntities(),
Predicates.and( Predicates.and(
ReferenceTypePredicates.<Reference>typeEquals(VCloudDirectorMediaType.VAPP), ReferenceTypePredicates.<Reference>typeEquals(VCloudDirectorMediaType.VAPP),
ReferenceTypePredicates.<Reference>nameIn(vAppNames) ReferenceTypePredicates.<Reference>nameIn(vAppNames)
) )
); );
vAppNames.clear();
// If we found any references, delete the VApp they point to // If we found any references, delete the VApp they point to
if (vApps != null && !Iterables.isEmpty(vApps)) { if (!Iterables.isEmpty(vApps)) {
for (Reference ref : vApps) { for (Reference ref : vApps) {
cleanUpVApp(ref.getHref()); // NOTE may fail, but should continue deleting cleanUpVApp(ref.getHref()); // NOTE may fail, but should continue deleting
} }

View File

@ -635,7 +635,7 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
@Test(testName = "PUT /vApp/{id}/networkConnectionSection", dependsOnMethods = { "testGetNetworkConnectionSection" }) @Test(testName = "PUT /vApp/{id}/networkConnectionSection", dependsOnMethods = { "testGetNetworkConnectionSection" })
public void testModifyNetworkConnectionSection() { public void testModifyNetworkConnectionSection() {
// Look up a network in the Vdc // Look up a network in the Vdc
Set<Reference> networks = vdc.getAvailableNetworks().getNetworks(); Set<Reference> networks = vdc.getAvailableNetworks();
Reference network = Iterables.getLast(networks); Reference network = Iterables.getLast(networks);
// Copy existing section and update fields // Copy existing section and update fields

View File

@ -371,7 +371,7 @@ public class VAppTemplateClientLiveTest extends AbstractVAppClientLiveTest {
@Test(testName = "PUT /vAppTemplate/{id}/networkConnectionSection") @Test(testName = "PUT /vAppTemplate/{id}/networkConnectionSection")
public void testEditNetworkConnectionSection() { public void testEditNetworkConnectionSection() {
// Look up a network in the Vdc // Look up a network in the Vdc
Set<Reference> networks = vdc.getAvailableNetworks().getNetworks(); Set<Reference> networks = vdc.getAvailableNetworks();
Reference network = Iterables.getLast(networks); Reference network = Iterables.getLast(networks);
// Copy existing section and update fields // Copy existing section and update fields

View File

@ -18,14 +18,14 @@
*/ */
package org.jclouds.vcloud.director.v1_5.features; package org.jclouds.vcloud.director.v1_5.features;
import static org.testng.Assert.*; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.fail;
import java.net.URI; import java.net.URI;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException; import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.AvailableNetworks;
import org.jclouds.vcloud.director.v1_5.domain.Capabilities; import org.jclouds.vcloud.director.v1_5.domain.Capabilities;
import org.jclouds.vcloud.director.v1_5.domain.CapacityWithUsage; import org.jclouds.vcloud.director.v1_5.domain.CapacityWithUsage;
import org.jclouds.vcloud.director.v1_5.domain.CaptureVAppParams; import org.jclouds.vcloud.director.v1_5.domain.CaptureVAppParams;
@ -41,8 +41,6 @@ import org.jclouds.vcloud.director.v1_5.domain.Media;
import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.MetadataValue; 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.Reference;
import org.jclouds.vcloud.director.v1_5.domain.ResourceEntities;
import org.jclouds.vcloud.director.v1_5.domain.SupportedHardwareVersions;
import org.jclouds.vcloud.director.v1_5.domain.UploadVAppTemplateParams; import org.jclouds.vcloud.director.v1_5.domain.UploadVAppTemplateParams;
import org.jclouds.vcloud.director.v1_5.domain.VApp; import org.jclouds.vcloud.director.v1_5.domain.VApp;
import org.jclouds.vcloud.director.v1_5.domain.VAppTemplate; import org.jclouds.vcloud.director.v1_5.domain.VAppTemplate;
@ -467,7 +465,6 @@ public class VdcClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
.overhead(0l) .overhead(0l)
.build()) .build())
.build()) .build())
.resourceEntities(ResourceEntities.builder()
.resourceEntity(Reference.builder() .resourceEntity(Reference.builder()
.type("application/vnd.vmware.vcloud.vApp+xml") .type("application/vnd.vmware.vcloud.vApp+xml")
.name("vcdcap-db9") .name("vcdcap-db9")
@ -483,8 +480,6 @@ public class VdcClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
.name("DansTestMedia") .name("DansTestMedia")
.href(URI.create("https://mycloud.greenhousedata.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1")) .href(URI.create("https://mycloud.greenhousedata.com/api/media/794eb334-754e-4917-b5a0-5df85cbd61d1"))
.build()) .build())
.build())
.availableNetworks(AvailableNetworks.builder()
.network(Reference.builder() .network(Reference.builder()
.type("application/vnd.vmware.vcloud.network+xml") .type("application/vnd.vmware.vcloud.network+xml")
.name("orgNet-cloudsoft-Isolated") .name("orgNet-cloudsoft-Isolated")
@ -500,14 +495,11 @@ public class VdcClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
.name("orgNet-cloudsoft-Internal-Routed") .name("orgNet-cloudsoft-Internal-Routed")
.href(URI.create("https://mycloud.greenhousedata.com/api/network/6d7392e2-c816-43fb-99be-f9ebcd70abf6")) .href(URI.create("https://mycloud.greenhousedata.com/api/network/6d7392e2-c816-43fb-99be-f9ebcd70abf6"))
.build()) .build())
.build())
.capabilities(Capabilities.builder() .capabilities(Capabilities.builder()
.supportedHardwareVersions(SupportedHardwareVersions.builder()
.supportedHardwareVersion("vmx-04") .supportedHardwareVersion("vmx-04")
.supportedHardwareVersion("vmx-07") .supportedHardwareVersion("vmx-07")
.supportedHardwareVersion("vmx-08") .supportedHardwareVersion("vmx-08")
.build()) .build())
.build())
.nicQuota(0) .nicQuota(0)
.networkQuota(10) .networkQuota(10)
.vmQuota(10) .vmQuota(10)

View File

@ -228,7 +228,7 @@ public class VdcClientLiveTest extends BaseVCloudDirectorClientLiveTest {
public void testInstantiateVAppTemplate() { public void testInstantiateVAppTemplate() {
Vdc vdc = vdcClient.getVdc(vdcURI); Vdc vdc = vdcClient.getVdc(vdcURI);
Set<Reference> networks = vdc.getAvailableNetworks().getNetworks(); Set<Reference> networks = vdc.getAvailableNetworks();
Optional<Reference> parentNetwork = Iterables.tryFind( Optional<Reference> parentNetwork = Iterables.tryFind(
networks, new Predicate<Reference>() { networks, new Predicate<Reference>() {
@Override @Override

View File

@ -97,7 +97,7 @@ import com.google.inject.Module;
public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServiceLiveTest { public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServiceLiveTest {
@Resource @Resource
protected Logger logger = Logger.NULL; protected Logger logger = Logger.CONSOLE;
protected static final long TASK_TIMEOUT_SECONDS = 100L; protected static final long TASK_TIMEOUT_SECONDS = 100L;
protected static final long LONG_TASK_TIMEOUT_SECONDS = 300L; protected static final long LONG_TASK_TIMEOUT_SECONDS = 300L;
@ -320,7 +320,7 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ
Vdc vdc = context.getApi().getVdcClient().getVdc(vdcURI); Vdc vdc = context.getApi().getVdcClient().getVdc(vdcURI);
assertNotNull(vdc, String.format(ENTITY_NON_NULL, VDC)); assertNotNull(vdc, String.format(ENTITY_NON_NULL, VDC));
Set<Reference> networks = vdc.getAvailableNetworks().getNetworks(); Set<Reference> networks = vdc.getAvailableNetworks();
// Look up the network in the Vdc with the id configured for the tests // Look up the network in the Vdc with the id configured for the tests
Optional<Reference> parentNetwork = Iterables.tryFind(networks, new Predicate<Reference>() { Optional<Reference> parentNetwork = Iterables.tryFind(networks, new Predicate<Reference>() {
@ -401,6 +401,7 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ
try { try {
Task task = vappClient.deleteVApp(vAppUri); Task task = vappClient.deleteVApp(vAppUri);
assertTaskSucceeds(task); assertTaskSucceeds(task);
vAppNames.remove(vApp.getName());
} catch (Exception e) { } catch (Exception e) {
try { try {
vApp = vappClient.getVApp(vAppUri); // refresh vApp = vappClient.getVApp(vAppUri); // refresh