Initial commit for CatalogClient with all operations defined and the client bound

This commit is contained in:
Andrew Donald Kennedy 2012-02-09 03:27:13 +00:00
parent c8148751ff
commit fbe68686d3
6 changed files with 732 additions and 2 deletions

View File

@ -20,6 +20,7 @@ package org.jclouds.vcloud.director.v1_5;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.vcloud.director.v1_5.domain.Session;
import org.jclouds.vcloud.director.v1_5.features.CatalogAsyncClient;
import org.jclouds.vcloud.director.v1_5.features.NetworkAsyncClient;
import org.jclouds.vcloud.director.v1_5.features.OrgAsyncClient;
import org.jclouds.vcloud.director.v1_5.features.TaskAsyncClient;

View File

@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.vcloud.director.v1_5.domain.Session;
import org.jclouds.vcloud.director.v1_5.features.CatalogClient;
import org.jclouds.vcloud.director.v1_5.features.NetworkClient;
import org.jclouds.vcloud.director.v1_5.features.OrgClient;
import org.jclouds.vcloud.director.v1_5.features.TaskClient;
@ -46,13 +47,13 @@ public interface VCloudDirectorClient {
Session getCurrentSession();
/**
* @return synchronous access to Org features
* @return synchronous access to {@link Org} features
*/
@Delegate
OrgClient getOrgClient();
/**
* @return synchronous access to Task features
* @return synchronous access to {@link Task} features
*/
@Delegate
TaskClient getTaskClient();
@ -62,4 +63,11 @@ public interface VCloudDirectorClient {
*/
@Delegate
NetworkClient getNetworkClient();
/**
* @return synchronous access to {@link Catalog} features
*/
@Delegate
CatalogClient getCatalogClient();
}

View File

@ -0,0 +1,65 @@
/**
* 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;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.vcloud.director.v1_5.domain.Session;
import org.jclouds.vcloud.director.v1_5.features.CatalogClient;
import org.jclouds.vcloud.director.v1_5.features.NetworkClient;
import org.jclouds.vcloud.director.v1_5.features.OrgClient;
import org.jclouds.vcloud.director.v1_5.features.TaskClient;
import com.google.inject.Provides;
/**
* Provides synchronous access to VCloudDirector.
*
* @see VCloudDirectorAsyncClient
* @author Adrian Cole
*/
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
public interface VCloudDirectorClient {
/**
* @return the current login session
*/
@Provides
Session getCurrentSession();
/**
* @return synchronous access to Org features
*/
@Delegate
OrgClient getOrgClient();
/**
* @return synchronous access to Task features
*/
@Delegate
TaskClient getTaskClient();
/**
* @return synchronous access to Network features
*/
@Delegate
NetworkClient getNetworkClient();
}

View File

@ -0,0 +1,189 @@
/**
* 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.features;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.JAXBResponseParser;
import org.jclouds.rest.annotations.Payload;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Catalog;
import org.jclouds.vcloud.director.v1_5.domain.CatalogItem;
import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry;
import org.jclouds.vcloud.director.v1_5.domain.ReferenceType;
import org.jclouds.vcloud.director.v1_5.domain.Task;
import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest;
import org.jclouds.vcloud.director.v1_5.functions.ReferenceToEndpoint;
import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx;
import com.google.common.util.concurrent.ListenableFuture;
/**
* @see CatalogClient
* @author grkvlt@apache.org
*/
@RequestFilters(AddVCloudAuthorizationToRequest.class)
public interface CatalogAsyncClient {
/**
* Retrieves a catalog.
*/
@GET
@Consumes
@Produces(VCloudDirectorMediaType.CATALOG)
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<Catalog> getCatalog(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType<?> catalogRef);
/**
* Creates a catalog item in a catalog.
*/
@POST
@Path("/catalogItems")
@Consumes(VCloudDirectorMediaType.CATALOG_ITEM)
@Produces(VCloudDirectorMediaType.CATALOG_ITEM)
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<CatalogItem> addCatalogItem(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType<?> catalogRef,
@PayloadParam("catalogItem") CatalogItem catalogItem);
/**
* Returns the metadata associated with the catalog.
*/
@GET
@Path("/metadata")
@Consumes
@Produces(VCloudDirectorMediaType.METADATA)
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<Metadata> getCatalogMetadata(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType<?> catalogRef);
/**
* Returns the metadata associated with the catalog for the specified key.
*/
@GET
@Path("/metadata/{key}")
@Consumes
@Produces(VCloudDirectorMediaType.METADATA_ENTRY)
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<MetadataEntry> getCatalogMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType<?> catalogRef,
@PathParam("key") String key);
/**
* Retrieves a catalog item.
*/
@GET
@Consumes
@Produces(VCloudDirectorMediaType.CATALOG_ITEM)
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<CatalogItem> getCatalogItem(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType<?> catalogItemRef);
/**
* Modifies a catalog item.
*/
@PUT
@Consumes(VCloudDirectorMediaType.CATALOG_ITEM)
@Produces(VCloudDirectorMediaType.CATALOG_ITEM)
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<CatalogItem> updateCatalogItem(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType<?> catalogItemRef,
@PayloadParam("catalogItem") CatalogItem catalogItem);
/**
* Deletes a catalog item.
*/
@DELETE
@Consumes
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<Void> deleteCatalogItem(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType<?> catalogItemRef);
/**
* Returns the metadata associated with the catalog item.
*/
@GET
@Path("/metadata")
@Consumes
@Produces(VCloudDirectorMediaType.METADATA)
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<Metadata> getCatalogItemMetadata(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType<?> catalogItemRef);
/**
* Merges the metadata for a catalog item with the information provided.
*/
@POST
@Path("/metadata")
@Consumes(VCloudDirectorMediaType.METADATA)
@Produces(VCloudDirectorMediaType.TASK)
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<Task> mergeCatalogItemMetadata(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType<?> catalogItemRef,
@PayloadParam("catalogItemMetadata") Metadata catalogItemMetadata);
/**
* Returns the metadata associated with the catalog item for the specified key.
*/
@GET
@Path("/metadata/{key}")
@Consumes
@Produces(VCloudDirectorMediaType.METADATA_ENTRY)
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<MetadataEntry> getCatalogItemMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType<?> catalogItemRef,
@PathParam("key") String key);
/**
* Sets the metadata for the particular key for the catalog item to the value provided.
*/
@PUT
@Path("/metadata/{key}")
@Consumes /* (VCloudDirectorMediaType.METADATA_VALUE) */
@Produces(VCloudDirectorMediaType.TASK)
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<Task> setCatalogItemMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType<?> catalogItemRef,
@PathParam("key") String key, @PayloadParam("metadataValue") /* MetadataValue */ Object metadataValue);
/**
* Deletes the metadata for the particular key for the catalog item.
*/
@DELETE
@Path("/metadata/{key}")
@Consumes
@Produces(VCloudDirectorMediaType.TASK)
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<Task> deleteCatalogItemMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType<?> catalogItemRef,
@PathParam("key") String key);
}

