mirror of https://github.com/apache/jclouds.git
Merge pull request #381 from danikov/vclouds-director-network
Issue 830 vCloud director Network
This commit is contained in:
commit
9f7d6cfeb7
|
@ -51,7 +51,7 @@ public class VCloudDirectorMediaType {
|
||||||
|
|
||||||
public static final String TASK = "application/vnd.vmware.vcloud.task+xml";
|
public static final String TASK = "application/vnd.vmware.vcloud.task+xml";
|
||||||
|
|
||||||
public static final String NETWORK = "application/vnd.vmware.vcloud.entity.network+xml";
|
public static final String NETWORK = "application/vnd.vmware.vcloud.network+xml";
|
||||||
|
|
||||||
public static final String ORG_NETWORK = "application/vnd.vmware.vcloud.orgNetwork+xml";
|
public static final String ORG_NETWORK = "application/vnd.vmware.vcloud.orgNetwork+xml";
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ public class VCloudDirectorMediaType {
|
||||||
|
|
||||||
public static final List<String> ALL = Arrays.asList(
|
public static final List<String> ALL = Arrays.asList(
|
||||||
SESSION, ERROR, ORG_LIST, METADATA, METADATA_ENTRY,
|
SESSION, ERROR, ORG_LIST, METADATA, METADATA_ENTRY,
|
||||||
METADATA_VALUE, ORG, TASKS_LIST, TASK, ORG_NETWORK,
|
METADATA_VALUE, ORG, TASKS_LIST, TASK, NETWORK, ORG_NETWORK,
|
||||||
CATALOG, CATALOG_ITEM, CATALOG_ITEMS, CATALOGS_LIST, PROPERTY,
|
CATALOG, CATALOG_ITEM, CATALOG_ITEMS, CATALOGS_LIST, PROPERTY,
|
||||||
MEDIA, OWNER, VDC, ADMIN_USER
|
MEDIA, OWNER, VDC, ADMIN_USER
|
||||||
);
|
);
|
||||||
|
|
|
@ -28,9 +28,9 @@ import org.jclouds.rest.annotations.ExceptionParser;
|
||||||
import org.jclouds.rest.annotations.JAXBResponseParser;
|
import org.jclouds.rest.annotations.JAXBResponseParser;
|
||||||
import org.jclouds.rest.annotations.RequestFilters;
|
import org.jclouds.rest.annotations.RequestFilters;
|
||||||
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.MetadataEntry;
|
import org.jclouds.vcloud.director.v1_5.domain.MetadataValue;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.OrgNetwork;
|
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.domain.Reference;
|
||||||
import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest;
|
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.ReferenceToEndpoint;
|
||||||
import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx;
|
import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx;
|
||||||
|
@ -46,33 +46,33 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
public interface NetworkAsyncClient {
|
public interface NetworkAsyncClient {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see NeworkClient#getNetwork(ReferenceType)
|
* @see NeworkClient#getNetwork(Reference)
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Consumes
|
@Consumes
|
||||||
@JAXBResponseParser
|
@JAXBResponseParser
|
||||||
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
|
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
|
||||||
ListenableFuture<OrgNetwork> getNetwork(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType<?> networkRef);
|
ListenableFuture<OrgNetwork> getNetwork(@EndpointParam(parser = ReferenceToEndpoint.class) Reference networkRef);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see NeworkClient#getMetadata(ReferenceType)
|
* @see NeworkClient#getMetadata(Reference)
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("/metadata")
|
@Path("/metadata")
|
||||||
@Consumes
|
@Consumes
|
||||||
@JAXBResponseParser
|
@JAXBResponseParser
|
||||||
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
|
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
|
||||||
ListenableFuture<Metadata> getMetadata(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType<?> networkRef);
|
ListenableFuture<Metadata> getMetadata(@EndpointParam(parser = ReferenceToEndpoint.class) Reference networkRef);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see NeworkClient#getMetadataEntry(ReferenceType, String)
|
* @see NeworkClient#getMetadataValue(Reference, String)
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("/metadata/{key}")
|
@Path("/metadata/{key}")
|
||||||
@Consumes
|
@Consumes
|
||||||
@JAXBResponseParser
|
@JAXBResponseParser
|
||||||
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
|
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
|
||||||
ListenableFuture<MetadataEntry> getMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType<?> networkRef ,
|
ListenableFuture<MetadataValue> getMetadataValue(@EndpointParam(parser = ReferenceToEndpoint.class) Reference networkRef ,
|
||||||
@PathParam("key") String key);
|
@PathParam("key") String key);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,9 +22,9 @@ import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.jclouds.concurrent.Timeout;
|
import org.jclouds.concurrent.Timeout;
|
||||||
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.MetadataEntry;
|
import org.jclouds.vcloud.director.v1_5.domain.MetadataValue;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.OrgNetwork;
|
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.domain.Reference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides synchronous access to Network.
|
* Provides synchronous access to Network.
|
||||||
|
@ -42,20 +42,20 @@ public interface NetworkClient {
|
||||||
*
|
*
|
||||||
* @return the network or null if not found
|
* @return the network or null if not found
|
||||||
*/
|
*/
|
||||||
OrgNetwork getNetwork(ReferenceType<?> networkRef);
|
OrgNetwork getNetwork(Reference networkRef);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves an list of the network's metadata
|
* Retrieves an list of the network's metadata
|
||||||
*
|
*
|
||||||
* @return a list of metadata
|
* @return a list of metadata
|
||||||
*/
|
*/
|
||||||
Metadata getMetadata(ReferenceType<?> networkRef);
|
Metadata getMetadata(Reference networkRef);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a metadata entry
|
* Retrieves a metadata value
|
||||||
*
|
*
|
||||||
* @return the metadata entry, or null if not found
|
* @return the metadata value, or null if not found
|
||||||
*/
|
*/
|
||||||
MetadataEntry getMetadataEntry(ReferenceType<?> networkRef, String key);
|
MetadataValue getMetadataValue(Reference networkRef, String key);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
|
||||||
|
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.google.common.net.InetAddresses;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author grkvlt@apache.org
|
* @author grkvlt@apache.org
|
||||||
|
@ -192,4 +193,122 @@ public class Checks {
|
||||||
assertTrue(Media.ImageType.ALL.contains(imageType),
|
assertTrue(Media.ImageType.ALL.contains(imageType),
|
||||||
"The Image type of a Media must be one of the allowed list");
|
"The Image type of a Media must be one of the allowed list");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void checkNetworkType(NetworkType<?> network) {
|
||||||
|
// Check optional fields
|
||||||
|
NetworkConfiguration config = network.getConfiguration();
|
||||||
|
if (config != null) {
|
||||||
|
checkNetworkConfiguration(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check parent type
|
||||||
|
checkEntityType(network);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkNetworkConfiguration(NetworkConfiguration config) {
|
||||||
|
// Check optional fields
|
||||||
|
if (config.getIpScope() != null) {
|
||||||
|
checkIpScope(config.getIpScope());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.getParentNetwork() != null) {
|
||||||
|
checkReferenceType(config.getParentNetwork());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.getNetworkFeatures() != null) {
|
||||||
|
checkNetworkFeatures(config.getNetworkFeatures());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.getSyslogServerSettings() != null) {
|
||||||
|
checkSyslogServerSettings(config.getSyslogServerSettings());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.getRouterInfo() != null) {
|
||||||
|
checkRouterInfo(config.getRouterInfo());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkIpScope(IpScope ipScope) {
|
||||||
|
// Check required fields
|
||||||
|
assertNotNull(ipScope.isInherited(), "isInherited attribute of IpScope must be set");
|
||||||
|
|
||||||
|
// Check optional fields
|
||||||
|
// NOTE dnsSuffix cannot be checked
|
||||||
|
if (ipScope.getGateway() != null) {
|
||||||
|
checkIpAddress(ipScope.getGateway());
|
||||||
|
}
|
||||||
|
if (ipScope.getNetmask() != null) {
|
||||||
|
checkIpAddress(ipScope.getNetmask());
|
||||||
|
}
|
||||||
|
if (ipScope.getDns1() != null) {
|
||||||
|
checkIpAddress(ipScope.getDns1());
|
||||||
|
}
|
||||||
|
if (ipScope.getDns2() != null) {
|
||||||
|
checkIpAddress(ipScope.getDns2());
|
||||||
|
}
|
||||||
|
if (ipScope.getIpRanges() != null) {
|
||||||
|
checkIpRanges(ipScope.getIpRanges());
|
||||||
|
}
|
||||||
|
if (ipScope.getAllocatedIpAddresses() != null) {
|
||||||
|
checkIpAddresses(ipScope.getAllocatedIpAddresses());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkNetworkFeatures(NetworkFeatures features) {
|
||||||
|
// Check optional fields
|
||||||
|
if (features.getNetworkServices() != null) {
|
||||||
|
for (NetworkService service : features.getNetworkServices()) {
|
||||||
|
checkNetworkService(service);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkSyslogServerSettings(SyslogServerSettings settings) {
|
||||||
|
// Check optional fields
|
||||||
|
if (settings.getSyslogServerIp1() != null) {
|
||||||
|
checkIpAddress(settings.getSyslogServerIp1());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings.getSyslogServerIp2() != null) {
|
||||||
|
checkIpAddress(settings.getSyslogServerIp2());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkRouterInfo(RouterInfo routerInfo) {
|
||||||
|
// Check required fields
|
||||||
|
assertNotNull(routerInfo.getExternalIp(), "The external IP attribute of a Router Info must be set");
|
||||||
|
checkIpAddress(routerInfo.getExternalIp());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkNetworkService(NetworkService service) {
|
||||||
|
// NOTE isEnabled cannot be checked
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkIpRanges(IpRanges ipRanges) {
|
||||||
|
// Check optional fields
|
||||||
|
for (IpRange range : ipRanges.getIpRanges()) {
|
||||||
|
checkIpRange(range);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkIpRange(IpRange range) {
|
||||||
|
// Check required fields
|
||||||
|
assertNotNull(range.getStartAddress(), "The start address attribute of an IP Range must be set");
|
||||||
|
checkIpAddress(range.getStartAddress());
|
||||||
|
|
||||||
|
assertNotNull(range.getEndAddress(), "The end address attribute of an IP Range must be set");
|
||||||
|
checkIpAddress(range.getEndAddress());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkIpAddresses(IpAddresses ipAddresses) {
|
||||||
|
// Check optional fields
|
||||||
|
for (String address : ipAddresses.getIpAddresses()) {
|
||||||
|
checkIpAddress(address);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkIpAddress(String ip) {
|
||||||
|
InetAddresses.isInetAddress(ip);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,7 +181,7 @@ public class NetworkClientExpectTest extends BaseVCloudDirectorRestClientExpectT
|
||||||
|
|
||||||
Reference networkRef = Reference.builder().href(networkUri).build();
|
Reference networkRef = Reference.builder().href(networkUri).build();
|
||||||
|
|
||||||
assertEquals(client.getNetworkClient().getMetadataEntry(networkRef, "KEY"), expected);
|
assertEquals(client.getNetworkClient().getMetadataValue(networkRef, "KEY"), expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OrgNetwork orgNetwork() {
|
public static OrgNetwork orgNetwork() {
|
||||||
|
|
|
@ -18,20 +18,33 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.vcloud.director.v1_5.features;
|
package org.jclouds.vcloud.director.v1_5.features;
|
||||||
|
|
||||||
|
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_ATTRB_REQ;
|
||||||
|
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_EQ;
|
||||||
|
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_REQ_LIVE;
|
||||||
|
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_REQ_LIVE;
|
||||||
|
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.REF_REQ_LIVE;
|
||||||
|
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkResourceType;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
import static org.testng.Assert.fail;
|
import static org.testng.Assert.assertFalse;
|
||||||
|
import static org.testng.Assert.assertNotNull;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
|
import org.jclouds.vcloud.director.v1_5.domain.Checks;
|
||||||
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.Metadata;
|
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.MetadataEntry;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.MetadataValue;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.OrgNetwork;
|
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.domain.Reference;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.ReferenceType;
|
||||||
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;
|
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;
|
||||||
|
import org.testng.annotations.BeforeGroups;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests behavior of {@code NetworkClient}
|
* Tests behavior of {@code NetworkClient}
|
||||||
*
|
*
|
||||||
|
@ -40,102 +53,87 @@ import org.testng.annotations.Test;
|
||||||
@Test(groups = { "live", "apitests" }, testName = "NetworkClientLiveTest")
|
@Test(groups = { "live", "apitests" }, testName = "NetworkClientLiveTest")
|
||||||
public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
public class NetworkClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
||||||
|
|
||||||
|
public static final String NETWORK = "network";
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convenience reference to API client.
|
||||||
|
*/
|
||||||
|
protected NetworkClient networkClient;
|
||||||
|
|
||||||
|
private Reference networkRef;
|
||||||
|
|
||||||
|
@BeforeGroups(groups = { "live" }, dependsOnMethods = { "setupClient" })
|
||||||
|
public void before() {
|
||||||
|
String networkId = "a604f3c2-0343-453e-ae1f-cddac5b7bd94"; // TODO: inject
|
||||||
|
networkRef = Reference.builder()
|
||||||
|
.type("application/vnd.vmware.vcloud.orgNetwork+xml")
|
||||||
|
.name("")
|
||||||
|
.href(URI.create(endpoint+"/network/"+networkId))
|
||||||
|
.id(networkId)
|
||||||
|
.build();
|
||||||
|
networkClient = context.getApi().getNetworkClient();
|
||||||
|
}
|
||||||
|
|
||||||
@Test(testName = "GET /network/{id}")
|
@Test(testName = "GET /network/{id}")
|
||||||
public void testWhenResponseIs2xxLoginReturnsValidNetwork() {
|
public void testGetNetwork() {
|
||||||
Reference networkRef = Reference.builder()
|
// required for testing
|
||||||
.href(URI.create(endpoint + "/network/" + networkId)).build();
|
assertNotNull(networkRef, String.format(REF_REQ_LIVE, NETWORK));
|
||||||
|
|
||||||
OrgNetwork network = context.getApi().getNetworkClient().getNetwork(networkRef);
|
OrgNetwork network = networkClient.getNetwork(networkRef);
|
||||||
|
assertNotNull(network, String.format(OBJ_REQ_LIVE, NETWORK));
|
||||||
//TODO assert network is valid
|
assertTrue(!network.getDescription().equals("DO NOT USE"), "Network isn't to be used for testing");
|
||||||
}
|
|
||||||
|
// parent type
|
||||||
@Test(testName = "GET /network/NOTAUUID", enabled=false)
|
Checks.checkNetworkType(network);
|
||||||
public void testWhenResponseIs400ForInvalidNetworkId() {
|
|
||||||
Reference networkRef = Reference.builder()
|
// optional
|
||||||
.href(URI.create(endpoint + "/network/NOTAUUID")).build();
|
ReferenceType<?> networkPoolRef = network.getNetworkPool();
|
||||||
|
if (networkPoolRef != null) {
|
||||||
Error expected = Error.builder()
|
Checks.checkReferenceType(networkPoolRef);
|
||||||
.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() {
|
|
||||||
String catalogId = "7212e451-76e1-4631-b2de-ba1dfd8080e4";
|
|
||||||
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()
|
IpAddresses allowedExternalIpAddresses = network.getAllowedExternalIpAddresses();
|
||||||
.message("This operation is denied.")
|
if (allowedExternalIpAddresses != null) {
|
||||||
.majorErrorCode(403)
|
Checks.checkIpAddresses(allowedExternalIpAddresses);
|
||||||
.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")
|
@Test(testName = "GET /network/{id}/metadata")
|
||||||
public void testWhenResponseIs2xxLoginReturnsValidMetadataList() {
|
public void testGetMetadata() {
|
||||||
Reference networkRef = Reference.builder()
|
Metadata metadata = networkClient.getMetadata(networkRef);
|
||||||
.href(URI.create(endpoint + "/network/" + networkId)).build();
|
// required for testing
|
||||||
|
assertFalse(Iterables.isEmpty(metadata.getMetadataEntries()),
|
||||||
Metadata expected = context.getApi().getNetworkClient().getMetadata(networkRef);
|
String.format(OBJ_FIELD_REQ_LIVE, NETWORK, "metadata.entries"));
|
||||||
|
|
||||||
// assert metadata is valid
|
// parent type
|
||||||
// assert has metadata in order to support subsequent test
|
checkResourceType(metadata);
|
||||||
// assign metadata key (todo- ordering)
|
|
||||||
|
for (MetadataEntry entry : metadata.getMetadataEntries()) {
|
||||||
|
// required elements and attributes
|
||||||
|
assertNotNull(entry.getKey(),
|
||||||
|
String.format(OBJ_FIELD_ATTRB_REQ, networkClient, "MetadataEntry", entry.getKey(), "key"));
|
||||||
|
assertNotNull(entry.getValue(),
|
||||||
|
String.format(OBJ_FIELD_ATTRB_REQ, networkClient, "MetadataEntry", entry.getValue(), "value"));
|
||||||
|
|
||||||
|
// parent type
|
||||||
|
checkResourceType(entry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String metadataKey = "key";
|
@Test(testName = "GET /network/{id}/metadata/{key}")
|
||||||
|
public void testGetMetadataValue() {
|
||||||
//TODO depends on previous
|
MetadataValue metadataValue = networkClient.getMetadataValue(networkRef, "key");
|
||||||
@Test(testName = "GET /network/{id}/metadata", enabled=false)
|
|
||||||
public void testWhenResponseIs2xxLoginReturnsValidMetadataEntry() {
|
// Check parent type
|
||||||
Reference networkRef = Reference.builder()
|
checkResourceType(metadataValue);
|
||||||
.href(URI.create(endpoint + "/network/" + networkId)).build();
|
|
||||||
|
// Check required elements and attributes
|
||||||
MetadataEntry expected = context.getApi().getNetworkClient().getMetadataEntry(networkRef, metadataKey);
|
String value = metadataValue.getValue();
|
||||||
|
assertNotNull(value,
|
||||||
// assert metadataEntry is valid
|
String.format(OBJ_FIELD_ATTRB_REQ, NETWORK, "MetadataEntry",
|
||||||
|
metadataValue.toString(), "value"));
|
||||||
|
assertEquals(value, "value",
|
||||||
|
String.format(OBJ_FIELD_EQ, NETWORK, "metadataEntry.value", "value", value));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue