Created initial Org live test

This commit is contained in:
Andrew Donald Kennedy 2012-02-12 16:43:38 +00:00
parent 9f14503cf6
commit 06661abe1e
10 changed files with 420 additions and 9 deletions

View File

@ -18,6 +18,9 @@
*/
package org.jclouds.vcloud.director.v1_5;
import java.util.Arrays;
import java.util.List;
/**
* Resource Types used in VCloud.
*
@ -60,4 +63,9 @@ public class VCloudDirectorMediaType {
public static final String PROPERTY = "application/vnd.vmware.vcloud.property+xml";
public static final List<String> ALL = Arrays.asList(
SESSION, ERROR, ORG_LIST, METADATA, METADATA_ENTRY,
METADATA_VALUE, ORG, TASKS_LIST, TASK, ORG_NETWORK,
CATALOG, CATALOG_ITEM, CATALOG_ITEMS, CATALOGS_LIST, PROPERTY
);
}

View File

@ -161,7 +161,7 @@ public class EntityType<T extends EntityType<T>> extends ResourceType<T> {
private TasksInProgress tasksInProgress;
@XmlAttribute
private String id;
@XmlAttribute
@XmlAttribute(required = true)
private String name;
protected EntityType(URI href, String name) {

View File

@ -22,6 +22,8 @@ import static com.google.common.base.Objects.*;
import static com.google.common.base.Preconditions.*;
import java.net.URI;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import javax.xml.bind.annotation.XmlAttribute;
@ -40,6 +42,17 @@ import com.google.common.base.Objects.ToStringHelper;
*/
public class Link extends ReferenceType<Link> {
public static final class Rel {
public static final String UP = "up";
public static final String DOWN = "down";
public static final String EDIT = "edit";
public static final String DELETE = "delete";
public static final List<String> ALL = Arrays.asList(
UP, DOWN, EDIT, DELETE
);
}
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
@ -133,7 +146,7 @@ public class Link extends ReferenceType<Link> {
}
}
@XmlAttribute
@XmlAttribute(required = true)
private String rel;
private Link(URI href, String rel) {

View File

@ -108,7 +108,7 @@ public class ReferenceType<T extends ReferenceType<T>> implements URISupplier {
}
}
@XmlAttribute
@XmlAttribute(required = true)
private URI href;
@XmlAttribute
private String id;

View File