View File

@ -0,0 +1,190 @@
/**
* 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.features;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.director.v1_5.domain.Catalog;
import org.jclouds.vcloud.director.v1_5.domain.CatalogItem;
import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry;
import org.jclouds.vcloud.director.v1_5.domain.ReferenceType;
import org.jclouds.vcloud.director.v1_5.domain.Task;
/**
* Provides synchronous access to {@link Catalog} objects.
*
* @see CatalogAsyncClient
* @author grkvlt@apache.org
*/
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public interface CatalogClient {
/**
* Retrieves a catalog.
*
* <pre>
* GET /catalog/{id}
* </pre>
*
* @param catalogRef the reference for the catalog
* @return a catalog
*/
Catalog getCatalog(ReferenceType<?> catalogRef);
/**
* Creates a catalog item in a catalog.
*
* <pre>
* POST /catalog/{id}/catalogItems
* </pre>
*
* @param catalogRef the reference for the catalog
* @param item the catalog item to create
* @return the created catalog item
*/
CatalogItem addCatalogItem(ReferenceType<?> catalogRef, CatalogItem item);
/**
* Returns the metadata associated with the catalog.
*
* <pre>
* GET /catalog/{id}/metadata
* </pre>
*
* @param catalogRef the reference for the catalog
* @return the catalog metadata
*/
Metadata getCatalogMetadata(ReferenceType<?> catalogRef);
/**
* Returns the metadata associated with the catalog for the specified key.
*
* <pre>
* GET /catalog/{id}/metadata/{key}
* </pre>
*
* @param catalogRef the reference for the catalog
* @param key the metadata entry key
* @return the catalog metadata entry
*/
MetadataEntry getCatalogMetadataEntry(ReferenceType<?> catalogRef, String key);
/**
* Retrieves a catalog item.
*
* <pre>
* GET /catalogItem/{id}
* </pre>
*
* @param catalogItemRef the reference for the catalog item
* @return the catalog item
*/
CatalogItem getCatalogItem(ReferenceType<?> catalogItemRef);
/**
* Modifies a catalog item.
*
* <pre>
* PUT /catalogItem/{id}
* </pre>
*
* @param catalogItemRef the reference for the catalog item
* @param catalogItem the catalog item
* @return the updated catalog item
*/
CatalogItem updateCatalogItem(ReferenceType<?> catalogItemRef, CatalogItem catalogItem);
/**
* Deletes a catalog item.
*
* <pre>
* DELETE /catalogItem/{id}
* </pre>
*
* @param catalogItemRef the reference for the catalog item
*/
void deleteCatalogItem(ReferenceType<?> catalogItemRef);
/**
* Returns the metadata associated with the catalog item.
*
* <pre>
* GET /catalogItem/{id}/metadata
* </pre>
*
* @param catalogItemRef the reference for the catalog item
* @return the catalog item metadata
*/
Metadata getCatalogItemMetadata(ReferenceType<?> catalogItemRef);
/**
* Merges the metadata for a catalog item with the information provided.
*
* <pre>
* POST /catalogItem/{id}/metadata
* </pre>
*
* @param catalogItemRef the reference for the catalog item
* @param catalogItemMetadata the metadata for the catalog item
* @return a task for the merge operation
*/
Task mergeCatalogItemMetadata(ReferenceType<?> catalogItemRef, Metadata catalogItemMetadata);
/**
* Returns the metadata associated with the catalog item for the specified key.
*
* <pre>
* GET /catalog/{id}/metadata/{key}
* </pre>
*
* @param catalogItemRef the reference for the catalog item
* @param key the metadata entry key
* @return the catalog item metadata entry
*/
MetadataEntry getCatalogItemMetadataEntry(ReferenceType<?> catalogItemRef, String key);
/**
* Sets the metadata for the particular key for the catalog item to the value provided.
*
* <pre>
* PUT /catalog/{id}/metadata/{key}
* </pre>
*
* @param catalogItemRef the reference for the catalog item
* @param key the metadata entry key
* @param value the metadata value
* @return a task for the set operation
*/
Task setCatalogItemMetadataEntry(ReferenceType<?> catalogItemRef, String key, /* MetadataValue */ Object value);
/**
* Deletes the metadata for the particular key for the catalog item.
*
* <pre>
* DELETE /catalog/{id}/metadata/{key}
* </pre>
*
* @param catalogItemRef the reference for the catalog item
* @param key the metadata entry key
* @return a task for the delete operation
*/
Task deleteCatalogItemMetadataEntry(ReferenceType<?> catalogItemRef, String key);
}

