diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientExpectTest.java index ffbcc5bc2c..31590b21bd 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/CatalogClientExpectTest.java @@ -25,16 +25,20 @@ 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.domain.CatalogItem; +import org.jclouds.vcloud.director.v1_5.domain.CatalogItems; +import org.jclouds.vcloud.director.v1_5.domain.Link; +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.MetadataValue; +import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.ImmutableSet; /** * Test the {@link CatalogClient} by observing its side effects. @@ -45,10 +49,10 @@ import com.google.common.collect.ImmutableMultimap; public class CatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { @Test - public void testCatalogListForValidOrg() { + public void testGetCatalog() { HttpRequest catalogRequest = HttpRequest.builder() .method("GET") - .endpoint(URI.create(endpoint + "/catalogsList/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .endpoint(URI.create(endpoint + "/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) .headers(ImmutableMultimap. builder() .put("Accept", "*/*") .put("x-vcloud-authorization", token) @@ -57,221 +61,158 @@ public class CatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectT HttpResponse catalogResponse = HttpResponse.builder() .statusCode(200) - .payload(payloadFromResourceWithContentType("/catalog/catalogslist.xml", VCloudDirectorMediaType.CATALOGS_LIST + ";version=1.5")) + .payload(payloadFromResourceWithContentType("/catalog/catalog.xml", VCloudDirectorMediaType.CATALOG + ";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")) + Catalog expected = Catalog.builder() + .name("QunyingTestCatalog") + .type("application/vnd.vmware.vcloud.catalog+xml") + .id("urn:vcloud:catalog:7212e451-76e1-4631-b2de-ba1dfd8080e4") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) + .link(Link.builder() + .rel("up") + .type("application/vnd.vmware.vcloud.org+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .build()) + .link(Link.builder() + .rel("add") + .type("application/vnd.vmware.vcloud.catalogItem+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/catalogItems")) + .build()) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.vcloud.metadata+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/metadata")) + .build()) + .catalogItems(CatalogItems.builder() + .item(Reference.builder() + .type("application/vnd.vmware.vcloud.catalogItem+xml") + .name("ubuntu10") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df")) .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")) + .item(Reference.builder() + .type("application/vnd.vmware.vcloud.catalogItem+xml") + .name("imageTesting") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a9e0afdb-a42b-4688-8409-2ac68cf22939")) .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()) + .description("Testing") .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. 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. 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. 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")) + .name("QunyingTestCatalog") + .href(URI.create(endpoint + "/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) .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() + public void testAddCatalogItem() { + HttpRequest catalogItemRequest = HttpRequest.builder() .method("POST") - .endpoint(URI.create(endpoint + "/catalog/5fcd2af3-d0ec-45ce-9451-8c585a2c766b/action/cancel")) + .endpoint(URI.create(endpoint + "/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/catalogItems")) + .headers(ImmutableMultimap. builder() + .put("Accept", "application/vnd.vmware.vcloud.catalogItem+xml") + .put("x-vcloud-authorization", token) + .build()) + .payload(payloadFromResourceWithContentType("/catalog/newCatalogItem.xml", VCloudDirectorMediaType.CATALOG_ITEM)) + .build(); + + HttpResponse catalogItemResponse = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResourceWithContentType("/catalog/catalogItem.xml", VCloudDirectorMediaType.CATALOG_ITEM + ";version=1.5")) + .build(); + + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse); + + Reference catalogRef = Reference.builder() + .type("application/vnd.vmware.vcloud.catalog+xml") + .name("QunyingTestCatalog") + .href(URI.create(endpoint + "/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) + .build(); + + Reference ubuntu = Reference.builder() + .type("application/vnd.vmware.vcloud.vAppTemplate+xml") + .name("ubuntu10") + .href(URI.create("https://vcloudbeta.bluelock.com/api/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9")) + .build(); + + CatalogItem newItem = CatalogItem.builder() + .name("newCatalogItem") + .description("New Catalog Item") + .entity(ubuntu) + .build(); + + CatalogItem expected = CatalogItem.builder() + .name("newCatalogItem") + .id("urn:vcloud:catalogitem:a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df") + .type("application/vnd.vmware.vcloud.catalogItem+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df")) + .link(Link.builder() + .rel("up") + .type("application/vnd.vmware.vcloud.catalog+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) + .build()) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.vcloud.metadata+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df/metadata")) + .build()) + .link(Link.builder() + .rel("edit") + .type("application/vnd.vmware.vcloud.catalogItem+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df")) + .build()) + .link(Link.builder() + .rel("remove") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df")) + .build()) + .description("New Catalog Item") + .entity(ubuntu) + .build(); + + assertEquals(client.getCatalogClient().addCatalogItem(catalogRef, newItem), expected); + } + + @Test + public void testGetCatalogMetadata() { + HttpRequest catalogItemRequest = HttpRequest.builder() + .method("GET") + .endpoint(URI.create(endpoint + "/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/metadata")) .headers(ImmutableMultimap. builder() .put("Accept", "*/*") .put("x-vcloud-authorization", token) .build()) .build(); - HttpResponse catalogResponse = HttpResponse.builder() - .statusCode(200) + HttpResponse catalogItemResponse = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResourceWithContentType("/catalog/catalogMetadata.xml", VCloudDirectorMediaType.METADATA + ";version=1.5")) .build(); - VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, catalogRequest, catalogResponse); + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse); Reference catalogRef = Reference.builder() .type("application/vnd.vmware.vcloud.catalog+xml") - .name("catalog") - .href(URI.create(endpoint + "/catalog/5fcd2af3-d0ec-45ce-9451-8c585a2c766b")) + .name("QunyingTestCatalog") + .href(URI.create(endpoint + "/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) .build(); - client.getCatalogClient().cancelCatalog(catalogRef); + Metadata expected = Metadata.builder() + .type("application/vnd.vmware.vcloud.metadata+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api//catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4/metadata")) + .link(Link.builder() + .rel("up") + .type("application/vnd.vmware.vcloud.catalog+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) + .build()) + .metadata(ImmutableSet.of(MetadataEntry.builder().entry("key", "value").build())) + .build(); + + assertEquals(client.getCatalogClient().getCatalogMetadata(catalogRef), expected); } } diff --git a/labs/vcloud-director/src/test/resources/catalog/catalog.xml b/labs/vcloud-director/src/test/resources/catalog/catalog.xml new file mode 100644 index 0000000000..f7fe4d9a94 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/catalog/catalog.xml @@ -0,0 +1,12 @@ + + + + + + Testing + + + + + false + \ No newline at end of file diff --git a/labs/vcloud-director/src/test/resources/catalog/catalogItem.xml b/labs/vcloud-director/src/test/resources/catalog/catalogItem.xml new file mode 100644 index 0000000000..39021f96d9 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/catalog/catalogItem.xml @@ -0,0 +1,9 @@ + + + + + + + New Catalog Item + + \ No newline at end of file diff --git a/labs/vcloud-director/src/test/resources/catalog/catalogMetadata.xml b/labs/vcloud-director/src/test/resources/catalog/catalogMetadata.xml new file mode 100644 index 0000000000..0ff3052583 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/catalog/catalogMetadata.xml @@ -0,0 +1,8 @@ + + + + + key + value + + \ No newline at end of file diff --git a/labs/vcloud-director/src/test/resources/catalog/newCatalogItem.xml b/labs/vcloud-director/src/test/resources/catalog/newCatalogItem.xml new file mode 100644 index 0000000000..d434d4f272 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/catalog/newCatalogItem.xml @@ -0,0 +1,5 @@ + + + New Catalog Item + +