diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorPropertiesBuilder.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorPropertiesBuilder.java index 05e724c3c1..0e0b74745a 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorPropertiesBuilder.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorPropertiesBuilder.java @@ -36,7 +36,7 @@ public class VCloudDirectorPropertiesBuilder extends PropertiesBuilder { @Override protected Properties 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_API_VERSION, "1.5"); return properties; diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java index 49e2865065..9c868d7f6e 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java @@ -88,8 +88,8 @@ public class VCloudDirectorRestClientModule extends RestClientModule getOrgList(); - /** - * @see OrgClient#getOrg(String) - */ - @GET - @Path("/org/{id}") - @Consumes - @JAXBResponseParser - @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture getOrg(@PathParam("id") String orgId); - /** * @see OrgClient#getOrg(ReferenceType) */ @@ -73,16 +63,6 @@ public interface OrgAsyncClient { @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture getOrg(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType orgRef); - /** - * @see OrgClient#getMetadata(String) - */ - @GET - @Path("/org/{id}/metadata") - @Consumes - @JAXBResponseParser - @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture getMetadata(@PathParam("id") String orgId); - /** * @see OrgClient#getMetadata(ReferenceType) */ @@ -93,16 +73,6 @@ public interface OrgAsyncClient { @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture getMetadata(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType orgRef); - /** - * @see OrgClient#getMetadataEntry(String, String) - */ - @GET - @Path("/org/{id}/metadata/{key}") - @Consumes - @JAXBResponseParser - @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture getMetadataEntry(@PathParam("id") String orgId, @PathParam("key") String key); - /** * @see OrgClient#getMetadataEntry(ReferenceType, String) */ @@ -111,5 +81,6 @@ public interface OrgAsyncClient { @Consumes @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture getMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType orgRef, @PathParam("key") String key); + ListenableFuture getMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType orgRef, + @PathParam("key") String key); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgClient.java index d72d99c17f..e52ac68748 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgClient.java @@ -39,6 +39,10 @@ public interface OrgClient { /** * Retrieves a list of organizations. + * + *
+    * GET /org
+    * 
* * @return a list of organizations */ @@ -46,28 +50,36 @@ public interface OrgClient { /** * Retrieves an organization. + * + *
+    * GET /org/{id}
+    * 
* * @return the org or null if not found */ - Org getOrg(String orgId); - Org getOrg(ReferenceType orgRef); + // FIXME throws exception on not found currently /** * Retrieves an list of the organization's metadata + * + *
+    * GET /org/{id}/metadata
+    * 
* * @return a list of metadata */ - Metadata getMetadata(String orgId); - Metadata getMetadata(ReferenceType orgRef); /** - * Retrieves a metadata + * Retrieves a metadata entry. + * + *
+    * GET /org/{id}/metadata{key}
+    * 
* - * @return the metadata or null if not found + * @return the metadata entry or null if not found */ - MetadataEntry getMetadataEntry(String orgId, String key); - MetadataEntry getMetadataEntry(ReferenceType orgRef, String key); + // FIXME throws exception on not found currently } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskAsyncClient.java index 833b918640..41050aee94 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskAsyncClient.java @@ -22,7 +22,6 @@ import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; -import javax.ws.rs.PathParam; import org.jclouds.rest.annotations.EndpointParam; 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.TasksList; 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.ThrowVCloudErrorOn4xx; @@ -45,24 +45,13 @@ import com.google.common.util.concurrent.ListenableFuture; public interface TaskAsyncClient { /** - * @see TaskClient#getTaskList(String) + * @see TaskClient#getTaskList(ReferenceType) */ @GET - @Path("/tasksList/{id}") @Consumes @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture getTaskList(@PathParam("id") String orgId); - - /** - * @see TaskClient#getTask(String id) - */ - @GET - @Path("/task/{id}") - @Consumes - @JAXBResponseParser - @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture getTask(@PathParam("id") String taskId); + ListenableFuture getTaskList(@EndpointParam(parser = OrgReferenceToTaskListEndpoint.class) ReferenceType orgRef); /** * @see TaskClient#getTask(ReferenceType) @@ -73,16 +62,6 @@ public interface TaskAsyncClient { @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture getTask(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType taskRef); - /** - * @see TaskClient#cancelTask(URI) - */ - @POST - @Path("/task/{id}/action/cancel") - @Consumes - @JAXBResponseParser - @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture cancelTask(@PathParam("id") String taskId); - /** * @see TaskClient#cancelTask(URI) */ diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskClient.java index be8734c722..9682316877 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/TaskClient.java @@ -36,25 +36,33 @@ public interface TaskClient { /** * Retrieves a list of tasks. + * + *
+    * GET /tasksList/{id}
+    * 
* * @param orgId the unique id for the organization * @return a list of tasks */ - TasksList getTaskList(String orgId); + TasksList getTaskList(ReferenceType orgRef); /** * Retrieves a task. + * + *
+    * GET /task/{id}
+    * 
* * @return the task or null if not found */ - Task getTask(String taskId); - Task getTask(ReferenceType taskRef); /** * Cancels a task. + * + *
+    * POST /task/{id}/action/cancel
+    * 
*/ - void cancelTask(String taskId); - void cancelTask(ReferenceType taskRef); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/OrgReferenceToTaskListEndpoint.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/OrgReferenceToTaskListEndpoint.java new file mode 100644 index 0000000000..42b7e07dee --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/functions/OrgReferenceToTaskListEndpoint.java @@ -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 { + 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)); + }; +} \ No newline at end of file diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientExpectTest.java index ff368206b4..b7c3dc7f6d 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/OrgClientExpectTest.java @@ -67,191 +67,36 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest 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.getHref()), 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(); + Org expected = org(); 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 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, getStandardRequest("GET", "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"), 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(); + Org expected = org(); - String orgId = getUuidFromReference.apply(Reference.builder().href(orgRef).build()); - assertEquals(client.getOrgClient().getOrg(orgId), expected); + Reference orgRef = Reference.builder().href(orgUri).build(); + + assertEquals(client.getOrgClient().getOrg(orgRef), expected); } @Test 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, getStandardRequest("GET", "/org/NOTAUUID"), @@ -263,9 +108,9 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest .minorErrorCode("BAD_REQUEST") .build(); - String orgId = getUuidFromReference.apply(Reference.builder().href(orgRef).build()); + Reference orgRef = Reference.builder().href(orgUri).build(); try { - client.getOrgClient().getOrg(orgId); + client.getOrgClient().getOrg(orgRef); fail("Should give HTTP 400 error"); } catch (VCloudDirectorException vde) { assertEquals(vde.getError(), expected); @@ -276,7 +121,7 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest @Test 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, getStandardRequest("GET", "/org/9e08c2f6-077a-42ce-bece-d5332e2ebb5c"), @@ -288,9 +133,10 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest .minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN") .build(); - String orgId = getUuidFromReference.apply(Reference.builder().href(orgRef).build()); + Reference orgRef = Reference.builder().href(orgUri).build(); + try { - client.getOrgClient().getOrg(orgId); + client.getOrgClient().getOrg(orgRef); fail("Should give HTTP 403 error"); } catch (VCloudDirectorException vde) { assertEquals(vde.getError(), expected); @@ -301,7 +147,7 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest @Test 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, getStandardRequest("GET", "/org/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"), @@ -313,9 +159,10 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest .minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN") .build(); - String orgId = getUuidFromReference.apply(Reference.builder().href(orgRef).build()); + Reference orgRef = Reference.builder().href(orgUri).build(); + try { - client.getOrgClient().getOrg(orgId); + client.getOrgClient().getOrg(orgRef); fail("Should give HTTP 403 error"); } catch (VCloudDirectorException vde) { assertEquals(vde.getError(), expected); @@ -326,7 +173,7 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest @Test 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, getStandardRequest("GET", "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata"), @@ -342,13 +189,14 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest .build()) .build(); - String orgId = getUuidFromReference.apply(Reference.builder().href(orgRef).build()); - assertEquals(client.getOrgClient().getMetadata(orgId), expected); + Reference orgRef = Reference.builder().href(orgUri).build(); + + assertEquals(client.getOrgClient().getMetadata(orgRef), expected); } @Test(enabled=false) // No metadata in exemplar xml... 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, getStandardRequest("GET", "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata/KEY"), @@ -358,7 +206,58 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest .key("KEY") .build(); - String orgId = getUuidFromReference.apply(Reference.builder().href(orgRef).build()); - assertEquals(client.getOrgClient().getMetadataEntry(orgId, "KEY"), expected); + Reference orgRef = Reference.builder().href(orgUri).build(); + + 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(); } } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientExpectTest.java index 2082fa2651..fae7bebf13 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/TaskClientExpectTest.java @@ -59,11 +59,23 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest .statusCode(200) .payload(payloadFromResourceWithContentType("/task/taskslist.xml", VCloudDirectorMediaType.TASKS_LIST + ";version=1.5")) .build(); - - VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse); - - String orgId = getUuidFromReference.apply(Reference.builder().href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")).build()); + HttpRequest orgRequest = HttpRequest.builder() + .method("GET") + .endpoint(URI.create(endpoint + "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .headers(ImmutableMultimap. builder() + .put("Accept", "*/*") + .put("x-vcloud-authorization", token) + .build()) + .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() .name("Tasks Lists") .type("application/vnd.vmware.vcloud.tasksList+xml") @@ -119,7 +131,9 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest .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 @@ -133,22 +147,34 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest .build()) .build(); - HttpResponse taskResponse = HttpResponse.builder() - .statusCode(400) - .payload(payloadFromResourceWithContentType("/task/error400.xml", VCloudDirectorMediaType.ERROR + ";version=1.5")) - .build(); + HttpResponse taskResponse = HttpResponse.builder().build(); + + HttpRequest orgRequest = HttpRequest.builder() + .method("GET") + .endpoint(URI.create(endpoint + "/org/NOTAUUID")) + .headers(ImmutableMultimap. builder() + .put("Accept", "*/*") + .put("x-vcloud-authorization", token) + .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() .message("validation error on field 'id': String value has invalid format or length") .majorErrorCode(400) .minorErrorCode("BAD_REQUEST") .build(); + + Reference orgRef = Reference.builder().href(URI.create("https://vcloudbeta.bluelock.com/api/org/NOTAUUID")).build(); + try { - client.getTaskClient().getTaskList(orgId); + client.getTaskClient().getTaskList(orgRef); fail("Should give HTTP 400 error"); } catch (VCloudDirectorException vde) { assertEquals(vde.getError(), expected); @@ -168,14 +194,23 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest .build()) .build(); - HttpResponse taskResponse = HttpResponse.builder() - .statusCode(403) - .payload(payloadFromResourceWithContentType("/task/error403.xml", VCloudDirectorMediaType.ERROR + ";version=1.5")) + HttpResponse taskResponse = HttpResponse.builder().build(); + + HttpRequest orgRequest = HttpRequest.builder() + .method("GET") + .endpoint(URI.create(endpoint + "/org/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")) + .headers(ImmutableMultimap. builder() + .put("Accept", "*/*") + .put("x-vcloud-authorization", token) + .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() .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") .build(); + Reference orgRef = Reference.builder().href(URI.create("https://vcloudbeta.bluelock.com/api/org/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")).build(); + try { - client.getTaskClient().getTaskList(orgId); - fail("Should give HTTP 400 error"); + client.getTaskClient().getTaskList(orgRef); + fail("Should give HTTP 403 error"); } catch (VCloudDirectorException vde) { assertEquals(vde.getError(), expected); } 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. 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 public void testGetTaskForTaskRef() { HttpRequest taskRequest = HttpRequest.builder() @@ -299,28 +285,6 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest 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. 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 public void testCancelTaskByTaskRef() { HttpRequest taskRequest = HttpRequest.builder() diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java index 560d348311..ff01e2a85a 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorRestClientExpectTest.java @@ -46,7 +46,7 @@ public class BaseVCloudDirectorRestClientExpectTest extends BaseRestClientExpect public static final String org = "JClouds"; public static final String password = "password"; 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; @@ -56,17 +56,9 @@ public class BaseVCloudDirectorRestClientExpectTest extends BaseRestClientExpect assert dateService != null; } - protected static final Function, String> getUuidFromReference = new Function, String>() { - @Override - public String apply(ReferenceType input) { - String uuid = Iterables.getLast(Splitter.on("/").split(input.getHref().getPath())); - return uuid; - } - }; - protected HttpRequest loginRequest = HttpRequest.builder() .method("POST") - .endpoint(URI.create("http://localhost/api/sessions")) + .endpoint(URI.create(endpoint + "/sessions")) .headers(ImmutableMultimap.builder() .put("Accept", "*/*") .put("Authorization", "Basic YWRyaWFuQGpjbG91ZHMub3JnQEpDbG91ZHM6cGFzc3dvcmQ=")