From 5e44ad39c293bdfaf279c02ab9310d6f16995261 Mon Sep 17 00:00:00 2001 From: danikov Date: Tue, 10 Apr 2012 14:03:22 +0100 Subject: [PATCH] xml enum annotation --- .../v1_5/domain/CustomOrgLdapSettings.java | 97 ++++++++--- .../vcloud/director/v1_5/domain/Error.java | 32 ++-- .../vcloud/director/v1_5/domain/Link.java | 161 ++++++++++-------- .../vcloud/director/v1_5/domain/Media.java | 52 +++++- .../vcloud/director/v1_5/domain/Network.java | 54 ++++-- .../v1_5/domain/NetworkConfiguration.java | 12 +- .../v1_5/domain/NetworkConnection.java | 46 +++-- .../director/v1_5/domain/OrgLdapSettings.java | 52 ++++-- .../vcloud/director/v1_5/domain/Role.java | 62 +++++-- .../vcloud/director/v1_5/domain/Task.java | 58 +++++-- .../v1_5/domain/UndeployVAppParams.java | 53 ++++-- .../v1_5/predicates/TaskStatusEquals.java | 15 +- .../vcloud/director/v1_5/domain/Checks.java | 8 +- .../v1_5/features/MediaClientExpectTest.java | 11 +- .../features/NetworkClientExpectTest.java | 3 +- .../VAppTemplateClientExpectTest.java | 3 +- .../v1_5/features/VdcClientExpectTest.java | 3 +- .../v1_5/features/VdcClientLiveTest.java | 3 +- .../features/admin/UserClientLiveTest.java | 2 +- .../BaseVCloudDirectorClientLiveTest.java | 10 +- .../internal/VCloudDirectorTestSession.java | 2 +- 21 files changed, 505 insertions(+), 234 deletions(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CustomOrgLdapSettings.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CustomOrgLdapSettings.java index 680948a69e..fea50b3925 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CustomOrgLdapSettings.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CustomOrgLdapSettings.java @@ -19,15 +19,22 @@ package org.jclouds.vcloud.director.v1_5.domain; import static com.google.common.base.Objects.equal; +import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Arrays; import java.util.List; +import java.util.Map; import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlEnumValue; import javax.xml.bind.annotation.XmlType; +import com.google.common.base.Function; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Maps; /** * Used when OrgLdapMode=CUSTOM to define connection details for @@ -76,34 +83,74 @@ import com.google.common.base.Objects.ToStringHelper; "groupAttributes" }) public class CustomOrgLdapSettings { - public static final class AuthenticationMechanism { - public static final String SIMPLE = "simple"; - public static final String KERBEROS = "kerberos"; - public static final String MD5DIGEST = "md5digest"; - public static final String NTLM = "ntlm"; + @XmlType + @XmlEnum(String.class) + public static enum AuthenticationMechanism { + @XmlEnumValue("simple") SIMPLE("simple"), + @XmlEnumValue("kerberos") KERBEROS("kerberos"), + @XmlEnumValue("md5digest") MD5DIGEST("md5digest"), + @XmlEnumValue("ntlm") NTLM("ntlm"), + UNRECOGNIZED("unrecognized"); + + public static final List ALL = ImmutableList.of( + SIMPLE, KERBEROS, MD5DIGEST, NTLM); - /** - * All acceptable {@link CustomOrgLdapSettings#getAuthenticationMechanism()} values. - *

- * This list must be updated whenever a new authentication mechanism is added. - */ - public static final List ALL = Arrays.asList( - SIMPLE, KERBEROS, MD5DIGEST, NTLM - ); + protected final String stringValue; + + AuthenticationMechanism(String stringValue) { + this.stringValue = stringValue; + } + + public String value() { + return stringValue; + } + + protected final static Map AUTHENTICATION_MECHANISM_BY_ID = Maps.uniqueIndex( + ImmutableSet.copyOf(AuthenticationMechanism.values()), new Function() { + @Override + public String apply(AuthenticationMechanism input) { + return input.stringValue; + } + }); + + public static AuthenticationMechanism fromValue(String value) { + AuthenticationMechanism authMechanism = AUTHENTICATION_MECHANISM_BY_ID.get(checkNotNull(value, "stringValue")); + return authMechanism == null ? UNRECOGNIZED : authMechanism; + } } - public static final class ConnectorType { - public static final String ACTIVE_DIRECTORY = "ACTIVE_DIRECTORY"; - public static final String OPEN_LDAP = "OPEN_LDAP"; + @XmlType + @XmlEnum(String.class) + public static enum ConnectorType { + @XmlEnumValue("ACTIVE_DIRECTORY") ACTIVE_DIRECTORY("ACTIVE_DIRECTORY"), + @XmlEnumValue("OPEN_LDAP") OPEN_LDAP("OPEN_LDAP"), + UNRECOGNIZED("unrecognized"); + + public static final List ALL = ImmutableList.of( + ACTIVE_DIRECTORY, OPEN_LDAP); - /** - * All acceptable {@link OrgLdapSettings#getLdapMode()} values. - *

- * This list must be updated whenever a new mode is added. - */ - public static final List ALL = Arrays.asList( - ACTIVE_DIRECTORY, OPEN_LDAP - ); + protected final String stringValue; + + ConnectorType(String stringValue) { + this.stringValue = stringValue; + } + + public String value() { + return stringValue; + } + + protected final static Map CONNECTOR_TYPE_BY_ID = Maps.uniqueIndex( + ImmutableSet.copyOf(ConnectorType.values()), new Function() { + @Override + public String apply(ConnectorType input) { + return input.stringValue; + } + }); + + public static ConnectorType fromValue(String value) { + ConnectorType type = CONNECTOR_TYPE_BY_ID.get(checkNotNull(value, "stringValue")); + return type == null ? UNRECOGNIZED : type; + } } public static Builder builder() { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Error.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Error.java index d76973c9e9..0082b3c4cd 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Error.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Error.java @@ -25,7 +25,10 @@ import java.util.Arrays; import javax.annotation.Resource; import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlEnumValue; import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; import org.jclouds.logging.Logger; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; @@ -50,21 +53,22 @@ public class Error { @Resource protected static Logger logger = Logger.NULL; + @XmlType + @XmlEnum(Integer.class) public static enum Code { - - OK(200), - CREATED(201), - ACCEPTED(202), - NO_CONTENT(204), - SEE_OTHER(303), - BAD_REQUEST(400), - UNAUTHORIZED(401), - FORBIDDEN(403), // NOTE also means 'not found' for entities - NOT_FOUND(404), - NOT_ALLOWED(405), - INTERNAL_ERROR(500), - NOT_IMPLEMENTED(501), - UNAVAILABLE(503), + @XmlEnumValue("200") OK(200), + @XmlEnumValue("201") CREATED(201), + @XmlEnumValue("202") ACCEPTED(202), + @XmlEnumValue("204") NO_CONTENT(204), + @XmlEnumValue("303") SEE_OTHER(303), + @XmlEnumValue("400") BAD_REQUEST(400), + @XmlEnumValue("401") UNAUTHORIZED(401), + @XmlEnumValue("403") FORBIDDEN(403), // NOTE also means 'not found' for entities + @XmlEnumValue("404") NOT_FOUND(404), + @XmlEnumValue("405") NOT_ALLOWED(405), + @XmlEnumValue("500") INTERNAL_ERROR(500), + @XmlEnumValue("501") NOT_IMPLEMENTED(501), + @XmlEnumValue("503") UNAVAILABLE(503), UNRECOGNIZED(-1); private Integer majorErrorCode; diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Link.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Link.java index d26c6c0aa9..f5bce3a2db 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Link.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Link.java @@ -21,15 +21,21 @@ package org.jclouds.vcloud.director.v1_5.domain; import static com.google.common.base.Objects.equal; import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Arrays; import java.util.List; import java.util.Map; import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlEnumValue; import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; +import com.google.common.base.Function; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Maps; /** * A link. @@ -42,71 +48,70 @@ import com.google.common.base.Objects.ToStringHelper; */ @XmlRootElement(name = "Link") public class Link extends Reference { + + @XmlType + @XmlEnum(String.class) + public static enum Rel { + @XmlEnumValue("add") ADD("add"), + @XmlEnumValue("alternate") ALTERNATE("alternate"), + @XmlEnumValue("catalogItem") CATALOG_ITEM("catalogItem"), + @XmlEnumValue("collaboration:abort") COLLABORATION_ABORT("collaboration:abort"), + @XmlEnumValue("collaboration:fail") COLLABORATION_FAIL("collaboration:fail"), + @XmlEnumValue("collaboration:resume") COLLABORATION_RESUME("collaboration:resume"), + @XmlEnumValue("consolidate") CONSOLIDATE("consolidate"), + @XmlEnumValue("controlAccess") CONTROL_ACCESS("controlAccess"), + @XmlEnumValue("copy") COPY("copy"), + @XmlEnumValue("deploy") DEPLOY("deploy"), + @XmlEnumValue("disable") DISABLE("disable"), + @XmlEnumValue("discardState") DISCARD_STATE("discardState"), + @XmlEnumValue("down") DOWN("down"), + @XmlEnumValue("download:alternate") DOWNLOAD_ALTERNATE("download:alternate"), + @XmlEnumValue("download:default") DOWNLOAD_DEFAULT("download:default"), + @XmlEnumValue("edit") EDIT("edit"), + @XmlEnumValue("enable") ENABLE("enable"), + @XmlEnumValue("firstPage") FIRST_PAGE("firstPage"), + @XmlEnumValue("installVmwareTools") INSTALL_VMWARE_TOOLS("installVmwareTools"), + @XmlEnumValue("lastPage") LAST_PAGE("lastPage"), + @XmlEnumValue("media:ejectMedia") EJECT_MEDIA("media:ejectMedia"), + @XmlEnumValue("media:insertMedia") INSERT_MEDIA("media:insertMedia"), + @XmlEnumValue("move") MOVE("move"), + @XmlEnumValue("nextPage") NEXT_PAGE("nextPage"), + @XmlEnumValue("ova") OVA("ova"), + @XmlEnumValue("ovf") OVF("ovf"), + @XmlEnumValue("power:powerOff") POWER_OFF("power:powerOff"), + @XmlEnumValue("power:powerOn") POWER_ON("power:powerOn"), + @XmlEnumValue("power:reboot") REBOOT("power:reboot"), + @XmlEnumValue("power:reset") RESET("power:reset"), + @XmlEnumValue("power:shutdown") SHUTDOWN("power:shutdown"), + @XmlEnumValue("power:suspend") SUSPEND("power:suspend"), + @XmlEnumValue("previousPage") PREVIOUS_PAGE("previousPage"), + @XmlEnumValue("publish") PUBLISH("publish"), + @XmlEnumValue("recompose") RECOMPOSE("recompose"), + @XmlEnumValue("reconnect") RECONNECT("reconnect"), + @XmlEnumValue("register") REGISTER("register"), + @XmlEnumValue("reject") REJECT("reject"), + @XmlEnumValue("relocate") RELOCATE("relocate"), + @XmlEnumValue("remove") REMOVE("remove"), + @XmlEnumValue("screen:acquireTicket") SCREEN_ACQUIRE_TICKET("screen:acquireTicket"), + @XmlEnumValue("screen:thumbnail") SCREEN_THUMBNAIL("screen:thumbnail"), + @XmlEnumValue("task:cancel") TASK_CANCEL("task:cancel"), + @XmlEnumValue("blockingTask") BLOCKING_TASK("blockingTask"), + @XmlEnumValue("taskOwner") TASK_OWNER("taskOwner"), + @XmlEnumValue("taskParams") TASK_PARAMS("taskParams"), + @XmlEnumValue("taskRequest") TASK_REQUEST("taskRequest"), + @XmlEnumValue("undeploy") UNDEPLOY("undeploy"), + @XmlEnumValue("unlock") UNLOCK("unlock"), + @XmlEnumValue("unregister") UNREGISTER("unregister"), + @XmlEnumValue("up") UP("up"), + @XmlEnumValue("updateProgress") UPDATE_PROGRESS("updateProgress"), + @XmlEnumValue("upgrade") UPGRADE("upgrade"), + @XmlEnumValue("upload:alternate") UPLOAD_ALTERNATE("upload:alternate"), + @XmlEnumValue("upload:default") UPLOAD_DEFAULT("upload:default"), + @XmlEnumValue("repair") REPAIR("repair"), - public static final class Rel { - public static final String ADD = "add"; - public static final String ALTERNATE = "alternate"; - public static final String CATALOG_ITEM = "catalogItem"; - public static final String COLLABORATION_ABORT = "collaboration:abort"; - public static final String COLLABORATION_FAIL = "collaboration:fail"; - public static final String COLLABORATION_RESUME = "collaboration:resume"; - public static final String CONSOLIDATE = "consolidate"; - public static final String CONTROL_ACCESS = "controlAccess"; - public static final String COPY = "copy"; - public static final String DEPLOY = "deploy"; - public static final String DISABLE = "disable"; - public static final String DISCARD_STATE = "discardState"; - public static final String DOWN = "down"; - public static final String DOWNLOAD_ALTERNATE = "download:alternate"; - public static final String DOWNLOAD_DEFAULT = "download:default"; - public static final String EDIT = "edit"; - public static final String ENABLE = "enable"; - public static final String FIRST_PAGE = "firstPage"; - public static final String INSTALL_VMWARE_TOOLS = "installVmwareTools"; - public static final String LAST_PAGE = "lastPage"; - public static final String EJECT_MEDIA = "media:ejectMedia"; - public static final String INSERT_MEDIA = "media:insertMedia"; - public static final String MOVE = "move"; - public static final String NEXT_PAGE = "nextPage"; - public static final String OVA = "ova"; - public static final String OVF = "ovf"; - public static final String POWER_OFF = "power:powerOff"; - public static final String POWER_ON = "power:powerOn"; - public static final String REBOOT = "power:reboot"; - public static final String RESET = "power:reset"; - public static final String SHUTDOWN = "power:shutdown"; - public static final String SUSPEND = "power:suspend"; - public static final String PREVIOUS_PAGE = "previousPage"; - public static final String PUBLISH = "publish"; - public static final String RECOMPOSE = "recompose"; - public static final String RECONNECT = "reconnect"; - public static final String REGISTER = "register"; - public static final String REJECT = "reject"; - public static final String RELOCATE = "relocate"; - public static final String REMOVE = "remove"; - public static final String SCREEN_ACQUIRE_TICKET = "screen:acquireTicket"; - public static final String SCREEN_THUMBNAIL = "screen:thumbnail"; - public static final String TASK_CANCEL = "task:cancel"; - public static final String BLOCKING_TASK = "blockingTask"; - public static final String TASK_OWNER = "taskOwner"; - public static final String TASK_PARAMS = "taskParams"; - public static final String TASK_REQUEST = "taskRequest"; - public static final String UNDEPLOY = "undeploy"; - public static final String UNLOCK = "unlock"; - public static final String UNREGISTER = "unregister"; - public static final String UP = "up"; - public static final String UPDATE_PROGRESS = "updateProgress"; - public static final String UPGRADE = "upgrade"; - public static final String UPLOAD_ALTERNATE = "upload:alternate"; - public static final String UPLOAD_DEFAULT = "upload:default"; - public static final String REPAIR = "repair"; - - /** - * All acceptable {@link Link#getRel()} values. - * - * This list must be updated whenever a new relationship is added. - */ - public static final List ALL = Arrays.asList( + UNRECOGNIZED("unrecognized"); + + public static final List ALL = ImmutableList.of( ADD, ALTERNATE, CATALOG_ITEM, COLLABORATION_ABORT, COLLABORATION_FAIL, COLLABORATION_RESUME, CONSOLIDATE, CONTROL_ACCESS, COPY, DEPLOY, DISABLE, DISCARD_STATE, DOWN, @@ -118,8 +123,30 @@ public class Link extends Reference { SCREEN_THUMBNAIL, TASK_CANCEL, BLOCKING_TASK, TASK_OWNER, TASK_PARAMS, TASK_REQUEST, UNDEPLOY, UNLOCK, UNREGISTER, UP, UPDATE_PROGRESS, UPGRADE, UPLOAD_ALTERNATE, UPLOAD_DEFAULT, - UPLOAD_DEFAULT - ); + UPLOAD_DEFAULT); + + protected final String stringValue; + + Rel(String stringValue) { + this.stringValue = stringValue; + } + + public String value() { + return stringValue; + } + + protected final static Map REL_BY_ID = Maps.uniqueIndex( + ImmutableSet.copyOf(Rel.values()), new Function() { + @Override + public String apply(Rel input) { + return input.stringValue; + } + }); + + public static Rel fromValue(String value) { + Rel rel = REL_BY_ID.get(checkNotNull(value, "stringValue")); + return rel == null ? UNRECOGNIZED : rel; + } } public static Builder builder() { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Media.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Media.java index 651c2c924d..ab00a90710 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Media.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Media.java @@ -19,16 +19,24 @@ f * Licensed to jclouds, Inc. (jclouds) under one or more package org.jclouds.vcloud.director.v1_5.domain; import static com.google.common.base.Objects.equal; +import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Arrays; import java.util.List; +import java.util.Map; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlEnumValue; import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; +import com.google.common.base.Function; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Maps; /** * Represents a media. @@ -39,12 +47,38 @@ import com.google.common.base.Objects.ToStringHelper; */ @XmlRootElement(name = "Media") public class Media extends ResourceEntityType { + + @XmlType + @XmlEnum(String.class) + public static enum ImageType { + @XmlEnumValue("iso") ISO("iso"), + @XmlEnumValue("floppy") FLOPPY("floppy"), + UNRECOGNIZED("unrecognized"); + + public static final List ALL = ImmutableList.of(ISO, FLOPPY); - public static final class ImageType { - public static final String ISO = "iso"; - public static final String FLOPPY = "floppy"; + protected final String stringValue; - public static final List ALL = Arrays.asList(ISO, FLOPPY); + ImageType(String stringValue) { + this.stringValue = stringValue; + } + + public String value() { + return stringValue; + } + + protected final static Map STATUS_BY_ID = Maps.uniqueIndex( + ImmutableSet.copyOf(ImageType.values()), new Function() { + @Override + public String apply(ImageType input) { + return input.stringValue; + } + }); + + public static ImageType fromValue(String value) { + ImageType type = STATUS_BY_ID.get(checkNotNull(value, "stringValue")); + return type == null ? UNRECOGNIZED : type; + } } public static Builder builder() { @@ -61,7 +95,7 @@ public class Media extends ResourceEntityType { public static abstract class Builder> extends ResourceEntityType.Builder { private Owner owner; - private String imageType; + private ImageType imageType; private long size; /** @@ -75,7 +109,7 @@ public class Media extends ResourceEntityType { /** * @see Media#getImageType() */ - public B imageType(String imageType) { + public B imageType(Media.ImageType imageType) { this.imageType = imageType; return self(); } @@ -113,7 +147,7 @@ public class Media extends ResourceEntityType { @XmlElement(name = "Owner") protected Owner owner; @XmlAttribute(required = true) - protected String imageType; + protected ImageType imageType; @XmlAttribute(required = true) protected long size; @@ -127,7 +161,7 @@ public class Media extends ResourceEntityType { /** * Gets the value of the imageType property. */ - public String getImageType() { + public ImageType getImageType() { return imageType; } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Network.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Network.java index 24dcfe1edc..d556416003 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Network.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Network.java @@ -19,32 +19,60 @@ package org.jclouds.vcloud.director.v1_5.domain; import static com.google.common.base.Objects.equal; +import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Arrays; import java.util.List; +import java.util.Map; import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlEnumValue; import javax.xml.bind.annotation.XmlSeeAlso; +import javax.xml.bind.annotation.XmlType; +import com.google.common.base.Function; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Maps; @XmlSeeAlso({ OrgNetwork.class, ExternalNetwork.class }) public abstract class Network extends EntityType { - public static final class FenceMode { + + @XmlType + @XmlEnum(String.class) + public static enum FenceMode { + @XmlEnumValue("bridged") BRIDGED("bridged"), + @XmlEnumValue("isolated") ISOLATED("isolated"), + @XmlEnumValue("natRouted") NAT_ROUTED("natRouted"), + UNRECOGNIZED("unrecognized"); + + public static final List ALL = ImmutableList.of( + BRIDGED, ISOLATED, NAT_ROUTED); - public static final String BRIDGED = "bridged"; - public static final String ISOLATED = "isolated"; - public static final String NAT_ROUTED = "natRouted"; + protected final String stringValue; - /** - * All acceptable {@link Network#getFenceMode()} values. - *

- * This list must be updated whenever a new mode is added. - */ - public static final List ALL = Arrays.asList( - BRIDGED, ISOLATED, NAT_ROUTED - ); + FenceMode(String stringValue) { + this.stringValue = stringValue; + } + + public String value() { + return stringValue; + } + + protected final static Map FENCE_MODE_BY_ID = Maps.uniqueIndex( + ImmutableSet.copyOf(FenceMode.values()), new Function() { + @Override + public String apply(FenceMode input) { + return input.stringValue; + } + }); + + public static FenceMode fromValue(String value) { + FenceMode mode = FENCE_MODE_BY_ID.get(checkNotNull(value, "stringValue")); + return mode == null ? UNRECOGNIZED : mode; + } } public abstract static class Builder> extends EntityType.Builder { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/NetworkConfiguration.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/NetworkConfiguration.java index a93d4e8cd1..eda312e713 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/NetworkConfiguration.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/NetworkConfiguration.java @@ -25,6 +25,8 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import org.jclouds.vcloud.director.v1_5.domain.Network.FenceMode; + import com.google.common.base.Objects; /** @@ -47,7 +49,7 @@ public class NetworkConfiguration { public static class Builder { private IpScope ipScope; private Reference parentNetwork; - private String fenceMode; + private FenceMode fenceMode; private Boolean retainNetInfoAcrossDeployments; private NetworkFeatures features; private SyslogServerSettings syslogServerSettings; @@ -72,7 +74,7 @@ public class NetworkConfiguration { /** * @see NetworkConfiguration#getFenceMode() */ - public Builder fenceMode(String fenceMode) { + public Builder fenceMode(FenceMode fenceMode) { this.fenceMode = fenceMode; return this; } @@ -122,7 +124,7 @@ public class NetworkConfiguration { } } - public NetworkConfiguration(IpScope ipScope, Reference parentNetwork, String fenceMode, Boolean retainNetInfoAcrossDeployments, + public NetworkConfiguration(IpScope ipScope, Reference parentNetwork, FenceMode fenceMode, Boolean retainNetInfoAcrossDeployments, NetworkFeatures features, SyslogServerSettings syslogServerSettings, RouterInfo routerInfo) { this.ipScope = ipScope; this.parentNetwork = parentNetwork; @@ -142,7 +144,7 @@ public class NetworkConfiguration { @XmlElement(name = "ParentNetwork") private Reference parentNetwork; @XmlElement(name = "FenceMode") - private String fenceMode; + private FenceMode fenceMode; @XmlElement(name = "RetainNetInfoAcrossDeployments") private Boolean retainNetInfoAcrossDeployments; @XmlElement(name = "Features") @@ -174,7 +176,7 @@ public class NetworkConfiguration { * isolated (not connected to any other network), natRouted (connected to the ParentNetwork via a * NAT service) */ - public String getFenceMode() { + public FenceMode getFenceMode() { return fenceMode; } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/NetworkConnection.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/NetworkConnection.java index f0982f92e7..7d1d3f981b 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/NetworkConnection.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/NetworkConnection.java @@ -23,13 +23,19 @@ import static com.google.common.base.Objects.equal; import static com.google.common.base.Preconditions.checkNotNull; import java.util.List; +import java.util.Map; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlEnumValue; import javax.xml.bind.annotation.XmlType; +import com.google.common.base.Function; import com.google.common.base.Objects; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Maps; /** @@ -70,30 +76,38 @@ import com.google.common.collect.ImmutableList; }) public class NetworkConnection { + @XmlType + @XmlEnum(String.class) public static enum IpAddressAllocationMode { - POOL("pool"), - DHCP("dhcp"), - MANUAL("manual"), - NONE("none"), + @XmlEnumValue("pool") POOL("pool"), + @XmlEnumValue("dhcp") DHCP("dhcp"), + @XmlEnumValue("manual") MANUAL("manual"), + @XmlEnumValue("none") NONE("none"), UNRECOGNIZED("unrecognized"); public static final List ALL = ImmutableList.of(POOL, DHCP, MANUAL, NONE); - - private final String label; - private IpAddressAllocationMode(String label) { - this.label = label; + + protected final String label; + + IpAddressAllocationMode(String stringValue) { + this.label = stringValue; } - - public String getLabel() { + + public String label() { return label; } - + + protected final static Map IP_ADDRESS_ALLOCATION_MODE_BY_ID = Maps.uniqueIndex( + ImmutableSet.copyOf(IpAddressAllocationMode.values()), new Function() { + @Override + public String apply(IpAddressAllocationMode input) { + return input.label; + } + }); + public static IpAddressAllocationMode fromValue(String value) { - try { - return valueOf(checkNotNull(value, "value").toUpperCase()); - } catch (IllegalArgumentException e) { - return UNRECOGNIZED; - } + IpAddressAllocationMode mode = IP_ADDRESS_ALLOCATION_MODE_BY_ID.get(checkNotNull(value, "stringValue")); + return mode == null ? UNRECOGNIZED : mode; } } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgLdapSettings.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgLdapSettings.java index f5e01a827a..913019a20e 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgLdapSettings.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgLdapSettings.java @@ -19,16 +19,23 @@ package org.jclouds.vcloud.director.v1_5.domain; import static com.google.common.base.Objects.equal; +import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Arrays; import java.util.List; +import java.util.Map; import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlEnumValue; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import com.google.common.base.Function; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Maps; /** * Base settings for LDAP connection * @@ -54,20 +61,39 @@ import com.google.common.base.Objects.ToStringHelper; "customOrgLdapSettings" }) public class OrgLdapSettings extends ResourceType { + + @XmlType + @XmlEnum(String.class) + public static enum LdapMode { + @XmlEnumValue("NONE") NONE("NONE"), + @XmlEnumValue("SYSTEM") SYSTEM("SYSTEM"), + @XmlEnumValue("CUSTOM") CUSTOM("CUSTOM"), + UNRECOGNIZED("unrecognized"); + + public static final List ALL = ImmutableList.of( NONE, SYSTEM, CUSTOM ); - public static final class LdapMode { - public static final String NONE = "NONE"; - public static final String SYSTEM = "SYSTEM"; - public static final String CUSTOM = "CUSTOM"; + protected final String stringValue; - /** - * All acceptable {@link #getLdapMode()} values. - * - * This list must be updated whenever a new mode is added. - */ - public static final List ALL = Arrays.asList( - NONE, SYSTEM, CUSTOM - ); + LdapMode(String stringValue) { + this.stringValue = stringValue; + } + + public String value() { + return stringValue; + } + + protected final static Map LDAP_MODE_BY_ID = Maps.uniqueIndex( + ImmutableSet.copyOf(LdapMode.values()), new Function() { + @Override + public String apply(LdapMode input) { + return input.stringValue; + } + }); + + public static LdapMode fromValue(String value) { + LdapMode mode = LDAP_MODE_BY_ID.get(checkNotNull(value, "stringValue")); + return mode == null ? UNRECOGNIZED : mode; + } } public static Builder builder() { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Role.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Role.java index 1616f0ce1e..d79919bed3 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Role.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Role.java @@ -1,27 +1,53 @@ package org.jclouds.vcloud.director.v1_5.domain; -import java.util.Arrays; -import java.util.List; +import static com.google.common.base.Preconditions.checkNotNull; -import org.jclouds.vcloud.director.v1_5.features.admin.AdminQueryClient; +import java.util.List; +import java.util.Map; + +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlEnumValue; +import javax.xml.bind.annotation.XmlType; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Maps; public class Role { //TODO: placeholder for implementation - public static final class DefaultRoles { - public static final String USER = "vApp User"; - public static final String AUTHOR = "vApp Author"; - public static final String CATALOG_AUTHOR = "Catalog Author"; - public static final String CONSOLE = "Console Access Only"; - public static final String ORG_ADMIN = "Organization Administrator"; + @XmlType + @XmlEnum(String.class) + public static enum DefaultRoles { + @XmlEnumValue("vApp User") USER("vApp User"), + @XmlEnumValue("vApp Author") AUTHOR("vApp Author"), + @XmlEnumValue("Catalog Author") CATALOG_AUTHOR("Catalog Author"), + @XmlEnumValue("Console Access Only") CONSOLE("Console Access Only"), + @XmlEnumValue("Organization Administrator") ORG_ADMIN("Organization Administrator"); - /** - * All default {@link AdminQueryClient#roleReferencesQueryAll()} values. - *

- * This list must be updated whenever a new default role is added. - */ - public static final List ALL = Arrays.asList( - USER, AUTHOR, CATALOG_AUTHOR, CONSOLE, ORG_ADMIN - ); + public static final List ALL = ImmutableList.of( + USER, AUTHOR, CATALOG_AUTHOR, CONSOLE, ORG_ADMIN); + + protected final String stringValue; + + DefaultRoles(String stringValue) { + this.stringValue = stringValue; + } + + public String value() { + return stringValue; + } + + protected final static Map DEFAULT_ROLES_BY_ID = Maps.uniqueIndex( + ImmutableSet.copyOf(DefaultRoles.values()), new Function() { + @Override + public String apply(DefaultRoles input) { + return input.stringValue; + } + }); + + public static DefaultRoles fromValue(String value) { + return DEFAULT_ROLES_BY_ID.get(checkNotNull(value, "stringValue")); + } } - } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Task.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Task.java index 26dd73cb95..3ba255190c 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Task.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Task.java @@ -19,19 +19,27 @@ package org.jclouds.vcloud.director.v1_5.domain; import static com.google.common.base.Objects.equal; +import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Arrays; import java.util.Date; import java.util.List; +import java.util.Map; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlEnumValue; import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import com.google.common.base.Function; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Maps; /** * Represents an asynchronous or long-running task in the vCloud environment. @@ -48,20 +56,44 @@ import com.google.common.base.Objects.ToStringHelper; public class Task extends EntityType { public static final String MEDIA_TYPE = VCloudDirectorMediaType.TASK; + + @XmlType + @XmlEnum(String.class) + public static enum Status { + @XmlEnumValue("queued") QUEUED("queued"), + @XmlEnumValue("preRunning") PRE_RUNNING("preRunning"), + @XmlEnumValue("running") RUNNING("running"), + @XmlEnumValue("success") SUCCESS("success"), + @XmlEnumValue("error") ERROR("error"), + @XmlEnumValue("canceled") CANCELED("canceled"), + @XmlEnumValue("aborted") ABORTED("aborted"), + UNRECOGNIZED("unrecognized"); + + public static final List ALL = ImmutableList.of( + QUEUED, PRE_RUNNING, RUNNING, SUCCESS, ERROR, CANCELED, ABORTED); - 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"; + protected final String stringValue; - public static final List ALL = Arrays.asList( - QUEUED, PRE_RUNNING, RUNNING, SUCCESS, - ERROR, CANCELED, ABORTED - ); + Status(String stringValue) { + this.stringValue = stringValue; + } + + public String value() { + return stringValue; + } + + protected final static Map STATUS_BY_ID = Maps.uniqueIndex( + ImmutableSet.copyOf(Status.values()), new Function() { + @Override + public String apply(Status input) { + return input.stringValue; + } + }); + + public static Status fromValue(String value) { + Status status = STATUS_BY_ID.get(checkNotNull(value, "stringValue")); + return status == null ? UNRECOGNIZED : status; + } } public static Builder builder() { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/UndeployVAppParams.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/UndeployVAppParams.java index ced084e9f5..9dae45bca0 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/UndeployVAppParams.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/UndeployVAppParams.java @@ -19,17 +19,24 @@ package org.jclouds.vcloud.director.v1_5.domain; import static com.google.common.base.Objects.equal; +import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Arrays; import java.util.List; +import java.util.Map; import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlEnumValue; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import com.google.common.base.Function; import com.google.common.base.Objects; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Maps; /** * Represents vApp/VM undeployment parameters. @@ -42,20 +49,42 @@ import com.google.common.base.Objects; @XmlRootElement(name = "UndeployVAppParams") @XmlType(name = "UndeployVAppParamsType") public class UndeployVAppParams { + + public static final String MEDIA_TYPE = VCloudDirectorMediaType.UNDEPLOY_VAPP_PARAMS; + + @XmlType + @XmlEnum(String.class) + public static enum PowerAction { + @XmlEnumValue("powerOff") POWER_OFF("powerOff"), + @XmlEnumValue("suspend") SUSPEND("suspend"), + @XmlEnumValue("shutdown") SHUTDOWN("shutdown"), + @XmlEnumValue("force") FORCE("force"), + UNRECOGNIZED("unrecognized"); + + public static final List ALL = ImmutableList.of( POWER_OFF, SUSPEND, SHUTDOWN, FORCE ); - public static final String MEDIA_TYPe = VCloudDirectorMediaType.UNDEPLOY_VAPP_PARAMS; + protected final String stringValue; - public static class PowerAction { - /** Power off the VMs. This is the default action if this attribute is missing or empty) */ - public static final String POWER_OFF = "powerOff"; - /** Suspend the VMs. */ - public static final String SUSPEND = "suspend"; - /** Shut down the VMs. */ - public static final String SHUTDOWN = "shutdown"; - /** Attempt to power off the VMs. */ - public static final String FORCE = "force"; + PowerAction(String stringValue) { + this.stringValue = stringValue; + } - public static final List ALL = Arrays.asList(POWER_OFF, SUSPEND, SHUTDOWN, FORCE); + public String value() { + return stringValue; + } + + protected final static Map POWER_ACTION_BY_ID = Maps.uniqueIndex( + ImmutableSet.copyOf(PowerAction.values()), new Function() { + @Override + public String apply(PowerAction input) { + return input.stringValue; + } + }); + + public static PowerAction fromValue(String value) { + PowerAction action = POWER_ACTION_BY_ID.get(checkNotNull(value, "stringValue")); + return action == null ? UNRECOGNIZED : action; + } } public static Builder builder() { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/predicates/TaskStatusEquals.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/predicates/TaskStatusEquals.java index 689b211f68..8b60ee1d63 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/predicates/TaskStatusEquals.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/predicates/TaskStatusEquals.java @@ -20,12 +20,14 @@ package org.jclouds.vcloud.director.v1_5.predicates; import java.util.Collection; import java.util.Collections; +import java.util.Set; import javax.annotation.Resource; import org.jclouds.logging.Logger; import org.jclouds.vcloud.director.v1_5.VCloudDirectorException; import org.jclouds.vcloud.director.v1_5.domain.Task; +import org.jclouds.vcloud.director.v1_5.domain.Task.Status; import org.jclouds.vcloud.director.v1_5.features.TaskClient; import com.google.common.base.Predicate; @@ -42,15 +44,14 @@ public class TaskStatusEquals implements Predicate { @Resource protected Logger logger = Logger.NULL; - private Collection expectedStatuses; - private Collection failingStatuses; + private Collection expectedStatuses; + private Collection failingStatuses; - // TODO Use Task.Status, once it is turned into an enumeration - public TaskStatusEquals(TaskClient taskClient, String expectedStatus, Collection failingStatuses) { + public TaskStatusEquals(TaskClient taskClient, Status expectedStatus, Set failingStatuses) { this(taskClient, Collections.singleton(expectedStatus), failingStatuses); } - public TaskStatusEquals(TaskClient taskClient, Collection expectedStatuses, Collection failingStatuses) { + public TaskStatusEquals(TaskClient taskClient, Set expectedStatuses, Set failingStatuses) { this.taskClient = taskClient; this.expectedStatuses = expectedStatuses; this.failingStatuses = failingStatuses; @@ -68,13 +69,13 @@ public class TaskStatusEquals implements Predicate { if (task == null) return false; logger.trace("%s: looking for status %s: currently: %s", task, expectedStatuses, task.getStatus()); - for (String failingStatus : failingStatuses) { + for (Status failingStatus : failingStatuses) { if (task.getStatus().equals(failingStatus)) { throw new VCloudDirectorException(task); } } - for (String expectedStatus : expectedStatuses) { + for (Status expectedStatus : expectedStatuses) { if (task.getStatus().equals(expectedStatus)) { return true; } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java index 1fa7d6d113..f4f6a80d88 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java @@ -345,11 +345,6 @@ public class Checks { checkEntityType(catalogItem); } - public static void checkImageType(String imageType) { - assertTrue(Media.ImageType.ALL.contains(imageType), - "The Image type of a Media must be one of the allowed list"); - } - public static void checkNetwork(Network network) { // Check optional fields NetworkConfiguration config = network.getConfiguration(); @@ -756,7 +751,8 @@ public class Checks { public static void checkMediaFor(String client, Media media) { // required assertNotNull(media.getImageType(), String.format(OBJ_FIELD_REQ, client, "imageType")); - checkImageType(media.getImageType()); + assertTrue(Media.ImageType.ALL.contains(media.getImageType()), + "The Image type of a Media must be one of the allowed list"); assertNotNull(media.getSize(), String.format(OBJ_FIELD_REQ, client, "size")); assertTrue(media.getSize() >= 0, String.format(OBJ_FIELD_GTE_0, client, "size", media.getSize())); diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java index 54f28366df..1350c0d714 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java @@ -31,6 +31,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Error; import org.jclouds.vcloud.director.v1_5.domain.File; import org.jclouds.vcloud.director.v1_5.domain.Link; import org.jclouds.vcloud.director.v1_5.domain.Media; +import org.jclouds.vcloud.director.v1_5.domain.Media.ImageType; import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; import org.jclouds.vcloud.director.v1_5.domain.MetadataValue; @@ -67,7 +68,7 @@ public class MediaClientExpectTest extends VCloudDirectorAdminClientExpectTest { Media source = Media.builder() .size(0) - .imageType("iso") + .imageType(ImageType.ISO) .name("Test media 1") .type("application/vnd.vmware.vcloud.media+xml") .description("Test media generated by testCreateMedia()") @@ -346,7 +347,7 @@ public class MediaClientExpectTest extends VCloudDirectorAdminClientExpectTest { static Media createMedia() { return Media.builder() .size(0) - .imageType("iso") + .imageType(ImageType.ISO) .status(0) .name("Test media 1") .id("urn:vcloud:media:d51b0b9d-099c-499f-97f8-4fbe40ba06d7") @@ -378,7 +379,7 @@ public class MediaClientExpectTest extends VCloudDirectorAdminClientExpectTest { static Media cloneMedia() { return Media.builder() .size(175163392) - .imageType("iso") + .imageType(ImageType.ISO) .status(0) .name("copied test media-copy-671136ae-b8f0-4389-bca6-50e9c42268f2") .id("urn:vcloud:media:a6b023f2-7f90-4e89-a24d-56e0eba83a5a") @@ -433,7 +434,7 @@ public class MediaClientExpectTest extends VCloudDirectorAdminClientExpectTest { private static Media getMedia() { return Media.builder() .size(175163392) - .imageType("iso") + .imageType(ImageType.ISO) .status(1) .name("DansTestMedia") .id("urn:vcloud:media:794eb334-754e-4917-b5a0-5df85cbd61d1") @@ -476,7 +477,7 @@ public class MediaClientExpectTest extends VCloudDirectorAdminClientExpectTest { private static Media updateMedia() { return Media.builder() .size(175163392) - .imageType("iso") + .imageType(ImageType.ISO) .status(1) .name("new testMedia1") .id("urn:vcloud:media:c93e5cdc-f29a-4749-8ed2-093df04cc75e") diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientExpectTest.java index 51a2542c21..4fdb7fd8cb 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientExpectTest.java @@ -37,6 +37,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; import org.jclouds.vcloud.director.v1_5.domain.MetadataValue; import org.jclouds.vcloud.director.v1_5.domain.Network; +import org.jclouds.vcloud.director.v1_5.domain.Network.FenceMode; import org.jclouds.vcloud.director.v1_5.domain.NetworkConfiguration; import org.jclouds.vcloud.director.v1_5.domain.NetworkFeatures; import org.jclouds.vcloud.director.v1_5.domain.OrgNetwork; @@ -217,7 +218,7 @@ public class NetworkClientExpectTest extends VCloudDirectorAdminClientExpectTest .build()) .build()) .build()) - .fenceMode("isolated") + .fenceMode(FenceMode.ISOLATED) .retainNetInfoAcrossDeployments(false) .features(NetworkFeatures.builder() .service(DhcpService.builder() diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppTemplateClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppTemplateClientExpectTest.java index 25e5863755..21a63f50d6 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppTemplateClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppTemplateClientExpectTest.java @@ -57,6 +57,7 @@ import org.jclouds.vcloud.director.v1_5.domain.MetadataValue; import org.jclouds.vcloud.director.v1_5.domain.NatOneToOneVmRule; import org.jclouds.vcloud.director.v1_5.domain.NatRule; import org.jclouds.vcloud.director.v1_5.domain.NatService; +import org.jclouds.vcloud.director.v1_5.domain.Network.FenceMode; import org.jclouds.vcloud.director.v1_5.domain.NetworkConfigSection; import org.jclouds.vcloud.director.v1_5.domain.NetworkConfiguration; import org.jclouds.vcloud.director.v1_5.domain.NetworkFeatures; @@ -679,7 +680,7 @@ public class VAppTemplateClientExpectTest extends VCloudDirectorAdminClientExpec .ipRanges(IpRanges.builder().ipRange(IpRange.builder().startAddress("10.147.56.1").endAddress("10.147.56.1").build()).build()) .build()) .parentNetwork(Reference.builder().href(URI.create("http://vcloud.example.com/api/v1.0/network/54")).type("application/vnd.vmware.vcloud.network+xml").name("Internet").build()) - .fenceMode("natRouted") + .fenceMode(FenceMode.NAT_ROUTED) .features(NetworkFeatures.builder().services(ImmutableSet.of(firewallService, natService)).build()) .build(); diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VdcClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VdcClientExpectTest.java index 1fb0d81610..69a9aff4db 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VdcClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VdcClientExpectTest.java @@ -38,6 +38,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Error; import org.jclouds.vcloud.director.v1_5.domain.InstantiateVAppTemplateParams; import org.jclouds.vcloud.director.v1_5.domain.Link; import org.jclouds.vcloud.director.v1_5.domain.Media; +import org.jclouds.vcloud.director.v1_5.domain.Media.ImageType; import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.MetadataValue; import org.jclouds.vcloud.director.v1_5.domain.Reference; @@ -297,7 +298,7 @@ public class VdcClientExpectTest extends VCloudDirectorAdminClientExpectTest { Media source = Media.builder() .size(0) - .imageType("iso") + .imageType(ImageType.ISO) .name("Test media 1") .type("application/vnd.vmware.vcloud.media+xml") .description("Test media generated by testCreateMedia()") diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VdcClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VdcClientLiveTest.java index 6724b662fa..472c2a0c10 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VdcClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VdcClientLiveTest.java @@ -40,6 +40,7 @@ import org.jclouds.vcloud.director.v1_5.domain.InstantiateVAppTemplateParams; import org.jclouds.vcloud.director.v1_5.domain.InstantiationParams; import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.MetadataValue; +import org.jclouds.vcloud.director.v1_5.domain.Network.FenceMode; import org.jclouds.vcloud.director.v1_5.domain.NetworkConfigSection; import org.jclouds.vcloud.director.v1_5.domain.NetworkConfiguration; import org.jclouds.vcloud.director.v1_5.domain.Reference; @@ -246,7 +247,7 @@ public class VdcClientLiveTest extends BaseVCloudDirectorClientLiveTest { NetworkConfiguration networkConfiguration = NetworkConfiguration.builder() .parentNetwork(parentNetwork.get()) - .fenceMode("bridged") + .fenceMode(FenceMode.BRIDGED) .build(); NetworkConfigSection networkConfigSection = NetworkConfigSection.builder() diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/UserClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/UserClientLiveTest.java index 93ad4f0ef9..fea82e4fc1 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/UserClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/UserClientLiveTest.java @@ -119,7 +119,7 @@ public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest { .password("newPassword") // TODO test setting other fields? // .name("new"+oldUser.getName()) - .role(getRoleReferenceFor(DefaultRoles.AUTHOR)) + .role(getRoleReferenceFor(DefaultRoles.AUTHOR.value())) .build(); userClient.updateUser(user.getHref(), newUser); diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java index d40b9cc13c..7d6cae701b 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java @@ -217,7 +217,7 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ } public User randomTestUser(String prefix) { - return randomTestUser(prefix, getRoleReferenceFor(DefaultRoles.USER)); + return randomTestUser(prefix, getRoleReferenceFor(DefaultRoles.USER.value())); } public User randomTestUser(String prefix, Reference role) { @@ -303,11 +303,11 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ assertTrue(retryTaskSuccessLong.apply(task), String.format(TASK_COMPLETE_TIMELY, task)); } - protected void assertTaskStatusEventually(Task task, String expectedStatus, Collection failingStatuses) { + protected void assertTaskStatusEventually(Task task, org.jclouds.vcloud.director.v1_5.domain.Task.Status running, ImmutableSet immutableSet) { TaskClient taskClient = context.getApi().getTaskClient(); - TaskStatusEquals predicate = new TaskStatusEquals(taskClient, expectedStatus, failingStatuses); + TaskStatusEquals predicate = new TaskStatusEquals(taskClient, running, immutableSet); RetryablePredicate retryablePredicate = new RetryablePredicate(predicate, TASK_TIMEOUT_SECONDS * 1000L); - assertTrue(retryablePredicate.apply(task), "Task must enter status "+expectedStatus); + assertTrue(retryablePredicate.apply(task), "Task must enter status "+running); } protected void assertTaskDoneEventually(Task task) { @@ -315,7 +315,7 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ TaskStatusEquals predicate = new TaskStatusEquals( taskClient, ImmutableSet.of(Task.Status.ABORTED, Task.Status.CANCELED, Task.Status.ERROR, Task.Status.SUCCESS), - Collections.emptySet()); + Collections.emptySet()); RetryablePredicate retryablePredicate = new RetryablePredicate(predicate, LONG_TASK_TIMEOUT_SECONDS * 1000L); assertTrue(retryablePredicate.apply(task), "Task must be done"); } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/VCloudDirectorTestSession.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/VCloudDirectorTestSession.java index 940d18fccd..6bbc1d92b3 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/VCloudDirectorTestSession.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/VCloudDirectorTestSession.java @@ -124,7 +124,7 @@ public class VCloudDirectorTestSession { .name(userIdentity) .password(userCredential) .description("test user with user-level privileges") - .role(BaseVCloudDirectorClientLiveTest.getRoleReferenceFor(DefaultRoles.USER, adminContext)) + .role(BaseVCloudDirectorClientLiveTest.getRoleReferenceFor(DefaultRoles.USER.value(), adminContext)) .deployedVmQuota(BaseVCloudDirectorClientLiveTest.REQUIRED_USER_VM_QUOTA) .isEnabled(true) .build());