mirror of https://github.com/apache/jclouds.git
improve expect test
This commit is contained in:
parent
b628daaa4e
commit
29fbfb36b7
|
@ -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;
|
||||
|
@ -48,14 +51,138 @@ 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()
|
||||
OrgNetwork expected = orgNetwork();
|
||||
|
||||
Reference networkRef = Reference.builder().href(networkUri).build();
|
||||
|
||||
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
|
||||
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()
|
||||
.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())
|
||||
.build();
|
||||
|
||||
Reference networkRef = Reference.builder().href(networkUri).build();
|
||||
|
||||
assertEquals(client.getNetworkClient().getMetadata(networkRef), expected);
|
||||
}
|
||||
|
||||
@Test(enabled=false) // No metadata in exemplar xml...
|
||||
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", "/network/55a677cf-ab3f-48ae-b880-fab90421980c/metadata/KEY"),
|
||||
getStandardPayloadResponse("/network/metadataEntry.xml", VCloudDirectorMediaType.METADATA_ENTRY));
|
||||
|
||||
MetadataEntry expected = MetadataEntry.builder()
|
||||
.key("KEY")
|
||||
.build();
|
||||
|
||||
Reference networkRef = Reference.builder().href(networkUri).build();
|
||||
|
||||
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)
|
||||
|
@ -91,48 +218,5 @@ public class NetworkClientExpectTest extends BaseVCloudDirectorRestClientExpectT
|
|||
.build())
|
||||
.allowedExternalIpAddresses(IpAddresses.builder().build())
|
||||
.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/");
|
||||
|
||||
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
|
||||
getStandardRequest("GET", metaUri),
|
||||
getStandardPayloadResponse("/network/metadata.xml", VCloudDirectorMediaType.METADATA));
|
||||
|
||||
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())
|
||||
.build();
|
||||
|
||||
// TODO change network client to use ReferenceType<?> params
|
||||
Reference orgRef = Reference.builder().href(orgUri).build();
|
||||
|
||||
assertEquals(client.getNetworkClient().getMetadata(orgUri), 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");
|
||||
|
||||
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
|
||||
getStandardRequest("GET", metadataUri),
|
||||
getStandardPayloadResponse("/network/metadata.xml", VCloudDirectorMediaType.METADATA_ENTRY));
|
||||
|
||||
MetadataEntry expected = MetadataEntry.builder().build();
|
||||
|
||||
// TODO change network client to use ReferenceType<?> params
|
||||
Reference orgRef = Reference.builder().href(metadataUri).build();
|
||||
|
||||
assertEquals(client.getNetworkClient().getMetadataEntry(metadataUri), expected);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>
|
Loading…
Reference in New Issue