mirror of https://github.com/apache/jclouds.git
Merge pull request #370 from danikov/vclouds-director-network
Issue 830 vCloud director Network
This commit is contained in:
commit
e2c5f5ebce
|
@ -51,6 +51,8 @@ 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 ORG_NETWORK = "application/vnd.vmware.vcloud.orgNetwork+xml";
|
||||
|
||||
public static final String CATALOG = "application/vnd.vmware.vcloud.catalog+xml";
|
||||
|
|
|
@ -0,0 +1,197 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
*(Link.builder().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(Link.builder().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 static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.VCLOUD_1_5_NS;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Objects.ToStringHelper;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "NetworkType")
|
||||
public class NetworkType<T extends NetworkType<T>> extends EntityType<T> {
|
||||
|
||||
public static <T extends NetworkType<T>> Builder<T> builder() {
|
||||
return new Builder<T>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder<T> toBuilder() {
|
||||
return new Builder<T>().fromNetworkType(this);
|
||||
}
|
||||
|
||||
public static class Builder<T extends NetworkType<T>> extends EntityType.Builder<T> {
|
||||
|
||||
protected NetworkConfiguration networkConfiguration;
|
||||
|
||||
/**
|
||||
* @see NetworkType#getConfiguration()
|
||||
*/
|
||||
public Builder<T> configuration(NetworkConfiguration networkConfiguration) {
|
||||
this.networkConfiguration = networkConfiguration;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkType<T> build() {
|
||||
NetworkType<T> network = new NetworkType<T>(href, name);
|
||||
network.setConfiguration(networkConfiguration);
|
||||
network.setDescription(description);
|
||||
network.setId(id);
|
||||
network.setType(type);
|
||||
network.setLinks(links);
|
||||
network.setTasksInProgress(tasksInProgress);
|
||||
return network;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see EntityType#getName()
|
||||
*/
|
||||
@Override
|
||||
public Builder<T> name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see EntityType#getDescription()
|
||||
*/
|
||||
@Override
|
||||
public Builder<T> description(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see EntityType#getId()
|
||||
*/
|
||||
@Override
|
||||
public Builder<T> id(String id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see EntityType#getTasksInProgress()
|
||||
*/
|
||||
@Override
|
||||
public Builder<T> tasksInProgress(TasksInProgress tasksInProgress) {
|
||||
this.tasksInProgress = tasksInProgress;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ReferenceType#getHref()
|
||||
*/
|
||||
@Override
|
||||
public Builder<T> href(URI href) {
|
||||
this.href = href;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ReferenceType#getType()
|
||||
*/
|
||||
@Override
|
||||
public Builder<T> type(String type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ReferenceType#getLinks()
|
||||
*/
|
||||
@Override
|
||||
public Builder<T> links(Set<Link> links) {
|
||||
this.links = Sets.newLinkedHashSet(checkNotNull(links, "links"));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ReferenceType#getLinks()
|
||||
*/
|
||||
@Override
|
||||
public Builder<T> link(Link link) {
|
||||
this.links.add(checkNotNull(link, "link"));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Builder<T> fromEntityType(EntityType<T> in) {
|
||||
return Builder.class.cast(super.fromEntityType(in));
|
||||
}
|
||||
|
||||
public Builder<T> fromNetworkType(NetworkType<T> in) {
|
||||
return fromEntityType(in).configuration(in.getConfiguration());
|
||||
}
|
||||
}
|
||||
|
||||
protected NetworkType() {
|
||||
// For JAXB and builder use
|
||||
}
|
||||
|
||||
protected NetworkType(URI href, String name) {
|
||||
super(href, name);
|
||||
}
|
||||
|
||||
@XmlElement(namespace = VCLOUD_1_5_NS, name = "Configuration")
|
||||
private NetworkConfiguration networkConfiguration;
|
||||
|
||||
/**
|
||||
* @return optional configuration
|
||||
*/
|
||||
public NetworkConfiguration getConfiguration() {
|
||||
return networkConfiguration;
|
||||
}
|
||||
|
||||
public void setConfiguration(NetworkConfiguration networkConfiguration) {
|
||||
this.networkConfiguration = networkConfiguration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!super.equals(o))
|
||||
return false;
|
||||
NetworkType<?> that = NetworkType.class.cast(o);
|
||||
return super.equals(that) && equal(networkConfiguration, that.networkConfiguration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return super.hashCode() + Objects.hashCode(networkConfiguration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ToStringHelper string() {
|
||||
return super.string().add("configuration", networkConfiguration);
|
||||
}
|
||||
|
||||
}
|
|
@ -18,9 +18,9 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.director.v1_5.domain;
|
||||
|
||||
import static com.google.common.base.Objects.*;
|
||||
import static com.google.common.base.Preconditions.*;
|
||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*;
|
||||
import static com.google.common.base.Objects.equal;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.VCLOUD_1_5_NS;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Set;
|
||||
|
@ -33,7 +33,7 @@ import com.google.common.base.Objects.ToStringHelper;
|
|||
import com.google.common.collect.Sets;
|
||||
|
||||
@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "OrgNetwork")
|
||||
public class OrgNetwork extends EntityType<OrgNetwork> {
|
||||
public class OrgNetwork extends NetworkType<OrgNetwork> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Builder builder() {
|
||||
|
@ -45,20 +45,11 @@ public class OrgNetwork extends EntityType<OrgNetwork> {
|
|||
return new Builder().fromOrgNetwork(this);
|
||||
}
|
||||
|
||||
public static class Builder extends EntityType.Builder<OrgNetwork> {
|
||||
public static class Builder extends NetworkType.Builder<OrgNetwork> {
|
||||
|
||||
private NetworkConfiguration networkConfiguration;
|
||||
private ReferenceType<?> networkPool;
|
||||
private IpAddresses allowedExternalIpAddresses;
|
||||
|
||||
/**
|
||||
* @see OrgNetwork#getConfiguration()
|
||||
*/
|
||||
public Builder configuration(NetworkConfiguration networkConfiguration) {
|
||||
this.networkConfiguration = networkConfiguration;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see OrgNetwork#getNetworkPool()
|
||||
*/
|
||||
|
@ -89,6 +80,14 @@ public class OrgNetwork extends EntityType<OrgNetwork> {
|
|||
return network;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see NetworkType#getConfiguration()
|
||||
*/
|
||||
public Builder configuration(NetworkConfiguration networkConfiguration) {
|
||||
this.networkConfiguration = networkConfiguration;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see EntityType#getName()
|
||||
*/
|
||||
|
@ -181,24 +180,11 @@ public class OrgNetwork extends EntityType<OrgNetwork> {
|
|||
super(href, name);
|
||||
}
|
||||
|
||||
@XmlElement(namespace = VCLOUD_1_5_NS, name = "Configuration")
|
||||
private NetworkConfiguration networkConfiguration;
|
||||
@XmlElement(namespace = VCLOUD_1_5_NS, name = "NetworkPool")
|
||||
private ReferenceType<?> networkPool;
|
||||
@XmlElement(namespace = VCLOUD_1_5_NS, name = "AllowedExternalIpAddresses")
|
||||
private IpAddresses allowedExternalIpAddresses;
|
||||
|
||||
/**
|
||||
* @return optional configuration
|
||||
*/
|
||||
public NetworkConfiguration getConfiguration() {
|
||||
return networkConfiguration;
|
||||
}
|
||||
|
||||
public void setConfiguration(NetworkConfiguration networkConfiguration) {
|
||||
this.networkConfiguration = networkConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return optional network pool
|
||||
*/
|
||||
|
@ -226,20 +212,18 @@ public class OrgNetwork extends EntityType<OrgNetwork> {
|
|||
if (!super.equals(o))
|
||||
return false;
|
||||
OrgNetwork that = OrgNetwork.class.cast(o);
|
||||
return super.equals(that) && equal(networkConfiguration, that.networkConfiguration) &&
|
||||
equal(networkPool, that.networkPool) &&
|
||||
return super.equals(that) && equal(networkPool, that.networkPool) &&
|
||||
equal(allowedExternalIpAddresses, that.allowedExternalIpAddresses);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return super.hashCode() + Objects.hashCode(networkConfiguration,
|
||||
networkPool, allowedExternalIpAddresses);
|
||||
return super.hashCode() + Objects.hashCode(networkPool, allowedExternalIpAddresses);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ToStringHelper string() {
|
||||
return super.string().add("configuration", networkConfiguration).add("networkPool", networkPool)
|
||||
return super.string().add("networkPool", networkPool)
|
||||
.add("allowedExternalIpAddresses", allowedExternalIpAddresses);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,21 +18,22 @@
|
|||
*/
|
||||
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.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
|
||||
import org.jclouds.rest.annotations.EndpointParam;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.JAXBResponseParser;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
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.OrgNetwork;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.ReferenceType;
|
||||
import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest;
|
||||
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;
|
||||
|
||||
|
@ -45,30 +46,33 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
public interface NetworkAsyncClient {
|
||||
|
||||
/**
|
||||
* @see NeworkClient#getNetwork()
|
||||
* @see NeworkClient#getNetwork(ReferenceType)
|
||||
*/
|
||||
@GET
|
||||
@Consumes
|
||||
@JAXBResponseParser
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<OrgNetwork> getNetwork(@EndpointParam URI uri);
|
||||
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
|
||||
ListenableFuture<OrgNetwork> getNetwork(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType<?> networkRef);
|
||||
|
||||
/**
|
||||
* @see NeworkClient#getMetadata()
|
||||
* @see NeworkClient#getMetadata(ReferenceType)
|
||||
*/
|
||||
@GET
|
||||
@Path("/metadata/")
|
||||
@Path("/metadata")
|
||||
@Consumes
|
||||
@JAXBResponseParser
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<Metadata> getMetadata(@EndpointParam URI orgRef);
|
||||
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
|
||||
ListenableFuture<Metadata> getMetadata(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType<?> networkRef);
|
||||
|
||||
/**
|
||||
* @see NeworkClient#getMetadataEntry()
|
||||
* @see NeworkClient#getMetadataEntry(ReferenceType, String)
|
||||
*/
|
||||
@GET
|
||||
@Path("/metadata/{key}")
|
||||
@Consumes
|
||||
@JAXBResponseParser
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<MetadataEntry> getMetadataEntry(@EndpointParam URI metaDataRef);
|
||||
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
|
||||
ListenableFuture<MetadataEntry> getMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType<?> networkRef ,
|
||||
@PathParam("key") String key);
|
||||
|
||||
}
|
||||
|
|
|
@ -18,13 +18,13 @@
|
|||
*/
|
||||
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.Metadata;
|
||||
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.ReferenceType;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Network.
|
||||
|
@ -42,20 +42,20 @@ public interface NetworkClient {
|
|||
*
|
||||
* @return the network or null if not found
|
||||
*/
|
||||
OrgNetwork getNetwork(URI networkRef);
|
||||
OrgNetwork getNetwork(ReferenceType<?> networkRef);
|
||||
|
||||
/**
|
||||
* Retrieves an list of the network's metadata
|
||||
*
|
||||
* @return a list of metadata
|
||||
*/
|
||||
Metadata getMetadata(URI networkRef);
|
||||
Metadata getMetadata(ReferenceType<?> networkRef);
|
||||
|
||||
/**
|
||||
* Retrieves a metadata entry
|
||||
*
|
||||
* @return the metadata entry, or null if not found
|
||||
*/
|
||||
MetadataEntry getMetadataEntry(URI metaDataRef);
|
||||
MetadataEntry getMetadataEntry(ReferenceType<?> networkRef, String key);
|
||||
|
||||
}
|
||||
|
|
|
@ -18,12 +18,15 @@
|
|||
*/
|
||||
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 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.IpAddresses;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.IpRange;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.IpRanges;
|
||||
|
@ -38,6 +41,8 @@ import org.jclouds.vcloud.director.v1_5.domain.SyslogServerSettings;
|
|||
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* Allows us to test a client via its side effects.
|
||||
*
|
||||
|
@ -48,60 +53,102 @@ public class NetworkClientExpectTest extends BaseVCloudDirectorRestClientExpectT
|
|||
|
||||
@Test
|
||||
public void testWhenResponseIs2xxLoginReturnsValidNetwork() {
|
||||
URI networkRef = URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c");
|
||||
URI networkUri = URI.create(endpoint + "/network/55a677cf-ab3f-48ae-b880-fab90421980c");
|
||||
|
||||
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
|
||||
getStandardRequest("GET", networkRef),
|
||||
getStandardRequest("GET", "/network/55a677cf-ab3f-48ae-b880-fab90421980c"),
|
||||
getStandardPayloadResponse("/network/network.xml", VCloudDirectorMediaType.ORG_NETWORK));
|
||||
|
||||
OrgNetwork expected = 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"))
|
||||
.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())
|
||||
.build())
|
||||
.fenceMode("bridged")
|
||||
.retainNetInfoAcrossDeployments(false)
|
||||
.syslogServerSettings(SyslogServerSettings.builder().build())
|
||||
.build())
|
||||
.allowedExternalIpAddresses(IpAddresses.builder().build())
|
||||
.build();
|
||||
OrgNetwork expected = orgNetwork();
|
||||
|
||||
Reference networkRef = Reference.builder().href(networkUri).build();
|
||||
|
||||
assertEquals(client.getNetworkClient().getNetwork(networkRef), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhenResponseIs2xxLoginReturnsValidMetadata() {
|
||||
URI orgUri = URI.create(endpoint + "/network/55a677cf-ab3f-48ae-b880-fab90421980c");
|
||||
URI metaUri = URI.create(orgUri.toASCIIString() + "/metadata/");
|
||||
public void testWhenResponseIs400ForInvalidNetworkId() {
|
||||
URI networkUri = URI.create(endpoint + "/network/NOTAUUID");
|
||||
|
||||
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
|
||||
getStandardRequest("GET", metaUri),
|
||||
getStandardRequest("GET", "/network/NOTAUUID"),
|
||||
getStandardPayloadResponse(400, "/network/error400.xml", VCloudDirectorMediaType.ERROR));
|
||||
|
||||
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();
|
||||
|
||||
Reference networkRef = Reference.builder().href(networkUri).build();
|
||||
try {
|
||||
client.getNetworkClient().getNetwork(networkRef);
|
||||
fail("Should give HTTP 400 error");
|
||||
} catch (VCloudDirectorException vde) {
|
||||
assertEquals(vde.getError(), expected);
|
||||
} catch (Exception e) {
|
||||
fail("Should have thrown a VCloudDirectorException");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhenResponseIs403ForCatalogIdUsedAsNetworkId() {
|
||||
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));
|
||||
|
||||
Error expected = Error.builder()
|
||||
.message("This operation is denied.")
|
||||
.majorErrorCode(403)
|
||||
.minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN")
|
||||
.build();
|
||||
|
||||
Reference networkRef = Reference.builder().href(networkUri).build();
|
||||
|
||||
try {
|
||||
client.getNetworkClient().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
|
||||
public void testWhenResponseIs403ForFakeNetworkId() {
|
||||
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));
|
||||
|
||||
Error expected = Error.builder()
|
||||
.message("This operation is denied.")
|
||||
.majorErrorCode(403)
|
||||
.minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN")
|
||||
.build();
|
||||
|
||||
Reference networkRef = Reference.builder().href(networkUri).build();
|
||||
|
||||
try {
|
||||
client.getNetworkClient().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
|
||||
public void testWhenResponseIs2xxLoginReturnsValidMetadataList() {
|
||||
URI networkUri = URI.create(endpoint + "/network/55a677cf-ab3f-48ae-b880-fab90421980c");
|
||||
|
||||
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
|
||||
getStandardRequest("GET", "/network/55a677cf-ab3f-48ae-b880-fab90421980c/metadata"),
|
||||
getStandardPayloadResponse("/network/metadata.xml", VCloudDirectorMediaType.METADATA));
|
||||
|
||||
Metadata expected = Metadata.builder()
|
||||
|
@ -112,27 +159,67 @@ public class NetworkClientExpectTest extends BaseVCloudDirectorRestClientExpectT
|
|||
.type("application/vnd.vmware.vcloud.network+xml")
|
||||
.href(URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c"))
|
||||
.build())
|
||||
.metadata(ImmutableSet.of(MetadataEntry.builder().entry("key", "value").build()))
|
||||
.build();
|
||||
|
||||
// TODO change network client to use ReferenceType<?> params
|
||||
Reference orgRef = Reference.builder().href(orgUri).build();
|
||||
Reference networkRef = Reference.builder().href(networkUri).build();
|
||||
|
||||
assertEquals(client.getNetworkClient().getMetadata(orgUri), expected);
|
||||
assertEquals(client.getNetworkClient().getMetadata(networkRef), expected);
|
||||
}
|
||||
|
||||
@Test(enabled=false) // No metadata in exemplar xml...
|
||||
public void testWhenResponseIs2xxLoginReturnsValidMetadataEntry() {
|
||||
URI metadataUri = URI.create(endpoint + "/network/55a677cf-ab3f-48ae-b880-fab90421980c/metadata/KEY");
|
||||
public void testWhenResponseIs2xxLoginReturnsValidMetadata() {
|
||||
URI networkUri = URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c");
|
||||
|
||||
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
|
||||
getStandardRequest("GET", metadataUri),
|
||||
getStandardPayloadResponse("/network/metadata.xml", VCloudDirectorMediaType.METADATA_ENTRY));
|
||||
getStandardRequest("GET", "/network/55a677cf-ab3f-48ae-b880-fab90421980c/metadata/KEY"),
|
||||
getStandardPayloadResponse("/network/metadataEntry.xml", VCloudDirectorMediaType.METADATA_ENTRY));
|
||||
|
||||
MetadataEntry expected = MetadataEntry.builder().build();
|
||||
MetadataEntry expected = MetadataEntry.builder()
|
||||
.entry("key", "value")
|
||||
.build();
|
||||
|
||||
// TODO change network client to use ReferenceType<?> params
|
||||
Reference orgRef = Reference.builder().href(metadataUri).build();
|
||||
Reference networkRef = Reference.builder().href(networkUri).build();
|
||||
|
||||
assertEquals(client.getNetworkClient().getMetadataEntry(metadataUri), expected);
|
||||
assertEquals(client.getNetworkClient().getMetadataEntry(networkRef, "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"))
|
||||
.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())
|
||||
.build())
|
||||
.fenceMode("bridged")
|
||||
.retainNetInfoAcrossDeployments(false)
|
||||
.syslogServerSettings(SyslogServerSettings.builder().build())
|
||||
.build())
|
||||
.allowedExternalIpAddresses(IpAddresses.builder().build())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,145 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
*(Link.builder().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(Link.builder().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.assertEquals;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
|
||||
import org.jclouds.vcloud.director.v1_5.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.OrgNetwork;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Reference;
|
||||
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code NetworkClient}
|
||||
*
|
||||
* @author danikov
|
||||
*/
|
||||
@Test(groups = { "live", "apitests" }, testName = "NetworkClientLiveTest")
|
||||
public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
||||
|
||||
// @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();
|
||||
|
||||
OrgNetwork network = context.getApi().getNetworkClient().getNetwork(networkRef);
|
||||
|
||||
//TODO assert network is valid
|
||||
}
|
||||
|
||||
@Test(testName = "GET /network/NOTAUUID", enabled=false)
|
||||
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.")
|
||||
.majorErrorCode(400)
|
||||
.minorErrorCode("BAD_REQUEST")
|
||||
.build();
|
||||
|
||||
try {
|
||||
context.getApi().getNetworkClient().getNetwork(networkRef);
|
||||
fail("Should give HTTP 400 error");
|
||||
} catch (VCloudDirectorException vde) {
|
||||
assertEquals(vde.getError(), expected);
|
||||
} catch (Exception e) {
|
||||
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 {
|
||||
context.getApi().getNetworkClient().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}")
|
||||
public void testWhenResponseIs403ForFakeNetworkId() {
|
||||
Reference networkRef = Reference.builder()
|
||||
.href(URI.create(endpoint + "/network/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")).build();
|
||||
|
||||
Error expected = Error.builder()
|
||||
.message("This operation is denied.")
|
||||
.majorErrorCode(403)
|
||||
.minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN")
|
||||
.build();
|
||||
|
||||
try {
|
||||
context.getApi().getNetworkClient().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/{id}/metadata")
|
||||
public void testWhenResponseIs2xxLoginReturnsValidMetadataList() {
|
||||
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)
|
||||
}
|
||||
|
||||
String metadataKey = "key";
|
||||
|
||||
//TODO depends on previous
|
||||
@Test(testName = "GET /network/{id}/metadata", enabled=false)
|
||||
public void testWhenResponseIs2xxLoginReturnsValidMetadataEntry() {
|
||||
Reference networkRef = Reference.builder()
|
||||
.href(URI.create(endpoint + "/network/"+networkId)).build();
|
||||
|
||||
MetadataEntry expected = context.getApi().getNetworkClient().getMetadataEntry(networkRef, metadataKey);
|
||||
|
||||
// assert metadataEntry is valid
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Error xmlns="http://www.vmware.com/vcloud/v1.5" minorErrorCode="BAD_REQUEST" message="validation error : EntityRef has incorrect type, expected type is com.vmware.vcloud.entity.network." majorErrorCode="400" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://vcloudbeta.bluelock.com/api/v1.5/schema/master.xsd"></Error>
|
|
@ -0,0 +1,2 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Error xmlns="http://www.vmware.com/vcloud/v1.5" minorErrorCode="ACCESS_TO_RESOURCE_IS_FORBIDDEN" message="This operation is denied." majorErrorCode="403" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://vcloudbeta.bluelock.com/api/v1.5/schema/master.xsd"></Error>
|
|
@ -0,0 +1,2 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Error xmlns="http://www.vmware.com/vcloud/v1.5" minorErrorCode="ACCESS_TO_RESOURCE_IS_FORBIDDEN" message="This operation is denied." majorErrorCode="403" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://vcloudbeta.bluelock.com/api/v1.5/schema/master.xsd"></Error>
|
|
@ -1,4 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Metadata xmlns="http://www.vmware.com/vcloud/v1.5" type="application/vnd.vmware.vcloud.metadata+xml" href="https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c/metadata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://vcloudbeta.bluelock.com/api/v1.5/schema/master.xsd">
|
||||
<Link rel="up" type="application/vnd.vmware.vcloud.network+xml" href="https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c"/>
|
||||
<MetadataEntry>
|
||||
<Key>key</Key>
|
||||
<Value>value</Value>
|
||||
</MetadataEntry>
|
||||
</Metadata>
|
||||
|
|
Loading…
Reference in New Issue