No enum for media types, after all...

This commit is contained in:
Andrew Donald Kennedy 2012-02-10 13:12:18 +00:00
parent d29bd2eec8
commit 97320fcc00
12 changed files with 65 additions and 34 deletions

View File

@ -26,24 +26,26 @@ package org.jclouds.vcloud.director.v1_5;
* *
* @see javax.ws.rs.core.MediaType; * @see javax.ws.rs.core.MediaType;
*/ */
public enum VCloudDirectorMediaType { public class VCloudDirectorMediaType {
ANY("*/*"),
SESSION("application/vnd.vmware.vcloud.session+xml"),
ERROR("application/vnd.vmware.vcloud.error+xml"),
ORG_LIST("application/vnd.vmware.vcloud.orgList+xml"),
METADATA("application/vnd.vmware.vcloud.metadata+xml"),
METADATA_ENTRY("*/*"), // TODO
ORG("application/vnd.vmware.vcloud.org+xml"),
TASKS_LIST("application/vnd.vmware.vcloud.tasksList+xml"),
TASK("application/vnd.vmware.vcloud.task+xml");
private final String mediaType; public static final String ANY = "*/*";
private VCloudDirectorMediaType(String mediaType) { public static final String SESSION = "application/vnd.vmware.vcloud.session+xml";
this.mediaType = mediaType;
} public static final String ERROR = "application/vnd.vmware.vcloud.error+xml";
public static final String ORG_LIST = "application/vnd.vmware.vcloud.orgList+xml";
public static final String METADATA = "application/vnd.vmware.vcloud.metadata+xml";
public static final String METADATA_ENTRY = "*/*"; // TODO
public static final String ORG = "application/vnd.vmware.vcloud.org+xml";
public static final String TASKS_LIST = "application/vnd.vmware.vcloud.tasksList+xml";
public static final String TASK = "application/vnd.vmware.vcloud.task+xml";
public static final String ORG_NETWORK = "application/vnd.vmware.vcloud.orgNetwork+xml";
public String getMediaType() {
return mediaType;
}
} }

View File