@ -23,7 +23,9 @@ import static com.google.common.base.Preconditions.*;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*;
import java.net.URI;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Set;
import javax.xml.bind.annotation.XmlAttribute;
@ -49,6 +51,21 @@ import com.google.common.collect.Sets;
public class Task extends EntityType<Task> {
public static final String MEDIA_TYPE = VCloudDirectorMediaType.TASK;
public static class Status {
public static final String QUEUED = "queued";
public static final String PRE_RUNNING = "preRunning";
public static final String RUNNING = "running";
public static final String SUCCESS = "success";
public static final String ERROR = "error";
public static final String CANCELED = "canceled";
public static final String ABORTED = "aborted";
public static final List<String> ALL = Arrays.asList(
QUEUED, PRE_RUNNING, RUNNING, SUCCESS,
ERROR, CANCELED, ABORTED
);
}
@SuppressWarnings("unchecked")
public static Builder builder() {

View File

@ -0,0 +1,148 @@
/**
* 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 org.testng.Assert.*;
import java.net.URI;
import java.util.Set;
import java.util.UUID;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
/**
* @author grkvlt@apache.org
*/
public class Checks {
protected void checkEntityType(EntityType<?> entity) {
// Check required fields
assertNotNull(entity.getName(), "The Name attribute of an EntityType must be set");
// Check optional fields
// String description = entity.getDescription(); // ???
TasksInProgress tasksInProgress = entity.getTasksInProgress();
if (tasksInProgress != null && tasksInProgress.getTasks() != null && !tasksInProgress.getTasks().isEmpty()) {
for (Task task : tasksInProgress.getTasks()) checkTask(task);
}
// Check parent type
checkResourceType(entity);
}
protected void checkReferenceType(ReferenceType<?> reference) {
// Check required fields
assertNotNull(reference.getHref(), "The Href attribute of a ReferenceType must be set");
// Check optional fields
String id = reference.getId();
if (id != null) checkId(id);
String type = reference.getType();
if (type != null) checkType(type);
// String name = reference.getName(); // ???
}
protected void checkResourceType(ResourceType<?> resource) {
// Check optional fields
URI href = resource.getHref();
if (href != null) checkHref(href);
String type = resource.getType();
if (type != null) checkType(type);
Set<Link> links = resource.getLinks();
if (links != null && !links.isEmpty()) {
for (Link link : links) checkLink(link);
}
}
protected void checkId(String id) {
Iterable<String> parts = Splitter.on(':').split(id);
assertEquals(Iterables.size(parts), 4, "The Id must be well formed");
assertEquals(Iterables.get(parts, 0), "urn", "The Id must start with 'urn'");
assertEquals(Iterables.get(parts, 1), "vcloud", "The Id must include 'vcloud'");
try {
UUID uuid = UUID.fromString(Iterables.get(parts, 3));
assertNotNull(uuid, "The UUID part of an Id must be well formed");
} catch (IllegalArgumentException iae) {
fail("The UUID part of an Id must be well formed");
}
}
protected void checkType(String type) {
assertTrue(VCloudDirectorMediaType.ALL.contains(type), "The Type must be a valid media type");
}
protected void checkHref(URI href) {
String uri = href.toASCIIString();
String auth = href.getAuthority();
String host = href.getHost();
String path = href.getPath();
// assertEquals(auth + "://" + host + path, endpoint, "The Href must contain the provider endpoint");
// assertTrue(uri.startsWith(endpoint), "The Href must contain the provider endpoint");
}
protected void checkLink(Link link) {
// Check required fields
assertNotNull(link.getRel(), "The Rel attribute of a Link must be set");
assertTrue(Link.Rel.ALL.contains(link.getRel()), "The Rel attribute of a Link must be one of the allowed list");
// Check parent type
checkReferenceType(link);
}
protected void checkTask(Task task) {
// Check required fields
assertNotNull(task.getStatus(), "The Status attribute of a Task must be set");
assertTrue(Task.Status.ALL.contains(task.getStatus()), "The Status of a Task must be one of the allowed list");
// Check optional fields
// String operation = task.getOperation(); // ???
// String operationName = task.getOperationName(); // ???;
// Date startTime = task.getStartTime(); // ???
// Date endTime = task.getEndTime(); // ???
// Date expiryTime = task.getExpiryTime(); // ???
// ReferenceType<?> owner = task.getOwner(); // ???
Error error = task.getError();
if (error != null) checkError(error);
// ReferenceType<?> user = task.getUser(); // ???
// ReferenceType<?> organization = task.getOrg(); // ???
Integer progress = task.getProgress();
if (progress != null) checkProgress(progress);
// Object params = task.getParams(); // ???
// Check parent type
checkEntityType(task);
}
protected void checkProgress(Integer progress) {
assertTrue(progress >= 0 && progress <= 100, "The Progress attribute must be between 0 and 100");
}
protected void checkError(Error error) {
// Check required fields
assertNotNull(error.getMessage(), "The Message attribute of an Error must be set");
assertNotNull(error.getMajorErrorCode(), "The MajorErrorCode attribute of an Error must be set");
assertNotNull(error.getMinorErrorCode(), "The MinorErrorCode attribute of an Error must be set");
// String vendorSpecificErrorCode = error.getVendorSpecificErrorCode(); // ???
// String stackTrace = error.getStackTrace(); // ???
}
}

View File

@ -38,7 +38,7 @@ import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
/**
* Allows us to test a client via its side effects.
* Allows us to test the {@link OrgClient} via its side effects.
*
* @author Adrian Cole
*/
@ -234,7 +234,7 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
.rel("down")
.type("application/vnd.vmware.vcloud.catalog+xml")
.name("Public")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c"))
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4"))
.build())
.link(Link.builder()
.rel("down")

View File

@ -0,0 +1,226 @@
/**
* 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.*;
import org.jclouds.vcloud.director.v1_5.domain.Org;
import org.jclouds.vcloud.director.v1_5.domain.OrgList;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
/**
* Tests live behavior of {@link OrgClient}.
*
* @author grkvlt@apache.org
*/
@Test(groups = { "live", "apitests" }, testName = "OrgClientLiveTest")
public class OrgClientLiveTest extends BaseVCloudDirectorClientLiveTest {
@Test(testName = "GET /org/{id}")
public void testGetOrg() {
OrgList orgList = context.getApi().getOrgClient().getOrgList();
assertFalse(Iterables.isEmpty(orgList.getOrgs()), "There must always be Org elements in the OrgList");
Reference orgRef = Iterables.getFirst(orgList.getOrgs(), null);
// Call the method being tested
Org org = context.getApi().getOrgClient().getOrg(orgRef);
// Check required elements and attributes of the Org
assertNotNull(org.getFullName(), "The FullName field of the Org must not be null");
// Check required elements and attributes of EntityType
checkEntityType(org);
assertNotNull(org.getName(), "The Name field of the Org must not be null");
// Check optional elements and attributes of the Org
org.getDescription();
org.g
}
// @Test
// public void testWhenResponseIs2xxLoginReturnsValidOrgList() {
// VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
// getStandardRequest("GET", "/org"),
// getStandardPayloadResponse("/org/orglist.xml", VCloudDirectorMediaType.ORG_LIST));
//
// OrgList expected = OrgList.builder()
// .org(Reference.builder()
// .type("application/vnd.vmware.vcloud.org+xml")
// .name("JClouds")
// .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
// .build())
// .build();
//
// assertEquals(client.getOrgClient().getOrgList(), expected);
// }
//
// @Test
// public void testWhenResponseIs2xxLoginReturnsValidOrgFromListByReference() {
// VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
// getStandardRequest("GET", "/org"),
// getStandardPayloadResponse("/org/orglist.xml", VCloudDirectorMediaType.ORG_LIST));
//
// Reference org = Iterables.getOnlyElement(client.getOrgClient().getOrgList().getOrgs());
//
// client = requestsSendResponses(loginRequest, sessionResponse,
// getStandardRequest("GET", org.getHref()),
// getStandardPayloadResponse("/org/org.xml", VCloudDirectorMediaType.ORG));
//
// Org expected = org();
//
// assertEquals(client.getOrgClient().getOrg(org), expected);
// }
//
// @Test
// public void testWhenResponseIs2xxLoginReturnsValidOrg() {
// URI orgUri = URI.create(endpoint + "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0");
//
// VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
// getStandardRequest("GET", "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"),
// getStandardPayloadResponse("/org/org.xml", VCloudDirectorMediaType.ORG));
//
// Org expected = org();
//
// Reference orgRef = Reference.builder().href(orgUri).build();
//
// assertEquals(client.getOrgClient().getOrg(orgRef), expected);
// }
//
// @Test
// public void testWhenResponseIs400ForInvalidOrgId() {
// URI orgUri = URI.create(endpoint + "/org/NOTAUUID");
//
// VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
// getStandardRequest("GET", "/org/NOTAUUID"),
// getStandardPayloadResponse(400, "/org/error400.xml", VCloudDirectorMediaType.ERROR));
//
// Error expected = Error.builder()
// .message("validation error on field 'id': String value has invalid format or length")
// .majorErrorCode(400)
// .minorErrorCode("BAD_REQUEST")
// .build();
//
// Reference orgRef = Reference.builder().href(orgUri).build();
// try {
// client.getOrgClient().getOrg(orgRef);
// 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 testWhenResponseIs403ForCatalogIdUsedAsOrgId() {
// URI orgUri = URI.create(endpoint + "/org/9e08c2f6-077a-42ce-bece-d5332e2ebb5c");
//
// VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
// getStandardRequest("GET", "/org/9e08c2f6-077a-42ce-bece-d5332e2ebb5c"),
// getStandardPayloadResponse(403, "/org/error403-catalog.xml", VCloudDirectorMediaType.ERROR));
//
// Error expected = Error.builder()
// .message("No access to entity \"com.vmware.vcloud.entity.org:9e08c2f6-077a-42ce-bece-d5332e2ebb5c\".")
// .majorErrorCode(403)
// .minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN")
// .build();
//
// Reference orgRef = Reference.builder().href(orgUri).build();
//
// try {
// client.getOrgClient().getOrg(orgRef);
// 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 testWhenResponseIs403ForFakeOrgId() {
// URI orgUri = URI.create(endpoint + "/org/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee");
//
// VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
// getStandardRequest("GET", "/org/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"),
// getStandardPayloadResponse(403, "/org/error403-fake.xml", VCloudDirectorMediaType.ERROR));
//
// Error expected = Error.builder()
// .message("No access to entity \"com.vmware.vcloud.entity.org:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee\".")
// .majorErrorCode(403)
// .minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN")
// .build();
//
// Reference orgRef = Reference.builder().href(orgUri).build();
//
// try {
// client.getOrgClient().getOrg(orgRef);
// 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 orgUri = URI.create(endpoint + "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0");
//
// VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
// getStandardRequest("GET", "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata"),
// getStandardPayloadResponse("/org/metadata.xml", VCloudDirectorMediaType.METADATA));
//
// Metadata expected = Metadata.builder()
// .type("application/vnd.vmware.vcloud.metadata+xml")
// .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata"))
// .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())
// .build();
//
// Reference orgRef = Reference.builder().href(orgUri).build();
//
// assertEquals(client.getOrgClient().getMetadata(orgRef), expected);
// }
//
// @Test(enabled=false) // No metadata in exemplar xml...
// public void testWhenResponseIs2xxLoginReturnsValidMetadata() {
// URI orgUri = URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0");
//
// VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
// getStandardRequest("GET", "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata/KEY"),
// getStandardPayloadResponse("/org/metadata.xml", VCloudDirectorMediaType.METADATA_ENTRY));
//
// MetadataEntry expected = MetadataEntry.builder()
// .key("KEY")
// .build();
//
// Reference orgRef = Reference.builder().href(orgUri).build();
//
// assertEquals(client.getOrgClient().getMetadataEntry(orgRef, "KEY"), expected);
// }
}

View File

@ -22,11 +22,11 @@ import java.util.Properties;
import org.jclouds.compute.BaseVersionedServiceLiveTest;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorAsyncClient;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.sshj.config.SshjSshClientModule;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorAsyncClient;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
@ -60,5 +60,4 @@ public class BaseVCloudDirectorClientLiveTest extends BaseVersionedServiceLiveTe
if (context != null)
context.close();
}
}