View File

@ -0,0 +1,277 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
*(Link.builder().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(Link.builder().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.features;
import static org.testng.Assert.*;
import java.net.URI;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Error;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.Catalog;
import org.jclouds.vcloud.director.v1_5.domain.CatalogsList;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMultimap;
/**
* Test the {@link CatalogClient} by observing its side effects.
*
* @author grkvlt@apache.org
*/
@Test(groups = "unit", singleThreaded = true, testName = "CatalogClientExpectTest")
public class CatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectTest {
@Test
public void testCatalogListForValidOrg() {
HttpRequest catalogRequest = HttpRequest.builder()
.method("GET")
.endpoint(URI.create(endpoint + "/catalogsList/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.headers(ImmutableMultimap.<String, String> builder()
.put("Accept", "*/*")
.put("x-vcloud-authorization", token)
.build())
.build();
HttpResponse catalogResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/catalogslist.xml", VCloudDirectorMediaType.CATALOGS_LIST + ";version=1.5"))
.build();
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, catalogRequest, catalogResponse);
CatalogsList expected = CatalogsList.builder()
.name("Catalogs Lists")
.type("application/vnd.vmware.vcloud.catalogsList+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalogsList/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.catalog(Catalog.builder()
.type("application/vnd.vmware.vcloud.catalog+xml")
.name("catalog")
.id("urn:vcloud:catalog:5fcd2af3-d0ec-45ce-9451-8c585a2c766b")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/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())
.catalog(Catalog.builder()
.type("application/vnd.vmware.vcloud.catalog+xml")
.name("catalog")
.id("urn:vcloud:catalog:bd22e745-9c2a-4f82-a954-0e35b6f76ba5")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/bd22e745-9c2a-4f82-a954-0e35b6f76ba5"))
.status("success")
.operation("Enabled User (967d317c-4273-4a95-b8a4-bf63b78e9c69)")
.operationName("jobEnable")
.startTime(dateService.iso8601DateParse("2012-02-06T17:30:38.507-05:00"))
.endTime(dateService.iso8601DateParse("2012-02-06T17:30:38.507-05:00"))
.expiryTime(dateService.iso8601DateParse("2012-05-06T17:30:38.507-04:00"))
.user(Reference.builder()
.type("application/vnd.vmware.admin.user+xml")
.name("adrian@jclouds.org")
.href(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/8c360b93-ed25-4c9a-8e24-d48cd9966d93"))
.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())
.build();
Reference orgRef = Reference.builder().href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")).build();
assertEquals(client.getCatalogClient().getCatalogList(orgRef), expected);
}
@Test
public void testCatalogListForInvalidOrgId() {
HttpRequest catalogRequest = HttpRequest.builder()
.method("GET")
.endpoint(URI.create(endpoint + "/catalogsList/NOTAUUID"))
.headers(ImmutableMultimap.<String, String> builder()
.put("Accept", "*/*")
.put("x-vcloud-authorization", token)
.build())
.build();
HttpResponse catalogResponse = HttpResponse.builder()
.statusCode(400)
.payload(payloadFromResourceWithContentType("/catalog/error400.xml", VCloudDirectorMediaType.ERROR + ";version=1.5"))
.build();
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, catalogRequest, catalogResponse);
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.getCatalogClient().getCatalogList(orgRef);
fail("Should give HTTP 400 error");
} catch (VCloudDirectorException vde) {
assertEquals(vde.getError(), expected);
} catch (Exception e) {
fail("Should have thrown a VCloudDirectorException");
}
}
@Test
public void testCatalogListForNotFoundOrgId() {
HttpRequest catalogRequest = HttpRequest.builder()
.method("GET")
.endpoint(URI.create(endpoint + "/catalogsList/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"))
.headers(ImmutableMultimap.<String, String> builder()
.put("Accept", "*/*")
.put("x-vcloud-authorization", token)
.build())
.build();
HttpResponse catalogResponse = HttpResponse.builder()
.statusCode(403)
.payload(payloadFromResourceWithContentType("/catalog/error403.xml", VCloudDirectorMediaType.ERROR + ";version=1.5"))
.build();
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, catalogRequest, catalogResponse);
Error expected = Error.builder()
.message("No access to entity \"com.vmware.vcloud.entity.org:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee\".")
.majorErrorCode(403)
.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.getCatalogClient().getCatalogList(orgRef);
fail("Should give HTTP 400 error");
} catch (VCloudDirectorException vde) {
assertEquals(vde.getError(), expected);
} catch (Exception e) {
fail("Should have thrown a VCloudDirectorException");
}
}
@Test
public void testGetCatalogForCatalogRef() {
HttpRequest catalogRequest = HttpRequest.builder()
.method("GET")
.endpoint(URI.create(endpoint + "/catalog/5fcd2af3-d0ec-45ce-9451-8c585a2c766b"))
.headers(ImmutableMultimap.<String, String> builder()
.put("Accept", "*/*")
.put("x-vcloud-authorization", token)
.build())
.build();
HttpResponse catalogResponse = HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResourceWithContentType("/catalog/catalog.xml", VCloudDirectorMediaType.catalog + ";version=1.5"))
.build();
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, catalogRequest, catalogResponse);
Reference catalogRef = Reference.builder()
.type("application/vnd.vmware.vcloud.catalog+xml")
.name("catalog")
.href(URI.create(endpoint + "/catalog/5fcd2af3-d0ec-45ce-9451-8c585a2c766b"))
.build();
Catalog expected = Catalog.builder()
.type("application/vnd.vmware.vcloud.catalog+xml")
.name("catalog")
.id("urn:vcloud:catalog:5fcd2af3-d0ec-45ce-9451-8c585a2c766b")
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/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.getCatalogClient().getCatalog(catalogRef), expected);
}
@Test
public void testCancelCatalogByCatalogRef() {
HttpRequest catalogRequest = HttpRequest.builder()
.method("POST")
.endpoint(URI.create(endpoint + "/catalog/5fcd2af3-d0ec-45ce-9451-8c585a2c766b/action/cancel"))
.headers(ImmutableMultimap.<String, String> builder()
.put("Accept", "*/*")
.put("x-vcloud-authorization", token)
.build())
.build();
HttpResponse catalogResponse = HttpResponse.builder()
.statusCode(200)
.build();
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, catalogRequest, catalogResponse);
Reference catalogRef = Reference.builder()
.type("application/vnd.vmware.vcloud.catalog+xml")
.name("catalog")
.href(URI.create(endpoint + "/catalog/5fcd2af3-d0ec-45ce-9451-8c585a2c766b"))
.build();
client.getCatalogClient().cancelCatalog(catalogRef);
}
}