Fixing live test failures due to new enums and DMTF changes

This commit is contained in:
Andrew Donald Kennedy 2012-04-10 17:53:01 +01:00
parent ad1250984b
commit 4de062c636
17 changed files with 190 additions and 216 deletions

View File

@ -129,8 +129,9 @@ public class ControlAccessParams {
public ControlAccessParams(Boolean sharedToEveryone, String everyoneAccessLevel, Iterable<AccessSetting> accessSettings) { public ControlAccessParams(Boolean sharedToEveryone, String everyoneAccessLevel, Iterable<AccessSetting> accessSettings) {
this.sharedToEveryone = sharedToEveryone; this.sharedToEveryone = sharedToEveryone;
this.everyoneAccessLevel = everyoneAccessLevel;
if (sharedToEveryone) { if (sharedToEveryone) {
this.everyoneAccessLevel = checkNotNull(everyoneAccessLevel, "everyoneAccessLevel");
} else {
checkNotNull(accessSettings, "accessSettings"); checkNotNull(accessSettings, "accessSettings");
} }
this.accessSettings = Iterables.isEmpty(accessSettings) ? null : ImmutableList.copyOf(accessSettings); this.accessSettings = Iterables.isEmpty(accessSettings) ? null : ImmutableList.copyOf(accessSettings);

View File

@ -21,7 +21,7 @@ package org.jclouds.vcloud.director.v1_5.domain;
import static com.google.common.base.Objects.equal; import static com.google.common.base.Objects.equal;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Set; import java.util.List;
import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
@ -30,8 +30,8 @@ import javax.xml.bind.annotation.XmlType;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableList;
import com.google.common.collect.Sets; import com.google.common.collect.Lists;
/** /**
* Basic entity type in the vCloud object model. * Basic entity type in the vCloud object model.
@ -63,7 +63,7 @@ public class EntityType extends ResourceType {
public static abstract class Builder<B extends Builder<B>> extends ResourceType.Builder<B> { public static abstract class Builder<B extends Builder<B>> extends ResourceType.Builder<B> {
private String description; private String description;
private Set<Task> tasks = Sets.newLinkedHashSet(); private List<Task> tasks = Lists.newArrayList();
private String name; private String name;
private String id; private String id;
@ -95,7 +95,7 @@ public class EntityType extends ResourceType {
* @see EntityType#getTasks() * @see EntityType#getTasks()
*/ */
public B tasks(Iterable<Task> tasks) { public B tasks(Iterable<Task> tasks) {
this.tasks = Sets.newLinkedHashSet(checkNotNull(tasks, "tasks")); this.tasks = Lists.newArrayList(checkNotNull(tasks, "tasks"));
return self(); return self();
} }
@ -124,7 +124,7 @@ public class EntityType extends ResourceType {
private String description; private String description;
@XmlElementWrapper(name = "Tasks") @XmlElementWrapper(name = "Tasks")
@XmlElement(name = "Task") @XmlElement(name = "Task")
private Set<Task> tasks; private List<Task> tasks;
@XmlAttribute @XmlAttribute
private String id; private String id;
@XmlAttribute(required = true) @XmlAttribute(required = true)
@ -133,7 +133,7 @@ public class EntityType extends ResourceType {
protected EntityType(Builder<?> builder) { protected EntityType(Builder<?> builder) {
super(builder); super(builder);
this.description = builder.description; this.description = builder.description;
this.tasks = builder.tasks == null || builder.tasks.isEmpty() ? null : ImmutableSet.copyOf(builder.tasks); this.tasks = builder.tasks == null || builder.tasks.isEmpty() ? null : ImmutableList.copyOf(builder.tasks);
this.id = builder.id; this.id = builder.id;
this.name = builder.name; this.name = builder.name;
} }
@ -156,8 +156,8 @@ public class EntityType extends ResourceType {
/** /**
* A list of queued, running, or recently completed tasks associated with this entity. * A list of queued, running, or recently completed tasks associated with this entity.
*/ */
public Set<Task> getTasks() { public List<Task> getTasks() {
return tasks == null ? ImmutableSet.<Task>of() : ImmutableSet.copyOf(tasks); return tasks == null ? ImmutableList.<Task>of() : ImmutableList.copyOf(tasks);
} }
/** /**

View File

@ -69,6 +69,7 @@ public class Link extends Reference {
@XmlEnumValue("download:default") DOWNLOAD_DEFAULT("download:default"), @XmlEnumValue("download:default") DOWNLOAD_DEFAULT("download:default"),
@XmlEnumValue("edit") EDIT("edit"), @XmlEnumValue("edit") EDIT("edit"),
@XmlEnumValue("enable") ENABLE("enable"), @XmlEnumValue("enable") ENABLE("enable"),
@XmlEnumValue("entityResolver") ENTITY_RESOLVER("entityResolver"),
@XmlEnumValue("firstPage") FIRST_PAGE("firstPage"), @XmlEnumValue("firstPage") FIRST_PAGE("firstPage"),
@XmlEnumValue("installVmwareTools") INSTALL_VMWARE_TOOLS("installVmwareTools"), @XmlEnumValue("installVmwareTools") INSTALL_VMWARE_TOOLS("installVmwareTools"),
@XmlEnumValue("lastPage") LAST_PAGE("lastPage"), @XmlEnumValue("lastPage") LAST_PAGE("lastPage"),
@ -115,7 +116,7 @@ public class Link extends Reference {
ADD, ALTERNATE, CATALOG_ITEM, COLLABORATION_ABORT, ADD, ALTERNATE, CATALOG_ITEM, COLLABORATION_ABORT,
COLLABORATION_FAIL, COLLABORATION_RESUME, CONSOLIDATE, COLLABORATION_FAIL, COLLABORATION_RESUME, CONSOLIDATE,
CONTROL_ACCESS, COPY, DEPLOY, DISABLE, DISCARD_STATE, DOWN, CONTROL_ACCESS, COPY, DEPLOY, DISABLE, DISCARD_STATE, DOWN,
DOWNLOAD_ALTERNATE, DOWNLOAD_DEFAULT, EDIT, ENABLE, FIRST_PAGE, DOWNLOAD_ALTERNATE, DOWNLOAD_DEFAULT, EDIT, ENABLE, ENTITY_RESOLVER, FIRST_PAGE,
INSTALL_VMWARE_TOOLS, LAST_PAGE, EJECT_MEDIA, INSERT_MEDIA, MOVE, INSTALL_VMWARE_TOOLS, LAST_PAGE, EJECT_MEDIA, INSERT_MEDIA, MOVE,
NEXT_PAGE, OVA, OVF, POWER_OFF, POWER_ON, REBOOT, RESET, SHUTDOWN, NEXT_PAGE, OVA, OVF, POWER_OFF, POWER_ON, REBOOT, RESET, SHUTDOWN,
SUSPEND, PREVIOUS_PAGE, PUBLISH, RECOMPOSE, RECONNECT, REGISTER, SUSPEND, PREVIOUS_PAGE, PUBLISH, RECOMPOSE, RECONNECT, REGISTER,
@ -163,12 +164,20 @@ public class Link extends Reference {
public static class Builder<B extends Builder<B>> extends Reference.Builder<B> { public static class Builder<B extends Builder<B>> extends Reference.Builder<B> {
private String rel; private Rel rel;
/** /**
* @see Link#getRel() * @see Link#getRel()
*/ */
public B rel(String rel) { public B rel(String rel) {
this.rel = Rel.fromValue(rel);
return self();
}
/**
* @see Link#getRel()
*/
public B rel(Rel rel) {
this.rel = rel; this.rel = rel;
return self(); return self();
} }
@ -194,7 +203,7 @@ public class Link extends Reference {
} }
@XmlAttribute(required = true) @XmlAttribute(required = true)
private String rel; private Rel rel;
protected Link(Builder<?> builder) { protected Link(Builder<?> builder) {
super(builder); super(builder);
@ -213,7 +222,7 @@ public class Link extends Reference {
* *
* @return relationship of the link to the object that contains it. * @return relationship of the link to the object that contains it.
*/ */
public String getRel() { public Rel getRel() {
return rel; return rel;
} }

View File

@ -110,18 +110,26 @@ public class OrgLdapSettings extends ResourceType {
public static abstract class Builder<B extends Builder<B>> extends ResourceType.Builder<B> { public static abstract class Builder<B extends Builder<B>> extends ResourceType.Builder<B> {
private String ldapMode; private LdapMode ldapMode;
private String customUsersOu; private String customUsersOu;
private CustomOrgLdapSettings customOrgLdapSettings; private CustomOrgLdapSettings customOrgLdapSettings;
/** /**
* @see OrgLdapSettings#getLdapMode() * @see OrgLdapSettings#getLdapMode()
*/ */
public B ldapMode(String ldapMode) { public B ldapMode(LdapMode ldapMode) {
this.ldapMode = ldapMode; this.ldapMode = ldapMode;
return self(); return self();
} }
/**
* @see OrgLdapSettings#getLdapMode()
*/
public B ldapMode(String ldapMode) {
this.ldapMode = LdapMode.fromValue(ldapMode);
return self();
}
/** /**
* @see OrgLdapSettings#getCustomUsersOu() * @see OrgLdapSettings#getCustomUsersOu()
*/ */
@ -162,8 +170,8 @@ public class OrgLdapSettings extends ResourceType {
this.customOrgLdapSettings = builder.customOrgLdapSettings; this.customOrgLdapSettings = builder.customOrgLdapSettings;
} }
@XmlElement(name = "OrgLdapMode") @XmlElement(name = "OrgLdapMode")
private String ldapMode; private LdapMode ldapMode;
@XmlElement(name = "CustomUsersOu") @XmlElement(name = "CustomUsersOu")
private String customUsersOu; private String customUsersOu;
@XmlElement(name = "CustomOrgLdapSettings") @XmlElement(name = "CustomOrgLdapSettings")
@ -171,23 +179,13 @@ public class OrgLdapSettings extends ResourceType {
/** /**
* Gets the value of the orgLdapMode property. * Gets the value of the orgLdapMode property.
*
* @return
* possible object is
* {@link String }
*
*/ */
public String getLdapMode() { public LdapMode getLdapMode() {
return ldapMode; return ldapMode;
} }
/** /**
* Gets the value of the customUsersOu property. * Gets the value of the customUsersOu property.
*
* @return
* possible object is
* {@link String }
*
*/ */
public String getCustomUsersOu() { public String getCustomUsersOu() {
return customUsersOu; return customUsersOu;
@ -195,11 +193,6 @@ public class OrgLdapSettings extends ResourceType {
/** /**
* Gets the value of the customOrgLdapSettings property. * Gets the value of the customOrgLdapSettings property.
*
* @return
* possible object is
* {@link CustomOrgLdapSettings }
*
*/ */
public CustomOrgLdapSettings getCustomOrgLdapSettings() { public CustomOrgLdapSettings getCustomOrgLdapSettings() {
return customOrgLdapSettings; return customOrgLdapSettings;

View File

@ -27,6 +27,8 @@ import java.util.Set;
import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlEnumValue;
import javax.xml.bind.annotation.XmlType; import javax.xml.bind.annotation.XmlType;
import com.google.common.base.Objects; import com.google.common.base.Objects;
@ -49,27 +51,30 @@ import com.google.common.collect.Iterables;
@XmlType(name = "ResourceEntityType") @XmlType(name = "ResourceEntityType")
public abstract class ResourceEntityType extends EntityType { public abstract class ResourceEntityType extends EntityType {
@XmlType
@XmlEnum(Integer.class)
public static enum Status { public static enum Status {
FAILED_CREATION(-1, "The object could not be created.", true, true, true), @XmlEnumValue("-1") FAILED_CREATION(-1, "The object could not be created.", true, true, true),
NOT_READY(0, "Not ready", true, false, false), // TODO duplicate code, but mentioned in `POST /vdc/{id}/action/uploadVAppTemplate` @XmlEnumValue("0") UNRESOLVED(0, "The object is unresolved.", true, true, true),
UNRESOLVED(0, "The object is unresolved.", true, true, true), @XmlEnumValue("1") RESOLVED(1, "The object is resolved.", true, true, true),
RESOLVED(1, "The object is resolved.", true, true, true), @XmlEnumValue("2") DEPLOYED(2, "The object is deployed.", false, false, false),
DEPLOYED(2, "The object is deployed.", false, false, false), @XmlEnumValue("3") SUSPENDED(3, "The object is suspended.", false, true, true),
SUSPENDED(3, "The object is suspended.", false, true, true), @XmlEnumValue("4") POWERED_ON(4, "The object is powered on.", false, true, true),
POWERED_ON(4, "The object is powered on.", false, true, true), @XmlEnumValue("5") WAITING_FOR_INPUT(5, "The object is waiting for user input.", false, true, true),
WAITING_FOR_INPUT(5, "The object is waiting for user input.", false, true, true), @XmlEnumValue("6") UNKNOWN(6, "The object is in an unknown state.", true, true, true),
UNKNOWN(6, "The object is in an unknown state.", true, true, true), @XmlEnumValue("7") UNRECOGNIZED(7, "The object is in an unrecognized state.", true, true, true),
UNRECOGNIZED(7, "The object is in an unrecognized state.", true, true, true), @XmlEnumValue("8") POWERED_OFF(8, "The object is powered off.", true, true, true),
POWERED_OFF(8, "The object is powered off.", true, true, true), @XmlEnumValue("9") INCONSISTENT_STATE(9, "The object is in an inconsistent state.", false, true, true),
INCONSISTENT_STATE(9, "The object is in an inconsistent state.", false, true, true), @XmlEnumValue("10") MIXED(10, "Children do not all have the same status.", true, true, false),
MIXED(10, "Children do not all have the same status.", true, true, false), @XmlEnumValue("11") UPLOAD_OVF_PENDING(11, "Upload initiated, OVF descriptor pending.", true, false, false),
UPLOAD_OVF_PENDING(11, "Upload initiated, OVF descriptor pending.", true, false, false), @XmlEnumValue("12") UPLOAD_COPYING(12, "Upload initiated, copying contents.", true, false, false),
UPLOAD_COPYING(12, "Upload initiated, copying contents.", true, false, false), @XmlEnumValue("13") UPLOAD_DISK_PENDING(13, "Upload initiated , disk contents pending.", true, false, false),
UPLOAD_DISK_PENDING(13, "Upload initiated , disk contents pending.", true, false, false), @XmlEnumValue("14") UPLOAD_QUARANTINED(14, "Upload has been quarantined.", true, false, false),
UPLOAD_QUARANTINED(14, "Upload has been quarantined.", true, false, false), @XmlEnumValue("15") UPLOAD_QUARANTINE_EXPIRED(15, "Upload quarantine period has expired.", true, false, false),
UPLOAD_QUARANTINE_EXPIRED(15, "Upload quarantine period has expired.", true, false, false),
// TODO duplicate code, but mentioned in `POST /vdc/{id}/action/uploadVAppTemplate`
NOT_READY(0, "Not ready", true, false, false),
// Convention is "UNRECOGNIZED", but that is already a valid state name! so using UNRECOGNIZED_VALUE // Convention is "UNRECOGNIZED", but that is already a valid state name! so using UNRECOGNIZED_VALUE
UNRECOGNIZED_VALUE(404, "Unrecognized", false, false, false); UNRECOGNIZED_VALUE(404, "Unrecognized", false, false, false);
@ -137,7 +142,7 @@ public abstract class ResourceEntityType extends EntityType {
public static abstract class Builder<B extends Builder<B>> extends EntityType.Builder<B> { public static abstract class Builder<B extends Builder<B>> extends EntityType.Builder<B> {
private Set<File> files; private Set<File> files;
private Integer status; private Status status;
/** /**
* @see ResourceEntityType#getFiles() * @see ResourceEntityType#getFiles()
@ -150,11 +155,19 @@ public abstract class ResourceEntityType extends EntityType {
/** /**
* @see ResourceEntityType#getStatus() * @see ResourceEntityType#getStatus()
*/ */
public B status(Integer status) { public B status(Status status) {
this.status = status; this.status = status;
return self(); return self();
} }
/**
* @see ResourceEntityType#getStatus()
*/
public B status(Integer status) {
this.status = Status.fromValue(status);
return self();
}
public B fromResourceEntityType(ResourceEntityType in) { public B fromResourceEntityType(ResourceEntityType in) {
return fromEntityType(in).files(in.getFiles()).status(in.getStatus()); return fromEntityType(in).files(in.getFiles()).status(in.getStatus());
} }
@ -163,9 +176,8 @@ public abstract class ResourceEntityType extends EntityType {
@XmlElementWrapper(name = "Files") @XmlElementWrapper(name = "Files")
@XmlElement(name = "File") @XmlElement(name = "File")
private Set<File> files; private Set<File> files;
@XmlAttribute @XmlAttribute
private Integer status; private Status status;
public ResourceEntityType(Builder<?> builder) { public ResourceEntityType(Builder<?> builder) {
super(builder); super(builder);
@ -187,7 +199,7 @@ public abstract class ResourceEntityType extends EntityType {
/** /**
* Gets the value of the status property. * Gets the value of the status property.
*/ */
public Integer getStatus() { public Status getStatus() {
return status; return status;
} }

View File

@ -60,12 +60,19 @@ public class Task extends EntityType {
@XmlType @XmlType
@XmlEnum(String.class) @XmlEnum(String.class)
public static enum Status { public static enum Status {
/** The task has been queued for execution. */
@XmlEnumValue("queued") QUEUED("queued"), @XmlEnumValue("queued") QUEUED("queued"),
/** The task is awaiting preprocessing or, if it is a blocking task, administrative action. */
@XmlEnumValue("preRunning") PRE_RUNNING("preRunning"), @XmlEnumValue("preRunning") PRE_RUNNING("preRunning"),
/** The task is runnning.*/
@XmlEnumValue("running") RUNNING("running"), @XmlEnumValue("running") RUNNING("running"),
/** The task completed with a status of success. */
@XmlEnumValue("success") SUCCESS("success"), @XmlEnumValue("success") SUCCESS("success"),
/** The task encountered an error while running. */
@XmlEnumValue("error") ERROR("error"), @XmlEnumValue("error") ERROR("error"),
/** The task was canceled by the owner or an administrator. */
@XmlEnumValue("canceled") CANCELED("canceled"), @XmlEnumValue("canceled") CANCELED("canceled"),
/** The task was aborted by an administrative action. */
@XmlEnumValue("aborted") ABORTED("aborted"), @XmlEnumValue("aborted") ABORTED("aborted"),
UNRECOGNIZED("unrecognized"); UNRECOGNIZED("unrecognized");
@ -116,7 +123,7 @@ public class Task extends EntityType {
private Reference user; private Reference user;
private Object params; private Object params;
private Integer progress; private Integer progress;
private String status; private Status status;
private String operation; private String operation;
private String operationName; private String operationName;
private Date startTime; private Date startTime;
@ -175,6 +182,14 @@ public class Task extends EntityType {
* @see Task#getStatus() * @see Task#getStatus()
*/ */
public B status(String status) { public B status(String status) {
this.status = Status.fromValue(status);
return self();
}
/**
* @see Task#getStatus()
*/
public B status(Status status) {
this.status = status; this.status = status;
return self(); return self();
} }
@ -274,7 +289,7 @@ public class Task extends EntityType {
@XmlElement(name = "Params") @XmlElement(name = "Params")
private Object params; private Object params;
@XmlAttribute @XmlAttribute
private String status; private Status status;
@XmlAttribute @XmlAttribute
private String operation; private String operation;
@XmlAttribute @XmlAttribute
@ -333,19 +348,8 @@ public class Task extends EntityType {
/** /**
* The execution status of the task. * The execution status of the task.
*
* One of:
* <ul>
* <li>queued - The task has been queued for execution.
* <li>preRunning - The task is awaiting preprocessing or, if it is a blocking task, administrative action.
* <li>running - The task is runnning.
* <li>success - The task completed with a status of success.
* <li>error - The task encountered an error while running.
* <li>canceled - The task was canceled by the owner or an administrator.
* <li>aborted - The task was aborted by an administrative action.
* </ul>
*/ */
public String getStatus() { public Status getStatus() {
return status; return status;
} }

View File

@ -35,22 +35,28 @@ public class LinkPredicates {
/** /**
* matches links of the given relation * matches links of the given relation
* *
* @param rel * @param rel from {@code context.getApi().getCurrentSession().getOrg().getLinks()}
* ex. {@code context.getApi().getCurrentSession().getOrg().getLinks()}
* @return predicate that will match links of the given rel * @return predicate that will match links of the given rel
*/ */
public static Predicate<Link> relEquals(final String rel) { public static Predicate<Link> relEquals(final String rel) {
checkNotNull(rel, "rel must be defined"); checkNotNull(rel, "rel must be defined");
return relEquals(Link.Rel.fromValue(rel));
}
/** @see #relEquals(String) */
public static Predicate<Link> relEquals(final Link.Rel rel) {
checkNotNull(rel, "rel must be defined");
return new Predicate<Link>() { return new Predicate<Link>() {
@Override @Override
public boolean apply(Link link) { public boolean apply(Link link) {
return rel.equals(link.getRel()); return rel == link.getRel();
} }
@Override @Override
public String toString() { public String toString() {
return "relEquals(" + rel + ")"; return "relEquals(" + rel.value() + ")";
} }
}; };
} }

View File

@ -31,6 +31,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Task.Status;
import org.jclouds.vcloud.director.v1_5.features.TaskClient; import org.jclouds.vcloud.director.v1_5.features.TaskClient;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
/** /**
* Test a {@link Task} to see if it has succeeded. * Test a {@link Task} to see if it has succeeded.
@ -69,22 +70,17 @@ public class TaskStatusEquals implements Predicate<Task> {
if (task == null) return false; if (task == null) return false;
logger.trace("%s: looking for status %s: currently: %s", task, expectedStatuses, task.getStatus()); logger.trace("%s: looking for status %s: currently: %s", task, expectedStatuses, task.getStatus());
for (Status failingStatus : failingStatuses) { if (failingStatuses.contains(task.getStatus())) {
if (task.getStatus().equals(failingStatus)) { throw new VCloudDirectorException(task);
throw new VCloudDirectorException(task);
}
} }
if (expectedStatuses.contains(task.getStatus())) {
for (Status expectedStatus : expectedStatuses) { return true;
if (task.getStatus().equals(expectedStatus)) {
return true;
}
} }
return false; return false;
} }
@Override @Override
public String toString() { public String toString() {
return "checkTaskSuccess()"; return "taskStatusEquals(" + Iterables.toString(expectedStatuses) + ")";
} }
} }

View File

@ -251,7 +251,7 @@ public abstract class AbstractVAppClientLiveTest extends BaseVCloudDirectorClien
protected VApp powerOn(final URI testVAppURI) { protected VApp powerOn(final URI testVAppURI) {
VApp testVApp = vAppClient.getVApp(testVAppURI); VApp testVApp = vAppClient.getVApp(testVAppURI);
Vm vm = Iterables.getOnlyElement(testVApp.getChildren().getVms()); Vm vm = Iterables.getOnlyElement(testVApp.getChildren().getVms());
Status status = Status.fromValue(vm.getStatus()); Status status = vm.getStatus();
if (status != Status.POWERED_ON) { if (status != Status.POWERED_ON) {
Task powerOn = vAppClient.powerOn(vm.getHref()); Task powerOn = vAppClient.powerOn(vm.getHref());
assertTaskSucceedsLong(powerOn); assertTaskSucceedsLong(powerOn);
@ -275,7 +275,7 @@ public abstract class AbstractVAppClientLiveTest extends BaseVCloudDirectorClien
protected VApp powerOff(final URI testVAppURI) { protected VApp powerOff(final URI testVAppURI) {
VApp testVApp = vAppClient.getVApp(testVAppURI); VApp testVApp = vAppClient.getVApp(testVAppURI);
Vm vm = Iterables.getOnlyElement(testVApp.getChildren().getVms()); Vm vm = Iterables.getOnlyElement(testVApp.getChildren().getVms());
Status status = Status.fromValue(vm.getStatus()); Status status = vm.getStatus();
if (status != Status.POWERED_OFF) { if (status != Status.POWERED_OFF) {
Task powerOff = vAppClient.powerOff(vm.getHref()); Task powerOff = vAppClient.powerOff(vm.getHref());
assertTaskSucceedsLong(powerOff); assertTaskSucceedsLong(powerOff);
@ -299,7 +299,7 @@ public abstract class AbstractVAppClientLiveTest extends BaseVCloudDirectorClien
protected VApp suspend(final URI testVAppURI) { protected VApp suspend(final URI testVAppURI) {
VApp testVApp = vAppClient.getVApp(testVAppURI); VApp testVApp = vAppClient.getVApp(testVAppURI);
Vm vm = Iterables.getOnlyElement(testVApp.getChildren().getVms()); Vm vm = Iterables.getOnlyElement(testVApp.getChildren().getVms());
Status status = Status.fromValue(vm.getStatus()); Status status = vm.getStatus();
if (status != Status.SUSPENDED) { if (status != Status.SUSPENDED) {
Task suspend = vAppClient.suspend(vm.getHref()); Task suspend = vAppClient.suspend(vm.getHref());
assertTaskSucceedsLong(suspend); assertTaskSucceedsLong(suspend);
@ -314,7 +314,7 @@ public abstract class AbstractVAppClientLiveTest extends BaseVCloudDirectorClien
protected void assertVAppStatus(final URI testVAppURI, final Status status) { protected void assertVAppStatus(final URI testVAppURI, final Status status) {
VApp testVApp = vAppClient.getVApp(testVAppURI); VApp testVApp = vAppClient.getVApp(testVAppURI);
Vm vm = Iterables.getOnlyElement(testVApp.getChildren().getVms()); Vm vm = Iterables.getOnlyElement(testVApp.getChildren().getVms());
assertEquals(vm.getStatus(), status.getValue(), String.format(OBJ_FIELD_EQ, VAPP, "status", status.toString(), Status.fromValue(vm.getStatus()).toString())); assertEquals(vm.getStatus(), status, String.format(OBJ_FIELD_EQ, VAPP, "status", status.toString(), vm.getStatus().toString()));
} }
/** /**

View File

@ -42,6 +42,7 @@ import static org.testng.Assert.fail;
import java.net.URI; import java.net.URI;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
@ -96,7 +97,7 @@ public class Checks {
// Check optional fields // Check optional fields
// NOTE description cannot be checked // NOTE description cannot be checked
Set<Task> tasks = entity.getTasks(); List<Task> tasks = entity.getTasks();
if (tasks != null && tasks != null && !tasks.isEmpty()) { if (tasks != null && tasks != null && !tasks.isEmpty()) {
for (Task task : tasks) checkTask(task); for (Task task : tasks) checkTask(task);
} }
@ -133,12 +134,28 @@ public class Checks {
// NOTE name cannot be checked // NOTE name cannot be checked
} }
/**
* Assumes the validTypes to be vcloud-specific types.
*
* @see #checkResourceType(ResourceType, Collection)
*/
public static void checkResourceType(ResourceType resource) { public static void checkResourceType(ResourceType resource) {
checkResourceType(resource, VCloudDirectorMediaType.ALL);
}
/**
* @see #checkResourceType(ResourceType, Collection)
*/
public static void checkResourceType(ResourceType resource, String type) {
checkResourceType(resource, ImmutableSet.of(type));
}
public static void checkResourceType(ResourceType resource, Collection<String> validTypes) {
// Check optional fields // Check optional fields
URI href = resource.getHref(); URI href = resource.getHref();
if (href != null) checkHref(href); if (href != null) checkHref(href);
String type = resource.getType(); String type = resource.getType();
if (type != null) checkType(type); if (type != null) checkType(type, validTypes);
Set<Link> links = resource.getLinks(); Set<Link> links = resource.getLinks();
if (links != null && !links.isEmpty()) { if (links != null && !links.isEmpty()) {
for (Link link : links) checkLink(link); for (Link link : links) checkLink(link);
@ -286,6 +303,7 @@ public class Checks {
public static void checkAdminOrg(AdminOrg org) { public static void checkAdminOrg(AdminOrg org) {
// required // required
assertNotNull(org.getSettings(), String.format(NOT_NULL_OBJ_FIELD_FMT, "settings", "AdminOrg")); assertNotNull(org.getSettings(), String.format(NOT_NULL_OBJ_FIELD_FMT, "settings", "AdminOrg"));
checkResourceType(org, VCloudDirectorMediaType.ADMIN_ORG);
// optional // optional
for (Reference user : org.getUsers()) { for (Reference user : org.getUsers()) {
@ -298,7 +316,7 @@ public class Checks {
checkReferenceType(catalog, VCloudDirectorMediaType.ADMIN_CATALOG); checkReferenceType(catalog, VCloudDirectorMediaType.ADMIN_CATALOG);
} }
for (Reference vdc : org.getVdcs()) { for (Reference vdc : org.getVdcs()) {
checkReferenceType(vdc, VCloudDirectorMediaType.ADMIN_VDC); checkReferenceType(vdc, VCloudDirectorMediaType.VDC);
} }
for (Reference network : org.getNetworks()) { for (Reference network : org.getNetworks()) {
checkReferenceType(network, VCloudDirectorMediaType.ADMIN_NETWORK); checkReferenceType(network, VCloudDirectorMediaType.ADMIN_NETWORK);
@ -841,7 +859,7 @@ public class Checks {
// NOTE customUsersOu cannot be checked // NOTE customUsersOu cannot be checked
if (settings.getLdapMode() != null) { if (settings.getLdapMode() != null) {
assertTrue(LdapMode.ALL.contains(settings.getLdapMode()), assertTrue(LdapMode.ALL.contains(settings.getLdapMode()),
String.format(REQUIRED_VALUE_OBJECT_FMT, "LdapMode", "OrdLdapSettings", settings.getLdapMode(), String.format(REQUIRED_VALUE_OBJECT_FMT, "LdapMode", "OrgLdapSettings", settings.getLdapMode(),
Iterables.toString(OrgLdapSettings.LdapMode.ALL))); Iterables.toString(OrgLdapSettings.LdapMode.ALL)));
} }
if (settings.getCustomOrgLdapSettings() != null) { if (settings.getCustomOrgLdapSettings() != null) {

View File

@ -177,8 +177,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
Checks.checkMediaFor(MEDIA, media); Checks.checkMediaFor(MEDIA, media);
} }
@Test(description = "GET /media/{id}/owner", @Test(description = "GET /media/{id}/owner", dependsOnMethods = { "testGetMedia" })
dependsOnMethods = { "testGetMedia" })
public void testGetMediaOwner() { public void testGetMediaOwner() {
Owner directOwner = mediaClient.getOwner(media.getHref()); Owner directOwner = mediaClient.getOwner(media.getHref());
assertEquals(owner.toBuilder() assertEquals(owner.toBuilder()
@ -196,8 +195,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
Checks.checkReferenceType(directOwner.getUser()); Checks.checkReferenceType(directOwner.getUser());
} }
@Test(description = "POST /vdc/{id}/action/cloneMedia", @Test(description = "POST /vdc/{id}/action/cloneMedia", dependsOnMethods = { "testGetMediaOwner" })
dependsOnMethods = { "testGetMediaOwner" })
public void testCloneMedia() { public void testCloneMedia() {
oldMedia = media; oldMedia = media;
media = vdcClient.cloneMedia(vdcURI, CloneMediaParams.builder() media = vdcClient.cloneMedia(vdcURI, CloneMediaParams.builder()
@ -246,8 +244,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
media.toString(), oldMedia.toString())); media.toString(), oldMedia.toString()));
} }
@Test(description = "PUT /media/{id}", @Test(description = "PUT /media/{id}", dependsOnMethods = { "testCloneMedia" })
dependsOnMethods = { "testCloneMedia" })
public void testSetMedia() { public void testSetMedia() {
String oldName = media.getName(); String oldName = media.getName();
String newName = "new "+oldName; String newName = "new "+oldName;
@ -276,8 +273,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
media = mediaClient.getMedia(media.getHref()); media = mediaClient.getMedia(media.getHref());
} }
@Test(description = "GET /media/{id}/metadata", @Test(description = "GET /media/{id}/metadata", dependsOnMethods = { "testSetMetadataValue" })
dependsOnMethods = { "testSetMetadataValue" })
public void testGetMetadata() { public void testGetMetadata() {
metadata = mediaClient.getMetadataClient().getMetadata(media.getHref()); metadata = mediaClient.getMetadataClient().getMetadata(media.getHref());
// required for testing // required for testing
@ -287,8 +283,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
Checks.checkMetadataFor(MEDIA, metadata); Checks.checkMetadataFor(MEDIA, metadata);
} }
@Test(description = "POST /media/{id}/metadata", @Test(description = "POST /media/{id}/metadata", dependsOnMethods = { "testGetMedia" })
dependsOnMethods = { "testGetMedia" })
public void testMergeMetadata() { public void testMergeMetadata() {
// test new // test new
Set<MetadataEntry> inputEntries = ImmutableSet.of(MetadataEntry.builder().entry("testKey", "testValue").build()); Set<MetadataEntry> inputEntries = ImmutableSet.of(MetadataEntry.builder().entry("testKey", "testValue").build());
@ -340,15 +335,13 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
} }
} }
@Test(description = "GET /media/{id}/metadata/{key}", @Test(description = "GET /media/{id}/metadata/{key}", dependsOnMethods = { "testSetMetadataValue" })
dependsOnMethods = { "testSetMetadataValue" })
public void testGetMetadataValue() { public void testGetMetadataValue() {
metadataValue = mediaClient.getMetadataClient().getMetadataValue(media.getHref(), "key"); metadataValue = mediaClient.getMetadataClient().getMetadataValue(media.getHref(), "key");
Checks.checkMetadataValueFor(MEDIA, metadataValue); Checks.checkMetadataValueFor(MEDIA, metadataValue);
} }
@Test(description = "PUT /media/{id}/metadata/{key}", @Test(description = "PUT /media/{id}/metadata/{key}", dependsOnMethods = { "testMergeMetadata" })
dependsOnMethods = { "testMergeMetadata" })
public void testSetMetadataValue() { public void testSetMetadataValue() {
metadataEntryValue = "value"; metadataEntryValue = "value";
MetadataValue newValue = MetadataValue.builder().value(metadataEntryValue).build(); MetadataValue newValue = MetadataValue.builder().value(metadataEntryValue).build();
@ -361,35 +354,17 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
Checks.checkMetadataValueFor(MEDIA, metadataValue); Checks.checkMetadataValueFor(MEDIA, metadataValue);
} }
@Test(description = "DELETE /media/{id}/metadata/{key}", @Test(description = "DELETE /media/{id}/metadata/{key}", dependsOnMethods = { "testGetMetadata", "testGetMetadataValue" } )
dependsOnMethods = { "testGetMetadata", "testGetMetadataValue" } )
public void testDeleteMetadata() { public void testDeleteMetadata() {
Task deleteMetadataEntry = mediaClient.getMetadataClient().deleteMetadataEntry(media.getHref(), "testKey"); Task deleteMetadataEntry = mediaClient.getMetadataClient().deleteMetadataEntry(media.getHref(), "testKey");
Checks.checkTask(deleteMetadataEntry); Checks.checkTask(deleteMetadataEntry);
assertTrue(retryTaskSuccess.apply(deleteMetadataEntry), assertTrue(retryTaskSuccess.apply(deleteMetadataEntry),
String.format(TASK_COMPLETE_TIMELY, "deleteMetadataEntry")); String.format(TASK_COMPLETE_TIMELY, "deleteMetadataEntry"));
Error expected = Error.builder() metadataValue = mediaClient.getMetadataClient().getMetadataValue(media.getHref(), "testKey");
.message("The access to the resource metadata_item with id testKey is forbidden") assertNull(metadataValue, String.format(OBJ_FIELD_ATTRB_DEL, MEDIA,
.majorErrorCode(403) "Metadata", metadataValue != null ? metadataValue.toString() : "",
.minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN") "MetadataEntry", metadataValue != null ? metadataValue.toString() : ""));
.build();
try {
metadataValue = mediaClient.getMetadataClient().getMetadataValue(media.getHref(), "testKey");
fail("Should give HTTP 403 error");
} catch (VCloudDirectorException vde) {
assertEquals(vde.getError(), expected);
metadataValue = null;
} catch (Exception e) {
fail("Should have thrown a VCloudDirectorException");
}
if (metadataValue != null) { // guard against NPE on the .toStrings
assertNull(metadataValue, String.format(OBJ_FIELD_ATTRB_DEL, MEDIA,
"Metadata", metadataValue.toString(),
"metadataEntry", metadataValue.toString()));
}
metadataValue = mediaClient.getMetadataClient().getMetadataValue(media.getHref(), "key"); metadataValue = mediaClient.getMetadataClient().getMetadataValue(media.getHref(), "key");
Checks.checkMetadataValueFor(MEDIA, metadataValue); Checks.checkMetadataValueFor(MEDIA, metadataValue);
@ -398,40 +373,19 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
Checks.checkMediaFor(MEDIA, media); Checks.checkMediaFor(MEDIA, media);
} }
@Test(description = "DELETE /media/{id}", @Test(description = "DELETE /media/{id}", dependsOnMethods = { "testDeleteMetadata" } )
dependsOnMethods = { "testDeleteMetadata" } )
public void testDeleteMedia() { public void testDeleteMedia() {
Task deleteMedia = mediaClient.deleteMedia(media.getHref()); Task deleteMedia = mediaClient.deleteMedia(media.getHref());
Checks.checkTask(deleteMedia); Checks.checkTask(deleteMedia);
assertTrue(retryTaskSuccess.apply(deleteMedia), assertTrue(retryTaskSuccess.apply(deleteMedia),
String.format(TASK_COMPLETE_TIMELY, "deleteMedia")); String.format(TASK_COMPLETE_TIMELY, "deleteMedia"));
Error expected = Error.builder() media = mediaClient.getMedia(media.getHref());
.message(String.format( assertNull(media, String.format(OBJ_DEL, MEDIA, media != null ? media.toString() : ""));
"No access to entity \"(com.vmware.vcloud.entity.media:%s)\".",
media.getId().substring("urn:vcloud:media:".length())))
.majorErrorCode(403)
.minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN")
.build();
try {
media = mediaClient.getMedia(media.getHref());
fail("Should give HTTP 403 error");
} catch (VCloudDirectorException vde) {
assertEquals(vde.getError(), expected);
media = null;
} catch (Exception e) {
fail("Should have thrown a VCloudDirectorException");
}
if (media != null) { // guard against NPE on the .toStrings
assertNull(metadataValue, String.format(OBJ_DEL, MEDIA, media.toString()));
}
deleteMedia = mediaClient.deleteMedia(oldMedia.getHref()); deleteMedia = mediaClient.deleteMedia(oldMedia.getHref());
Checks.checkTask(deleteMedia); Checks.checkTask(deleteMedia);
assertTrue(retryTaskSuccess.apply(deleteMedia), assertTrue(retryTaskSuccess.apply(deleteMedia), String.format(TASK_COMPLETE_TIMELY, "deleteMedia"));
String.format(TASK_COMPLETE_TIMELY, "deleteMedia"));
oldMedia = null; oldMedia = null;
} }
} }

View File

@ -166,7 +166,7 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
if (media.getTasks().size() == 1) { if (media.getTasks().size() == 1) {
Task uploadTask = Iterables.getOnlyElement(media.getTasks()); Task uploadTask = Iterables.getOnlyElement(media.getTasks());
Checks.checkTask(uploadTask); Checks.checkTask(uploadTask);
assertEquals(uploadTask.getStatus(), "running"); assertEquals(uploadTask.getStatus(), Task.Status.RUNNING);
assertTrue(retryTaskSuccess.apply(uploadTask), String.format(TASK_COMPLETE_TIMELY, "uploadTask")); assertTrue(retryTaskSuccess.apply(uploadTask), String.format(TASK_COMPLETE_TIMELY, "uploadTask"));
media = context.getApi().getMediaClient().getMedia(media.getHref()); media = context.getApi().getMediaClient().getMedia(media.getHref());
} }
@ -184,6 +184,7 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
} }
} }
@Override
@AfterClass(alwaysRun = true) @AfterClass(alwaysRun = true)
public void cleanUp() { public void cleanUp() {
if (adminContext != null && mediaURI != null) { if (adminContext != null && mediaURI != null) {

View File

@ -35,15 +35,18 @@ import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkVAppTemplate;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.metadataToMap; import static org.jclouds.vcloud.director.v1_5.domain.Checks.metadataToMap;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail; import static org.testng.Assert.fail;
import java.net.URI; import java.net.URI;
import java.util.EnumSet;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.jclouds.dmtf.ovf.NetworkSection; import org.jclouds.dmtf.ovf.NetworkSection;
import org.jclouds.vcloud.director.v1_5.AbstractVAppClientLiveTest; import org.jclouds.vcloud.director.v1_5.AbstractVAppClientLiveTest;
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.Checks;
import org.jclouds.vcloud.director.v1_5.domain.CloneVAppTemplateParams; import org.jclouds.vcloud.director.v1_5.domain.CloneVAppTemplateParams;
import org.jclouds.vcloud.director.v1_5.domain.CustomizationSection; import org.jclouds.vcloud.director.v1_5.domain.CustomizationSection;
@ -51,6 +54,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Envelope;
import org.jclouds.vcloud.director.v1_5.domain.GuestCustomizationSection; import org.jclouds.vcloud.director.v1_5.domain.GuestCustomizationSection;
import org.jclouds.vcloud.director.v1_5.domain.LeaseSettingsSection; import org.jclouds.vcloud.director.v1_5.domain.LeaseSettingsSection;
import org.jclouds.vcloud.director.v1_5.domain.Link; import org.jclouds.vcloud.director.v1_5.domain.Link;
import org.jclouds.vcloud.director.v1_5.domain.Link.Rel;
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.MetadataValue;
@ -69,6 +73,7 @@ import org.testng.annotations.AfterClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
@ -404,11 +409,8 @@ public class VAppTemplateClientLiveTest extends AbstractVAppClientLiveTest {
retryTaskSuccess.apply(task); retryTaskSuccess.apply(task);
// Confirm that can't access post-delete, i.e. template has been deleted // Confirm that can't access post-delete, i.e. template has been deleted
try { VAppTemplate deleted = vAppTemplateClient.getVAppTemplate(clonedVappTemplate.getHref());
vAppTemplateClient.getVAppTemplate(clonedVappTemplate.getHref()); assertNull(deleted);
} catch (VCloudDirectorException e) {
// success; should get a 403 because vAppTemplate no longer exists
}
} }
@Test(description = "POST /vAppTemplate/{id}/action/disableDownload") @Test(description = "POST /vAppTemplate/{id}/action/disableDownload")
@ -418,11 +420,10 @@ public class VAppTemplateClientLiveTest extends AbstractVAppClientLiveTest {
// TODO Check that it really is disabled. The only thing I can see for determining this // TODO Check that it really is disabled. The only thing I can see for determining this
// is the undocumented "download" link in the VAppTemplate. But that is brittle and we // is the undocumented "download" link in the VAppTemplate. But that is brittle and we
// don't know what timing guarantees there are for adding/removing the link. // don't know what timing guarantees there are for adding/removing the link.
// VAppTemplate vAppTemplate = vAppTemplateClient.getVAppTemplate(vAppTemplateURI);
// For example: Set<Link> links = vAppTemplate.getLinks();
// VAppTemplate vAppTemplate = vAppTemplateClient.getVAppTemplate(vAppTemplateURI); assertTrue(Iterables.all(Iterables.transform(links, rel), Predicates.not(Predicates.in(EnumSet.of(Link.Rel.DOWNLOAD_DEFAULT, Link.Rel.DOWNLOAD_ALTERNATE)))),
// Set<Link> links = vAppTemplate.getLinks(); "Should not offer download link after disabling download: "+vAppTemplate);
// assertFalse(hasLinkMatchingRel(links, "download.*"), "Should not offer download link after disabling download: "+vAppTemplate);
} }
@Test(description = "POST /vAppTemplate/{id}/action/enableDownload") @Test(description = "POST /vAppTemplate/{id}/action/enableDownload")
@ -435,22 +436,18 @@ public class VAppTemplateClientLiveTest extends AbstractVAppClientLiveTest {
// TODO Check that it really is enabled. The only thing I can see for determining this // TODO Check that it really is enabled. The only thing I can see for determining this
// is the undocumented "download" link in the VAppTemplate. But that is brittle and we // is the undocumented "download" link in the VAppTemplate. But that is brittle and we
// don't know what timing guarantees there are for adding/removing the link. // don't know what timing guarantees there are for adding/removing the link.
// VAppTemplate vAppTemplate = vAppTemplateClient.getVAppTemplate(vAppTemplateURI);
// For example: Set<Link> links = vAppTemplate.getLinks();
// VAppTemplate vAppTemplate = vAppTemplateClient.getVAppTemplate(vAppTemplateURI); assertTrue(Iterables.any(Iterables.transform(links, rel), Predicates.in(EnumSet.of(Link.Rel.DOWNLOAD_DEFAULT, Link.Rel.DOWNLOAD_ALTERNATE))),
// Set<Link> links = vAppTemplate.getLinks(); "Should offer download link after enabling download: "+vAppTemplate);
// assertTrue(hasLinkMatchingRel(links, "download.*"), "Should offer download link after enabling download: "+vAppTemplate);
} }
@SuppressWarnings("unused") private Function<Link, Link.Rel> rel = new Function<Link, Link.Rel>() {
private boolean hasLinkMatchingRel(Set<Link> links, String regex) { @Override
for (Link link : links) { public Rel apply(Link input) {
if (link.getRel() != null && link.getRel().matches(regex)) { return input.getRel();
return true;
}
} }
return false; };
}
@Test(description = "POST /vAppTemplate/{id}/action/consolidate") @Test(description = "POST /vAppTemplate/{id}/action/consolidate")
public void testConsolidateVAppTemplate() throws Exception { public void testConsolidateVAppTemplate() throws Exception {
@ -490,11 +487,11 @@ public class VAppTemplateClientLiveTest extends AbstractVAppClientLiveTest {
// Ask the VAppTemplate for its tasks, and the status of the matching task if it exists // Ask the VAppTemplate for its tasks, and the status of the matching task if it exists
VAppTemplate vAppTemplate = vAppTemplateClient.getVAppTemplate(vAppTemplateURI); VAppTemplate vAppTemplate = vAppTemplateClient.getVAppTemplate(vAppTemplateURI);
Set<Task> tasks = vAppTemplate.getTasks(); List<Task> tasks = vAppTemplate.getTasks();
for (Task contender : tasks) { for (Task contender : tasks) {
if (task.getId().equals(contender.getId())) { if (task.getId().equals(contender.getId())) {
String status = contender.getStatus(); Task.Status status = contender.getStatus();
if (status.equals(Task.Status.QUEUED) || status.equals(Task.Status.PRE_RUNNING) || status.equals(Task.Status.RUNNING)) { if (EnumSet.of(Task.Status.QUEUED, Task.Status.PRE_RUNNING, Task.Status.RUNNING).contains(status)) {
fail("Task "+contender+" reported complete, but is included in VAppTemplate in status "+status); fail("Task "+contender+" reported complete, but is included in VAppTemplate in status "+status);
} }
} }

View File

@ -305,8 +305,8 @@ public class VdcClientLiveTest extends BaseVCloudDirectorClientLiveTest {
String.format(OBJ_FIELD_EQ, "VAppTemplate", "name", name, uploadedVAppTemplate.getName())); String.format(OBJ_FIELD_EQ, "VAppTemplate", "name", name, uploadedVAppTemplate.getName()));
ResourceEntityType.Status expectedStatus = ResourceEntityType.Status.NOT_READY; ResourceEntityType.Status expectedStatus = ResourceEntityType.Status.NOT_READY;
Integer actualStatus = uploadedVAppTemplate.getStatus(); ResourceEntityType.Status actualStatus = uploadedVAppTemplate.getStatus();
assertEquals(actualStatus, expectedStatus.getValue(), assertEquals(actualStatus, expectedStatus,
String.format(OBJ_FIELD_EQ, "VAppTemplate", "status", expectedStatus, actualStatus)); String.format(OBJ_FIELD_EQ, "VAppTemplate", "status", expectedStatus, actualStatus));
} }

View File

@ -107,23 +107,20 @@ public class AdminCatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest
// FIXME: documentation suggests we should wait for a task here // FIXME: documentation suggests we should wait for a task here
} }
@Test(description = "GET /admin/catalog/{id}", @Test(description = "GET /admin/catalog/{id}", dependsOnMethods = { "testCreateCatalog" })
dependsOnMethods = { "testCreateCatalog" })
public void testGetCatalog() { public void testGetCatalog() {
catalog = catalogClient.getCatalog(catalog.getHref()); catalog = catalogClient.getCatalog(catalog.getHref());
Checks.checkAdminCatalog(catalog); Checks.checkAdminCatalog(catalog);
} }
@Test(description = "GET /admin/catalog/{id}/owner", @Test(description = "GET /admin/catalog/{id}/owner", dependsOnMethods = { "testGetCatalog" })
dependsOnMethods = { "testGetCatalog" })
public void testGetCatalogOwner() { public void testGetCatalogOwner() {
owner = catalogClient.getOwner(catalog.getHref()); owner = catalogClient.getOwner(catalog.getHref());
Checks.checkOwner(owner); Checks.checkOwner(owner);
} }
@Test(description = "PUT /admin/catalog/{id}/owner", @Test(description = "PUT /admin/catalog/{id}/owner", dependsOnMethods = { "testGetCatalog" })
dependsOnMethods = { "testGetCatalog" })
public void updateCatalogOwner() { public void updateCatalogOwner() {
User newOwnerUser = randomTestUser("testUpdateCatalogOwner"); User newOwnerUser = randomTestUser("testUpdateCatalogOwner");
newOwnerUser = adminContext.getApi().getUserClient().createUser(orgRef.getHref(), newOwnerUser); newOwnerUser = adminContext.getApi().getUserClient().createUser(orgRef.getHref(), newOwnerUser);
@ -187,8 +184,8 @@ public class AdminCatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest
} }
} }
@Test(description = "POST /admin/catalog/{id}/action/publish", // FIXME fails with a 403
dependsOnMethods = { "testUpdateCatalog" } ) // FIXME: fails with a 403 @Test(description = "POST /admin/catalog/{id}/action/publish", dependsOnMethods = { "testUpdateCatalog" } )
public void testPublishCatalog() { public void testPublishCatalog() {
assertNotNull(catalog, String.format(NOT_NULL_OBJ_FMT, "Catalog")); assertNotNull(catalog, String.format(NOT_NULL_OBJ_FMT, "Catalog"));
assertTrue(!catalog.isPublished(), String.format(OBJ_FIELD_EQ, assertTrue(!catalog.isPublished(), String.format(OBJ_FIELD_EQ,
@ -205,8 +202,7 @@ public class AdminCatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest
CATALOG, "isPublished", true, catalog.isPublished())); CATALOG, "isPublished", true, catalog.isPublished()));
} }
@Test(description = "DELETE /admin/catalog/{id}", @Test(description = "DELETE /admin/catalog/{id}", dependsOnMethods = { "testCreateCatalog" } )
dependsOnMethods = { "testCreateCatalog" } )
public void testDeleteCatalog() { public void testDeleteCatalog() {
// assertEquals(catalog.getCatalogItems().getCatalogItems().size(), 0, // assertEquals(catalog.getCatalogItems().getCatalogItems().size(), 0,
// String.format(OBJ_FIELD_EMPTY_TO_DELETE, "Catalog", "CatalogItems", // String.format(OBJ_FIELD_EMPTY_TO_DELETE, "Catalog", "CatalogItems",
@ -218,25 +214,7 @@ public class AdminCatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest
deleteCatalog = catalogClient.createCatalog(orgRef.getHref(), deleteCatalog); deleteCatalog = catalogClient.createCatalog(orgRef.getHref(), deleteCatalog);
catalogClient.deleteCatalog(deleteCatalog.getHref()); catalogClient.deleteCatalog(deleteCatalog.getHref());
Error expected = Error.builder() deleteCatalog = catalogClient.getCatalog(deleteCatalog.getHref());
.message("No access to entity \"(com.vmware.vcloud.entity.catalog:"+ assertNull(deleteCatalog, String.format(OBJ_DEL, CATALOG, deleteCatalog != null ? deleteCatalog.toString() : ""));
deleteCatalog.getId().substring("urn:vcloud:catalog:".length())+")\".")
.majorErrorCode(403)
.minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN")
.build();
try {
deleteCatalog = catalogClient.getCatalog(deleteCatalog.getHref());
fail("Should give HTTP 403 error");
} catch (VCloudDirectorException vde) {
assertEquals(vde.getError(), expected);
deleteCatalog = null;
} catch (Exception e) {
fail("Should have thrown a VCloudDirectorException");
}
if (deleteCatalog != null) { // guard against NPE on the .toStrings
assertNull(deleteCatalog, String.format(OBJ_DEL, CATALOG, deleteCatalog.toString()));
}
} }
} }

View File

@ -303,7 +303,7 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ
assertTrue(retryTaskSuccessLong.apply(task), String.format(TASK_COMPLETE_TIMELY, task)); assertTrue(retryTaskSuccessLong.apply(task), String.format(TASK_COMPLETE_TIMELY, task));
} }
protected void assertTaskStatusEventually(Task task, org.jclouds.vcloud.director.v1_5.domain.Task.Status running, ImmutableSet<org.jclouds.vcloud.director.v1_5.domain.Task.Status> immutableSet) { protected void assertTaskStatusEventually(Task task, Task.Status running, ImmutableSet<Task.Status> immutableSet) {
TaskClient taskClient = context.getApi().getTaskClient(); TaskClient taskClient = context.getApi().getTaskClient();
TaskStatusEquals predicate = new TaskStatusEquals(taskClient, running, immutableSet); TaskStatusEquals predicate = new TaskStatusEquals(taskClient, running, immutableSet);
RetryablePredicate<Task> retryablePredicate = new RetryablePredicate<Task>(predicate, TASK_TIMEOUT_SECONDS * 1000L); RetryablePredicate<Task> retryablePredicate = new RetryablePredicate<Task>(predicate, TASK_TIMEOUT_SECONDS * 1000L);

View File

@ -39,6 +39,11 @@ public class LinkPredicatesTest {
@Test @Test
public void testRelEqualsWhenEqual() { public void testRelEqualsWhenEqual() {
assert relEquals(Link.Rel.ADD).apply(ref);
}
@Test
public void testRelEqualsWhenEqualString() {
assert relEquals("add").apply(ref); assert relEquals("add").apply(ref);
} }