From b5ae8073dafe6f1c258df14bf2d0fa675a8361ba Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Fri, 30 Mar 2012 09:48:08 -0700 Subject: [PATCH] expect test structure for new admin client --- .../features/VAppTemplateAsyncClient.java | 10 + .../v1_5/VCloudDirectorClientExpectTest.java | 4 +- .../AdminCatalogClientExpectTest.java | 5 +- .../AdminNetworkClientExpectTest.java | 6 +- .../features/AdminOrgClientExpectTest.java | 4 +- .../features/AdminQueryClientExpectTest.java | 4 +- .../features/AdminVdcClientExpectTest.java | 5 +- .../features/CatalogClientExpectTest.java | 30 +- .../v1_5/features/GroupClientExpectTest.java | 4 +- .../v1_5/features/MediaClientExpectTest.java | 4 +- .../features/NetworkClientExpectTest.java | 4 +- .../v1_5/features/OrgClientExpectTest.java | 4 +- .../v1_5/features/QueryClientExpectTest.java | 4 +- .../v1_5/features/TaskClientExpectTest.java | 4 +- .../v1_5/features/UserClientExpectTest.java | 4 +- .../v1_5/features/VAppClientExpectTest.java | 4 +- .../VAppTemplateClientExpectTest.java | 5 +- .../v1_5/features/VdcClientExpectTest.java | 4 +- .../BaseVCloudDirectorExpectTest.java | 261 ++++++++++++++++++ ...aseVCloudDirectorRestClientExpectTest.java | 226 +-------------- .../VCloudDirectorAdminClientExpectTest.java | 57 ++++ 21 files changed, 379 insertions(+), 274 deletions(-) create mode 100644 labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorExpectTest.java create mode 100644 labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/VCloudDirectorAdminClientExpectTest.java diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/VAppTemplateAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/VAppTemplateAsyncClient.java index 213bfff88c..7219a37fc4 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/VAppTemplateAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/VAppTemplateAsyncClient.java @@ -200,6 +200,16 @@ public interface VAppTemplateAsyncClient { ListenableFuture modifyLeaseSettingsSection(@EndpointParam URI templateURI, @BinderParam(BindToXMLPayload.class) LeaseSettingsSection settingsSection); + /** + * @see VAppTemplateClient#getNetworkConnectionSection(URI) + */ + @GET + @Consumes(NETWORK_CONFIG_SECTION) + @Path("/networkConnectionSection") + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getNetworkConnectionSection(@EndpointParam URI templateURI); + /** * @see VAppTemplateClient#getNetworkConfigSection(URI) */ diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClientExpectTest.java index 191d450b66..3692a6501b 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClientExpectTest.java @@ -20,7 +20,7 @@ package org.jclouds.vcloud.director.v1_5; import static org.testng.Assert.assertEquals; -import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; +import org.jclouds.vcloud.director.v1_5.internal.VCloudDirectorAdminClientExpectTest; import org.jclouds.vcloud.director.v1_5.login.SessionClientExpectTest; import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorClient; import org.testng.annotations.Test; @@ -29,7 +29,7 @@ import org.testng.annotations.Test; * @author Adrian Cole */ @Test(groups = "unit", testName = "VCloudDirectorClient") -public class VCloudDirectorClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { +public class VCloudDirectorClientExpectTest extends VCloudDirectorAdminClientExpectTest { public void testRestClientModuleWorksProperly() throws Exception { diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminCatalogClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminCatalogClientExpectTest.java index 6b0459a99e..02750ddb0a 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminCatalogClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminCatalogClientExpectTest.java @@ -30,7 +30,8 @@ import org.jclouds.vcloud.director.v1_5.domain.Owner; import org.jclouds.vcloud.director.v1_5.domain.PublishCatalogParams; import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.domain.Task; -import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; +import org.jclouds.vcloud.director.v1_5.features.admin.AdminCatalogClient; +import org.jclouds.vcloud.director.v1_5.internal.VCloudDirectorAdminClientExpectTest; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; @@ -41,7 +42,7 @@ import com.google.common.collect.ImmutableSet; * @author grkvlt@apache.org */ @Test(groups = { "unit", "admin", "catalog" }, singleThreaded = true, testName = "CatalogClientExpectTest") -public class AdminCatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { +public class AdminCatalogClientExpectTest extends VCloudDirectorAdminClientExpectTest { private Reference catalogRef = Reference.builder() .type("application/vnd.vmware.vcloud.catalog+xml") diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminNetworkClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminNetworkClientExpectTest.java index 5660528e52..3927872382 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminNetworkClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminNetworkClientExpectTest.java @@ -28,8 +28,8 @@ import org.jclouds.vcloud.director.v1_5.domain.Link; import org.jclouds.vcloud.director.v1_5.domain.OrgNetwork; import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.domain.Task; -import org.jclouds.vcloud.director.v1_5.features.admin.GroupClient; -import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; +import org.jclouds.vcloud.director.v1_5.features.admin.AdminNetworkClient; +import org.jclouds.vcloud.director.v1_5.internal.VCloudDirectorAdminClientExpectTest; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; @@ -40,7 +40,7 @@ import com.google.common.collect.ImmutableSet; * @author danikov */ @Test(groups = { "unit", "admin", "network"}, singleThreaded = true, testName = "AdminNetworkClientExpectTest") -public class AdminNetworkClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { +public class AdminNetworkClientExpectTest extends VCloudDirectorAdminClientExpectTest { Reference networkRef = Reference.builder() .href(URI.create(endpoint+"/admin/network/b466c0c5-8a5c-4335-b703-a2e2e6b5f3e1")) diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientExpectTest.java index 5b6ae6192d..088515dad6 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientExpectTest.java @@ -36,7 +36,7 @@ import org.jclouds.vcloud.director.v1_5.domain.OrgVAppTemplateLeaseSettings; import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.domain.SmtpServerSettings; import org.jclouds.vcloud.director.v1_5.features.admin.AdminOrgClient; -import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; +import org.jclouds.vcloud.director.v1_5.internal.VCloudDirectorAdminClientExpectTest; import org.testng.annotations.Test; /** @@ -45,7 +45,7 @@ import org.testng.annotations.Test; * @author danikov */ @Test(groups = { "unit", "user", "org"}, singleThreaded = true, testName = "AdminOrgClientExpectTest") -public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { +public class AdminOrgClientExpectTest extends VCloudDirectorAdminClientExpectTest { private Reference orgRef = Reference.builder() .href(URI.create(endpoint + "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminQueryClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminQueryClientExpectTest.java index d9f5b1331e..23840cb589 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminQueryClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminQueryClientExpectTest.java @@ -30,7 +30,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Link; import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecords; import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRoleRecord; import org.jclouds.vcloud.director.v1_5.features.admin.AdminQueryClient; -import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; +import org.jclouds.vcloud.director.v1_5.internal.VCloudDirectorAdminClientExpectTest; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMultimap; @@ -41,7 +41,7 @@ import com.google.common.collect.ImmutableMultimap; * @author Aled Sage */ @Test(groups = { "unit", "admin", "query" }, singleThreaded = true, testName = "AdminQueryClientExpectTest") -public class AdminQueryClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { +public class AdminQueryClientExpectTest extends VCloudDirectorAdminClientExpectTest { // TODO Write expect tests for all other admin-query operations diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminVdcClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminVdcClientExpectTest.java index 22abfc5275..9de490f029 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminVdcClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminVdcClientExpectTest.java @@ -26,7 +26,8 @@ import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminClient; import org.jclouds.vcloud.director.v1_5.domain.AdminVdc; import org.jclouds.vcloud.director.v1_5.domain.Reference; -import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; +import org.jclouds.vcloud.director.v1_5.features.admin.AdminVdcClient; +import org.jclouds.vcloud.director.v1_5.internal.VCloudDirectorAdminClientExpectTest; import org.testng.annotations.Test; /** @@ -35,7 +36,7 @@ import org.testng.annotations.Test; * @author danikov */ @Test(groups = { "unit", "admin", "vdc" }, singleThreaded = true, testName = "AdminVdcClientExpectTest") -public class AdminVdcClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { +public class AdminVdcClientExpectTest extends VCloudDirectorAdminClientExpectTest { private Reference vdcRef = Reference.builder() .href(URI.create(endpoint + "???")) 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 72189c2ea9..0c5a194843 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 @@ -24,8 +24,8 @@ import java.net.URI; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorClientExpectTest; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; -import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminClient; import org.jclouds.vcloud.director.v1_5.domain.CatalogItem; import org.jclouds.vcloud.director.v1_5.domain.CatalogType; import org.jclouds.vcloud.director.v1_5.domain.Link; @@ -34,7 +34,7 @@ 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.domain.Task; -import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; +import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorClient; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMultimap; @@ -46,7 +46,7 @@ import com.google.common.collect.ImmutableSet; * @author grkvlt@apache.org */ @Test(groups = { "unit", "user", "catalog" }, singleThreaded = true, testName = "CatalogClientExpectTest") -public class CatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { +public class CatalogClientExpectTest extends VCloudDirectorClientExpectTest { @Test public void testGetCatalog() { @@ -64,7 +64,7 @@ public class CatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectT .payload(payloadFromResourceWithContentType("/catalog/catalog.xml", VCloudDirectorMediaType.CATALOG + ";version=1.5")) .build(); - VCloudDirectorAdminClient client = requestsSendResponses(loginRequest, sessionResponse, catalogRequest, catalogResponse); + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, catalogRequest, catalogResponse); CatalogType expected = catalog(); @@ -89,7 +89,7 @@ public class CatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectT .payload(payloadFromResourceWithContentType("/catalog/createdCatalogItem.xml", VCloudDirectorMediaType.CATALOG_ITEM + ";version=1.5")) .build(); - VCloudDirectorAdminClient client = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse); + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse); URI catalogURI = URI.create(endpoint + "/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4"); @@ -120,7 +120,7 @@ public class CatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectT .payload(payloadFromResourceWithContentType("/catalog/catalogMetadata.xml", VCloudDirectorMediaType.METADATA)) .build(); - VCloudDirectorAdminClient client = requestsSendResponses(loginRequest, sessionResponse, catalogRequest, catalogResponse); + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, catalogRequest, catalogResponse); URI catalogURI = URI.create(endpoint + "/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4"); @@ -154,7 +154,7 @@ public class CatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectT .payload(payloadFromResourceWithContentType("/catalog/catalogMetadataValue.xml", VCloudDirectorMediaType.METADATA_VALUE)) .build(); - VCloudDirectorAdminClient client = requestsSendResponses(loginRequest, sessionResponse, catalogRequest, catalogResponse); + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, catalogRequest, catalogResponse); URI catalogURI = URI.create(endpoint + "/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4"); @@ -179,7 +179,7 @@ public class CatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectT .payload(payloadFromResourceWithContentType("/catalog/catalogItem.xml", VCloudDirectorMediaType.CATALOG_ITEM)) .build(); - VCloudDirectorAdminClient client = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse); + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse); URI catalogItemURI = URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df"); @@ -205,7 +205,7 @@ public class CatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectT .payload(payloadFromResourceWithContentType("/catalog/updateCatalogItem.xml", VCloudDirectorMediaType.CATALOG_ITEM + ";version=1.5")) .build(); - VCloudDirectorAdminClient client = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse); + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse); URI catalogItemURI = URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df"); CatalogItem expected = catalogItem(); @@ -228,7 +228,7 @@ public class CatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectT .statusCode(200) .build(); - VCloudDirectorAdminClient client = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse); + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse); URI catalogItemURI = URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df"); @@ -251,7 +251,7 @@ public class CatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectT .payload(payloadFromResourceWithContentType("/catalog/catalogItemMetadata.xml", VCloudDirectorMediaType.METADATA)) .build(); - VCloudDirectorAdminClient client = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse); + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse); URI catalogItemURI = URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df"); @@ -286,7 +286,7 @@ public class CatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectT .payload(payloadFromResourceWithContentType("/catalog/mergeMetadataTask.xml", VCloudDirectorMediaType.TASK + ";version=1.5")) .build(); - VCloudDirectorAdminClient client = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse); + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse); URI catalogItemURI = URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df"); @@ -313,7 +313,7 @@ public class CatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectT .payload(payloadFromResourceWithContentType("/catalog/catalogItemMetadataValue.xml", VCloudDirectorMediaType.METADATA_VALUE + ";version=1.5")) .build(); - VCloudDirectorAdminClient client = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse); + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse); URI catalogItemURI = URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df"); @@ -339,7 +339,7 @@ public class CatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectT .payload(payloadFromResourceWithContentType("/catalog/setMetadataValueTask.xml", VCloudDirectorMediaType.TASK + ";version=1.5")) .build(); - VCloudDirectorAdminClient client = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse); + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse); URI catalogItemURI = URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df"); @@ -366,7 +366,7 @@ public class CatalogClientExpectTest extends BaseVCloudDirectorRestClientExpectT .payload(payloadFromResourceWithContentType("/catalog/deleteMetadataEntryTask.xml", VCloudDirectorMediaType.TASK)) .build(); - VCloudDirectorAdminClient client = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse); + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, catalogItemRequest, catalogItemResponse); URI catalogItemURI = URI.create("https://vcloudbeta.bluelock.com/api/catalogItem/a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df"); diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/GroupClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/GroupClientExpectTest.java index 8b1957c28e..fa8dc98c79 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/GroupClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/GroupClientExpectTest.java @@ -27,7 +27,7 @@ import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminClient; import org.jclouds.vcloud.director.v1_5.domain.Group; import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.features.admin.GroupClient; -import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; +import org.jclouds.vcloud.director.v1_5.internal.VCloudDirectorAdminClientExpectTest; import org.testng.annotations.Test; /** @@ -36,7 +36,7 @@ import org.testng.annotations.Test; * @author danikov */ @Test(groups = { "unit", "admin", "group"}, singleThreaded = true, testName = "GroupClientExpectTest") -public class GroupClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { +public class GroupClientExpectTest extends VCloudDirectorAdminClientExpectTest { private Reference groupRef = Reference.builder() .type("application/vnd.vmware.admin.group+xml") diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java index 4a80a6c8f6..54f28366df 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java @@ -37,7 +37,7 @@ import org.jclouds.vcloud.director.v1_5.domain.MetadataValue; import org.jclouds.vcloud.director.v1_5.domain.Owner; import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.domain.Task; -import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; +import org.jclouds.vcloud.director.v1_5.internal.VCloudDirectorAdminClientExpectTest; import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorClient; import org.testng.annotations.Test; @@ -49,7 +49,7 @@ import com.google.common.collect.ImmutableSet; * @author danikov */ @Test(groups = { "unit", "user", "media" }, singleThreaded = true, testName = "MediaClientExpectTest") -public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { +public class MediaClientExpectTest extends VCloudDirectorAdminClientExpectTest { @Test public void testCreateMedia() { diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientExpectTest.java index aeeaad135b..51a2542c21 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/NetworkClientExpectTest.java @@ -41,7 +41,7 @@ import org.jclouds.vcloud.director.v1_5.domain.NetworkConfiguration; import org.jclouds.vcloud.director.v1_5.domain.NetworkFeatures; import org.jclouds.vcloud.director.v1_5.domain.OrgNetwork; import org.jclouds.vcloud.director.v1_5.domain.SyslogServerSettings; -import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; +import org.jclouds.vcloud.director.v1_5.internal.VCloudDirectorAdminClientExpectTest; import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorClient; import org.testng.annotations.Test; @@ -53,7 +53,7 @@ import com.google.common.collect.ImmutableSet; * @author danikov */ @Test(groups = { "unit", "user", "network" }, singleThreaded = true, testName = "NetworkClientExpectTest") -public class NetworkClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { +public class NetworkClientExpectTest extends VCloudDirectorAdminClientExpectTest { @Test public void testGetNetwork() { 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 91d048459e..2c5ddd9c24 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 @@ -34,7 +34,7 @@ import org.jclouds.vcloud.director.v1_5.domain.MetadataValue; import org.jclouds.vcloud.director.v1_5.domain.Org; import org.jclouds.vcloud.director.v1_5.domain.OrgList; import org.jclouds.vcloud.director.v1_5.domain.Reference; -import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; +import org.jclouds.vcloud.director.v1_5.internal.VCloudDirectorAdminClientExpectTest; import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorClient; import org.testng.annotations.Test; @@ -47,7 +47,7 @@ import com.google.common.collect.Iterables; * @author Adrian Cole */ @Test(groups = { "unit", "user", "org" }, singleThreaded = true, testName = "OrgClientExpectTest") -public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { +public class OrgClientExpectTest extends VCloudDirectorAdminClientExpectTest { @Test public void testGetOrgList() { diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientExpectTest.java index f7e98b0e08..287598d308 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/QueryClientExpectTest.java @@ -30,7 +30,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Link; import org.jclouds.vcloud.director.v1_5.domain.query.CatalogReferences; import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultCatalogRecord; import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecords; -import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; +import org.jclouds.vcloud.director.v1_5.internal.VCloudDirectorAdminClientExpectTest; import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorClient; import org.testng.annotations.Test; @@ -42,7 +42,7 @@ import com.google.common.collect.ImmutableMultimap; * @author grkvlt@apache.org */ @Test(groups = { "unit", "user", "query" }, singleThreaded = true, testName = "QueryClientExpectTest") -public class QueryClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { +public class QueryClientExpectTest extends VCloudDirectorAdminClientExpectTest { @Test public void testQueryAllCatalogs() { 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 9a9e197d8e..5539424c47 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 @@ -32,7 +32,7 @@ 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.Task; import org.jclouds.vcloud.director.v1_5.domain.TasksList; -import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; +import org.jclouds.vcloud.director.v1_5.internal.VCloudDirectorAdminClientExpectTest; import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorClient; import org.testng.annotations.Test; @@ -44,7 +44,7 @@ import com.google.common.collect.ImmutableMultimap; * @author grkvlt@apache.org */ @Test(groups = { "unit", "user", "task" }, singleThreaded = true, testName = "TaskClientExpectTest") -public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { +public class TaskClientExpectTest extends VCloudDirectorAdminClientExpectTest { @Test public void testTaskListForValidOrg() { diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientExpectTest.java index 84fa8b7dfb..b957599973 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientExpectTest.java @@ -30,7 +30,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Link; import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.domain.User; import org.jclouds.vcloud.director.v1_5.features.admin.UserClient; -import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; +import org.jclouds.vcloud.director.v1_5.internal.VCloudDirectorAdminClientExpectTest; import org.testng.annotations.Test; /** @@ -39,7 +39,7 @@ import org.testng.annotations.Test; * @author danikov */ @Test(groups = { "unit", "admin", "adminUser"}, singleThreaded = true, testName = "UserClientExpectTest") -public class UserClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { +public class UserClientExpectTest extends VCloudDirectorAdminClientExpectTest { private Reference orgRef = Reference.builder() .href(URI.create(endpoint + "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppClientExpectTest.java index ea539effa1..c8d273b91d 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppClientExpectTest.java @@ -50,7 +50,7 @@ import org.jclouds.vcloud.director.v1_5.domain.ovf.NetworkSection; import org.jclouds.vcloud.director.v1_5.domain.ovf.OperatingSystemSection; import org.jclouds.vcloud.director.v1_5.domain.ovf.StartupSection; import org.jclouds.vcloud.director.v1_5.domain.ovf.VirtualHardwareSection; -import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; +import org.jclouds.vcloud.director.v1_5.internal.VCloudDirectorAdminClientExpectTest; import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorClient; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -65,7 +65,7 @@ import com.google.common.collect.Multimaps; * @author grkvlt@apache.org */ @Test(groups = { "unit", "user", "vapp" }, singleThreaded = true, testName = "VAppClientExpectTest") -public class VAppClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { +public class VAppClientExpectTest extends VCloudDirectorAdminClientExpectTest { private String vAppId = "vapp-d0e2b6b9-4381-4ddc-9572-cdfae54059be"; private URI vAppURI = URI.create(endpoint + vAppId); diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppTemplateClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppTemplateClientExpectTest.java index f1e46eeb82..25e5863755 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppTemplateClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppTemplateClientExpectTest.java @@ -66,8 +66,7 @@ import org.jclouds.vcloud.director.v1_5.domain.RelocateParams; import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.domain.VAppNetworkConfiguration; import org.jclouds.vcloud.director.v1_5.domain.VAppTemplate; -import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; -import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorClient; +import org.jclouds.vcloud.director.v1_5.internal.VCloudDirectorAdminClientExpectTest; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; @@ -78,7 +77,7 @@ import com.google.common.collect.ImmutableSet; * @author Adam Lowe */ @Test(groups = { "unit", "user", "vapptemplate" }, testName = "VAppTemplateClientExpectTest") -public class VAppTemplateClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { +public class VAppTemplateClientExpectTest extends VCloudDirectorAdminClientExpectTest { public VAppTemplateClientExpectTest() { TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles")); diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VdcClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VdcClientExpectTest.java index 62359ff3ff..1fb0d81610 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VdcClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VdcClientExpectTest.java @@ -45,7 +45,7 @@ import org.jclouds.vcloud.director.v1_5.domain.UploadVAppTemplateParams; import org.jclouds.vcloud.director.v1_5.domain.VApp; import org.jclouds.vcloud.director.v1_5.domain.VAppTemplate; import org.jclouds.vcloud.director.v1_5.domain.Vdc; -import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; +import org.jclouds.vcloud.director.v1_5.internal.VCloudDirectorAdminClientExpectTest; import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorClient; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -56,7 +56,7 @@ import org.testng.annotations.Test; * @author danikov */ @Test(groups = { "unit", "user", "vdc" }, singleThreaded = true, testName = "VdcClientExpectTest") -public class VdcClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { +public class VdcClientExpectTest extends VCloudDirectorAdminClientExpectTest { private URI vdcURI; diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorExpectTest.java new file mode 100644 index 0000000000..75a45c3327 --- /dev/null +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorExpectTest.java @@ -0,0 +1,261 @@ +/** + * 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.internal; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.rest.RestContextFactory.createContext; +import static org.testng.Assert.assertNotNull; + +import java.net.URI; +import java.util.Properties; + +import org.jclouds.Constants; +import org.jclouds.date.DateService; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.logging.config.NullLoggingModule; +import org.jclouds.rest.BaseRestClientExpectTest; +import org.jclouds.rest.RestContextSpec; +import org.jclouds.rest.BaseRestClientExpectTest.ExpectModule; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.jclouds.vcloud.director.v1_5.domain.Reference; +import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorClient; +import org.testng.annotations.BeforeGroups; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.LinkedListMultimap; +import com.google.common.collect.Multimap; +import com.google.inject.Guice; +import com.google.inject.Module; + +/** + * Base class for writing KeyStone Rest Client Expect tests + * + * @author Adrian Cole + */ +public abstract class BaseVCloudDirectorExpectTest extends BaseRestClientExpectTest { + + public BaseVCloudDirectorExpectTest() { + provider = "vcloud-director"; + identity = String.format("%s@%s", user, org); + credential = password; + } + + public static final String user = "adrian@jclouds.org"; + 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 = "https://vcloudbeta.bluelock.com/api"; + + protected static DateService dateService; + + @BeforeGroups("unit") + protected static void setupDateService() { + dateService = Guice.createInjector().getInstance(DateService.class); + assertNotNull(dateService); + } + + @Override + public Properties setupProperties() { + Properties props = new Properties(); + props.put(Constants.PROPERTY_MAX_RETRIES, 1); + return props; + } + + @Override + public HttpRequestComparisonType compareHttpRequestAsType(HttpRequest input) { + if (input.getPayload() == null || input.getPayload().getContentMetadata().getContentLength() == 0) { + return HttpRequestComparisonType.DEFAULT; + } + return HttpRequestComparisonType.XML; + } + + protected HttpRequest loginRequest = HttpRequest.builder() + .method("POST") + .endpoint(URI.create(endpoint + "/sessions")) + .headers(ImmutableMultimap.builder() + .put("Accept", "*/*") + .put("Authorization", "Basic YWRyaWFuQGpjbG91ZHMub3JnQEpDbG91ZHM6cGFzc3dvcmQ=") + .build()) + .build(); + + protected HttpResponse sessionResponse = HttpResponse.builder() + .statusCode(200) + .headers(ImmutableMultimap. builder() + .put("x-vcloud-authorization", token) + .put("Set-Cookie", String.format("vcloud-token=%s; Secure; Path=/", token)) + .build()) + .payload(payloadFromResourceWithContentType("/session.xml", VCloudDirectorMediaType.SESSION + ";version=1.5")) + .build(); + + + @Deprecated + protected HttpRequest getStandardRequest(String method, String path) { + return getStandardRequest(method, path, VCloudDirectorMediaType.ANY); + } + + @Deprecated + protected HttpRequest getStandardRequest(String method, URI uri) { + return getStandardRequest(method, uri, VCloudDirectorMediaType.ANY); + } + + @Deprecated + protected HttpRequest getStandardRequest(String method, String path, String mediaType) { + return getStandardRequest(method, URI.create(endpoint + path), VCloudDirectorMediaType.ANY); + } + + @Deprecated + protected HttpRequest getStandardPayloadRequest(String method, String command, String relativeFilePath, + String postMediaType) { + return getStandardPayloadRequest(method, URI.create(endpoint + command), relativeFilePath, postMediaType); + } + + @Deprecated + protected HttpRequest getStandardPayloadRequest(String method, URI uri, String relativeFilePath, + String postMediaType) { + return getStandardRequestWithPayload(method, uri, VCloudDirectorMediaType.ANY, relativeFilePath, postMediaType); + } + + @Deprecated + protected HttpRequest getStandardRequest(String method, URI uri, String mediaType) { + return HttpRequest.builder() + .method(method) + .endpoint(uri) + .headers(ImmutableMultimap. builder() + .put("Accept", mediaType) + .put("x-vcloud-authorization", token) + .build()) + .build(); + } + + @Deprecated + protected HttpRequest getStandardRequestWithPayload(String method, String path, String relativeFilePath, String mediaType) { + return getStandardRequestWithPayload(method, path, VCloudDirectorMediaType.ANY, relativeFilePath, mediaType); + } + + @Deprecated + protected HttpRequest getStandardRequestWithPayload(String method, URI uri, String relativeFilePath, String mediaType) { + return getStandardRequestWithPayload(method, uri, VCloudDirectorMediaType.ANY, relativeFilePath, mediaType); + } + + @Deprecated + protected HttpRequest getStandardRequestWithPayload(String method, String path, String acceptType, String relativeFilePath, String mediaType) { + URI uri = URI.create(endpoint + path); + return getStandardRequestWithPayload(method, uri, acceptType, relativeFilePath, mediaType); + } + + @Deprecated + protected HttpRequest getStandardRequestWithPayload(String method, URI uri, String acceptType, String relativeFilePath, String mediaType) { + return HttpRequest.builder() + .method(method) + .endpoint(uri) + .headers(ImmutableMultimap. builder() + .put("Accept", acceptType) + .put("x-vcloud-authorization", token) + .build()) + .payload(payloadFromResourceWithContentType(relativeFilePath, mediaType)) + .build(); + } + + @Deprecated + protected HttpResponse getStandardPayloadResponse(String relativeFilePath, String mediaType) { + return getStandardPayloadResponse(200, relativeFilePath, mediaType); + } + + @Deprecated + protected HttpResponse getStandardPayloadResponse(int statusCode, String relativeFilePath, String mediaType) { + return HttpResponse.builder() + .statusCode(statusCode) + .payload(payloadFromResourceWithContentType(relativeFilePath, mediaType + ";version=1.5")) + .build(); + } + + /** + * Implicitly adds x-vcloud-authorization header with token. + * Provides convenience methods for priming a HttpRequest.Builder for vCloud testing + * + * @author danikov + */ + public class VcloudHttpRequestPrimer { + private Multimap headers = LinkedListMultimap.create(); + private HttpRequest.Builder builder = HttpRequest.builder(); + + public VcloudHttpRequestPrimer() { + } + + public VcloudHttpRequestPrimer apiCommand(String method, String command) { + builder.method(method).endpoint(URI.create(endpoint + command)); + return this; + } + + public VcloudHttpRequestPrimer xmlFilePayload(String relativeFilePath, String mediaType) { + builder.payload(payloadFromResourceWithContentType(relativeFilePath, mediaType)); + return this; + } + + public VcloudHttpRequestPrimer headers(Multimap headers) { + this.headers.putAll(ImmutableMultimap.copyOf(checkNotNull(headers, "headers"))); + return this; + } + + public VcloudHttpRequestPrimer acceptAnyMedia() { + return acceptMedia(VCloudDirectorMediaType.ANY); + } + + public VcloudHttpRequestPrimer acceptMedia(String media) { + return header("Accept", media); + } + + public VcloudHttpRequestPrimer header(String name, String value) { + headers.put(checkNotNull(name, "header.name"), checkNotNull(value, "header.value")); + return this; + } + + public HttpRequest.Builder httpRequestBuilder() { + header("x-vcloud-authorization", token); + builder.headers(headers); + return builder; + } + } + + protected class VcloudHttpResponsePrimer { + private HttpResponse.Builder builder = HttpResponse.builder(); + + public VcloudHttpResponsePrimer() { + } + + public VcloudHttpResponsePrimer xmlFilePayload(String relativeFilePath, String mediaType) { + builder.payload(payloadFromResourceWithContentType(relativeFilePath, mediaType)); + return this; + } + public HttpResponse.Builder httpResponseBuilder() { + return builder; + } + } + + public URI toAdminUri(Reference ref) { + return toAdminUri(ref.getHref()); + } + + public URI toAdminUri(URI uri) { + return Reference.builder().href(uri).build().toAdminReference(endpoint).getHref(); + } +} 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 d637902415..cff0b5c3df 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 @@ -18,237 +18,13 @@ */ package org.jclouds.vcloud.director.v1_5.internal; -import static com.google.common.base.Preconditions.checkNotNull; -import static org.testng.Assert.assertNotNull; - -import java.net.URI; -import java.util.Properties; - -import org.jclouds.Constants; -import org.jclouds.date.DateService; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; -import org.jclouds.rest.BaseRestClientExpectTest; -import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; -import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorClient; -import org.testng.annotations.BeforeGroups; - -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.LinkedListMultimap; -import com.google.common.collect.Multimap; -import com.google.inject.Guice; /** * Base class for writing KeyStone Rest Client Expect tests * * @author Adrian Cole */ -public abstract class BaseVCloudDirectorRestClientExpectTest - extends BaseRestClientExpectTest { +public abstract class BaseVCloudDirectorRestClientExpectTest extends BaseVCloudDirectorExpectTest { - public static final String user = "adrian@jclouds.org"; - 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 = "https://vcloudbeta.bluelock.com/api"; - - protected static DateService dateService; - - @BeforeGroups("unit") - protected static void setupDateService() { - dateService = Guice.createInjector().getInstance(DateService.class); - assertNotNull(dateService); - } - - @Override - public Properties setupProperties() { - Properties props = new Properties(); - props.put(Constants.PROPERTY_MAX_RETRIES, 1); - return props; - } - - @Override - public HttpRequestComparisonType compareHttpRequestAsType(HttpRequest input) { - if (input.getPayload() == null || input.getPayload().getContentMetadata().getContentLength() == 0) { - return HttpRequestComparisonType.DEFAULT; - } - return HttpRequestComparisonType.XML; - } - - protected HttpRequest loginRequest = HttpRequest.builder() - .method("POST") - .endpoint(URI.create(endpoint + "/sessions")) - .headers(ImmutableMultimap.builder() - .put("Accept", "*/*") - .put("Authorization", "Basic YWRyaWFuQGpjbG91ZHMub3JnQEpDbG91ZHM6cGFzc3dvcmQ=") - .build()) - .build(); - - protected HttpResponse sessionResponse = HttpResponse.builder() - .statusCode(200) - .headers(ImmutableMultimap. builder() - .put("x-vcloud-authorization", token) - .put("Set-Cookie", String.format("vcloud-token=%s; Secure; Path=/", token)) - .build()) - .payload(payloadFromResourceWithContentType("/session.xml", VCloudDirectorMediaType.SESSION + ";version=1.5")) - .build(); - - public BaseVCloudDirectorRestClientExpectTest() { - provider = "vcloud-director"; - identity = String.format("%s@%s", user, org); - credential = password; - } - - @Deprecated - protected HttpRequest getStandardRequest(String method, String path) { - return getStandardRequest(method, path, VCloudDirectorMediaType.ANY); - } - - @Deprecated - protected HttpRequest getStandardRequest(String method, URI uri) { - return getStandardRequest(method, uri, VCloudDirectorMediaType.ANY); - } - - @Deprecated - protected HttpRequest getStandardRequest(String method, String path, String mediaType) { - return getStandardRequest(method, URI.create(endpoint + path), VCloudDirectorMediaType.ANY); - } - - @Deprecated - protected HttpRequest getStandardPayloadRequest(String method, String command, String relativeFilePath, - String postMediaType) { - return getStandardPayloadRequest(method, URI.create(endpoint + command), relativeFilePath, postMediaType); - } - - @Deprecated - protected HttpRequest getStandardPayloadRequest(String method, URI uri, String relativeFilePath, - String postMediaType) { - return getStandardRequestWithPayload(method, uri, VCloudDirectorMediaType.ANY, relativeFilePath, postMediaType); - } - - @Deprecated - protected HttpRequest getStandardRequest(String method, URI uri, String mediaType) { - return HttpRequest.builder() - .method(method) - .endpoint(uri) - .headers(ImmutableMultimap. builder() - .put("Accept", mediaType) - .put("x-vcloud-authorization", token) - .build()) - .build(); - } - - @Deprecated - protected HttpRequest getStandardRequestWithPayload(String method, String path, String relativeFilePath, String mediaType) { - return getStandardRequestWithPayload(method, path, VCloudDirectorMediaType.ANY, relativeFilePath, mediaType); - } - - @Deprecated - protected HttpRequest getStandardRequestWithPayload(String method, URI uri, String relativeFilePath, String mediaType) { - return getStandardRequestWithPayload(method, uri, VCloudDirectorMediaType.ANY, relativeFilePath, mediaType); - } - - @Deprecated - protected HttpRequest getStandardRequestWithPayload(String method, String path, String acceptType, String relativeFilePath, String mediaType) { - URI uri = URI.create(endpoint + path); - return getStandardRequestWithPayload(method, uri, acceptType, relativeFilePath, mediaType); - } - - @Deprecated - protected HttpRequest getStandardRequestWithPayload(String method, URI uri, String acceptType, String relativeFilePath, String mediaType) { - return HttpRequest.builder() - .method(method) - .endpoint(uri) - .headers(ImmutableMultimap. builder() - .put("Accept", acceptType) - .put("x-vcloud-authorization", token) - .build()) - .payload(payloadFromResourceWithContentType(relativeFilePath, mediaType)) - .build(); - } - - @Deprecated - protected HttpResponse getStandardPayloadResponse(String relativeFilePath, String mediaType) { - return getStandardPayloadResponse(200, relativeFilePath, mediaType); - } - - @Deprecated - protected HttpResponse getStandardPayloadResponse(int statusCode, String relativeFilePath, String mediaType) { - return HttpResponse.builder() - .statusCode(statusCode) - .payload(payloadFromResourceWithContentType(relativeFilePath, mediaType + ";version=1.5")) - .build(); - } - - /** - * Implicitly adds x-vcloud-authorization header with token. - * Provides convenience methods for priming a HttpRequest.Builder for vCloud testing - * - * @author danikov - */ - public class VcloudHttpRequestPrimer { - private Multimap headers = LinkedListMultimap.create(); - private HttpRequest.Builder builder = HttpRequest.builder(); - - public VcloudHttpRequestPrimer() { - } - - public VcloudHttpRequestPrimer apiCommand(String method, String command) { - builder.method(method).endpoint(URI.create(endpoint + command)); - return this; - } - - public VcloudHttpRequestPrimer xmlFilePayload(String relativeFilePath, String mediaType) { - builder.payload(payloadFromResourceWithContentType(relativeFilePath, mediaType)); - return this; - } - - public VcloudHttpRequestPrimer headers(Multimap headers) { - this.headers.putAll(ImmutableMultimap.copyOf(checkNotNull(headers, "headers"))); - return this; - } - - public VcloudHttpRequestPrimer acceptAnyMedia() { - return acceptMedia(VCloudDirectorMediaType.ANY); - } - - public VcloudHttpRequestPrimer acceptMedia(String media) { - return header("Accept", media); - } - - public VcloudHttpRequestPrimer header(String name, String value) { - headers.put(checkNotNull(name, "header.name"), checkNotNull(value, "header.value")); - return this; - } - - public HttpRequest.Builder httpRequestBuilder() { - header("x-vcloud-authorization", token); - builder.headers(headers); - return builder; - } - } - - protected class VcloudHttpResponsePrimer { - private HttpResponse.Builder builder = HttpResponse.builder(); - - public VcloudHttpResponsePrimer() { - } - - public VcloudHttpResponsePrimer xmlFilePayload(String relativeFilePath, String mediaType) { - builder.payload(payloadFromResourceWithContentType(relativeFilePath, mediaType)); - return this; - } - public HttpResponse.Builder httpResponseBuilder() { - return builder; - } - } - - public URI toAdminUri(Reference ref) { - return toAdminUri(ref.getHref()); - } - - public URI toAdminUri(URI uri) { - return Reference.builder().href(uri).build().toAdminReference(endpoint).getHref(); - } } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/VCloudDirectorAdminClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/VCloudDirectorAdminClientExpectTest.java new file mode 100644 index 0000000000..f713b33bf2 --- /dev/null +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/VCloudDirectorAdminClientExpectTest.java @@ -0,0 +1,57 @@ +/** + * 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.internal; + +import java.util.Properties; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.logging.config.NullLoggingModule; +import org.jclouds.rest.RestContextFactory; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorContext; +import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminClient; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableSet; +import com.google.inject.Module; + +/** + * + * @author Adrian Cole + */ +public abstract class VCloudDirectorAdminClientExpectTest extends + BaseVCloudDirectorExpectTest implements + Function { + + @Override + public VCloudDirectorAdminClient createClient(Function fn, Module module, Properties props) { + return apply(createVCloudDirectorContext(fn, module, props)); + } + + @Override + public VCloudDirectorAdminClient apply(VCloudDirectorContext input) { + return input.getAdminContext().getApi(); + } + + private VCloudDirectorContext createVCloudDirectorContext(Function fn, Module module, + Properties props) { + return VCloudDirectorContext.class.cast(new RestContextFactory(setupRestProperties()).createContext(provider, + identity, credential, ImmutableSet. of(new ExpectModule(fn), new NullLoggingModule(), module), props)); + } +}