improve expect test

This commit is contained in:
danikov 2012-02-10 17:38:14 +00:00
parent b628daaa4e
commit 29fbfb36b7
4 changed files with 146 additions and 56 deletions

View File

@ -18,12 +18,15 @@
*/ */
package org.jclouds.vcloud.director.v1_5.features; package org.jclouds.vcloud.director.v1_5.features;
import static org.testng.Assert.*; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.fail;
import java.net.URI; import java.net.URI;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; 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.IpAddresses;
import org.jclouds.vcloud.director.v1_5.domain.IpRange; import org.jclouds.vcloud.director.v1_5.domain.IpRange;
import org.jclouds.vcloud.director.v1_5.domain.IpRanges; import org.jclouds.vcloud.director.v1_5.domain.IpRanges;
@ -48,60 +51,102 @@ public class NetworkClientExpectTest extends BaseVCloudDirectorRestClientExpectT
@Test @Test
public void testWhenResponseIs2xxLoginReturnsValidNetwork() { 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, VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
getStandardRequest("GET", networkRef), getStandardRequest("GET", "/network/55a677cf-ab3f-48ae-b880-fab90421980c"),
getStandardPayloadResponse("/network/network.xml", VCloudDirectorMediaType.ORG_NETWORK)); getStandardPayloadResponse("/network/network.xml", VCloudDirectorMediaType.ORG_NETWORK));
OrgNetwork expected = OrgNetwork OrgNetwork expected = orgNetwork();
.builder()
.name("internet01-Jclouds") Reference networkRef = Reference.builder().href(networkUri).build();
.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();
assertEquals(client.getNetworkClient().getNetwork(networkRef), expected); assertEquals(client.getNetworkClient().getNetwork(networkRef), expected);
} }
@Test
public void testWhenResponseIs400ForInvalidNetworkId() {
URI networkUri = URI.create(endpoint + "/network/NOTAUUID");
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
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 @Test
public void testWhenResponseIs2xxLoginReturnsValidMetadata() { public void testWhenResponseIs2xxLoginReturnsValidMetadataList() {
URI orgUri = URI.create(endpoint + "/network/55a677cf-ab3f-48ae-b880-fab90421980c"); URI networkUri = URI.create(endpoint + "/network/55a677cf-ab3f-48ae-b880-fab90421980c");
URI metaUri = URI.create(orgUri.toASCIIString() + "/metadata/");
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
getStandardRequest("GET", metaUri), getStandardRequest("GET", "/network/55a677cf-ab3f-48ae-b880-fab90421980c/metadata"),
getStandardPayloadResponse("/network/metadata.xml", VCloudDirectorMediaType.METADATA)); getStandardPayloadResponse("/network/metadata.xml", VCloudDirectorMediaType.METADATA));
Metadata expected = Metadata.builder() Metadata expected = Metadata.builder()
@ -114,25 +159,64 @@ public class NetworkClientExpectTest extends BaseVCloudDirectorRestClientExpectT
.build()) .build())
.build(); .build();
// TODO change network client to use ReferenceType<?> params Reference networkRef = Reference.builder().href(networkUri).build();
Reference orgRef = Reference.builder().href(orgUri).build();
assertEquals(client.getNetworkClient().getMetadata(networkRef), expected);
assertEquals(client.getNetworkClient().getMetadata(orgUri), expected);
} }
@Test(enabled=false) // No metadata in exemplar xml... @Test(enabled=false) // No metadata in exemplar xml...
public void testWhenResponseIs2xxLoginReturnsValidMetadataEntry() { public void testWhenResponseIs2xxLoginReturnsValidMetadata() {
URI metadataUri = URI.create(endpoint + "/network/55a677cf-ab3f-48ae-b880-fab90421980c/metadata/KEY"); URI networkUri = URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c");
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
getStandardRequest("GET", metadataUri), getStandardRequest("GET", "/network/55a677cf-ab3f-48ae-b880-fab90421980c/metadata/KEY"),
getStandardPayloadResponse("/network/metadata.xml", VCloudDirectorMediaType.METADATA_ENTRY)); getStandardPayloadResponse("/network/metadataEntry.xml", VCloudDirectorMediaType.METADATA_ENTRY));
MetadataEntry expected = MetadataEntry.builder().build(); MetadataEntry expected = MetadataEntry.builder()
.key("KEY")
.build();
// TODO change network client to use ReferenceType<?> params Reference networkRef = Reference.builder().href(networkUri).build();
Reference orgRef = Reference.builder().href(metadataUri).build();
assertEquals(client.getNetworkClient().getMetadataEntry(metadataUri), expected); assertEquals(client.getOrgClient().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();
} }
} }

View File

@ -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>

View File

@ -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>

View File

@ -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>