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;
*/
public enum 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");
public class VCloudDirectorMediaType {
private final String mediaType;
public static final String ANY = "*/*";
private VCloudDirectorMediaType(String mediaType) {
this.mediaType = mediaType;
}
public static final String SESSION = "application/vnd.vmware.vcloud.session+xml";
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.XmlRootElement;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import com.google.common.base.Objects;
/**
@ -42,6 +44,8 @@ import com.google.common.base.Objects;
@XmlAccessorType(XmlAccessType.FIELD)
public class Error {
public static final String MEDIA_TYPE = VCloudDirectorMediaType.ERROR;
public static Builder 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.XmlRootElement;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableSet;
@ -45,6 +47,8 @@ import com.google.common.collect.Sets;
@XmlRootElement(namespace = XMLNS, name = "Metadata")
public class Metadata extends ResourceType<Metadata> {
public static final String MEDIA_TYPE = VCloudDirectorMediaType.METADATA;
@SuppressWarnings("unchecked")
public static Builder 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.XmlRootElement;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.Sets;
@ -44,6 +46,8 @@ import com.google.common.collect.Sets;
@XmlRootElement(namespace = XMLNS, name = "MetadataEntry")
public class MetadataEntry extends ResourceType<MetadataEntry> {
public static final String MEDIA_TYPE = VCloudDirectorMediaType.METADATA_ENTRY;
@SuppressWarnings("unchecked")
public static Builder 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.XmlRootElement;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.Sets;
@ -46,6 +48,8 @@ import com.google.common.collect.Sets;
@XmlRootElement(namespace = XMLNS, name = "Org")
public class Org extends EntityType<Org> {
public static final String MEDIA_TYPE = VCloudDirectorMediaType.ORG;
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();

View File

@ -27,6 +27,8 @@ import java.util.Set;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
@ -39,6 +41,8 @@ import com.google.common.collect.Sets;
@XmlRootElement(namespace = XMLNS, name = "OrgList")
public class OrgList {
public static final String MEDIA_TYPE = VCloudDirectorMediaType.ORG_LIST;
public static Builder 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.XmlRootElement;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
@ -46,6 +48,8 @@ import com.google.common.collect.Sets;
@XmlAccessorType(XmlAccessType.FIELD)
public class Session {
public static final String MEDIA_TYPE = VCloudDirectorMediaType.SESSION;
public static Builder 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.XmlRootElement;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.Sets;
@ -46,6 +48,8 @@ import com.google.common.collect.Sets;
@XmlRootElement(namespace = XMLNS, name = "Task")
public class Task extends EntityType<Task> {
public static final String MEDIA_TYPE = VCloudDirectorMediaType.TASK;
@SuppressWarnings("unchecked")
public static Builder 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.XmlRootElement;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableSet;
@ -41,6 +43,8 @@ import com.google.common.collect.Sets;
@XmlRootElement(namespace = XMLNS, name = "TasksList")
public class TasksList extends EntityType<TasksList> {
public static final String MEDIA_TYPE = VCloudDirectorMediaType.TASKS_LIST;
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();

View File

@ -57,7 +57,7 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
HttpResponse taskResponse = HttpResponse.builder()
.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();
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse);
@ -135,7 +135,7 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
HttpResponse taskResponse = HttpResponse.builder()
.statusCode(400)
.payload(payloadFromResourceWithContentType("/task/error400.xml", VCloudDirectorMediaType.ERROR.getMediaType() + ";version=1.5"))
.payload(payloadFromResourceWithContentType("/task/error400.xml", VCloudDirectorMediaType.ERROR + ";version=1.5"))
.build();
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse);
@ -170,7 +170,7 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
HttpResponse taskResponse = HttpResponse.builder()
.statusCode(403)
.payload(payloadFromResourceWithContentType("/task/error403.xml", VCloudDirectorMediaType.ERROR.getMediaType() + ";version=1.5"))
.payload(payloadFromResourceWithContentType("/task/error403.xml", VCloudDirectorMediaType.ERROR + ";version=1.5"))
.build();
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse);
@ -206,7 +206,7 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
HttpResponse taskResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/task/task.xml", VCloudDirectorMediaType.TASK.getMediaType() + ";version=1.5"))
.payload(payloadFromResourceWithContentType("/task/task.xml", VCloudDirectorMediaType.TASK + ";version=1.5"))
.build();
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse);
@ -257,7 +257,7 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
HttpResponse taskResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/task/task.xml", VCloudDirectorMediaType.TASK.getMediaType() + ";version=1.5"))
.payload(payloadFromResourceWithContentType("/task/task.xml", VCloudDirectorMediaType.TASK + ";version=1.5"))
.build();
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.domain.ReferenceType;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeTest;
import com.google.common.base.Function;
import com.google.common.base.Splitter;
@ -80,7 +79,7 @@ public class BaseVCloudDirectorRestClientExpectTest extends BaseRestClientExpect
.put("x-vcloud-authorization", token)
.put("Set-Cookie", String.format("vcloud-token=%s; Secure; Path=/", token))
.build())
.payload(payloadFromResourceWithContentType("/session.xml", VCloudDirectorMediaType.SESSION.getMediaType() + ";version=1.5"))
.payload(payloadFromResourceWithContentType("/session.xml", VCloudDirectorMediaType.SESSION + ";version=1.5"))
.build();
public BaseVCloudDirectorRestClientExpectTest() {
@ -97,24 +96,24 @@ public class BaseVCloudDirectorRestClientExpectTest extends BaseRestClientExpect
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()
.method(method)
.endpoint(uri)
.headers(ImmutableMultimap.<String, String> builder()
.put("Accept", mediaType.getMediaType())
.put("Accept", mediaType)
.put("x-vcloud-authorization", token)
.build())
.build();
}
protected HttpResponse getStandardPayloadResponse(String relativeFilePath, VCloudDirectorMediaType mediaType) {
protected HttpResponse getStandardPayloadResponse(String relativeFilePath, String 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()
.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",
String.format("vcloud-token=%s; Secure; Path=/", token)).build())
.payload(
payloadFromResourceWithContentType("/session.xml", VCloudDirectorMediaType.SESSION.getMediaType()
+ ";version=1.5")).build()
payloadFromResourceWithContentType("/session.xml", VCloudDirectorMediaType.SESSION + ";version=1.5")).build()
);
@ -97,8 +96,7 @@ public class SessionClientExpectTest extends BaseRestClientExpectTest<SessionCli
HttpResponse.builder().statusCode(200)
.payload(
payloadFromResourceWithContentType("/session.xml", VCloudDirectorMediaType.SESSION.getMediaType()
+ ";version=1.5")).build()
payloadFromResourceWithContentType("/session.xml", VCloudDirectorMediaType.SESSION + ";version=1.5")).build()
);