View File

@ -2,7 +2,7 @@
<Org xmlns="http://www.vmware.com/vcloud/v1.5" name="JClouds" id="urn:vcloud:org:6f312e42-cd2b-488d-a2bb-97519cd57ed0" type="application/vnd.vmware.vcloud.org+xml" href="https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0" 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="down" type="application/vnd.vmware.vcloud.vdc+xml" name="Cluster01-JClouds" href="https://vcloudbeta.bluelock.com/api/vdc/d16d333b-e3c0-4176-845d-a5ee6392df07"/>
<Link rel="down" type="application/vnd.vmware.vcloud.tasksList+xml" href="https://vcloudbeta.bluelock.com/api/tasksList/6f312e42-cd2b-488d-a2bb-97519cd57ed0"/>
<Link rel="down" type="application/vnd.vmware.vcloud.catalog+xml" name="Public" href="https://vcloudbeta.bluelock.com/api/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c"/>
<Link rel="down" type="application/vnd.vmware.vcloud.catalog+xml" name="Public" href="https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4"/>
<Link rel="down" type="application/vnd.vmware.vcloud.controlAccess+xml" href="https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c/controlAccess/"/>
<Link rel="down" type="application/vnd.vmware.vcloud.orgNetwork+xml" name="ilsolation01-Jclouds" href="https://vcloudbeta.bluelock.com/api/network/f3ba8256-6f48-4512-aad6-600e85b4dc38"/>
<Link rel="down" type="application/vnd.vmware.vcloud.orgNetwork+xml" name="internet01-Jclouds" href="https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c"/>