@ -27,6 +27,8 @@ import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import com.google.common.base.Objects; import com.google.common.base.Objects;
/** /**
@ -41,6 +43,8 @@ import com.google.common.base.Objects;
@XmlRootElement(namespace = XMLNS, name = "Error") @XmlRootElement(namespace = XMLNS, name = "Error")
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
public class Error { public class Error {
public static final String MEDIA_TYPE = VCloudDirectorMediaType.ERROR;
public static Builder builder() { public static Builder builder() {
return new Builder(); return new Builder();

View File

@ -28,6 +28,8 @@ import java.util.Set;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
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.ImmutableSet;
@ -43,7 +45,9 @@ import com.google.common.collect.Sets;
* @author danikov * @author danikov
*/ */
@XmlRootElement(namespace = XMLNS, name = "Metadata") @XmlRootElement(namespace = XMLNS, name = "Metadata")
public class Metadata extends ResourceType<Metadata>{ public class Metadata extends ResourceType<Metadata> {
public static final String MEDIA_TYPE = VCloudDirectorMediaType.METADATA;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static Builder builder() { public static Builder builder() {

View File

@ -28,6 +28,8 @@ import java.util.Set;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
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.Sets; import com.google.common.collect.Sets;
@ -43,6 +45,8 @@ import com.google.common.collect.Sets;
*/ */
@XmlRootElement(namespace = XMLNS, name = "MetadataEntry") @XmlRootElement(namespace = XMLNS, name = "MetadataEntry")
public class MetadataEntry extends ResourceType<MetadataEntry> { public class MetadataEntry extends ResourceType<MetadataEntry> {
public static final String MEDIA_TYPE = VCloudDirectorMediaType.METADATA_ENTRY;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static Builder builder() { public static Builder builder() {

View File

@ -28,6 +28,8 @@ import java.util.Set;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
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.Sets; import com.google.common.collect.Sets;
@ -45,6 +47,8 @@ import com.google.common.collect.Sets;
*/ */
@XmlRootElement(namespace = XMLNS, name = "Org") @XmlRootElement(namespace = XMLNS, name = "Org")
public class Org extends EntityType<Org> { public class Org extends EntityType<Org> {
public static final String MEDIA_TYPE = VCloudDirectorMediaType.ORG;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static Builder builder() { public static Builder builder() {

View File

@ -27,6 +27,8 @@ import java.util.Set;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
@ -38,6 +40,8 @@ import com.google.common.collect.Sets;
*/ */
@XmlRootElement(namespace = XMLNS, name = "OrgList") @XmlRootElement(namespace = XMLNS, name = "OrgList")
public class OrgList { public class OrgList {
public static final String MEDIA_TYPE = VCloudDirectorMediaType.ORG_LIST;
public static Builder builder() { public static Builder builder() {
return new Builder(); return new Builder();

View File

@ -31,6 +31,8 @@ import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
@ -45,6 +47,8 @@ import com.google.common.collect.Sets;
@XmlRootElement(namespace = XMLNS, name = "Session") @XmlRootElement(namespace = XMLNS, name = "Session")
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
public class Session { public class Session {
public static final String MEDIA_TYPE = VCloudDirectorMediaType.SESSION;
public static Builder builder() { public static Builder builder() {
return new Builder(); return new Builder();

View File

@ -30,6 +30,8 @@ import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
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.Sets; import com.google.common.collect.Sets;
@ -45,6 +47,8 @@ import com.google.common.collect.Sets;
*/ */
@XmlRootElement(namespace = XMLNS, name = "Task") @XmlRootElement(namespace = XMLNS, name = "Task")
public class Task extends EntityType<Task> { public class Task extends EntityType<Task> {
public static final String MEDIA_TYPE = VCloudDirectorMediaType.TASK;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static Builder builder() { public static Builder builder() {

View File

@ -28,6 +28,8 @@ import java.util.Set;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
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.ImmutableSet;
@ -40,6 +42,8 @@ import com.google.common.collect.Sets;
*/ */
@XmlRootElement(namespace = XMLNS, name = "TasksList") @XmlRootElement(namespace = XMLNS, name = "TasksList")
public class TasksList extends EntityType<TasksList> { public class TasksList extends EntityType<TasksList> {
public static final String MEDIA_TYPE = VCloudDirectorMediaType.TASKS_LIST;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static Builder builder() { public static Builder builder() {

View File

@ -57,7 +57,7 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
HttpResponse taskResponse = HttpResponse.builder() HttpResponse taskResponse = HttpResponse.builder()
.statusCode(200) .statusCode(200)
.payload(payloadFromResourceWithContentType("/task/taskslist.xml", VCloudDirectorMediaType.TASKS_LIST.getMediaType() + ";version=1.5")) .payload(payloadFromResourceWithContentType("/task/taskslist.xml", VCloudDirectorMediaType.TASKS_LIST + ";version=1.5"))
.build(); .build();
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse);
@ -135,7 +135,7 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
HttpResponse taskResponse = HttpResponse.builder() HttpResponse taskResponse = HttpResponse.builder()
.statusCode(400) .statusCode(400)
.payload(payloadFromResourceWithContentType("/task/error400.xml", VCloudDirectorMediaType.ERROR.getMediaType() + ";version=1.5")) .payload(payloadFromResourceWithContentType("/task/error400.xml", VCloudDirectorMediaType.ERROR + ";version=1.5"))
.build(); .build();
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse);
@ -170,7 +170,7 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
HttpResponse taskResponse = HttpResponse.builder() HttpResponse taskResponse = HttpResponse.builder()
.statusCode(403) .statusCode(403)
.payload(payloadFromResourceWithContentType("/task/error403.xml", VCloudDirectorMediaType.ERROR.getMediaType() + ";version=1.5")) .payload(payloadFromResourceWithContentType("/task/error403.xml", VCloudDirectorMediaType.ERROR + ";version=1.5"))
.build(); .build();
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse);
@ -206,7 +206,7 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
HttpResponse taskResponse = HttpResponse.builder() HttpResponse taskResponse = HttpResponse.builder()
.statusCode(200) .statusCode(200)
.payload(payloadFromResourceWithContentType("/task/task.xml", VCloudDirectorMediaType.TASK.getMediaType() + ";version=1.5")) .payload(payloadFromResourceWithContentType("/task/task.xml", VCloudDirectorMediaType.TASK + ";version=1.5"))
.build(); .build();
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse);
@ -257,7 +257,7 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
HttpResponse taskResponse = HttpResponse.builder() HttpResponse taskResponse = HttpResponse.builder()
.statusCode(200) .statusCode(200)
.payload(payloadFromResourceWithContentType("/task/task.xml", VCloudDirectorMediaType.TASK.getMediaType() + ";version=1.5")) .payload(payloadFromResourceWithContentType("/task/task.xml", VCloudDirectorMediaType.TASK + ";version=1.5"))
.build(); .build();
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse); VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse);

View File

@ -28,7 +28,6 @@ import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; import org.jclouds.vcloud.director.v1_5.domain.ReferenceType;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeTest;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
@ -80,7 +79,7 @@ public class BaseVCloudDirectorRestClientExpectTest extends BaseRestClientExpect
.put("x-vcloud-authorization", token) .put("x-vcloud-authorization", token)
.put("Set-Cookie", String.format("vcloud-token=%s; Secure; Path=/", token)) .put("Set-Cookie", String.format("vcloud-token=%s; Secure; Path=/", token))
.build()) .build())
.payload(payloadFromResourceWithContentType("/session.xml", VCloudDirectorMediaType.SESSION.getMediaType() + ";version=1.5")) .payload(payloadFromResourceWithContentType("/session.xml", VCloudDirectorMediaType.SESSION + ";version=1.5"))
.build(); .build();
public BaseVCloudDirectorRestClientExpectTest() { public BaseVCloudDirectorRestClientExpectTest() {
@ -97,24 +96,24 @@ public class BaseVCloudDirectorRestClientExpectTest extends BaseRestClientExpect
return getStandardRequest(method, uri, VCloudDirectorMediaType.ANY); return getStandardRequest(method, uri, VCloudDirectorMediaType.ANY);
} }
protected HttpRequest getStandardRequest(String method, URI uri, VCloudDirectorMediaType mediaType) { protected HttpRequest getStandardRequest(String method, URI uri, String mediaType) {
return HttpRequest.builder() return HttpRequest.builder()
.method(method) .method(method)
.endpoint(uri) .endpoint(uri)
.headers(ImmutableMultimap.<String, String> builder() .headers(ImmutableMultimap.<String, String> builder()
.put("Accept", mediaType.getMediaType()) .put("Accept", mediaType)
.put("x-vcloud-authorization", token) .put("x-vcloud-authorization", token)
.build()) .build())
.build(); .build();
} }
protected HttpResponse getStandardPayloadResponse(String relativeFilePath, VCloudDirectorMediaType mediaType) { protected HttpResponse getStandardPayloadResponse(String relativeFilePath, String mediaType) {
return getStandardPayloadResponse(200, relativeFilePath, mediaType); return getStandardPayloadResponse(200, relativeFilePath, mediaType);
} }
protected HttpResponse getStandardPayloadResponse(int statusCode, String relativeFilePath, VCloudDirectorMediaType mediaType) { protected HttpResponse getStandardPayloadResponse(int statusCode, String relativeFilePath, String mediaType) {
return HttpResponse.builder() return HttpResponse.builder()
.statusCode(statusCode) .statusCode(statusCode)
.payload(payloadFromResourceWithContentType(relativeFilePath, mediaType.getMediaType()+";version=1.5")).build(); .payload(payloadFromResourceWithContentType(relativeFilePath, mediaType + ";version=1.5")).build();
} }
} }

View File

@ -72,8 +72,7 @@ public class SessionClientExpectTest extends BaseRestClientExpectTest<SessionCli
ImmutableMultimap.<String, String> builder().put("x-vcloud-authorization", token).put("Set-Cookie", ImmutableMultimap.<String, String> builder().put("x-vcloud-authorization", token).put("Set-Cookie",
String.format("vcloud-token=%s; Secure; Path=/", token)).build()) String.format("vcloud-token=%s; Secure; Path=/", token)).build())
.payload( .payload(
payloadFromResourceWithContentType("/session.xml", VCloudDirectorMediaType.SESSION.getMediaType() payloadFromResourceWithContentType("/session.xml", VCloudDirectorMediaType.SESSION + ";version=1.5")).build()
+ ";version=1.5")).build()
); );
@ -97,8 +96,7 @@ public class SessionClientExpectTest extends BaseRestClientExpectTest<SessionCli
HttpResponse.builder().statusCode(200) HttpResponse.builder().statusCode(200)
.payload( .payload(
payloadFromResourceWithContentType("/session.xml", VCloudDirectorMediaType.SESSION.getMediaType() payloadFromResourceWithContentType("/session.xml", VCloudDirectorMediaType.SESSION + ";version=1.5")).build()
+ ";version=1.5")).build()
); );