Remove client methods which rely on parsing URIs and add new function for tasksList operation

This commit is contained in:
Andrew Donald Kennedy 2012-02-10 13:21:55 +00:00
parent 11b5938903
commit 64e698d4ff
10 changed files with 235 additions and 350 deletions

View File

@ -36,7 +36,7 @@ public class VCloudDirectorPropertiesBuilder extends PropertiesBuilder {
@Override @Override
protected Properties defaultProperties() { protected Properties defaultProperties() {
Properties properties = super.defaultProperties(); Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_ENDPOINT, "http://localhost/api"); properties.setProperty(PROPERTY_ENDPOINT, "https://vcloudbeta.bluelock.com/api");
properties.setProperty(PROPERTY_SESSION_INTERVAL, 30*60 + ""); properties.setProperty(PROPERTY_SESSION_INTERVAL, 30*60 + "");
properties.setProperty(PROPERTY_API_VERSION, "1.5"); properties.setProperty(PROPERTY_API_VERSION, "1.5");
return properties; return properties;

View File

@ -88,8 +88,8 @@ public class VCloudDirectorRestClientModule extends RestClientModule<VCloudDirec
protected void configure() { protected void configure() {
// session client is used directly for filters and retry handlers, so let's bind it explicitly // session client is used directly for filters and retry handlers, so let's bind it explicitly
bindClientAndAsyncClient(binder(), SessionClient.class, SessionAsyncClient.class); bindClientAndAsyncClient(binder(), SessionClient.class, SessionAsyncClient.class);
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to( bindClientAndAsyncClient(binder(), OrgClient.class, OrgAsyncClient.class);
InvalidateSessionAndRetryOn401AndLogoutOnClose.class); bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(InvalidateSessionAndRetryOn401AndLogoutOnClose.class);
super.configure(); super.configure();
} }

View File

@ -54,16 +54,6 @@ public interface OrgAsyncClient {
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<OrgList> getOrgList(); ListenableFuture<OrgList> getOrgList();
/**
* @see OrgClient#getOrg(String)
*/
@GET
@Path("/org/{id}")
@Consumes
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<Org> getOrg(@PathParam("id") String orgId);
/** /**
* @see OrgClient#getOrg(ReferenceType) * @see OrgClient#getOrg(ReferenceType)
*/ */
@ -73,16 +63,6 @@ public interface OrgAsyncClient {
@ExceptionParser(ThrowVCloudErrorOn4xx.class) @ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<Org> getOrg(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType<?> orgRef); ListenableFuture<Org> getOrg(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType<?> orgRef);
/**
* @see OrgClient#getMetadata(String)
*/
@GET
@Path("/org/{id}/metadata")
@Consumes
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<Metadata> getMetadata(@PathParam("id") String orgId);
/** /**
* @see OrgClient#getMetadata(ReferenceType) * @see OrgClient#getMetadata(ReferenceType)
*/ */
@ -93,16 +73,6 @@ public interface OrgAsyncClient {
@ExceptionParser(ThrowVCloudErrorOn4xx.class) @ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<Metadata> getMetadata(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType<?> orgRef); ListenableFuture<Metadata> getMetadata(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType<?> orgRef);
/**
* @see OrgClient#getMetadataEntry(String, String)
*/
@GET
@Path("/org/{id}/metadata/{key}")
@Consumes
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<MetadataEntry> getMetadataEntry(@PathParam("id") String orgId, @PathParam("key") String key);
/** /**
* @see OrgClient#getMetadataEntry(ReferenceType, String) * @see OrgClient#getMetadataEntry(ReferenceType, String)
*/ */
@ -111,5 +81,6 @@ public interface OrgAsyncClient {
@Consumes @Consumes
@JAXBResponseParser @JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class) @ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<MetadataEntry> getMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType<?> orgRef, @PathParam("key") String key); ListenableFuture<MetadataEntry> getMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType<?> orgRef,
@PathParam("key") String key);
} }

View File

@ -40,6 +40,10 @@ public interface OrgClient {
/** /**
* Retrieves a list of organizations. * Retrieves a list of organizations.
* *
* <pre>
* GET /org
* </pre>
*
* @return a list of organizations * @return a list of organizations
*/ */
OrgList getOrgList(); OrgList getOrgList();
@ -47,27 +51,35 @@ public interface OrgClient {
/** /**
* Retrieves an organization. * Retrieves an organization.
* *
* <pre>
* GET /org/{id}
* </pre>
*
* @return the org or null if not found * @return the org or null if not found
*/ */
Org getOrg(String orgId);
Org getOrg(ReferenceType<?> orgRef); Org getOrg(ReferenceType<?> orgRef);
// FIXME throws exception on not found currently
/** /**
* Retrieves an list of the organization's metadata * Retrieves an list of the organization's metadata
* *
* <pre>
* GET /org/{id}/metadata
* </pre>
*
* @return a list of metadata * @return a list of metadata
*/ */
Metadata getMetadata(String orgId);
Metadata getMetadata(ReferenceType<?> orgRef); Metadata getMetadata(ReferenceType<?> orgRef);
/** /**
* Retrieves a metadata * Retrieves a metadata entry.
* *
* @return the metadata or null if not found * <pre>
* GET /org/{id}/metadata{key}
* </pre>
*
* @return the metadata entry or null if not found
*/ */
MetadataEntry getMetadataEntry(String orgId, String key);
MetadataEntry getMetadataEntry(ReferenceType<?> orgRef, String key); MetadataEntry getMetadataEntry(ReferenceType<?> orgRef, String key);
// FIXME throws exception on not found currently
} }

View File

@ -22,7 +22,6 @@ import javax.ws.rs.Consumes;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.ExceptionParser;
@ -32,6 +31,7 @@ import org.jclouds.vcloud.director.v1_5.domain.ReferenceType;
import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.domain.Task;
import org.jclouds.vcloud.director.v1_5.domain.TasksList; import org.jclouds.vcloud.director.v1_5.domain.TasksList;
import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest;
import org.jclouds.vcloud.director.v1_5.functions.OrgReferenceToTaskListEndpoint;
import org.jclouds.vcloud.director.v1_5.functions.ReferenceToEndpoint; import org.jclouds.vcloud.director.v1_5.functions.ReferenceToEndpoint;
import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx; import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx;
@ -45,24 +45,13 @@ import com.google.common.util.concurrent.ListenableFuture;
public interface TaskAsyncClient { public interface TaskAsyncClient {
/** /**
* @see TaskClient#getTaskList(String) * @see TaskClient#getTaskList(ReferenceType<?>)
*/ */
@GET @GET
@Path("/tasksList/{id}")
@Consumes @Consumes
@JAXBResponseParser @JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class) @ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<TasksList> getTaskList(@PathParam("id") String orgId); ListenableFuture<TasksList> getTaskList(@EndpointParam(parser = OrgReferenceToTaskListEndpoint.class) ReferenceType<?> orgRef);
/**
* @see TaskClient#getTask(String id)
*/
@GET
@Path("/task/{id}")
@Consumes
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<Task> getTask(@PathParam("id") String taskId);
/** /**
* @see TaskClient#getTask(ReferenceType<?>) * @see TaskClient#getTask(ReferenceType<?>)
@ -73,16 +62,6 @@ public interface TaskAsyncClient {
@ExceptionParser(ThrowVCloudErrorOn4xx.class) @ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<Task> getTask(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType<?> taskRef); ListenableFuture<Task> getTask(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType<?> taskRef);
/**
* @see TaskClient#cancelTask(URI)
*/
@POST
@Path("/task/{id}/action/cancel")
@Consumes
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<Void> cancelTask(@PathParam("id") String taskId);
/** /**
* @see TaskClient#cancelTask(URI) * @see TaskClient#cancelTask(URI)
*/ */

View File

@ -37,24 +37,32 @@ public interface TaskClient {
/** /**
* Retrieves a list of tasks. * Retrieves a list of tasks.
* *
* <pre>
* GET /tasksList/{id}
* </pre>
*
* @param orgId the unique id for the organization * @param orgId the unique id for the organization
* @return a list of tasks * @return a list of tasks
*/ */
TasksList getTaskList(String orgId); TasksList getTaskList(ReferenceType<?> orgRef);
/** /**
* Retrieves a task. * Retrieves a task.
* *
* <pre>
* GET /task/{id}
* </pre>
*
* @return the task or null if not found * @return the task or null if not found
*/ */
Task getTask(String taskId);
Task getTask(ReferenceType<?> taskRef); Task getTask(ReferenceType<?> taskRef);
/** /**
* Cancels a task. * Cancels a task.
*
* <pre>
* POST /task/{id}/action/cancel
* </pre>
*/ */
void cancelTask(String taskId);
void cancelTask(ReferenceType<?> taskRef); void cancelTask(ReferenceType<?> taskRef);
} }

View File

@ -0,0 +1,60 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.vcloud.director.v1_5.functions;
import java.net.URI;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Link;
import org.jclouds.vcloud.director.v1_5.domain.Org;
import org.jclouds.vcloud.director.v1_5.domain.ReferenceType;
import org.jclouds.vcloud.director.v1_5.features.OrgClient;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
/**
* @author grkvlt@apache.org
*/
@Singleton
public class OrgReferenceToTaskListEndpoint implements Function<Object, URI> {
private final OrgClient client;
@Inject
public OrgReferenceToTaskListEndpoint(OrgClient client) {
this.client = client;
}
@Override
public URI apply(Object input) {
Preconditions.checkNotNull(input);
Preconditions.checkArgument(input instanceof ReferenceType<?>);
ReferenceType<?> reference = (ReferenceType<?>) input;
Org org = client.getOrg(reference);
for (Link link : org.getLinks()) {
if (link.getType().equals(VCloudDirectorMediaType.TASKS_LIST)) {
return link.getHref();
}
}
throw new RuntimeException(String.format("Could not find a link of type %s", VCloudDirectorMediaType.TASKS_LIST));
};
}

View File

@ -67,191 +67,36 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
getStandardRequest("GET", "/org"), getStandardRequest("GET", "/org"),
getStandardPayloadResponse("/org/orglist.xml", VCloudDirectorMediaType.ORG_LIST)); getStandardPayloadResponse("/org/orglist.xml", VCloudDirectorMediaType.ORG_LIST));
Reference org = Iterables.getOnlyElement(client.getOrgClient().getOrgList().getOrgs()); Reference org = Iterables.getOnlyElement(client.getOrgClient().getOrgList().getOrgs());
client = requestsSendResponses(loginRequest, sessionResponse, client = requestsSendResponses(loginRequest, sessionResponse,
getStandardRequest("GET", org.getHref()), getStandardRequest("GET", org.getHref()),
getStandardPayloadResponse("/org/org.xml", VCloudDirectorMediaType.ORG)); getStandardPayloadResponse("/org/org.xml", VCloudDirectorMediaType.ORG));
Org expected = Org Org expected = org();
.builder()
.name("JClouds")
.description("")
.fullName("JClouds")
.id("urn:vcloud:org:6f312e42-cd2b-488d-a2bb-97519cd57ed0")
.type("application/vnd.vmware.vcloud.org+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.link(Link.builder()
.rel("down")
.type("application/vnd.vmware.vcloud.vdc+xml")
.name("Cluster01-JClouds")
.href(URI.create("https://vcloudbeta.bluelock.com/api/vdc/d16d333b-e3c0-4176-845d-a5ee6392df07"))
.build())
.link(Link.builder()
.rel("down")
.type("application/vnd.vmware.vcloud.tasksList+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/tasksList/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.build())
.link(Link.builder()
.rel("down")
.type("application/vnd.vmware.vcloud.catalog+xml")
.name("Public")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c"))
.build())
.link(Link.builder()
.rel("down")
.type("application/vnd.vmware.vcloud.controlAccess+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c/controlAccess/"))
.build())
.link(Link.builder()
.rel("down")
.type("application/vnd.vmware.vcloud.orgNetwork+xml")
.name("ilsolation01-Jclouds")
.href(URI.create("https://vcloudbeta.bluelock.com/api/network/f3ba8256-6f48-4512-aad6-600e85b4dc38"))
.build())
.link(Link.builder()
.rel("down")
.type("application/vnd.vmware.vcloud.orgNetwork+xml")
.name("internet01-Jclouds")
.href(URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c"))
.build())
.link(Link.builder()
.rel("down")
.type("application/vnd.vmware.vcloud.metadata+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata"))
.build())
.build();
assertEquals(client.getOrgClient().getOrg(org), expected); assertEquals(client.getOrgClient().getOrg(org), expected);
} }
@Test
public void testWhenResponseIs2xxLoginReturnsValidOrgFromListById() {
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
getStandardRequest("GET", "/org"),
getStandardPayloadResponse("/org/orglist.xml", VCloudDirectorMediaType.ORG_LIST));
Reference org = Iterables.getOnlyElement(client.getOrgClient().getOrgList().getOrgs());
client = requestsSendResponses(loginRequest, sessionResponse,
getStandardRequest("GET", "/org/" + org.getUuid()),
getStandardPayloadResponse("/org/org.xml", VCloudDirectorMediaType.ORG));
Org expected = Org
.builder()
.name("JClouds")
.description("")
.fullName("JClouds")
.id("urn:vcloud:org:6f312e42-cd2b-488d-a2bb-97519cd57ed0")
.type("application/vnd.vmware.vcloud.org+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.link(Link.builder()
.rel("down")
.type("application/vnd.vmware.vcloud.vdc+xml")
.name("Cluster01-JClouds")
.href(URI.create("https://vcloudbeta.bluelock.com/api/vdc/d16d333b-e3c0-4176-845d-a5ee6392df07"))
.build())
.link(Link.builder()
.rel("down")
.type("application/vnd.vmware.vcloud.tasksList+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/tasksList/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.build())
.link(Link.builder()
.rel("down")
.type("application/vnd.vmware.vcloud.catalog+xml")
.name("Public")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c"))
.build())
.link(Link.builder()
.rel("down")
.type("application/vnd.vmware.vcloud.controlAccess+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c/controlAccess/"))
.build())
.link(Link.builder()
.rel("down")
.type("application/vnd.vmware.vcloud.orgNetwork+xml")
.name("ilsolation01-Jclouds")
.href(URI.create("https://vcloudbeta.bluelock.com/api/network/f3ba8256-6f48-4512-aad6-600e85b4dc38"))
.build())
.link(Link.builder()
.rel("down")
.type("application/vnd.vmware.vcloud.orgNetwork+xml")
.name("internet01-Jclouds")
.href(URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c"))
.build())
.link(Link.builder()
.rel("down")
.type("application/vnd.vmware.vcloud.metadata+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata"))
.build())
.build();
assertEquals(org.getUuid(), "6f312e42-cd2b-488d-a2bb-97519cd57ed0");
assertEquals(client.getOrgClient().getOrg(org.getUuid()), expected);
}
@Test @Test
public void testWhenResponseIs2xxLoginReturnsValidOrg() { public void testWhenResponseIs2xxLoginReturnsValidOrg() {
URI orgRef = URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"); URI orgUri = URI.create(endpoint + "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0");
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
getStandardRequest("GET", "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"), getStandardRequest("GET", "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"),
getStandardPayloadResponse("/org/org.xml", VCloudDirectorMediaType.ORG)); getStandardPayloadResponse("/org/org.xml", VCloudDirectorMediaType.ORG));
Org expected = Org Org expected = org();
.builder()
.name("JClouds")
.description("")
.fullName("JClouds")
.id("urn:vcloud:org:6f312e42-cd2b-488d-a2bb-97519cd57ed0")
.type("application/vnd.vmware.vcloud.org+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.link(Link.builder()
.rel("down")
.type("application/vnd.vmware.vcloud.vdc+xml")
.name("Cluster01-JClouds")
.href(URI.create("https://vcloudbeta.bluelock.com/api/vdc/d16d333b-e3c0-4176-845d-a5ee6392df07"))
.build())
.link(Link.builder()
.rel("down")
.type("application/vnd.vmware.vcloud.tasksList+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/tasksList/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.build())
.link(Link.builder()
.rel("down")
.type("application/vnd.vmware.vcloud.catalog+xml")
.name("Public")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c"))
.build())
.link(Link.builder()
.rel("down")
.type("application/vnd.vmware.vcloud.controlAccess+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c/controlAccess/"))
.build())
.link(Link.builder()
.rel("down")
.type("application/vnd.vmware.vcloud.orgNetwork+xml")
.name("ilsolation01-Jclouds")
.href(URI.create("https://vcloudbeta.bluelock.com/api/network/f3ba8256-6f48-4512-aad6-600e85b4dc38"))
.build())
.link(Link.builder()
.rel("down")
.type("application/vnd.vmware.vcloud.orgNetwork+xml")
.name("internet01-Jclouds")
.href(URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c"))
.build())
.link(Link.builder()
.rel("down")
.type("application/vnd.vmware.vcloud.metadata+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata"))
.build())
.build();
String orgId = getUuidFromReference.apply(Reference.builder().href(orgRef).build()); Reference orgRef = Reference.builder().href(orgUri).build();
assertEquals(client.getOrgClient().getOrg(orgId), expected);
assertEquals(client.getOrgClient().getOrg(orgRef), expected);
} }
@Test @Test
public void testWhenResponseIs400ForInvalidOrgId() { public void testWhenResponseIs400ForInvalidOrgId() {
URI orgRef = URI.create("https://vcloudbeta.bluelock.com/api/org/NOTAUUID"); URI orgUri = URI.create(endpoint + "/org/NOTAUUID");
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
getStandardRequest("GET", "/org/NOTAUUID"), getStandardRequest("GET", "/org/NOTAUUID"),
@ -263,9 +108,9 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
.minorErrorCode("BAD_REQUEST") .minorErrorCode("BAD_REQUEST")
.build(); .build();
String orgId = getUuidFromReference.apply(Reference.builder().href(orgRef).build()); Reference orgRef = Reference.builder().href(orgUri).build();
try { try {
client.getOrgClient().getOrg(orgId); client.getOrgClient().getOrg(orgRef);
fail("Should give HTTP 400 error"); fail("Should give HTTP 400 error");
} catch (VCloudDirectorException vde) { } catch (VCloudDirectorException vde) {
assertEquals(vde.getError(), expected); assertEquals(vde.getError(), expected);
@ -276,7 +121,7 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
@Test @Test
public void testWhenResponseIs403ForCatalogIdUsedAsOrgId() { public void testWhenResponseIs403ForCatalogIdUsedAsOrgId() {
URI orgRef = URI.create("https://vcloudbeta.bluelock.com/api/org/9e08c2f6-077a-42ce-bece-d5332e2ebb5c"); URI orgUri = URI.create(endpoint + "/org/9e08c2f6-077a-42ce-bece-d5332e2ebb5c");
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
getStandardRequest("GET", "/org/9e08c2f6-077a-42ce-bece-d5332e2ebb5c"), getStandardRequest("GET", "/org/9e08c2f6-077a-42ce-bece-d5332e2ebb5c"),
@ -288,9 +133,10 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
.minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN") .minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN")
.build(); .build();
String orgId = getUuidFromReference.apply(Reference.builder().href(orgRef).build()); Reference orgRef = Reference.builder().href(orgUri).build();
try { try {
client.getOrgClient().getOrg(orgId); client.getOrgClient().getOrg(orgRef);
fail("Should give HTTP 403 error"); fail("Should give HTTP 403 error");
} catch (VCloudDirectorException vde) { } catch (VCloudDirectorException vde) {
assertEquals(vde.getError(), expected); assertEquals(vde.getError(), expected);
@ -301,7 +147,7 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
@Test @Test
public void testWhenResponseIs403ForFakeOrgId() { public void testWhenResponseIs403ForFakeOrgId() {
URI orgRef = URI.create("https://vcloudbeta.bluelock.com/api/org/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"); URI orgUri = URI.create(endpoint + "/org/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee");
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
getStandardRequest("GET", "/org/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"), getStandardRequest("GET", "/org/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"),
@ -313,9 +159,10 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
.minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN") .minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN")
.build(); .build();
String orgId = getUuidFromReference.apply(Reference.builder().href(orgRef).build()); Reference orgRef = Reference.builder().href(orgUri).build();
try { try {
client.getOrgClient().getOrg(orgId); client.getOrgClient().getOrg(orgRef);
fail("Should give HTTP 403 error"); fail("Should give HTTP 403 error");
} catch (VCloudDirectorException vde) { } catch (VCloudDirectorException vde) {
assertEquals(vde.getError(), expected); assertEquals(vde.getError(), expected);
@ -326,7 +173,7 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
@Test @Test
public void testWhenResponseIs2xxLoginReturnsValidMetadataList() { public void testWhenResponseIs2xxLoginReturnsValidMetadataList() {
URI orgRef = URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"); URI orgUri = URI.create(endpoint + "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0");
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
getStandardRequest("GET", "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata"), getStandardRequest("GET", "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata"),
@ -342,13 +189,14 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
.build()) .build())
.build(); .build();
String orgId = getUuidFromReference.apply(Reference.builder().href(orgRef).build()); Reference orgRef = Reference.builder().href(orgUri).build();
assertEquals(client.getOrgClient().getMetadata(orgId), expected);
assertEquals(client.getOrgClient().getMetadata(orgRef), expected);
} }
@Test(enabled=false) // No metadata in exemplar xml... @Test(enabled=false) // No metadata in exemplar xml...
public void testWhenResponseIs2xxLoginReturnsValidMetadata() { public void testWhenResponseIs2xxLoginReturnsValidMetadata() {
URI orgRef = URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"); URI orgUri = URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0");
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
getStandardRequest("GET", "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata/KEY"), getStandardRequest("GET", "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata/KEY"),
@ -358,7 +206,58 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
.key("KEY") .key("KEY")
.build(); .build();
String orgId = getUuidFromReference.apply(Reference.builder().href(orgRef).build()); Reference orgRef = Reference.builder().href(orgUri).build();
assertEquals(client.getOrgClient().getMetadataEntry(orgId, "KEY"), expected);
assertEquals(client.getOrgClient().getMetadataEntry(orgRef, "KEY"), expected);
}
public static Org org() {
return Org.builder()
.name("JClouds")
.description("")
.fullName("JClouds")
.id("urn:vcloud:org:6f312e42-cd2b-488d-a2bb-97519cd57ed0")
.type("application/vnd.vmware.vcloud.org+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.link(Link.builder()
.rel("down")
.type("application/vnd.vmware.vcloud.vdc+xml")
.name("Cluster01-JClouds")
.href(URI.create("https://vcloudbeta.bluelock.com/api/vdc/d16d333b-e3c0-4176-845d-a5ee6392df07"))
.build())
.link(Link.builder()
.rel("down")
.type("application/vnd.vmware.vcloud.tasksList+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/tasksList/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.build())
.link(Link.builder()
.rel("down")
.type("application/vnd.vmware.vcloud.catalog+xml")
.name("Public")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c"))
.build())
.link(Link.builder()
.rel("down")
.type("application/vnd.vmware.vcloud.controlAccess+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c/controlAccess/"))
.build())
.link(Link.builder()
.rel("down")
.type("application/vnd.vmware.vcloud.orgNetwork+xml")
.name("ilsolation01-Jclouds")
.href(URI.create("https://vcloudbeta.bluelock.com/api/network/f3ba8256-6f48-4512-aad6-600e85b4dc38"))
.build())
.link(Link.builder()
.rel("down")
.type("application/vnd.vmware.vcloud.orgNetwork+xml")
.name("internet01-Jclouds")
.href(URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c"))
.build())
.link(Link.builder()
.rel("down")
.type("application/vnd.vmware.vcloud.metadata+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata"))
.build())
.build();
} }
} }

View File

@ -60,9 +60,21 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
.payload(payloadFromResourceWithContentType("/task/taskslist.xml", VCloudDirectorMediaType.TASKS_LIST + ";version=1.5")) .payload(payloadFromResourceWithContentType("/task/taskslist.xml", VCloudDirectorMediaType.TASKS_LIST + ";version=1.5"))
.build(); .build();
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse); HttpRequest orgRequest = HttpRequest.builder()
.method("GET")
.endpoint(URI.create(endpoint + "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.headers(ImmutableMultimap.<String, String> builder()
.put("Accept", "*/*")
.put("x-vcloud-authorization", token)
.build())
.build();
String orgId = getUuidFromReference.apply(Reference.builder().href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")).build()); HttpResponse orgResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/org/org.xml", VCloudDirectorMediaType.TASKS_LIST + ";version=1.5"))
.build();
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse, orgRequest, orgResponse);
TasksList expected = TasksList.builder() TasksList expected = TasksList.builder()
.name("Tasks Lists") .name("Tasks Lists")
@ -119,7 +131,9 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
.build()) .build())
.build(); .build();
assertEquals(client.getTaskClient().getTaskList(orgId), expected); Reference orgRef = Reference.builder().href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")).build();
assertEquals(client.getTaskClient().getTaskList(orgRef), expected);
} }
@Test @Test
@ -133,22 +147,34 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
.build()) .build())
.build(); .build();
HttpResponse taskResponse = HttpResponse.builder() HttpResponse taskResponse = HttpResponse.builder().build();
.statusCode(400)
.payload(payloadFromResourceWithContentType("/task/error400.xml", VCloudDirectorMediaType.ERROR + ";version=1.5")) HttpRequest orgRequest = HttpRequest.builder()
.method("GET")
.endpoint(URI.create(endpoint + "/org/NOTAUUID"))
.headers(ImmutableMultimap.<String, String> builder()
.put("Accept", "*/*")
.put("x-vcloud-authorization", token)
.build())
.build(); .build();
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse); HttpResponse orgResponse = HttpResponse.builder()
.statusCode(400)
.payload(payloadFromResourceWithContentType("/org/error400.xml", VCloudDirectorMediaType.ERROR + ";version=1.5"))
.build();
String orgId = "NOTAUUID"; VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse, orgRequest, orgResponse);
Error expected = Error.builder() Error expected = Error.builder()
.message("validation error on field 'id': String value has invalid format or length") .message("validation error on field 'id': String value has invalid format or length")
.majorErrorCode(400) .majorErrorCode(400)
.minorErrorCode("BAD_REQUEST") .minorErrorCode("BAD_REQUEST")
.build(); .build();
Reference orgRef = Reference.builder().href(URI.create("https://vcloudbeta.bluelock.com/api/org/NOTAUUID")).build();
try { try {
client.getTaskClient().getTaskList(orgId); client.getTaskClient().getTaskList(orgRef);
fail("Should give HTTP 400 error"); fail("Should give HTTP 400 error");
} catch (VCloudDirectorException vde) { } catch (VCloudDirectorException vde) {
assertEquals(vde.getError(), expected); assertEquals(vde.getError(), expected);
@ -168,14 +194,23 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
.build()) .build())
.build(); .build();
HttpResponse taskResponse = HttpResponse.builder() HttpResponse taskResponse = HttpResponse.builder().build();
.statusCode(403)
.payload(payloadFromResourceWithContentType("/task/error403.xml", VCloudDirectorMediaType.ERROR + ";version=1.5")) HttpRequest orgRequest = HttpRequest.builder()
.method("GET")
.endpoint(URI.create(endpoint + "/org/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"))
.headers(ImmutableMultimap.<String, String> builder()
.put("Accept", "*/*")
.put("x-vcloud-authorization", token)
.build())
.build(); .build();
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse); HttpResponse orgResponse = HttpResponse.builder()
.statusCode(403)
.payload(payloadFromResourceWithContentType("/org/error403-fake.xml", VCloudDirectorMediaType.ERROR + ";version=1.5"))
.build();
String orgId = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"; VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse, orgRequest, orgResponse);
Error expected = Error.builder() Error expected = Error.builder()
.message("No access to entity \"com.vmware.vcloud.entity.org:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee\".") .message("No access to entity \"com.vmware.vcloud.entity.org:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee\".")
@ -183,9 +218,11 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
.minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN") .minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN")
.build(); .build();
Reference orgRef = Reference.builder().href(URI.create("https://vcloudbeta.bluelock.com/api/org/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")).build();
try { try {
client.getTaskClient().getTaskList(orgId); client.getTaskClient().getTaskList(orgRef);
fail("Should give HTTP 400 error"); fail("Should give HTTP 403 error");
} catch (VCloudDirectorException vde) { } catch (VCloudDirectorException vde) {
assertEquals(vde.getError(), expected); assertEquals(vde.getError(), expected);
} catch (Exception e) { } catch (Exception e) {
@ -193,57 +230,6 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
} }
} }
@Test
public void testGetTaskForTaskId() {
HttpRequest taskRequest = HttpRequest.builder()
.method("GET")
.endpoint(URI.create(endpoint + "/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b"))
.headers(ImmutableMultimap.<String, String> builder()
.put("Accept", "*/*")
.put("x-vcloud-authorization", token)
.build())
.build();
HttpResponse taskResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/task/task.xml", VCloudDirectorMediaType.TASK + ";version=1.5"))
.build();
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse);
String taskId = "5fcd2af3-d0ec-45ce-9451-8c585a2c766b";
Task expected = Task.builder()
.type("application/vnd.vmware.vcloud.task+xml")
.name("task")
.id("urn:vcloud:task:5fcd2af3-d0ec-45ce-9451-8c585a2c766b")
.href(URI.create("https://vcloudbeta.bluelock.com/api/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b"))
.status("success")
.operation("Created Catalog QunyingTestCatalog(7212e451-76e1-4631-b2de-ba1dfd8080e4)")
.operationName("catalogCreateCatalog")
.startTime(dateService.iso8601DateParse("2012-02-07T00:16:28.450-05:00"))
.endTime(dateService.iso8601DateParse("2012-02-07T00:16:28.867-05:00"))
.expiryTime(dateService.iso8601DateParse("2012-05-07T00:16:28.450-04:00"))
.owner(Reference.builder()
.type("application/vnd.vmware.vcloud.catalog+xml")
.name("QunyingTestCatalog")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4"))
.build())
.user(Reference.builder()
.type("application/vnd.vmware.admin.user+xml")
.name("JClouds")
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.build())
.org(Reference.builder()
.type("application/vnd.vmware.vcloud.org+xml")
.name("JClouds")
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.build())
.build();
assertEquals(client.getTaskClient().getTask(taskId), expected);
}
@Test @Test
public void testGetTaskForTaskRef() { public void testGetTaskForTaskRef() {
HttpRequest taskRequest = HttpRequest.builder() HttpRequest taskRequest = HttpRequest.builder()
@ -299,28 +285,6 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
assertEquals(client.getTaskClient().getTask(taskRef), expected); assertEquals(client.getTaskClient().getTask(taskRef), expected);
} }
@Test
public void testCancelTaskByTaskId() {
HttpRequest taskRequest = HttpRequest.builder()
.method("POST")
.endpoint(URI.create(endpoint + "/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b/action/cancel"))
.headers(ImmutableMultimap.<String, String> builder()
.put("Accept", "*/*")
.put("x-vcloud-authorization", token)
.build())
.build();
HttpResponse taskResponse = HttpResponse.builder()
.statusCode(200)
.build();
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse);
String taskId = "5fcd2af3-d0ec-45ce-9451-8c585a2c766b";
client.getTaskClient().cancelTask(taskId);
}
@Test @Test
public void testCancelTaskByTaskRef() { public void testCancelTaskByTaskRef() {
HttpRequest taskRequest = HttpRequest.builder() HttpRequest taskRequest = HttpRequest.builder()

View File

@ -46,7 +46,7 @@ public class BaseVCloudDirectorRestClientExpectTest extends BaseRestClientExpect
public static final String org = "JClouds"; public static final String org = "JClouds";
public static final String password = "password"; public static final String password = "password";
public static final String token = "mIaR3/6Lna8DWImd7/JPR5rK8FcUHabt+G/UCJV5pJQ="; public static final String token = "mIaR3/6Lna8DWImd7/JPR5rK8FcUHabt+G/UCJV5pJQ=";
public static final String endpoint = "http://localhost/api"; public static final String endpoint = "https://vcloudbeta.bluelock.com/api";
protected DateService dateService; protected DateService dateService;
@ -56,17 +56,9 @@ public class BaseVCloudDirectorRestClientExpectTest extends BaseRestClientExpect
assert dateService != null; assert dateService != null;
} }
protected static final Function<ReferenceType<?>, String> getUuidFromReference = new Function<ReferenceType<?>, String>() {
@Override
public String apply(ReferenceType<?> input) {
String uuid = Iterables.getLast(Splitter.on("/").split(input.getHref().getPath()));
return uuid;
}
};
protected HttpRequest loginRequest = HttpRequest.builder() protected HttpRequest loginRequest = HttpRequest.builder()
.method("POST") .method("POST")
.endpoint(URI.create("http://localhost/api/sessions")) .endpoint(URI.create(endpoint + "/sessions"))
.headers(ImmutableMultimap.<String, String>builder() .headers(ImmutableMultimap.<String, String>builder()
.put("Accept", "*/*") .put("Accept", "*/*")
.put("Authorization", "Basic YWRyaWFuQGpjbG91ZHMub3JnQEpDbG91ZHM6cGFzc3dvcmQ=") .put("Authorization", "Basic YWRyaWFuQGpjbG91ZHMub3JnQEpDbG91ZHM6cGFzc3dvcmQ=")