From 5fdc6dd5223ebbb4b3802db024b3fba03bf5bb04 Mon Sep 17 00:00:00 2001 From: danikov Date: Wed, 14 Mar 2012 16:52:11 +0000 Subject: [PATCH] adminNetwork getNetwork w/tests --- .../v1_5/VCloudDirectorMediaType.java | 5 +- .../VCloudDirectorRestClientModule.java | 2 + .../director/v1_5/domain/ExternalNetwork.java | 149 ++++++++++++ .../vcloud/director/v1_5/domain/Link.java | 4 +- .../domain/{NetworkType.java => Network.java} | 55 ++--- .../director/v1_5/domain/OrgNetwork.java | 49 ++-- .../director/v1_5/domain/Reference.java | 2 +- .../director/v1_5/domain/ResourceType.java | 4 +- .../features/AdminNetworkAsyncClient.java | 22 +- .../v1_5/features/AdminNetworkClient.java | 17 +- .../v1_5/features/NetworkAsyncClient.java | 4 +- .../director/v1_5/features/NetworkClient.java | 4 +- .../vcloud/director/v1_5/domain/Checks.java | 25 +- .../AdminNetworkClientExpectTest.java | 70 +++++- .../v1_5/features/AdminNetworkLiveTest.java | 40 +++- .../features/NetworkClientExpectTest.java | 224 +++++++++++------- .../v1_5/features/NetworkClientLiveTest.java | 24 +- .../BaseVCloudDirectorClientLiveTest.java | 4 +- ...aseVCloudDirectorRestClientExpectTest.java | 10 + .../resources/network/admin/orgNetwork.xml | 40 ++++ .../test/resources/network/metadataValue.xml | 5 + .../src/test/resources/network/network.xml | 29 ++- 22 files changed, 595 insertions(+), 193 deletions(-) create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ExternalNetwork.java rename labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/{NetworkType.java => Network.java} (64%) create mode 100644 labs/vcloud-director/src/test/resources/network/admin/orgNetwork.xml create mode 100644 labs/vcloud-director/src/test/resources/network/metadataValue.xml 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 8225e9f422..b35804a70f 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 @@ -193,6 +193,8 @@ public class VCloudDirectorMediaType { public static final String TEXT_XML = "text/xml"; + public static final String NETWORK_POOL = "application/vnd.vmware.admin.networkPool+xml"; + /** * All acceptable media types. */ @@ -216,8 +218,7 @@ public class VCloudDirectorMediaType { ADMIN_ORG_NETWORK, USER, ROLE, DEPLOY_VAPP_PARAMS, RECOMPOSE_VAPP_PARAMS, RELOCATE_VM_PARAMS, UNDEPLOY_VAPP_PARAMS, ADMIN_VDC, MEDIA_PARAMS, RUNTIME_INFO_SECTION, SCREEN_TICKET, VAPP_NETWORK, - - TEXT_XML + TEXT_XML, ADMIN_VDC, NETWORK_POOL ); // NOTE These lists must be updated whenever a new media type constant is added. 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 016876ea20..ee97af73f8 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 @@ -44,6 +44,8 @@ import org.jclouds.vcloud.director.v1_5.domain.Session; import org.jclouds.vcloud.director.v1_5.domain.SessionWithToken; import org.jclouds.vcloud.director.v1_5.features.AdminCatalogAsyncClient; import org.jclouds.vcloud.director.v1_5.features.AdminCatalogClient; +import org.jclouds.vcloud.director.v1_5.features.AdminNetworkAsyncClient; +import org.jclouds.vcloud.director.v1_5.features.AdminNetworkClient; import org.jclouds.vcloud.director.v1_5.features.AdminOrgAsyncClient; import org.jclouds.vcloud.director.v1_5.features.AdminOrgClient; import org.jclouds.vcloud.director.v1_5.features.AdminVdcAsyncClient; diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ExternalNetwork.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ExternalNetwork.java new file mode 100644 index 0000000000..89dede1c44 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ExternalNetwork.java @@ -0,0 +1,149 @@ +/** + * 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 javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; + + +/** + * + * Admin representation of external network. + * + * + *

Java class for ExternalNetwork complex type. + * + *

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

+ * <complexType name="ExternalNetwork">
+ *   <complexContent>
+ *     <extension base="{http://www.vmware.com/vcloud/v1.5}NetworkType">
+ *       <sequence>
+ *         <element name="ProviderInfo" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ *       </sequence>
+ *       <anyAttribute processContents='lax' namespace='##other'/>
+ *     </extension>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlRootElement(name = "ExternalNetwork") +@XmlType(propOrder = { + "providerInfo" +}) +public class ExternalNetwork extends Network { + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toNewBuilder() { + return new ConcreteBuilder().fromExternalNetwork(this); + } + + @Deprecated + public EntityType.Builder toBuilder() { + throw new UnsupportedOperationException("Use toNewBuilder() instead"); + } + + public static abstract class Builder> extends Network.Builder { + private String providerInfo; + + /** + * @see ExternalNetwork#getProviderInfo() + */ + public T providerInfo(String providerInfo) { + this.providerInfo = providerInfo; + return self(); + } + + public ExternalNetwork build() { + return new ExternalNetwork(this); + } + + public T fromExternalNetwork(ExternalNetwork in) { + return fromNetworkType(in) + .providerInfo(in.getProviderInfo()); + } + } + + private static class ConcreteBuilder extends Builder { + @Override protected ConcreteBuilder self() { + return this; + } + } + + private ExternalNetwork() { + // For JAXB + } + + private ExternalNetwork(Builder b) { + super(b); + providerInfo = b.providerInfo; + } + + @XmlElement(name = "ProviderInfo", required = true) + protected String providerInfo; + + /** + * Gets the value of the providerInfo property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getProviderInfo() { + return providerInfo; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + ExternalNetwork that = ExternalNetwork.class.cast(o); + return super.equals(that) && equal(providerInfo, that.providerInfo); + } + + @Override + public int hashCode() { + return Objects.hashCode(super.hashCode(), providerInfo); + } + + @Override + public ToStringHelper string() { + return super.string() + .add("providerInfo", providerInfo); + } + +} 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 ab41ad3f18..4b4b2871cd 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 @@ -100,6 +100,7 @@ public class Link extends Reference { public static final String UPGRADE = "upgrade"; public static final String UPLOAD_ALTERNATE = "upload:alternate"; public static final String UPLOAD_DEFAULT = "upload:default"; + public static final String REPAIR = "repair"; /** * All acceptable {@link Link#getRel()} values. @@ -117,7 +118,8 @@ public class Link extends Reference { REJECT, RELOCATE, REMOVE, REPAIR, SCREEN_ACQUIRE_TICKET, SCREEN_THUMBNAIL, TASK_CANCEL, BLOCKING_TASK, TASK_OWNER, TASK_PARAMS, TASK_REQUEST, UNDEPLOY, UNLOCK, UNREGISTER, UP, - UPDATE_PROGRESS, UPGRADE, UPLOAD_ALTERNATE, UPLOAD_DEFAULT + UPDATE_PROGRESS, UPGRADE, UPLOAD_ALTERNATE, UPLOAD_DEFAULT, + UPLOAD_DEFAULT, REPAIR ); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/NetworkType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Network.java similarity index 64% rename from labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/NetworkType.java rename to labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Network.java index 36fb7dc579..d7bd8622ba 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/NetworkType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Network.java @@ -21,55 +21,43 @@ package org.jclouds.vcloud.director.v1_5.domain; import static com.google.common.base.Objects.equal; import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlSeeAlso; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; -@XmlRootElement(name = "NetworkType") -public class NetworkType extends EntityType { - - public static Builder builder() { - return new ConcreteBuilder(); - } - - public Builder toBuilder() { - return builder().fromNetworkType(this); - } - - private static class ConcreteBuilder extends Builder { - } - - public static abstract class Builder> extends EntityType.Builder { - - private NetworkConfiguration networkConfiguration; +@XmlSeeAlso( {OrgNetwork.class, ExternalNetwork.class} ) +public abstract class Network extends EntityType { + public abstract static class Builder> extends EntityType.Builder { + protected NetworkConfiguration networkConfiguration; /** - * @see NetworkType#getConfiguration() + * @see Network#getConfiguration() */ - public B configuration(NetworkConfiguration networkConfiguration) { + public T configuration(NetworkConfiguration networkConfiguration) { this.networkConfiguration = networkConfiguration; return self(); } - @Override - public NetworkType build() { - return new NetworkType(this); - } - - public B fromNetworkType(NetworkType in) { + public T fromNetworkType(Network in) { return fromEntityType(in).configuration(in.getConfiguration()); } } - - public NetworkType(Builder builder) { - super(builder); - this.networkConfiguration = builder.networkConfiguration; + + public Network(Builder b) { + super(b); + networkConfiguration = b.networkConfiguration; } - protected NetworkType() { + protected Network() { // for JAXB } + + @SuppressWarnings("unchecked") + public static T toSubType(Network clazz) { + assert clazz instanceof Network; + return (T)clazz; + } @XmlElement(name = "Configuration") private NetworkConfiguration networkConfiguration; @@ -85,18 +73,17 @@ public class NetworkType extends EntityType { public boolean equals(Object o) { if (!super.equals(o)) return false; - NetworkType that = NetworkType.class.cast(o); + Network that = Network.class.cast(o); return super.equals(that) && equal(networkConfiguration, that.networkConfiguration); } @Override public int hashCode() { - return Objects.hashCode(super.hashCode(), networkConfiguration); + return super.hashCode() + Objects.hashCode(networkConfiguration); } @Override public ToStringHelper string() { return super.string().add("configuration", networkConfiguration); } - } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgNetwork.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgNetwork.java index 85ed49658a..6ba622207b 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgNetwork.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgNetwork.java @@ -27,28 +27,24 @@ import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; @XmlRootElement(name = "OrgNetwork") -public class OrgNetwork extends NetworkType { - +public class OrgNetwork extends Network { public static Builder builder() { return new ConcreteBuilder(); } + @Override public Builder toBuilder() { - return builder().fromOrgNetwork(this); + return new ConcreteBuilder().fromOrgNetwork(this); } - private static class ConcreteBuilder extends Builder { - } - - public static abstract class Builder> extends NetworkType.Builder { - + public static abstract class Builder> extends Network.Builder { private Reference networkPool; private IpAddresses allowedExternalIpAddresses; /** * @see OrgNetwork#getNetworkPool() */ - public B networkPool(Reference networkPool) { + public T networkPool(Reference networkPool) { this.networkPool = networkPool; return self(); } @@ -56,7 +52,7 @@ public class OrgNetwork extends NetworkType { /** * @see OrgNetwork#getAllowedExternalIpAddresses() */ - public B allowedExternalIpAddresses(IpAddresses allowedExternalIpAddresses) { + public T allowedExternalIpAddresses(IpAddresses allowedExternalIpAddresses) { this.allowedExternalIpAddresses = allowedExternalIpAddresses; return self(); } @@ -65,22 +61,29 @@ public class OrgNetwork extends NetworkType { public OrgNetwork build() { return new OrgNetwork(this); } - - public B fromOrgNetwork(OrgNetwork in) { - return fromNetworkType(in).configuration(in.getConfiguration()) + + public T fromOrgNetwork(OrgNetwork in) { + return fromEntityType(in).configuration(in.getConfiguration()) .networkPool(in.getNetworkPool()) .allowedExternalIpAddresses(in.getAllowedExternalIpAddresses()); } } - + + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + protected OrgNetwork() { // For JAXB } - protected OrgNetwork(Builder builder) { - super(builder); - this.networkPool = builder.networkPool; - this.allowedExternalIpAddresses = builder.allowedExternalIpAddresses; + private OrgNetwork(Builder b) { + super(b); + networkPool = b.networkPool; + allowedExternalIpAddresses = b.allowedExternalIpAddresses; } @XmlElement(name = "NetworkPool") @@ -107,18 +110,22 @@ public class OrgNetwork extends NetworkType { if (!super.equals(o)) return false; OrgNetwork that = OrgNetwork.class.cast(o); - return super.equals(that) && equal(networkPool, that.networkPool) && + return super.equals(that) && + equal(networkPool, that.networkPool) && equal(allowedExternalIpAddresses, that.allowedExternalIpAddresses); } @Override public int hashCode() { - return Objects.hashCode(super.hashCode(), networkPool, allowedExternalIpAddresses); + return Objects.hashCode(super.hashCode(), + networkPool, + allowedExternalIpAddresses); } @Override public ToStringHelper string() { - return super.string().add("networkPool", networkPool) + return super.string() + .add("networkPool", networkPool) .add("allowedExternalIpAddresses", allowedExternalIpAddresses); } } 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 b5dba21794..4046c20888 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 @@ -232,4 +232,4 @@ public class Reference { .href(URI.create(getHref().toASCIIString().replace(endpoint, endpoint+"/admin"))) .build(); } -} \ No newline at end of file +} 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 b356adb7e8..878665c694 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 @@ -125,7 +125,7 @@ public class ResourceType { @XmlAttribute private String type; @XmlElement(name = "Link") - private Set links; + private Set links = Sets.newLinkedHashSet(); protected ResourceType(Builder builder) { this.href = builder.href; @@ -136,7 +136,7 @@ public class ResourceType { public ResourceType(URI href, String type, @Nullable Set links) { this.href = href; this.type = type; - // nullable so that jaxb wont persist empty collections + // nullable so that jaxb wont persist empty collections? this.links = links != null && links.isEmpty() ? null : links; } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminNetworkAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminNetworkAsyncClient.java index 12169c38e5..d15efa5fa3 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminNetworkAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminNetworkAsyncClient.java @@ -18,8 +18,20 @@ */ package org.jclouds.vcloud.director.v1_5.features; +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; + +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.ExternalNetwork; import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; +import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx; + +import com.google.common.util.concurrent.ListenableFuture; /** * @see AdminNetworkClient @@ -28,7 +40,15 @@ import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; @RequestFilters(AddVCloudAuthorizationToRequest.class) public interface AdminNetworkAsyncClient extends NetworkAsyncClient { - // GET /admin/network/{id} + /** + * @see NetworkClient#getNetwork(URI) + */ + @GET + @Consumes + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + @Override + ListenableFuture getNetwork(@EndpointParam URI networkRef); // PUT /admin/network/{id} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminNetworkClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminNetworkClient.java index a297e6ef30..b8e989fb60 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminNetworkClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminNetworkClient.java @@ -18,9 +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.Network; /** * Provides synchronous access to admin {@link Network} objects. @@ -31,7 +33,20 @@ import org.jclouds.concurrent.Timeout; @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) public interface AdminNetworkClient extends NetworkClient { - // GET /admin/network/{id} + /** + * Gets admin representation of network. This operation could return admin + * representation of organization network or external network. vApp networks + * do not have admin representation. + * + *
+    * GET /admin/network/{id}
+    * 
+ * + * @param catalogUri the reference for the catalog + * @return a catalog + */ + @Override + Network getNetwork(URI networkRef); // PUT /admin/network/{id} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/NetworkAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/NetworkAsyncClient.java index a207290600..2ad64d8ee7 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/NetworkAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/NetworkAsyncClient.java @@ -29,7 +29,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.OrgNetwork; +import org.jclouds.vcloud.director.v1_5.domain.Network; import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx; @@ -50,7 +50,7 @@ public interface NetworkAsyncClient { @Consumes @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture getNetwork(@EndpointParam URI networkUri); + ListenableFuture getNetwork(@EndpointParam URI networkUri); /** * @return asynchronous access to {@link Metadata.Readable} features diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/NetworkClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/NetworkClient.java index 8c29f509c9..d1570f2470 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/NetworkClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/NetworkClient.java @@ -24,7 +24,7 @@ import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; import org.jclouds.rest.annotations.Delegate; import org.jclouds.vcloud.director.v1_5.domain.Metadata; -import org.jclouds.vcloud.director.v1_5.domain.OrgNetwork; +import org.jclouds.vcloud.director.v1_5.domain.Network; /** * Provides synchronous access to Network. @@ -42,7 +42,7 @@ public interface NetworkClient { * * @return the network or null if not found */ - OrgNetwork getNetwork(URI networkUri); + Network getNetwork(URI networkUri); /** * @return synchronous access to {@link Metadata.Readable} features 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 825e473072..3945f4c319 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 @@ -360,7 +360,7 @@ public class Checks { "The Image type of a Media must be one of the allowed list"); } - public static void checkNetworkType(NetworkType network) { + public static void checkNetworkType(Network network) { // Check optional fields NetworkConfiguration config = network.getConfiguration(); if (config != null) { @@ -1365,6 +1365,29 @@ public class Checks { private static void checkCimResourceAllocationSettingData(ResourceAllocationSettingData val) { // TODO Could do more assertions... assertNotNull(val, String.format(NOT_NULL_OBJ_FMT, "ResouorceAllocatoinSettingData")); + + public static void checkOrgNetwork(OrgNetwork network) { + // optional + ReferenceType networkPoolRef = network.getNetworkPool(); + if (networkPoolRef != null) { + Checks.checkReferenceType(networkPoolRef); + } + IpAddresses allowedExternalIpAddresses = network.getAllowedExternalIpAddresses(); + if (allowedExternalIpAddresses != null) { + Checks.checkIpAddresses(allowedExternalIpAddresses); + } + + // parent type + checkNetworkType(network); + } + + public static void checkExternalNetwork(ExternalNetwork network) { + // required + assertNotNull(network.getProviderInfo(), String.format(OBJ_FIELD_REQ, + "ExternalNetwork", "providerInfo")); + + // parent type + checkNetworkType(network); } public static void checkAdminVdc(AdminVdc vdc) { diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminNetworkClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminNetworkClientExpectTest.java index 84690fa702..f7e4f72cd7 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminNetworkClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminNetworkClientExpectTest.java @@ -18,20 +18,86 @@ */ package org.jclouds.vcloud.director.v1_5.features; +import static org.testng.Assert.assertEquals; + +import java.net.URI; + +import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; +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.OrgNetwork; +import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; import org.testng.annotations.Test; +import com.google.common.collect.ImmutableSet; + /** * Test the {@link GroupClient} by observing its side effects. * * @author danikov */ -@Test(groups = { "unit", "user", "adminNetwork"}, singleThreaded = true, testName = "AdminNetworkClientExpectTest") +@Test(groups = { "unit", "admin", "adminNetwork"}, singleThreaded = true, testName = "AdminNetworkClientExpectTest") public class AdminNetworkClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { - // GET /admin/network/{id} + Reference networkRef = Reference.builder() + .href(URI.create(endpoint+"/admin/network/b466c0c5-8a5c-4335-b703-a2e2e6b5f3e1")) + .build(); + + @Test + public void testGetNetworkWithOrgNetwork() { + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("GET", "/admin/network/b466c0c5-8a5c-4335-b703-a2e2e6b5f3e1") + .acceptAnyMedia() + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/network/admin/orgNetwork.xml", VCloudDirectorMediaType.ORG_NETWORK) + .httpResponseBuilder().build()); + + OrgNetwork expected = orgNetwork(); + + assertEquals(client.getAdminNetworkClient().getNetwork(networkRef.getHref()), expected); + } // PUT /admin/network/{id} // POST /admin/network/{id}/action/reset + + public final OrgNetwork orgNetwork() { + return NetworkClientExpectTest.orgNetwork().toNewBuilder() + .href(toAdminUri(NetworkClientExpectTest.orgNetwork().getHref())) + .links(ImmutableSet.of( + Link.builder() + .rel("alternate") + .type("application/vnd.vmware.vcloud.orgNetwork+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/network/f3ba8256-6f48-4512-aad6-600e85b4dc38")) + .build(), + Link.builder() + .rel("edit") + .type("application/vnd.vmware.admin.orgNetwork+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/network/f3ba8256-6f48-4512-aad6-600e85b4dc38")) + .build(), + Link.builder() + .rel("up") + .type("application/vnd.vmware.admin.organization+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .build(), + Link.builder() + .rel("repair") + .type("application/vnd.vmware.admin.orgNetwork+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/network/f3ba8256-6f48-4512-aad6-600e85b4dc38/action/reset")) + .build(), + Link.builder() + .rel("down") + .type("application/vnd.vmware.vcloud.metadata+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/network/f3ba8256-6f48-4512-aad6-600e85b4dc38/metadata")) + .build())) + .networkPool(Reference.builder() + .type("application/vnd.vmware.admin.networkPool+xml") + .name("vcdni01") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/extension/networkPool/e86bfdb5-b3e0-4ece-9125-e764ac64c95c")) + .build()) + .build(); + } } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminNetworkLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminNetworkLiveTest.java index 1add59536c..e3d25fa5b8 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminNetworkLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminNetworkLiveTest.java @@ -18,36 +18,62 @@ */ package org.jclouds.vcloud.director.v1_5.features; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.*; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.fail; + +import java.net.URI; + +import org.jclouds.vcloud.director.v1_5.domain.Checks; +import org.jclouds.vcloud.director.v1_5.domain.ExternalNetwork; +import org.jclouds.vcloud.director.v1_5.domain.Network; +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.BeforeClass; import org.testng.annotations.Test; /** - * Tests live behavior of {@link AdminCatalogClient}. + * Tests live behavior of {@link AdminNetworkClient}. * * @author danikov */ -@Test(groups = { "live", "admin", "group" }, singleThreaded = true, testName = "CatalogClientLiveTest") +@Test(groups = { "live", "admin", "network" }, singleThreaded = true, testName = "AdminNetworkLiveTest") public class AdminNetworkLiveTest extends BaseVCloudDirectorClientLiveTest { - public static final String GROUP = "admin group"; + public static final String NETWORK = "AdminNetwork"; /* * Convenience references to API clients. */ - private AdminNetworkClient networkClient; /* * Shared state between dependant tests. */ - + Reference networkRef; + Network network; + @BeforeClass(inheritGroups = true) - public void setupRequiredClients() { + protected void setupRequiredClients() { networkClient = context.getApi().getAdminNetworkClient(); + networkRef = Reference.builder().href(networkURI).build().toAdminReference(endpoint); } - // GET /admin/network/{id} + @Test(testName = "GET /admin/network/{id}") + public void testGetNetwork() { + assertNotNull(networkRef, String.format(REF_REQ_LIVE, NETWORK)); + network = networkClient.getNetwork(networkRef.getHref()); + + if(network instanceof ExternalNetwork) { + Checks.checkExternalNetwork(Network.toSubType(network)); + } else if (network instanceof OrgNetwork) { + Checks.checkOrgNetwork(Network.toSubType(network)); + } else { + fail(String.format(REQUIRED_VALUE_OBJECT_FMT, ".class", NETWORK, + network.getClass(),"ExternalNetwork,. OrgNetwork")); + } + } // PUT /admin/network/{id} 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 eb6c86fa72..b0f7056439 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 @@ -26,6 +26,7 @@ import java.net.URI; 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.DhcpService; import org.jclouds.vcloud.director.v1_5.domain.Error; import org.jclouds.vcloud.director.v1_5.domain.IpAddresses; import org.jclouds.vcloud.director.v1_5.domain.IpRange; @@ -34,7 +35,10 @@ import org.jclouds.vcloud.director.v1_5.domain.IpScope; 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.Network; import org.jclouds.vcloud.director.v1_5.domain.NetworkConfiguration; +import org.jclouds.vcloud.director.v1_5.domain.NetworkFeatures; import org.jclouds.vcloud.director.v1_5.domain.OrgNetwork; import org.jclouds.vcloud.director.v1_5.domain.SyslogServerSettings; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; @@ -51,30 +55,40 @@ import com.google.common.collect.ImmutableSet; public class NetworkClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { @Test - public void testWhenResponseIs2xxLoginReturnsValidNetwork() { - URI networkUri = URI.create(endpoint + "/network/55a677cf-ab3f-48ae-b880-fab90421980c"); + public void testGetNetwork() { + URI networkUri = URI.create(endpoint + "/network/f3ba8256-6f48-4512-aad6-600e85b4dc38"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, - getStandardRequest("GET", "/network/55a677cf-ab3f-48ae-b880-fab90421980c"), - getStandardPayloadResponse("/network/network.xml", VCloudDirectorMediaType.ORG_NETWORK)); + new VcloudHttpRequestPrimer() + .apiCommand("GET", "/network/f3ba8256-6f48-4512-aad6-600e85b4dc38") + .acceptAnyMedia() + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/network/network.xml", VCloudDirectorMediaType.ORG_NETWORK) + .httpResponseBuilder().build()); OrgNetwork expected = orgNetwork(); - assertEquals(client.getNetworkClient().getNetwork(networkUri), expected); + assertEquals(Network.toSubType(client.getNetworkClient().getNetwork(networkUri)), expected); } @Test - public void testWhenResponseIs400ForInvalidNetworkId() { + public void testGetNetworkWithInvalidId() { URI networkUri = URI.create(endpoint + "/network/NOTAUUID"); - VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, - getStandardRequest("GET", "/network/NOTAUUID"), - getStandardPayloadResponse(400, "/network/error400.xml", VCloudDirectorMediaType.ERROR)); - + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("GET", "/network/NOTAUUID") + .acceptAnyMedia() + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/network/error400.xml", VCloudDirectorMediaType.ERROR) + .httpResponseBuilder().statusCode(400).build()); + Error expected = Error.builder() - .message("validation error : EntityRef has incorrect type, expected type is com.vmware.vcloud.entity.network.") - .majorErrorCode(400) - .minorErrorCode("BAD_REQUEST") - .build(); + .message("validation error : EntityRef has incorrect type, expected type is com.vmware.vcloud.entity.network.") + .majorErrorCode(400) + .minorErrorCode("BAD_REQUEST") + .build(); try { client.getNetworkClient().getNetwork(networkUri); @@ -87,18 +101,23 @@ public class NetworkClientExpectTest extends BaseVCloudDirectorRestClientExpectT } @Test - public void testWhenResponseIs403ForCatalogIdUsedAsNetworkId() { + public void testGetNetworkWithCatalogId() { URI networkUri = URI.create(endpoint + "/network/9e08c2f6-077a-42ce-bece-d5332e2ebb5c"); - VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, - getStandardRequest("GET", "/network/9e08c2f6-077a-42ce-bece-d5332e2ebb5c"), - getStandardPayloadResponse(403, "/network/error403-catalog.xml", VCloudDirectorMediaType.ERROR)); - + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("GET", "/network/9e08c2f6-077a-42ce-bece-d5332e2ebb5c") + .acceptAnyMedia() + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/network/error403-catalog.xml", VCloudDirectorMediaType.ERROR) + .httpResponseBuilder().statusCode(403).build()); + Error expected = Error.builder() - .message("This operation is denied.") - .majorErrorCode(403) - .minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN") - .build(); + .message("This operation is denied.") + .majorErrorCode(403) + .minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN") + .build(); try { client.getNetworkClient().getNetwork(networkUri); @@ -111,18 +130,23 @@ public class NetworkClientExpectTest extends BaseVCloudDirectorRestClientExpectT } @Test - public void testWhenResponseIs403ForFakeNetworkId() { + public void testGetNetworkWithFakeId() { URI networkUri = URI.create(endpoint + "/network/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"); - VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, - getStandardRequest("GET", "/network/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"), - getStandardPayloadResponse(403, "/network/error403-fake.xml", VCloudDirectorMediaType.ERROR)); - + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("GET", "/network/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee") + .acceptAnyMedia() + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/network/error403-fake.xml", VCloudDirectorMediaType.ERROR) + .httpResponseBuilder().statusCode(403).build()); + Error expected = Error.builder() - .message("This operation is denied.") - .majorErrorCode(403) - .minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN") - .build(); + .message("This operation is denied.") + .majorErrorCode(403) + .minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN") + .build(); try { client.getNetworkClient().getNetwork(networkUri); @@ -135,83 +159,105 @@ public class NetworkClientExpectTest extends BaseVCloudDirectorRestClientExpectT } @Test - public void testWhenResponseIs2xxLoginReturnsValidMetadataList() { + public void testGetMetadata() { URI networkUri = URI.create(endpoint + "/network/55a677cf-ab3f-48ae-b880-fab90421980c"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, - new VcloudHttpRequestPrimer() - .apiCommand("GET", "/network/55a677cf-ab3f-48ae-b880-fab90421980c/metadata") - .acceptAnyMedia() - .httpRequestBuilder().build(), - new VcloudHttpResponsePrimer() - .xmlFilePayload("/network/metadata.xml", VCloudDirectorMediaType.METADATA) - .httpResponseBuilder().build()); + new VcloudHttpRequestPrimer() + .apiCommand("GET", "/network/55a677cf-ab3f-48ae-b880-fab90421980c/metadata") + .acceptAnyMedia() + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/network/metadata.xml", VCloudDirectorMediaType.METADATA) + .httpResponseBuilder().build()); Metadata expected = Metadata.builder() - .type("application/vnd.vmware.vcloud.metadata+xml") - .href(URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c/metadata")) - .link(Link.builder() - .rel("up") - .type("application/vnd.vmware.vcloud.network+xml") - .href(URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c")) - .build()) - .entries(ImmutableSet.of(MetadataEntry.builder().entry("key", "value").build())) - .build(); + .type("application/vnd.vmware.vcloud.metadata+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c/metadata")) + .link(Link.builder() + .rel("up") + .type("application/vnd.vmware.vcloud.network+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c")) + .build()) + .entries(ImmutableSet.of(MetadataEntry.builder().entry("key", "value").build())) + .build(); assertEquals(client.getNetworkClient().getMetadataClient().getMetadata(networkUri), expected); } - @Test(enabled=false) // No metadata in exemplar xml... - public void testWhenResponseIs2xxLoginReturnsValidMetadata() { + @Test + public void testGetMetadataValue() { URI networkUri = URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c"); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, - getStandardRequest("GET", "/network/55a677cf-ab3f-48ae-b880-fab90421980c/metadata/KEY"), - getStandardPayloadResponse("/network/metadataEntry.xml", VCloudDirectorMediaType.METADATA_ENTRY)); + new VcloudHttpRequestPrimer() + .apiCommand("GET", "/network/55a677cf-ab3f-48ae-b880-fab90421980c/metadata/KEY") + .acceptAnyMedia() + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/network/metadataValue.xml", VCloudDirectorMediaType.METADATA_ENTRY) + .httpResponseBuilder().build()); - MetadataEntry expected = MetadataEntry.builder() - .entry("key", "value") - .build(); + MetadataValue expected = MetadataValue.builder() + .href(URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c/metadata/key")) + .link(Link.builder() + .rel("up") + .type("application/vnd.vmware.vcloud.metadata+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c/metadata")) + .build()) + .value("value") + .build(); assertEquals(client.getNetworkClient().getMetadataClient().getMetadataValue(networkUri, "KEY"), expected); } - + public static OrgNetwork orgNetwork() { return OrgNetwork.builder() - .name("internet01-Jclouds") - .id("urn:vcloud:network:55a677cf-ab3f-48ae-b880-fab90421980c") - .type(VCloudDirectorMediaType.ORG_NETWORK) - .href(URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c")) - .link(Link.builder() - .rel("up") - .type("application/vnd.vmware.vcloud.org+xml") - .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .name("ilsolation01-Jclouds") + .id("urn:vcloud:network:f3ba8256-6f48-4512-aad6-600e85b4dc38") + .type("application/vnd.vmware.vcloud.orgNetwork+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/network/f3ba8256-6f48-4512-aad6-600e85b4dc38")) + .link(Link.builder() + .rel("up") + .type("application/vnd.vmware.vcloud.org+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .build()) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.vcloud.metadata+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/network/f3ba8256-6f48-4512-aad6-600e85b4dc38/metadata")) + .build()) + .description("") + .configuration(NetworkConfiguration.builder() + .ipScope(IpScope.builder() + .isInherited(false) + .gateway("192.168.1.1") + .netmask("255.255.255.0") + .dns1("173.240.111.52") + .dns2("173.240.111.53") + .ipRanges(IpRanges.builder() + .ipRange(IpRange.builder() + .startAddress("192.168.1.100") + .endAddress("192.168.1.199") + .build()) + .build()) .build()) - .link(Link.builder() - .rel("down") - .type("application/vnd.vmware.vcloud.metadata+xml") - .href(URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c/metadata")) - .build()) - .description("") - .configuration(NetworkConfiguration.builder() - .ipScope(IpScope.builder() - .isInherited(true) - .gateway("173.240.107.49") - .netmask("255.255.255.240") - .dns1("173.240.111.52") - .dns2("173.240.111.53") - .ipRanges(IpRanges.builder() - .ipRange(IpRange.builder() - .startAddress("173.240.107.50") - .endAddress("173.240.107.62") - .build()) - .build()) + .fenceMode("isolated") + .retainNetInfoAcrossDeployments(false) + .features(NetworkFeatures.builder() + .service(DhcpService.builder() + .enabled(false) + .defaultLeaseTime(3600) + .maxLeaseTime(7200) + .ipRange(IpRange.builder() + .startAddress("192.168.1.2") + .endAddress("192.168.1.99") + .build()) .build()) - .fenceMode("bridged") - .retainNetInfoAcrossDeployments(false) - .syslogServerSettings(SyslogServerSettings.builder().build()) .build()) - .allowedExternalIpAddresses(IpAddresses.builder().build()) - .build(); + .syslogServerSettings(SyslogServerSettings.builder().build()) + .build()) + .allowedExternalIpAddresses(IpAddresses.builder().build()) + .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 ec74b7807b..7ed45d2a44 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 @@ -23,6 +23,7 @@ import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.O import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_REQ_LIVE; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_REQ_LIVE; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.REF_REQ_LIVE; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.REQUIRED_VALUE_OBJECT_FMT; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkResourceType; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; @@ -30,10 +31,10 @@ import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; import org.jclouds.vcloud.director.v1_5.domain.Checks; -import org.jclouds.vcloud.director.v1_5.domain.IpAddresses; 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.Network; 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; @@ -62,29 +63,20 @@ public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest { public void setupRequiredClients() { networkClient = context.getApi().getNetworkClient(); } - + @Test(testName = "GET /network/{id}") public void testGetNetwork() { // required for testing assertNotNull(networkURI, String.format(REF_REQ_LIVE, NETWORK)); - OrgNetwork network = networkClient.getNetwork(networkURI); + Network abstractNetwork = networkClient.getNetwork(networkURI); + assertTrue(abstractNetwork instanceof OrgNetwork, String.format(REQUIRED_VALUE_OBJECT_FMT, + ".class", NETWORK, abstractNetwork.getClass(),"OrgNetwork")); + OrgNetwork network = Network.toSubType(abstractNetwork); assertNotNull(network, String.format(OBJ_REQ_LIVE, NETWORK)); assertTrue(!network.getDescription().equals("DO NOT USE"), "Network isn't to be used for testing"); - // parent type - Checks.checkNetworkType(network); - - // optional - Reference networkPoolRef = network.getNetworkPool(); - if (networkPoolRef != null) { - Checks.checkReferenceType(networkPoolRef); - } - - IpAddresses allowedExternalIpAddresses = network.getAllowedExternalIpAddresses(); - if (allowedExternalIpAddresses != null) { - Checks.checkIpAddresses(allowedExternalIpAddresses); - } + Checks.checkOrgNetwork(network); } @Test(testName = "GET /network/{id}/metadata") 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 a170d6f8f7..64b2f1c5d5 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 @@ -85,7 +85,7 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ } // NOTE Implement as required to populate xxxClient fields, or NOP - public abstract void setupRequiredClients() throws Exception; + protected abstract void setupRequiredClients() throws Exception; public Predicate retryTaskSuccess; public Predicate retryTaskSuccessLong; @@ -104,7 +104,7 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ protected Session session; @BeforeClass(groups = { "live" }) - public void setupContext() throws Exception { + protected void setupContext() throws Exception { setupCredentials(); Properties overrides = setupProperties(); 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 eb0b78e0fd..b85203e6a5 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 @@ -31,6 +31,8 @@ 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.domain.Reference; +import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; import org.testng.annotations.BeforeGroups; import com.google.common.collect.ImmutableMultimap; @@ -241,4 +243,12 @@ public class BaseVCloudDirectorRestClientExpectTest extends BaseRestClientExpect return builder; } } + + public URI toAdminUri(ReferenceType ref) { + return toAdminUri(ref.getHref()); + } + + public URI toAdminUri(URI uri) { + return Reference.builder().href(uri).build().toAdminReference(endpoint).getHref(); + } } diff --git a/labs/vcloud-director/src/test/resources/network/admin/orgNetwork.xml b/labs/vcloud-director/src/test/resources/network/admin/orgNetwork.xml new file mode 100644 index 0000000000..acf99d1872 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/network/admin/orgNetwork.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + false + 192.168.1.1 + 255.255.255.0 + 173.240.111.52 + 173.240.111.53 + + + 192.168.1.100 + 192.168.1.199 + + + + isolated + false + + + false + 3600 + 7200 + + 192.168.1.2 + 192.168.1.99 + + + + + + + + \ No newline at end of file diff --git a/labs/vcloud-director/src/test/resources/network/metadataValue.xml b/labs/vcloud-director/src/test/resources/network/metadataValue.xml new file mode 100644 index 0000000000..a9b0461494 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/network/metadataValue.xml @@ -0,0 +1,5 @@ + + + + value + diff --git a/labs/vcloud-director/src/test/resources/network/network.xml b/labs/vcloud-director/src/test/resources/network/network.xml index b3a53f615a..d1ef57e72a 100644 --- a/labs/vcloud-director/src/test/resources/network/network.xml +++ b/labs/vcloud-director/src/test/resources/network/network.xml @@ -1,25 +1,36 @@ - + - + - true - 173.240.107.49 - 255.255.255.240 + false + 192.168.1.1 + 255.255.255.0 173.240.111.52 173.240.111.53 - 173.240.107.50 - 173.240.107.62 + 192.168.1.100 + 192.168.1.199 - bridged + isolated false + + + false + 3600 + 7200 + + 192.168.1.2 + 192.168.1.99 + + + - + \ No newline at end of file