From 1df9409a3a54af10c8dc55ca12bbb2769f899a6b Mon Sep 17 00:00:00 2001 From: danikov Date: Fri, 9 Mar 2012 16:42:59 +0000 Subject: [PATCH 01/10] adminOrg base continued- media types, restClient config, and checks --- .../v1_5/VCloudDirectorMediaType.java | 6 +- .../VCloudDirectorRestClientModule.java | 1 + .../v1_5/domain/CustomOrgLdapSettings.java | 33 ++++ .../director/v1_5/domain/OrgLdapSettings.java | 17 ++ .../domain/OrgPasswordPolicySettings.java | 4 +- .../director/v1_5/domain/Reference.java | 7 + .../vcloud/director/v1_5/domain/Checks.java | 185 ++++++++++++++++++ 7 files changed, 250 insertions(+), 3 deletions(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java index a81599610d..3ed614c2c0 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java @@ -135,6 +135,8 @@ public class VCloudDirectorMediaType { public static final String GROUP = "application/vnd.vmware.admin.group+xml"; + public static final String ORG_VAPP_TEMPLATE_LEASE_SETTINGS = "application/vnd.vmware.admin.vAppTemplateLeaseSettings+xml"; + /** * * All acceptable media types. @@ -153,6 +155,8 @@ public class VCloudDirectorMediaType { CONTROL_ACCESS, VAPP_TEMPLATE, CUSTOMIZATION_SECTION, GUEST_CUSTOMIZATION_SECTION, NETWORK_SECTION, NETWORK_CONFIG_SECTION, NETWORK_CONNECTION_SECTION, CLONE_MEDIA_PARAMS, LEASE_SETTINGS_SECTION, RELOCATE_TEMPLATE, ENVELOPE, - PUBLISH_CATALOG_PARAMS, GROUP + PUBLISH_CATALOG_PARAMS, GROUP, ORG_VAPP_TEMPLATE_LEASE_SETTINGS ); + + } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java index b77551ea0a..a92216b0f3 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java @@ -109,6 +109,7 @@ public class VCloudDirectorRestClientModule extends RestClientModule + * This list must be updated whenever a new authentication mechanism is added. + */ + public static final List ALL = Arrays.asList( + SIMPLE, KERBEROS, MD5DIGEST, NTLM + ); + } + + public static final class ConnectorType { + public static final String ACTIVE_DIRECTORY = "ACTIVE_DIRECTORY"; + public static final String OPEN_LDAP = "OPEN_LDAP"; + + /** + * All acceptable {@link OrgLdapSettings#getOrgLdapMode()} values. + *

+ * This list must be updated whenever a new mode is added. + */ + public static final List ALL = Arrays.asList( + ACTIVE_DIRECTORY, OPEN_LDAP + ); + } + public static Builder builder() { return new ConcreteBuilder(); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgLdapSettings.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgLdapSettings.java index 667ec88a20..fa5eca660c 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgLdapSettings.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgLdapSettings.java @@ -22,6 +22,8 @@ package org.jclouds.vcloud.director.v1_5.domain; import static com.google.common.base.Objects.equal; import java.net.URI; +import java.util.Arrays; +import java.util.List; import java.util.Set; import javax.xml.bind.annotation.XmlAccessType; @@ -66,6 +68,21 @@ import com.google.common.base.Objects.ToStringHelper; "customOrgLdapSettings" }) public class OrgLdapSettings extends ResourceType { + public static final class LdapMode { + public static final String NONE = "none"; + public static final String SYSTEM = "system"; + public static final String CUSTOM = "custom"; + + /** + * All acceptable {@link OrgLdapSettings#getOrgLdapMode()} values. + *

+ * This list must be updated whenever a new mode is added. + */ + public static final List ALL = Arrays.asList( + NONE, SYSTEM, CUSTOM + ); + } + public static Builder builder() { return new Builder(); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgPasswordPolicySettings.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgPasswordPolicySettings.java index d766f513ae..3974e1ca04 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgPasswordPolicySettings.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgPasswordPolicySettings.java @@ -193,7 +193,7 @@ public class OrgPasswordPolicySettings extends ResourceType { Reference that = Reference.class.cast(o); return super.equals(that); } + + public ReferenceType toAdminReference(String endpoint) { + return toBuilder() + .type(null) + .href(URI.create(getHref().toASCIIString().replace(endpoint, endpoint+"/admin"))) + .build(); + } } \ No newline at end of file diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java index 963ca76c3b..4654241f5d 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java @@ -38,6 +38,9 @@ import java.util.Set; import java.util.UUID; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.jclouds.vcloud.director.v1_5.domain.CustomOrgLdapSettings.AuthenticationMechanism; +import org.jclouds.vcloud.director.v1_5.domain.CustomOrgLdapSettings.ConnectorType; +import org.jclouds.vcloud.director.v1_5.domain.OrgLdapSettings.LdapMode; import com.google.common.base.Splitter; import com.google.common.collect.Iterables; @@ -524,4 +527,186 @@ public class Checks { } } } + + public static void checkOrgSetting(OrgSettings settings) { + // Check optional fields + if (settings.getOrgGeneralSettings() != null) { + checkOrgGeneralSettings(settings.getOrgGeneralSettings()); + } + if (settings.getVAppLeaseSettings() != null) { + checkVAppLeaseSettings(settings.getVAppLeaseSettings()); + } + if (settings.getVAppTemplateLeaseSettings() != null) { + checkVAppTemplateLeaseSettings(settings.getVAppTemplateLeaseSettings()); + } + if (settings.getOrgLdapSettings() != null) { + checkLdapSettings(settings.getOrgLdapSettings()); + } + if (settings.getOrgEmailSettings() != null) { + checkEmailSettings(settings.getOrgEmailSettings()); + } + if (settings.getOrgPasswordPolicySettings() != null) { + checkPasswordPolicySettings(settings.getOrgPasswordPolicySettings()); + } + + // parent type + checkResourceType(settings); + } + + public static void checkEmailSettings(OrgEmailSettings settings) { + // required + assertNotNull(settings.isDefaultSmtpServer(), String.format(OBJ_FIELD_REQ, "OrgEmailSettings", "isDefaultSmtpServer")); + assertNotNull(settings.isDefaultOrgEmail(), String.format(OBJ_FIELD_REQ, "OrgEmailSettings", "isDefaultOrgEmail")); + assertNotNull(settings.getFromEmailAddress(), String.format(OBJ_FIELD_REQ, "OrgEmailSettings", "fromEmailAddress")); + checkEmailAddress(settings.getFromEmailAddress()); + assertNotNull(settings.getDefaultSubjectPrefix(), String.format(OBJ_FIELD_REQ, "OrgEmailSettings", "defaultSubjectPrefix")); + assertNotNull(settings.isAlertEmailToAllAdmins(), String.format(OBJ_FIELD_REQ, "OrgEmailSettings", "isAlertEmailToAllAdmins")); + assertNotNull(settings.getAlertEmailsTo(), String.format(OBJ_FIELD_REQ, "OrgEmailSettings", "alertEmailsTo")); + + // optional + // NOTE alertEmailsTo cannot be checked + + // parent type + checkResourceType(settings); + } + + public static void checkEmailAddress(String email) { + // TODO: validate email addresses + } + + public static void checkOrgGeneralSettings(OrgGeneralSettings settings) { + // Check optional fields + // NOTE canPublishCatalogs cannot be checked + // NOTE useServerBootSequence cannot be checked + if (settings.getDeployedVMQuota() != null) { + assertTrue(settings.getDeployedVMQuota() >= 0, String.format( + OBJ_FIELD_GTE_0, "deployedVMQuota", "port", settings.getDeployedVMQuota())); + } + if (settings.getStoredVmQuota() != null) { + assertTrue(settings.getStoredVmQuota() >= 0, String.format( + OBJ_FIELD_GTE_0, "storedVmQuota", "port", settings.getStoredVmQuota())); + } + if (settings.getDelayAfterPowerOnSeconds() != null) { + assertTrue(settings.getDelayAfterPowerOnSeconds() >= 0, String.format( + OBJ_FIELD_GTE_0, "delayAfterPowerOnSeconds", "port", settings.getDelayAfterPowerOnSeconds())); + } + + // parent type + checkResourceType(settings); + } + + public static void checkLdapSettings(OrgLdapSettings settings) { + // Check optional fields + // NOTE customUsersOu cannot be checked + if (settings.getOrgLdapMode() != null) { + assertTrue(LdapMode.ALL.contains(settings.getOrgLdapMode()), String.format(REQUIRED_VALUE_OBJECT_FMT, + "LdapMode", "OrdLdapSettings", settings.getOrgLdapMode(), Iterables.toString(OrgLdapSettings.LdapMode.ALL))); + } + if (settings.getCustomOrgLdapSettings() != null) { + checkCustomOrgLdapSettings(settings.getCustomOrgLdapSettings()); + } + + // parent type + checkResourceType(settings); + } + + public static void checkCustomOrgLdapSettings(CustomOrgLdapSettings settings) { + // required + assertNotNull(settings.getHostName(), String.format(OBJ_FIELD_REQ, "CustomOrgLdapSettings", "hostName")); + assertNotNull(settings.getPort(), String.format(OBJ_FIELD_REQ, "CustomOrgLdapSettings", "port")); + assertTrue(settings.getPort() >= 0, String.format( + OBJ_FIELD_GTE_0, "CustomOrgLdapSettings", "port", settings.getPort())); + assertNotNull(settings.getAuthenticationMechanism(), String.format(OBJ_FIELD_REQ, "CustomOrgLdapSettings", "authenticationMechanism")); + assertTrue(AuthenticationMechanism.ALL.contains(settings.getAuthenticationMechanism()), String.format(REQUIRED_VALUE_OBJECT_FMT, + "AuthenticationMechanism", "CustomOrdLdapSettings", settings.getAuthenticationMechanism(), + Iterables.toString(CustomOrgLdapSettings.AuthenticationMechanism.ALL))); + assertNotNull(settings.isGroupSearchBaseEnabled(), String.format(OBJ_FIELD_REQ, "CustomOrgLdapSettings", "isGroupSearchBaseEnabled")); + assertNotNull(settings.getConnectorType(), String.format(OBJ_FIELD_REQ, "CustomOrgLdapSettings", "connectorType")); + assertTrue(ConnectorType.ALL.contains(settings.getConnectorType()), String.format(REQUIRED_VALUE_OBJECT_FMT, + "ConnectorType", "CustomOrdLdapSettings", settings.getConnectorType(), + Iterables.toString(CustomOrgLdapSettings.ConnectorType.ALL))); + assertNotNull(settings.getUserAttributes(), String.format(OBJ_FIELD_REQ, "CustomOrgLdapSettings", "userAttributes")); + checkUserAttributes("CustomOrdLdapSettings", settings.getUserAttributes()); + assertNotNull(settings.getGroupAttributes(), String.format(OBJ_FIELD_REQ, "CustomOrgLdapSettings", "groupAttributes")); + checkGroupAttributes("CustomOrdLdapSettings", settings.getGroupAttributes()); + + // optional + // NOTE isSsl cannot be checked + // NOTE isSSlAcceptAll cannot be checked + // NOTE realm cannot be checked + // NOTE searchBase cannot be checked + // NOTE userName cannot be checked + // NOTE password cannot be checked + // NOTE groupSearchBase cannot be checked + } + + public static void checkUserAttributes(String client, OrgLdapUserAttributes attributes) { + // required + assertNotNull(attributes.getObjectClass(), String.format(OBJ_FIELD_REQ, client, "objectClass")); + assertNotNull(attributes.getObjectIdentifier(), String.format(OBJ_FIELD_REQ, client, "objectIdentifier")); + assertNotNull(attributes.getUserName(), String.format(OBJ_FIELD_REQ, client, "userName")); + assertNotNull(attributes.getEmail(), String.format(OBJ_FIELD_REQ, client, "email")); + assertNotNull(attributes.getFullName(), String.format(OBJ_FIELD_REQ, client, "fullName")); + assertNotNull(attributes.getGivenName(), String.format(OBJ_FIELD_REQ, client, "givenName")); + assertNotNull(attributes.getSurname(), String.format(OBJ_FIELD_REQ, client, "surname")); + assertNotNull(attributes.getTelephone(), String.format(OBJ_FIELD_REQ, client, "telephone")); + assertNotNull(attributes.getGroupMembershipIdentifier(), String.format(OBJ_FIELD_REQ, client, "groupMembershipIdentifier")); + + // optional + // NOTE groupBackLinkIdentifier cannot be checked + } + + public static void checkGroupAttributes(String client, OrgLdapGroupAttributes attributes) { + // required + assertNotNull(attributes.getObjectClass(), String.format(OBJ_FIELD_REQ, client, "objectClass")); + assertNotNull(attributes.getObjectIdentifier(), String.format(OBJ_FIELD_REQ, client, "objectIdentifier")); + assertNotNull(attributes.getGroupName(), String.format(OBJ_FIELD_REQ, client, "groupName")); + assertNotNull(attributes.getMembership(), String.format(OBJ_FIELD_REQ, client, "membership")); + assertNotNull(attributes.getMembershipIdentifier(), String.format(OBJ_FIELD_REQ, client, "membershipIdentifier")); + + // optional + // NOTE backLinkIdentifier cannot be checked + } + + public static void checkPasswordPolicySettings(OrgPasswordPolicySettings settings) { + // required + assertNotNull(settings.isAccountLockoutEnabled(), String.format(OBJ_FIELD_REQ, "OrgPasswordPolicySettings", "isAccountLockoutEnabled")); + assertNotNull(settings.getInvalidLoginsBeforeLockout(), String.format(OBJ_FIELD_REQ, "OrgPasswordPolicySettings", "invalidLoginsBeforeLockout")); + assertTrue(settings.getInvalidLoginsBeforeLockout() >= 0, String.format( + OBJ_FIELD_GTE_0, "OrgPasswordPolicySettings", "storageLeaseSeconds", settings.getInvalidLoginsBeforeLockout())); + assertNotNull(settings.getAccountLockoutIntervalMinutes(), String.format(OBJ_FIELD_REQ, "OrgPasswordPolicySettings", "accountLockoutIntervalMinutes")); + assertTrue(settings.getAccountLockoutIntervalMinutes() >= 0, String.format( + OBJ_FIELD_GTE_0, "OrgPasswordPolicySettings", "accountLockoutIntervalMinutes", settings.getAccountLockoutIntervalMinutes())); + + // parent type + checkResourceType(settings); + } + + public static void checkVAppLeaseSettings(OrgLeaseSettings settings) { + // Check optional fields + // NOTE deleteOnStorageLeaseExpiration cannot be checked + if (settings.getStorageLeaseSeconds() != null) { + assertTrue(settings.getStorageLeaseSeconds() >= 0, String.format( + OBJ_FIELD_GTE_0, "OrgLeaseSettings", "storageLeaseSeconds", settings.getStorageLeaseSeconds())); + } + if (settings.getDeploymentLeaseSeconds() != null) { + assertTrue(settings.getDeploymentLeaseSeconds() >= 0, String.format( + OBJ_FIELD_GTE_0, "OrgLeaseSettings", "deploymentLeaseSeconds", settings.getDeploymentLeaseSeconds())); + } + + // parent type + checkResourceType(settings); + } + + public static void checkVAppTemplateLeaseSettings(OrgVAppTemplateLeaseSettings settings) { + // Check optional fields + // NOTE deleteOnStorageLeaseExpiration cannot be checked + if (settings.getStorageLeaseSeconds() != null) { + assertTrue(settings.getStorageLeaseSeconds() >= 0, String.format( + OBJ_FIELD_GTE_0, "OrgVAppTemplateLeaseSettings", "storageLeaseSeconds", settings.getStorageLeaseSeconds())); + } + + // parent type + checkResourceType(settings); + } } From a05d76fabf305da4769fa8c69a13752f30109e27 Mon Sep 17 00:00:00 2001 From: danikov Date: Fri, 9 Mar 2012 16:44:15 +0000 Subject: [PATCH 02/10] get/put vAppTemplateLeaseSettings --- .../v1_5/features/AdminOrgAsyncClient.java | 50 ++++++++++++--- .../v1_5/features/AdminOrgClient.java | 30 ++++++++- .../features/AdminOrgClientExpectTest.java | 55 +++++++++++++++- .../v1_5/features/AdminOrgClientLiveTest.java | 64 ++++++++++++++++--- .../org/admin/updateVAppLeaseSettings.xml | 0 .../admin/updateVAppLeaseSettingsSource.xml | 0 .../resources/org/admin/vAppLeaseSettings.xml | 0 7 files changed, 175 insertions(+), 24 deletions(-) create mode 100644 labs/vcloud-director/src/test/resources/org/admin/updateVAppLeaseSettings.xml create mode 100644 labs/vcloud-director/src/test/resources/org/admin/updateVAppLeaseSettingsSource.xml create mode 100644 labs/vcloud-director/src/test/resources/org/admin/vAppLeaseSettings.xml diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java index c88edee6e4..c4fc90fec0 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java @@ -18,15 +18,33 @@ */ package org.jclouds.vcloud.director.v1_5.features; +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.jclouds.rest.annotations.BinderParam; +import org.jclouds.rest.annotations.EndpointParam; +import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.JAXBResponseParser; import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.binders.BindToXMLPayload; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.jclouds.vcloud.director.v1_5.domain.OrgVAppTemplateLeaseSettings; import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; +import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx; + +import com.google.common.util.concurrent.ListenableFuture; /** * @see GroupClient * @author danikov */ @RequestFilters(AddVCloudAuthorizationToRequest.class) -public interface AdminOrgAsyncClient { +public interface AdminOrgAsyncClient extends OrgAsyncClient { // GET /admin/org/{id} @@ -52,12 +70,28 @@ public interface AdminOrgAsyncClient { // PUT /admin/org/{id}/settings/passwordPolicy -// GET /admin/org/{id}/settings/vAppLeaseSettings + /** + * @see AdminOrgClient#getVAppTemplateLeaseSettings(URI) + */ + @GET + @Path("/settings/vAppTemplateLeaseSettings") + @Consumes + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture getVAppTemplateLeaseSettings( + @EndpointParam URI orgRef); + + /** + * @see AdminOrgClient#updateVAppTemplateLeaseSettings(URI, OrgVAppTemplateLeaseSettings) + */ + @PUT + @Path("/settings/vAppTemplateLeaseSettings") + @Consumes(VCloudDirectorMediaType.ORG_VAPP_TEMPLATE_LEASE_SETTINGS) + @Produces(VCloudDirectorMediaType.ORG_VAPP_TEMPLATE_LEASE_SETTINGS) + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture updateVAppTemplateLeaseSettings( + @EndpointParam URI orgRef, + @BinderParam(BindToXMLPayload.class) OrgVAppTemplateLeaseSettings group); -// PUT /admin/org/{id}/settings/vAppLeaseSettings - -// GET /admin/org/{id}/settings/vAppTemplateLeaseSettings - -// PUT /admin/org/{id}/settings/vAppTemplateLeaseSettings - } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java index b584713fbf..a1bf2d399c 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java @@ -18,9 +18,12 @@ */ package org.jclouds.vcloud.director.v1_5.features; +import java.net.URI; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; +import org.jclouds.vcloud.director.v1_5.domain.Group; +import org.jclouds.vcloud.director.v1_5.domain.OrgVAppTemplateLeaseSettings; /** * Provides synchronous access to {@link Group} objects. @@ -29,7 +32,7 @@ import org.jclouds.concurrent.Timeout; * @author danikov */ @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) -public interface AdminOrgClient { +public interface AdminOrgClient extends OrgClient { // GET /admin/org/{id} @@ -59,8 +62,29 @@ public interface AdminOrgClient { // PUT /admin/org/{id}/settings/vAppLeaseSettings -// GET /admin/org/{id}/settings/vAppTemplateLeaseSettings + /** + * Retrieves expiration and storage policy for vApp templates in an organization. + * + *

+    * GET /admin/org/{id}/settings/vAppTemplateLeaseSettings
+    * 
+ * + * @param orgRef the reference for the admin org + * @return the lease settings + */ + OrgVAppTemplateLeaseSettings getVAppTemplateLeaseSettings(URI orgRef); -// PUT /admin/org/{id}/settings/vAppTemplateLeaseSettings + /** + * Updates vApp template policy settings for organization. + * + *
+    * PUT /admin/org/{id}/settings/vAppTemplateLeaseSettings
+    * 
+ * @param orgRef the reference for the admin org + * @param newSettings the requested updated settings + * @return the resultant settings + */ + OrgVAppTemplateLeaseSettings updateVAppTemplateLeaseSettings(URI orgRef, + OrgVAppTemplateLeaseSettings newSettings); } 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 e6f295ea15..0554271b2a 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 @@ -18,8 +18,13 @@ */ package org.jclouds.vcloud.director.v1_5.features; +import static org.testng.Assert.assertEquals; + import java.net.URI; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +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.internal.BaseVCloudDirectorRestClientExpectTest; import org.testng.annotations.Test; @@ -66,7 +71,51 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect // PUT /admin/org/{id}/settings/vAppLeaseSettings -// GET /admin/org/{id}/settings/vAppTemplateLeaseSettings - -// PUT /admin/org/{id}/settings/vAppTemplateLeaseSettings + @Test(enabled = false) + public void testGetVAppTemplateLeaseSettings() { + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("GET", "/admin/org/???/settings/vAppTemplateLeaseSettings") + .acceptAnyMedia() + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/org/admin/vAppTemplateLeaseSettings.xml", + VCloudDirectorMediaType.ORG_VAPP_TEMPLATE_LEASE_SETTINGS) + .httpResponseBuilder().build()); + + OrgVAppTemplateLeaseSettings expected = orgVAppTemplateLeaseSettings(); + + assertEquals(client.getAdminOrgClient().getVAppTemplateLeaseSettings(orgRef.getURI()), expected); + } + + public static final OrgVAppTemplateLeaseSettings orgVAppTemplateLeaseSettings() { + return OrgVAppTemplateLeaseSettings.builder() + + .build(); + } + + @Test(enabled = false) + public void testUpdateOrgVAppTemplateLeaseSettings() { + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("PUT", "/admin/org/???/settings/vAppTemplateLeaseSettings") + .xmlFilePayload("/org/admin/updateVAppLeaseSettingsSource.xml", + VCloudDirectorMediaType.ORG_VAPP_TEMPLATE_LEASE_SETTINGS) + .acceptMedia(VCloudDirectorMediaType.ORG_VAPP_TEMPLATE_LEASE_SETTINGS) + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/org/admin/updateVAppLeaseSettings.xml", + VCloudDirectorMediaType.ORG_VAPP_TEMPLATE_LEASE_SETTINGS) + .httpResponseBuilder().build()); + + OrgVAppTemplateLeaseSettings expected = updateOrgVAppTemplateLeaseSettings(); + + assertEquals(client.getAdminOrgClient().updateVAppTemplateLeaseSettings(orgRef.getURI(), expected), expected); + } + + public static final OrgVAppTemplateLeaseSettings updateOrgVAppTemplateLeaseSettings() { + return orgVAppTemplateLeaseSettings().toBuilder() + + .build(); + } } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java index 3c6d1f77cb..b5105f4552 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java @@ -18,15 +18,20 @@ */ package org.jclouds.vcloud.director.v1_5.features; -import java.net.URI; - +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.REF_REQ_LIVE; +import static org.testng.Assert.assertNotNull; import org.jclouds.vcloud.director.v1_5.domain.AdminOrg; -import org.jclouds.vcloud.director.v1_5.domain.Reference; +import org.jclouds.vcloud.director.v1_5.domain.Error; +import org.jclouds.vcloud.director.v1_5.domain.Group; +import org.jclouds.vcloud.director.v1_5.domain.Checks; +import org.jclouds.vcloud.director.v1_5.domain.OrgVAppTemplateLeaseSettings; import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import com.google.common.collect.Iterables; + /** * Tests live behavior of {@link AdminGroupClient}. * @@ -35,7 +40,7 @@ import org.testng.annotations.Test; @Test(groups = { "live", "admin", "org" }, singleThreaded = true, testName = "AdminOrgClientLiveTest") public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { - public static final String GROUP = "admin org"; + public static final String ORG = "admin org"; /* * Convenience references to API clients. @@ -48,14 +53,14 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { */ private ReferenceType orgRef; private AdminOrg org; + OrgVAppTemplateLeaseSettings vAppTemplateLeaseSettings; @Override @BeforeClass(inheritGroups = true) public void setupRequiredClients() { orgClient = context.getApi().getAdminOrgClient(); - orgRef = Reference.builder() - .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/???")) - .build(); + orgRef = Iterables.getFirst(orgClient.getOrgList().getOrgs(), null).toAdminReference(endpoint); + assertNotNull(orgRef, String.format(REF_REQ_LIVE, "admin org")); } // GET /admin/org/{id} @@ -86,7 +91,46 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { // PUT /admin/org/{id}/settings/vAppLeaseSettings -// GET /admin/org/{id}/settings/vAppTemplateLeaseSettings - -// PUT /admin/org/{id}/settings/vAppTemplateLeaseSettings + @Test(testName = "GET /admin/org/{id}/settings/vAppTemplateLeaseSettings") + public void testGetVAppTemplateLeaseSettings() { + vAppTemplateLeaseSettings = orgClient.getVAppTemplateLeaseSettings(orgRef.getURI()); + + Checks.checkVAppTemplateLeaseSettings(vAppTemplateLeaseSettings); + } + + @Test(testName = "PUT /admin/org/{id}/settings/vAppTemplateLeaseSettings", + dependsOnMethods = { "testGetVAppTemplateLeaseSettings" }, enabled = false) // FIXME: fails with 403 forbidden + public void testUpdateVAppTemplateLeaseSettings() { + boolean deleteOnStorageLeaseExpiration = vAppTemplateLeaseSettings.deleteOnStorageLeaseExpiration(); + Integer storageLeaseSeconds = vAppTemplateLeaseSettings.getStorageLeaseSeconds(); + + try { + vAppTemplateLeaseSettings = vAppTemplateLeaseSettings.toBuilder() + .deleteOnStorageLeaseExpiration(!deleteOnStorageLeaseExpiration) + .storageLeaseSeconds(storageLeaseSeconds+1) + .build(); + + vAppTemplateLeaseSettings = orgClient.updateVAppTemplateLeaseSettings( + orgRef.getURI(), vAppTemplateLeaseSettings); + + assertTrue(equal(vAppTemplateLeaseSettings.deleteOnStorageLeaseExpiration(), !deleteOnStorageLeaseExpiration), + String.format(OBJ_FIELD_UPDATABLE, + "vAppTemplateLeaseSettings", "deleteOnStorageLeaseExpiration")); + assertTrue(equal(vAppTemplateLeaseSettings.getStorageLeaseSeconds(), storageLeaseSeconds+1), + String.format(OBJ_FIELD_UPDATABLE, + "vAppTemplateLeaseSettings", "storageLeaseSeconds")); + + //TODO negative tests? + + Checks.checkVAppTemplateLeaseSettings(vAppTemplateLeaseSettings); + } finally { + vAppTemplateLeaseSettings = vAppTemplateLeaseSettings.toBuilder() + .deleteOnStorageLeaseExpiration(deleteOnStorageLeaseExpiration) + .storageLeaseSeconds(storageLeaseSeconds) + .build(); + + vAppTemplateLeaseSettings = orgClient.updateVAppTemplateLeaseSettings( + orgRef.getURI(), vAppTemplateLeaseSettings); + } + } } diff --git a/labs/vcloud-director/src/test/resources/org/admin/updateVAppLeaseSettings.xml b/labs/vcloud-director/src/test/resources/org/admin/updateVAppLeaseSettings.xml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/labs/vcloud-director/src/test/resources/org/admin/updateVAppLeaseSettingsSource.xml b/labs/vcloud-director/src/test/resources/org/admin/updateVAppLeaseSettingsSource.xml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/labs/vcloud-director/src/test/resources/org/admin/vAppLeaseSettings.xml b/labs/vcloud-director/src/test/resources/org/admin/vAppLeaseSettings.xml new file mode 100644 index 0000000000..e69de29bb2 From d4843a5c3187eaafe7989e329fd5297f869df257 Mon Sep 17 00:00:00 2001 From: danikov Date: Sun, 11 Mar 2012 13:00:17 +0000 Subject: [PATCH 03/10] get/put vAppLeaseSettings --- .../v1_5/VCloudDirectorMediaType.java | 7 ++- .../v1_5/domain/OrgLeaseSettings.java | 4 +- .../v1_5/features/AdminOrgAsyncClient.java | 25 +++++++++ .../v1_5/features/AdminOrgClient.java | 26 ++++++++- .../features/AdminOrgClientExpectTest.java | 51 ++++++++++++++++- .../v1_5/features/AdminOrgClientLiveTest.java | 55 +++++++++++++++++-- 6 files changed, 155 insertions(+), 13 deletions(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java index 3ed614c2c0..05ae7f2421 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java @@ -137,6 +137,8 @@ public class VCloudDirectorMediaType { public static final String ORG_VAPP_TEMPLATE_LEASE_SETTINGS = "application/vnd.vmware.admin.vAppTemplateLeaseSettings+xml"; + public static final String ORG_LEASE_SETTINGS = "application/vnd.vmware.admin.vAppLeaseSettings+xml"; + /** * * All acceptable media types. @@ -155,8 +157,7 @@ public class VCloudDirectorMediaType { CONTROL_ACCESS, VAPP_TEMPLATE, CUSTOMIZATION_SECTION, GUEST_CUSTOMIZATION_SECTION, NETWORK_SECTION, NETWORK_CONFIG_SECTION, NETWORK_CONNECTION_SECTION, CLONE_MEDIA_PARAMS, LEASE_SETTINGS_SECTION, RELOCATE_TEMPLATE, ENVELOPE, - PUBLISH_CATALOG_PARAMS, GROUP, ORG_VAPP_TEMPLATE_LEASE_SETTINGS + PUBLISH_CATALOG_PARAMS, GROUP, ORG_VAPP_TEMPLATE_LEASE_SETTINGS, + ORG_LEASE_SETTINGS ); - - } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgLeaseSettings.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgLeaseSettings.java index 26e9ace80e..b6722e8d5d 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgLeaseSettings.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgLeaseSettings.java @@ -27,6 +27,7 @@ import java.util.Set; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; import com.google.common.base.Objects; @@ -60,7 +61,8 @@ import com.google.common.base.Objects.ToStringHelper; * */ @XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "OrgLeaseSettings", propOrder = { +@XmlRootElement(name = "VAppLeaseSettings") +@XmlType(propOrder = { "deleteOnStorageLeaseExpiration", "deploymentLeaseSeconds", "storageLeaseSeconds" diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java index c4fc90fec0..74c38465b2 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java @@ -33,6 +33,7 @@ import org.jclouds.rest.annotations.JAXBResponseParser; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.binders.BindToXMLPayload; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.jclouds.vcloud.director.v1_5.domain.OrgLeaseSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgVAppTemplateLeaseSettings; import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx; @@ -69,6 +70,30 @@ public interface AdminOrgAsyncClient extends OrgAsyncClient { // GET /admin/org/{id}/settings/passwordPolicy // PUT /admin/org/{id}/settings/passwordPolicy + + /** + * @see AdminOrgClient#getVAppLeaseSettings(URI) + */ + @GET + @Path("/settings/vAppLeaseSettings") + @Consumes + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture getVAppLeaseSettings( + @EndpointParam URI orgRef); + + /** + * @see AdminOrgClient#updateVAppLeaseSettings(URI, OrgVAppLeaseSettings) + */ + @PUT + @Path("/settings/vAppLeaseSettings") + @Consumes(VCloudDirectorMediaType.ORG_LEASE_SETTINGS) + @Produces(VCloudDirectorMediaType.ORG_LEASE_SETTINGS) + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture updateVAppLeaseSettings( + @EndpointParam URI orgRef, + @BinderParam(BindToXMLPayload.class) OrgLeaseSettings group); /** * @see AdminOrgClient#getVAppTemplateLeaseSettings(URI) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java index a1bf2d399c..fdb3f962da 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java @@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; import org.jclouds.vcloud.director.v1_5.domain.Group; +import org.jclouds.vcloud.director.v1_5.domain.OrgLeaseSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgVAppTemplateLeaseSettings; /** @@ -58,9 +59,30 @@ public interface AdminOrgClient extends OrgClient { // PUT /admin/org/{id}/settings/passwordPolicy -// GET /admin/org/{id}/settings/vAppLeaseSettings + /** + * Gets organization resource cleanup settings on the level of vApp. + * + *
+    * GET /admin/org/{id}/settings/vAppLeaseSettings
+    * 
+ * + * @param orgRef the reference for the admin org + * @return the lease settings + */ + OrgLeaseSettings getVAppLeaseSettings(URI orgRef); -// PUT /admin/org/{id}/settings/vAppLeaseSettings + /** + * Updates organization resource cleanup settings on the level of vApp. + * + *
+    * PUT /admin/org/{id}/settings/vAppLeaseSettings
+    * 
+ * @param orgRef the reference for the admin org + * @param newSettings the requested updated settings + * @return the resultant settings + */ + OrgLeaseSettings updateVAppLeaseSettings(URI orgRef, + OrgLeaseSettings newSettings); /** * Retrieves expiration and storage policy for vApp templates in an organization. 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 0554271b2a..44b37023d0 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 @@ -24,6 +24,7 @@ import java.net.URI; import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.jclouds.vcloud.director.v1_5.domain.OrgLeaseSettings; 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.internal.BaseVCloudDirectorRestClientExpectTest; @@ -67,9 +68,53 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect // PUT /admin/org/{id}/settings/passwordPolicy -// GET /admin/org/{id}/settings/vAppLeaseSettings - -// PUT /admin/org/{id}/settings/vAppLeaseSettings + @Test(enabled = false) + public void testGetVAppLeaseSettings() { + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("GET", "/admin/org/???/settings/vAppLeaseSettings") + .acceptAnyMedia() + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/org/admin/vAppLeaseSettings.xml", + VCloudDirectorMediaType.ORG_LEASE_SETTINGS) + .httpResponseBuilder().build()); + + OrgLeaseSettings expected = orgVAppLeaseSettings(); + + assertEquals(client.getAdminOrgClient().getVAppLeaseSettings(orgRef.getURI()), expected); + } + + public static final OrgLeaseSettings orgVAppLeaseSettings() { + return OrgLeaseSettings.builder() + + .build(); + } + + @Test(enabled = false) + public void testUpdateOrgVAppLeaseSettings() { + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("PUT", "/admin/org/???/settings/vAppLeaseSettings") + .xmlFilePayload("/org/admin/updateVAppLeaseSettingsSource.xml", + VCloudDirectorMediaType.ORG_LEASE_SETTINGS) + .acceptMedia(VCloudDirectorMediaType.ORG_LEASE_SETTINGS) + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/org/admin/updateVAppLeaseSettings.xml", + VCloudDirectorMediaType.ORG_LEASE_SETTINGS) + .httpResponseBuilder().build()); + + OrgLeaseSettings expected = updateOrgVAppLeaseSettings(); + + assertEquals(client.getAdminOrgClient().updateVAppLeaseSettings(orgRef.getURI(), expected), expected); + } + + public static final OrgLeaseSettings updateOrgVAppLeaseSettings() { + return orgVAppLeaseSettings().toBuilder() + + .build(); + } @Test(enabled = false) public void testGetVAppTemplateLeaseSettings() { diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java index b5105f4552..7e81d09ec6 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java @@ -24,6 +24,7 @@ import org.jclouds.vcloud.director.v1_5.domain.AdminOrg; import org.jclouds.vcloud.director.v1_5.domain.Error; import org.jclouds.vcloud.director.v1_5.domain.Group; import org.jclouds.vcloud.director.v1_5.domain.Checks; +import org.jclouds.vcloud.director.v1_5.domain.OrgLeaseSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgVAppTemplateLeaseSettings; import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest; @@ -54,6 +55,7 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { private ReferenceType orgRef; private AdminOrg org; OrgVAppTemplateLeaseSettings vAppTemplateLeaseSettings; + OrgLeaseSettings vAppLeaseSettings; @Override @BeforeClass(inheritGroups = true) @@ -86,10 +88,55 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { // GET /admin/org/{id}/settings/passwordPolicy // PUT /admin/org/{id}/settings/passwordPolicy - -// GET /admin/org/{id}/settings/vAppLeaseSettings - -// PUT /admin/org/{id}/settings/vAppLeaseSettings + + @Test(testName = "GET /admin/org/{id}/settings/vAppLeaseSettings") + public void testGetVAppLeaseSettings() { + vAppLeaseSettings = orgClient.getVAppLeaseSettings(orgRef.getURI()); + + Checks.checkVAppLeaseSettings(vAppLeaseSettings); + } + + @Test(testName = "PUT /admin/org/{id}/settings/vAppLeaseSettings", + dependsOnMethods = { "testGetVAppLeaseSettings" }, enabled = false) // FIXME: fails with 403 forbidden + public void testUpdateVAppLeaseSettings() { + boolean deleteOnStorageLeaseExpiration = vAppLeaseSettings.deleteOnStorageLeaseExpiration(); + Integer storageLeaseSeconds = vAppLeaseSettings.getStorageLeaseSeconds(); + Integer deploymentLeaseSeconds = vAppLeaseSettings.getDeploymentLeaseSeconds(); + + try { + vAppLeaseSettings = vAppLeaseSettings.toBuilder() + .deleteOnStorageLeaseExpiration(!deleteOnStorageLeaseExpiration) + .storageLeaseSeconds(storageLeaseSeconds+1) + .deploymentLeaseSeconds(deploymentLeaseSeconds+1) + .build(); + + vAppLeaseSettings = orgClient.updateVAppLeaseSettings( + orgRef.getURI(), vAppLeaseSettings); + + assertTrue(equal(vAppLeaseSettings.deleteOnStorageLeaseExpiration(), !deleteOnStorageLeaseExpiration), + String.format(OBJ_FIELD_UPDATABLE, + "vAppLeaseSettings", "deleteOnStorageLeaseExpiration")); + assertTrue(equal(vAppLeaseSettings.getStorageLeaseSeconds(), storageLeaseSeconds+1), + String.format(OBJ_FIELD_UPDATABLE, + "vAppLeaseSettings", "storageLeaseSeconds")); + assertTrue(equal(vAppLeaseSettings.getDeploymentLeaseSeconds(), deploymentLeaseSeconds+1), + String.format(OBJ_FIELD_UPDATABLE, + "vAppLeaseSettings", "deploymentLeaseSeconds")); + + //TODO negative tests? + + Checks.checkVAppLeaseSettings(vAppLeaseSettings); + } finally { + vAppLeaseSettings = vAppLeaseSettings.toBuilder() + .deleteOnStorageLeaseExpiration(deleteOnStorageLeaseExpiration) + .storageLeaseSeconds(storageLeaseSeconds) + .deploymentLeaseSeconds(deploymentLeaseSeconds) + .build(); + + vAppLeaseSettings = orgClient.updateVAppLeaseSettings( + orgRef.getURI(), vAppLeaseSettings); + } + } @Test(testName = "GET /admin/org/{id}/settings/vAppTemplateLeaseSettings") public void testGetVAppTemplateLeaseSettings() { From 969141a7ebfc3d0f43c4847da10832888e27a4f8 Mon Sep 17 00:00:00 2001 From: danikov Date: Sun, 11 Mar 2012 13:25:25 +0000 Subject: [PATCH 04/10] get/put passwordPolicy --- .../v1_5/VCloudDirectorMediaType.java | 4 +- .../v1_5/features/AdminOrgAsyncClient.java | 31 +++++++-- .../v1_5/features/AdminOrgClient.java | 26 ++++++- .../features/AdminOrgClientExpectTest.java | 67 +++++++++++++++++-- .../v1_5/features/AdminOrgClientLiveTest.java | 55 +++++++++++++-- .../resources/org/admin/passwordPolicy.xml | 7 ++ .../org/admin/updatePasswordPolicy.xml | 7 ++ .../org/admin/updatePasswordPolicySource.xml | 7 ++ 8 files changed, 187 insertions(+), 17 deletions(-) create mode 100644 labs/vcloud-director/src/test/resources/org/admin/passwordPolicy.xml create mode 100644 labs/vcloud-director/src/test/resources/org/admin/updatePasswordPolicy.xml create mode 100644 labs/vcloud-director/src/test/resources/org/admin/updatePasswordPolicySource.xml diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java index 05ae7f2421..64b187d015 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java @@ -139,6 +139,8 @@ public class VCloudDirectorMediaType { public static final String ORG_LEASE_SETTINGS = "application/vnd.vmware.admin.vAppLeaseSettings+xml"; + public static final String ORG_PASSWORD_POLICY_SETTINGS = "application/vnd.vmware.admin.organizationPasswordPolicySettings+xml"; + /** * * All acceptable media types. @@ -158,6 +160,6 @@ public class VCloudDirectorMediaType { NETWORK_SECTION, NETWORK_CONFIG_SECTION, NETWORK_CONNECTION_SECTION, CLONE_MEDIA_PARAMS, LEASE_SETTINGS_SECTION, RELOCATE_TEMPLATE, ENVELOPE, PUBLISH_CATALOG_PARAMS, GROUP, ORG_VAPP_TEMPLATE_LEASE_SETTINGS, - ORG_LEASE_SETTINGS + ORG_LEASE_SETTINGS, ORG_PASSWORD_POLICY_SETTINGS ); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java index 74c38465b2..063c23f639 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java @@ -34,6 +34,7 @@ import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.binders.BindToXMLPayload; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; import org.jclouds.vcloud.director.v1_5.domain.OrgLeaseSettings; +import org.jclouds.vcloud.director.v1_5.domain.OrgPasswordPolicySettings; import org.jclouds.vcloud.director.v1_5.domain.OrgVAppTemplateLeaseSettings; import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx; @@ -67,9 +68,29 @@ public interface AdminOrgAsyncClient extends OrgAsyncClient { // GET /admin/org/{id}/settings/ldap -// GET /admin/org/{id}/settings/passwordPolicy - -// PUT /admin/org/{id}/settings/passwordPolicy + /** + * @see AdminOrgClient#getPasswordPolicy(URI) + */ + @GET + @Path("/settings/passwordPolicy") + @Consumes + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture getPasswordPolicy( + @EndpointParam URI orgRef); + + /** + * @see AdminOrgClient#updatePasswordPolicy(URI, OrgPasswordPolicySettings) + */ + @PUT + @Path("/settings/passwordPolicy") + @Consumes(VCloudDirectorMediaType.ORG_PASSWORD_POLICY_SETTINGS) + @Produces(VCloudDirectorMediaType.ORG_PASSWORD_POLICY_SETTINGS) + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture updatePasswordPolicy( + @EndpointParam URI orgRef, + @BinderParam(BindToXMLPayload.class) OrgPasswordPolicySettings settings); /** * @see AdminOrgClient#getVAppLeaseSettings(URI) @@ -93,7 +114,7 @@ public interface AdminOrgAsyncClient extends OrgAsyncClient { @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture updateVAppLeaseSettings( @EndpointParam URI orgRef, - @BinderParam(BindToXMLPayload.class) OrgLeaseSettings group); + @BinderParam(BindToXMLPayload.class) OrgLeaseSettings settings); /** * @see AdminOrgClient#getVAppTemplateLeaseSettings(URI) @@ -117,6 +138,6 @@ public interface AdminOrgAsyncClient extends OrgAsyncClient { @ExceptionParser(ThrowVCloudErrorOn4xx.class) ListenableFuture updateVAppTemplateLeaseSettings( @EndpointParam URI orgRef, - @BinderParam(BindToXMLPayload.class) OrgVAppTemplateLeaseSettings group); + @BinderParam(BindToXMLPayload.class) OrgVAppTemplateLeaseSettings settings); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java index fdb3f962da..2b86054340 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java @@ -24,6 +24,7 @@ import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; import org.jclouds.vcloud.director.v1_5.domain.Group; import org.jclouds.vcloud.director.v1_5.domain.OrgLeaseSettings; +import org.jclouds.vcloud.director.v1_5.domain.OrgPasswordPolicySettings; import org.jclouds.vcloud.director.v1_5.domain.OrgVAppTemplateLeaseSettings; /** @@ -55,9 +56,30 @@ public interface AdminOrgClient extends OrgClient { // GET /admin/org/{id}/settings/ldap -// GET /admin/org/{id}/settings/passwordPolicy + /** + * Retrieves password policy settings for an organization. + * + *
+    * GET /admin/org/{id}/settings/passwordPolicy
+    * 
+ * + * @param orgRef the reference for the admin org + * @return the lease settings + */ + OrgPasswordPolicySettings getPasswordPolicy(URI orgRef); -// PUT /admin/org/{id}/settings/passwordPolicy + /** + * Updates password policy settings for organization. + * + *
+    * PUT /admin/org/{id}/settings/passwordPolicy
+    * 
+ * @param orgRef the reference for the admin org + * @param newSettings the requested updated settings + * @return the resultant settings + */ + OrgPasswordPolicySettings updatePasswordPolicy(URI orgRef, + OrgPasswordPolicySettings newSettings); /** * Gets organization resource cleanup settings on the level of vApp. 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 44b37023d0..b177892512 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 @@ -24,7 +24,9 @@ import java.net.URI; import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.jclouds.vcloud.director.v1_5.domain.Link; import org.jclouds.vcloud.director.v1_5.domain.OrgLeaseSettings; +import org.jclouds.vcloud.director.v1_5.domain.OrgPasswordPolicySettings; 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.internal.BaseVCloudDirectorRestClientExpectTest; @@ -39,9 +41,9 @@ import org.testng.annotations.Test; public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { private Reference orgRef = Reference.builder() - .type("application/vnd.vmware.admin.???+xml") +// .type("application/vnd.vmware.admin.???+xml") .name("???") - .href(URI.create(endpoint + "/admin/org/???")) + .href(URI.create(endpoint + "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) .build(); // GET /admin/org/{id} @@ -64,9 +66,64 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect // GET /admin/org/{id}/settings/ldap -// GET /admin/org/{id}/settings/passwordPolicy - -// PUT /admin/org/{id}/settings/passwordPolicy + @Test + public void testGetPasswordPolicy() { + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("GET", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/passwordPolicy") + .acceptAnyMedia() + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/org/admin/passwordPolicy.xml", + VCloudDirectorMediaType.ORG_PASSWORD_POLICY_SETTINGS) + .httpResponseBuilder().build()); + + OrgPasswordPolicySettings expected = orgPasswordPolicy(); + + assertEquals(client.getAdminOrgClient().getPasswordPolicy(orgRef.getURI()), expected); + } + + public static final OrgPasswordPolicySettings orgPasswordPolicy() { + return OrgPasswordPolicySettings.builder() + .type("application/vnd.vmware.admin.organizationPasswordPolicySettings+xml") + .link(Link.builder() + .rel("edit") + .type("application/vnd.vmware.admin.organizationPasswordPolicySettings+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/passwordPolicy")) + .build()) + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/passwordPolicy")) + .accountLockoutEnabled(false) + .invalidLoginsBeforeLockout(5) + .accountLockoutIntervalMinutes(10) + .build(); + } + + @Test + public void testUpdateOrgPasswordPolicy() { + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("PUT", "/admin/org/???/settings/passwordPolicy") + .xmlFilePayload("/org/admin/updatePasswordPolicySource.xml", + VCloudDirectorMediaType.ORG_PASSWORD_POLICY_SETTINGS) + .acceptMedia(VCloudDirectorMediaType.ORG_PASSWORD_POLICY_SETTINGS) + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/org/admin/updatePasswordPolicy.xml", + VCloudDirectorMediaType.ORG_PASSWORD_POLICY_SETTINGS) + .httpResponseBuilder().build()); + + OrgPasswordPolicySettings expected = updateOrgPasswordPolicy(); + + assertEquals(client.getAdminOrgClient().updatePasswordPolicy(orgRef.getURI(), expected), expected); + } + + public static final OrgPasswordPolicySettings updateOrgPasswordPolicy() { + return orgPasswordPolicy().toBuilder() + .accountLockoutEnabled(true) + .invalidLoginsBeforeLockout(6) + .accountLockoutIntervalMinutes(11) + .build(); + } @Test(enabled = false) public void testGetVAppLeaseSettings() { diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java index 7e81d09ec6..bcb7913871 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java @@ -25,6 +25,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Error; import org.jclouds.vcloud.director.v1_5.domain.Group; import org.jclouds.vcloud.director.v1_5.domain.Checks; import org.jclouds.vcloud.director.v1_5.domain.OrgLeaseSettings; +import org.jclouds.vcloud.director.v1_5.domain.OrgPasswordPolicySettings; import org.jclouds.vcloud.director.v1_5.domain.OrgVAppTemplateLeaseSettings; import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest; @@ -54,8 +55,9 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { */ private ReferenceType orgRef; private AdminOrg org; - OrgVAppTemplateLeaseSettings vAppTemplateLeaseSettings; + OrgPasswordPolicySettings passwordPolicy; OrgLeaseSettings vAppLeaseSettings; + OrgVAppTemplateLeaseSettings vAppTemplateLeaseSettings; @Override @BeforeClass(inheritGroups = true) @@ -85,9 +87,54 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { // GET /admin/org/{id}/settings/ldap -// GET /admin/org/{id}/settings/passwordPolicy - -// PUT /admin/org/{id}/settings/passwordPolicy + @Test(testName = "GET /admin/org/{id}/settings/passwordPolicy") + public void testGetPasswordPolicy() { + passwordPolicy = orgClient.getPasswordPolicy(orgRef.getURI()); + + Checks.checkPasswordPolicySettings(passwordPolicy); + } + + @Test(testName = "PUT /admin/org/{id}/settings/passwordPolicy", + dependsOnMethods = { "testGetPasswordPolicy" }) + public void testUpdatePasswordPolicy() { + boolean accountLockoutEnabled = passwordPolicy.isAccountLockoutEnabled(); + Integer invalidLoginsBeforeLockout = passwordPolicy.getInvalidLoginsBeforeLockout(); + Integer accountLockoutIntervalMinutes = passwordPolicy.getAccountLockoutIntervalMinutes(); + + try { + passwordPolicy = passwordPolicy.toBuilder() + .accountLockoutEnabled(!accountLockoutEnabled) + .invalidLoginsBeforeLockout(invalidLoginsBeforeLockout+1) + .accountLockoutIntervalMinutes(accountLockoutIntervalMinutes+1) + .build(); + + passwordPolicy = orgClient.updatePasswordPolicy( + orgRef.getURI(), passwordPolicy); + + assertTrue(equal(passwordPolicy.isAccountLockoutEnabled(), !accountLockoutEnabled), + String.format(OBJ_FIELD_UPDATABLE, + "PasswordPolicySettings", "deleteOnStorageLeaseExpiration")); + assertTrue(equal(passwordPolicy.getInvalidLoginsBeforeLockout(), invalidLoginsBeforeLockout+1), + String.format(OBJ_FIELD_UPDATABLE, + "PasswordPolicySettings", "storageLeaseSeconds")); + assertTrue(equal(passwordPolicy.getAccountLockoutIntervalMinutes(), accountLockoutIntervalMinutes+1), + String.format(OBJ_FIELD_UPDATABLE, + "PasswordPolicySettings", "deploymentLeaseSeconds")); + + //TODO negative tests? + + Checks.checkPasswordPolicySettings(passwordPolicy); + } finally { + passwordPolicy = passwordPolicy.toBuilder() + .accountLockoutEnabled(accountLockoutEnabled) + .invalidLoginsBeforeLockout(invalidLoginsBeforeLockout) + .accountLockoutIntervalMinutes(accountLockoutIntervalMinutes) + .build(); + + passwordPolicy = orgClient.updatePasswordPolicy( + orgRef.getURI(), passwordPolicy); + } + } @Test(testName = "GET /admin/org/{id}/settings/vAppLeaseSettings") public void testGetVAppLeaseSettings() { diff --git a/labs/vcloud-director/src/test/resources/org/admin/passwordPolicy.xml b/labs/vcloud-director/src/test/resources/org/admin/passwordPolicy.xml new file mode 100644 index 0000000000..e48f20fbfd --- /dev/null +++ b/labs/vcloud-director/src/test/resources/org/admin/passwordPolicy.xml @@ -0,0 +1,7 @@ + + + + false + 5 + 10 + \ No newline at end of file diff --git a/labs/vcloud-director/src/test/resources/org/admin/updatePasswordPolicy.xml b/labs/vcloud-director/src/test/resources/org/admin/updatePasswordPolicy.xml new file mode 100644 index 0000000000..da245c8361 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/org/admin/updatePasswordPolicy.xml @@ -0,0 +1,7 @@ + + + + true + 6 + 11 + \ No newline at end of file diff --git a/labs/vcloud-director/src/test/resources/org/admin/updatePasswordPolicySource.xml b/labs/vcloud-director/src/test/resources/org/admin/updatePasswordPolicySource.xml new file mode 100644 index 0000000000..706ac57a85 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/org/admin/updatePasswordPolicySource.xml @@ -0,0 +1,7 @@ + + + + true + 6 + 11 + \ No newline at end of file From 709c7bff63e80fc1176bf8b8fe86b239a0e6fe05 Mon Sep 17 00:00:00 2001 From: danikov Date: Sun, 11 Mar 2012 13:40:30 +0000 Subject: [PATCH 05/10] get ldapSettings --- .../v1_5/VCloudDirectorMediaType.java | 4 +- .../v1_5/domain/CustomOrgLdapSettings.java | 2 +- .../director/v1_5/domain/OrgLdapSettings.java | 42 ++++++++++--------- .../v1_5/features/AdminOrgAsyncClient.java | 13 +++++- .../v1_5/features/AdminOrgClient.java | 13 ++++++ .../vcloud/director/v1_5/domain/Checks.java | 6 +-- .../features/AdminOrgClientExpectTest.java | 26 +++++++++++- .../v1_5/features/AdminOrgClientLiveTest.java | 8 +++- .../test/resources/org/admin/ldapSettings.xml | 4 ++ 9 files changed, 89 insertions(+), 29 deletions(-) create mode 100644 labs/vcloud-director/src/test/resources/org/admin/ldapSettings.xml diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java index 64b187d015..84ac301472 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java @@ -141,6 +141,8 @@ public class VCloudDirectorMediaType { public static final String ORG_PASSWORD_POLICY_SETTINGS = "application/vnd.vmware.admin.organizationPasswordPolicySettings+xml"; + public static final String ORG_LDAP_SETTINGS = "application/vnd.vmware.admin.organizationLdapSettings+xml"; + /** * * All acceptable media types. @@ -160,6 +162,6 @@ public class VCloudDirectorMediaType { NETWORK_SECTION, NETWORK_CONFIG_SECTION, NETWORK_CONNECTION_SECTION, CLONE_MEDIA_PARAMS, LEASE_SETTINGS_SECTION, RELOCATE_TEMPLATE, ENVELOPE, PUBLISH_CATALOG_PARAMS, GROUP, ORG_VAPP_TEMPLATE_LEASE_SETTINGS, - ORG_LEASE_SETTINGS, ORG_PASSWORD_POLICY_SETTINGS + ORG_LEASE_SETTINGS, ORG_PASSWORD_POLICY_SETTINGS, ORG_LDAP_SETTINGS ); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CustomOrgLdapSettings.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CustomOrgLdapSettings.java index 47a8f13782..aa3b75d18e 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CustomOrgLdapSettings.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CustomOrgLdapSettings.java @@ -110,7 +110,7 @@ public class CustomOrgLdapSettings { public static final String OPEN_LDAP = "OPEN_LDAP"; /** - * All acceptable {@link OrgLdapSettings#getOrgLdapMode()} values. + * All acceptable {@link OrgLdapSettings#getLdapMode()} values. *

* This list must be updated whenever a new mode is added. */ diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgLdapSettings.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgLdapSettings.java index fa5eca660c..e239eba6df 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgLdapSettings.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgLdapSettings.java @@ -29,6 +29,7 @@ import java.util.Set; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; import com.google.common.base.Objects; @@ -62,19 +63,20 @@ import com.google.common.base.Objects.ToStringHelper; * */ @XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "OrgLdapSettings", propOrder = { - "orgLdapMode", +@XmlRootElement(name = "OrgLdapSettings") +@XmlType(propOrder = { + "ldapMode", "customUsersOu", "customOrgLdapSettings" }) public class OrgLdapSettings extends ResourceType { public static final class LdapMode { - public static final String NONE = "none"; - public static final String SYSTEM = "system"; - public static final String CUSTOM = "custom"; + public static final String NONE = "NONE"; + public static final String SYSTEM = "SYSTEM"; + public static final String CUSTOM = "CUSTOM"; /** - * All acceptable {@link OrgLdapSettings#getOrgLdapMode()} values. + * All acceptable {@link OrgLdapSettings#getLdapMode()} values. *

* This list must be updated whenever a new mode is added. */ @@ -93,15 +95,15 @@ public class OrgLdapSettings extends ResourceType { public static class Builder extends ResourceType.Builder { - private String orgLdapMode; + private String ldapMode; private String customUsersOu; private CustomOrgLdapSettings customOrgLdapSettings; /** - * @see OrgLdapSettings#getOrgLdapMode() + * @see OrgLdapSettings#getLdapMode() */ - public Builder orgLdapMode(String orgLdapMode) { - this.orgLdapMode = orgLdapMode; + public Builder ldapMode(String ldapMode) { + this.ldapMode = ldapMode; return this; } @@ -123,7 +125,7 @@ public class OrgLdapSettings extends ResourceType { public OrgLdapSettings build() { OrgLdapSettings orgLdapSettings = new OrgLdapSettings(href, type, links, - orgLdapMode, customUsersOu, customOrgLdapSettings); + ldapMode, customUsersOu, customOrgLdapSettings); return orgLdapSettings; } @@ -171,7 +173,7 @@ public class OrgLdapSettings extends ResourceType { } public Builder fromOrgLdapSettings(OrgLdapSettings in) { return fromResourceType(in) - .orgLdapMode(in.getOrgLdapMode()) + .ldapMode(in.getLdapMode()) .customUsersOu(in.getCustomUsersOu()) .customOrgLdapSettings(in.getCustomOrgLdapSettings()); } @@ -183,9 +185,9 @@ public class OrgLdapSettings extends ResourceType { } public OrgLdapSettings(URI href, String type, Set links, - String orgLdapMode, String customUsersOu, CustomOrgLdapSettings customOrgLdapSettings) { + String ldapMode, String customUsersOu, CustomOrgLdapSettings customOrgLdapSettings) { super(href, type, links); - this.orgLdapMode = orgLdapMode; + this.ldapMode = ldapMode; this.customUsersOu = customUsersOu; this.customOrgLdapSettings = customOrgLdapSettings; } @@ -193,7 +195,7 @@ public class OrgLdapSettings extends ResourceType { @XmlElement(name = "OrgLdapMode") - protected String orgLdapMode; + protected String ldapMode; @XmlElement(name = "CustomUsersOu") protected String customUsersOu; @XmlElement(name = "CustomOrgLdapSettings") @@ -207,8 +209,8 @@ public class OrgLdapSettings extends ResourceType { * {@link String } * */ - public String getOrgLdapMode() { - return orgLdapMode; + public String getLdapMode() { + return ldapMode; } /** @@ -243,7 +245,7 @@ public class OrgLdapSettings extends ResourceType { return false; OrgLdapSettings that = OrgLdapSettings.class.cast(o); return super.equals(that) && - equal(orgLdapMode, that.orgLdapMode) && + equal(ldapMode, that.ldapMode) && equal(customUsersOu, that.customUsersOu) && equal(customOrgLdapSettings, that.customOrgLdapSettings); } @@ -251,7 +253,7 @@ public class OrgLdapSettings extends ResourceType { @Override public int hashCode() { return Objects.hashCode(super.hashCode(), - orgLdapMode, + ldapMode, customUsersOu, customOrgLdapSettings); } @@ -259,7 +261,7 @@ public class OrgLdapSettings extends ResourceType { @Override public ToStringHelper string() { return super.string() - .add("orgLdapMode", orgLdapMode) + .add("orgLdapMode", ldapMode) .add("customUsersOu", customUsersOu) .add("customOrgLdapSettings", customOrgLdapSettings); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java index 063c23f639..57987184ef 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java @@ -33,6 +33,7 @@ import org.jclouds.rest.annotations.JAXBResponseParser; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.binders.BindToXMLPayload; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.jclouds.vcloud.director.v1_5.domain.OrgLdapSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgLeaseSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgPasswordPolicySettings; import org.jclouds.vcloud.director.v1_5.domain.OrgVAppTemplateLeaseSettings; @@ -65,8 +66,16 @@ public interface AdminOrgAsyncClient extends OrgAsyncClient { // GET /admin/org/{id}/settings/general // PUT /admin/org/{id}/settings/general - -// GET /admin/org/{id}/settings/ldap + + /** + * @see AdminOrgClient#getPasswordPolicy(URI) + */ + @GET + @Path("/settings/ldap") + @Consumes + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture getLdapSettings(@EndpointParam URI orgRef); /** * @see AdminOrgClient#getPasswordPolicy(URI) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java index 2b86054340..a54eb7cc6e 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java @@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; import org.jclouds.vcloud.director.v1_5.domain.Group; +import org.jclouds.vcloud.director.v1_5.domain.OrgLdapSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgLeaseSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgPasswordPolicySettings; import org.jclouds.vcloud.director.v1_5.domain.OrgVAppTemplateLeaseSettings; @@ -56,6 +57,18 @@ public interface AdminOrgClient extends OrgClient { // GET /admin/org/{id}/settings/ldap + /** + * Retrieves LDAP settings for an organization. + * + *

+    * GET /admin/org/{id}/settings/ldap
+    * 
+ * + * @param orgRef the reference for the admin org + * @return the ldap settings + */ + OrgLdapSettings getLdapSettings(URI orgRef); + /** * Retrieves password policy settings for an organization. * diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java index 4654241f5d..a167a88264 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java @@ -598,9 +598,9 @@ public class Checks { public static void checkLdapSettings(OrgLdapSettings settings) { // Check optional fields // NOTE customUsersOu cannot be checked - if (settings.getOrgLdapMode() != null) { - assertTrue(LdapMode.ALL.contains(settings.getOrgLdapMode()), String.format(REQUIRED_VALUE_OBJECT_FMT, - "LdapMode", "OrdLdapSettings", settings.getOrgLdapMode(), Iterables.toString(OrgLdapSettings.LdapMode.ALL))); + if (settings.getLdapMode() != null) { + assertTrue(LdapMode.ALL.contains(settings.getLdapMode()), String.format(REQUIRED_VALUE_OBJECT_FMT, + "LdapMode", "OrdLdapSettings", settings.getLdapMode(), Iterables.toString(OrgLdapSettings.LdapMode.ALL))); } if (settings.getCustomOrgLdapSettings() != null) { checkCustomOrgLdapSettings(settings.getCustomOrgLdapSettings()); 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 b177892512..3db97dfc8f 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 @@ -25,6 +25,7 @@ import java.net.URI; import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; import org.jclouds.vcloud.director.v1_5.domain.Link; +import org.jclouds.vcloud.director.v1_5.domain.OrgLdapSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgLeaseSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgPasswordPolicySettings; import org.jclouds.vcloud.director.v1_5.domain.OrgVAppTemplateLeaseSettings; @@ -64,7 +65,30 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect // PUT /admin/org/{id}/settings/general -// GET /admin/org/{id}/settings/ldap + @Test + public void testGetLdapSettings() { + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("GET", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/ldap") + .acceptAnyMedia() + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/org/admin/ldapSettings.xml", + VCloudDirectorMediaType.ORG_LDAP_SETTINGS) + .httpResponseBuilder().build()); + + OrgLdapSettings expected = ldapSettings(); + + assertEquals(client.getAdminOrgClient().getLdapSettings(orgRef.getURI()), expected); + } + + public static final OrgLdapSettings ldapSettings() { + return OrgLdapSettings.builder() + .type("application/vnd.vmware.admin.organizationLdapSettings+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/ldap")) + .ldapMode("NONE") + .build(); + } @Test public void testGetPasswordPolicy() { diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java index bcb7913871..5a0bd45cb8 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java @@ -24,6 +24,7 @@ import org.jclouds.vcloud.director.v1_5.domain.AdminOrg; import org.jclouds.vcloud.director.v1_5.domain.Error; import org.jclouds.vcloud.director.v1_5.domain.Group; import org.jclouds.vcloud.director.v1_5.domain.Checks; +import org.jclouds.vcloud.director.v1_5.domain.OrgLdapSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgLeaseSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgPasswordPolicySettings; import org.jclouds.vcloud.director.v1_5.domain.OrgVAppTemplateLeaseSettings; @@ -85,7 +86,12 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { // PUT /admin/org/{id}/settings/general -// GET /admin/org/{id}/settings/ldap + @Test(testName = "GET /admin/org/{id}/settings/ldap") + public void getLdapSettings() { + OrgLdapSettings ldapSettings = orgClient.getLdapSettings(orgRef.getURI()); + + Checks.checkLdapSettings(ldapSettings); + } @Test(testName = "GET /admin/org/{id}/settings/passwordPolicy") public void testGetPasswordPolicy() { diff --git a/labs/vcloud-director/src/test/resources/org/admin/ldapSettings.xml b/labs/vcloud-director/src/test/resources/org/admin/ldapSettings.xml new file mode 100644 index 0000000000..4e13f0d9ae --- /dev/null +++ b/labs/vcloud-director/src/test/resources/org/admin/ldapSettings.xml @@ -0,0 +1,4 @@ + + + NONE + \ No newline at end of file From 8e5ec325ae26fae08d25d12b2d0c386c5b076301 Mon Sep 17 00:00:00 2001 From: danikov Date: Sun, 11 Mar 2012 15:02:09 +0000 Subject: [PATCH 06/10] get/put generalSettings --- .../v1_5/VCloudDirectorMediaType.java | 5 +- .../v1_5/domain/OrgGeneralSettings.java | 2 +- .../v1_5/features/AdminOrgAsyncClient.java | 27 +++++++- .../v1_5/features/AdminOrgClient.java | 28 ++++++-- .../vcloud/director/v1_5/domain/Checks.java | 4 +- .../features/AdminOrgClientExpectTest.java | 51 ++++++++++++++- .../v1_5/features/AdminOrgClientLiveTest.java | 65 ++++++++++++++++++- 7 files changed, 165 insertions(+), 17 deletions(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java index 84ac301472..28059c86a7 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java @@ -143,6 +143,8 @@ public class VCloudDirectorMediaType { public static final String ORG_LDAP_SETTINGS = "application/vnd.vmware.admin.organizationLdapSettings+xml"; + public static final String ORG_GENERAL_SETTINGS = "application/vnd.vmware.admin.organizationGeneralSettings+xml"; + /** * * All acceptable media types. @@ -162,6 +164,7 @@ public class VCloudDirectorMediaType { NETWORK_SECTION, NETWORK_CONFIG_SECTION, NETWORK_CONNECTION_SECTION, CLONE_MEDIA_PARAMS, LEASE_SETTINGS_SECTION, RELOCATE_TEMPLATE, ENVELOPE, PUBLISH_CATALOG_PARAMS, GROUP, ORG_VAPP_TEMPLATE_LEASE_SETTINGS, - ORG_LEASE_SETTINGS, ORG_PASSWORD_POLICY_SETTINGS, ORG_LDAP_SETTINGS + ORG_LEASE_SETTINGS, ORG_PASSWORD_POLICY_SETTINGS, ORG_LDAP_SETTINGS, + ORG_GENERAL_SETTINGS ); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgGeneralSettings.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgGeneralSettings.java index 67eec98430..9557a8bcd6 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgGeneralSettings.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgGeneralSettings.java @@ -63,7 +63,7 @@ import com.google.common.base.Objects.ToStringHelper; * */ @XmlAccessorType(XmlAccessType.FIELD) -@XmlRootElement(name = "OrgGeneralSettings") +@XmlRootElement(name = "GeneralOrgSettings") @XmlType(propOrder = { "canPublishCatalogs", "deployedVMQuota", diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java index 57987184ef..c25497e3bc 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java @@ -33,6 +33,7 @@ import org.jclouds.rest.annotations.JAXBResponseParser; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.binders.BindToXMLPayload; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.jclouds.vcloud.director.v1_5.domain.OrgGeneralSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgLdapSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgLeaseSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgPasswordPolicySettings; @@ -63,9 +64,29 @@ public interface AdminOrgAsyncClient extends OrgAsyncClient { // PUT /admin/org/{id}/settings/email -// GET /admin/org/{id}/settings/general - -// PUT /admin/org/{id}/settings/general + /** + * @see AdminOrgClient#getGeneralSettings(URI) + */ + @GET + @Path("/settings/general") + @Consumes + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture getGeneralSettings( + @EndpointParam URI orgRef); + + /** + * @see AdminOrgClient#updateGeneralSettings(URI, OrgGeneralSettings) + */ + @PUT + @Path("/settings/general") + @Consumes(VCloudDirectorMediaType.ORG_GENERAL_SETTINGS) + @Produces(VCloudDirectorMediaType.ORG_GENERAL_SETTINGS) + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture updateGeneralSettings( + @EndpointParam URI orgRef, + @BinderParam(BindToXMLPayload.class) OrgGeneralSettings settings); /** * @see AdminOrgClient#getPasswordPolicy(URI) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java index a54eb7cc6e..2c5c9c86d0 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java @@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; import org.jclouds.vcloud.director.v1_5.domain.Group; +import org.jclouds.vcloud.director.v1_5.domain.OrgGeneralSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgLdapSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgLeaseSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgPasswordPolicySettings; @@ -51,11 +52,30 @@ public interface AdminOrgClient extends OrgClient { // PUT /admin/org/{id}/settings/email -// GET /admin/org/{id}/settings/general + /** + * Gets general organization settings. + * + *
+    * GET /admin/org/{id}/settings/general
+    * 
+ * + * @param orgRef the reference for the admin org + * @return the lease settings + */ + OrgGeneralSettings getGeneralSettings(URI orgRef); -// PUT /admin/org/{id}/settings/general - -// GET /admin/org/{id}/settings/ldap + /** + * Updates general organization settings. + * + *
+    * PUT /admin/org/{id}/settings/general
+    * 
+ * @param orgRef the reference for the admin org + * @param newSettings the requested updated settings + * @return the resultant settings + */ + OrgGeneralSettings updateGeneralSettings(URI orgRef, + OrgGeneralSettings newSettings); /** * Retrieves LDAP settings for an organization. diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java index a167a88264..c6f07b3735 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java @@ -531,7 +531,7 @@ public class Checks { public static void checkOrgSetting(OrgSettings settings) { // Check optional fields if (settings.getOrgGeneralSettings() != null) { - checkOrgGeneralSettings(settings.getOrgGeneralSettings()); + checkGeneralSettings(settings.getOrgGeneralSettings()); } if (settings.getVAppLeaseSettings() != null) { checkVAppLeaseSettings(settings.getVAppLeaseSettings()); @@ -574,7 +574,7 @@ public class Checks { // TODO: validate email addresses } - public static void checkOrgGeneralSettings(OrgGeneralSettings settings) { + public static void checkGeneralSettings(OrgGeneralSettings settings) { // Check optional fields // NOTE canPublishCatalogs cannot be checked // NOTE useServerBootSequence cannot be checked 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 3db97dfc8f..17350e13a1 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 @@ -25,6 +25,7 @@ import java.net.URI; import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; import org.jclouds.vcloud.director.v1_5.domain.Link; +import org.jclouds.vcloud.director.v1_5.domain.OrgGeneralSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgLdapSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgLeaseSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgPasswordPolicySettings; @@ -61,9 +62,53 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect // PUT /admin/org/{id}/settings/email -// GET /admin/org/{id}/settings/general - -// PUT /admin/org/{id}/settings/general + @Test(enabled = false) + public void testGetGeneralSettings() { + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("GET", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/general") + .acceptAnyMedia() + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/org/admin/generalSettings.xml", + VCloudDirectorMediaType.ORG_GENERAL_SETTINGS) + .httpResponseBuilder().build()); + + OrgGeneralSettings expected = generalSettings(); + + assertEquals(client.getAdminOrgClient().getGeneralSettings(orgRef.getURI()), expected); + } + + public static final OrgGeneralSettings generalSettings() { + return OrgGeneralSettings.builder() + + .build(); + } + + @Test(enabled = false) + public void testUpdateGeneralSettings() { + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("PUT", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/general") + .xmlFilePayload("/org/admin/updateGeneralSettingsSource.xml", + VCloudDirectorMediaType.ORG_GENERAL_SETTINGS) + .acceptMedia(VCloudDirectorMediaType.ORG_GENERAL_SETTINGS) + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/org/admin/updateGeneralSettings.xml", + VCloudDirectorMediaType.ORG_GENERAL_SETTINGS) + .httpResponseBuilder().build()); + + OrgGeneralSettings expected = updateGeneralSettings(); + + assertEquals(client.getAdminOrgClient().updateGeneralSettings(orgRef.getURI(), expected), expected); + } + + public static final OrgGeneralSettings updateGeneralSettings() { + return generalSettings().toBuilder() + + .build(); + } @Test public void testGetLdapSettings() { diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java index 5a0bd45cb8..31ef28692a 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java @@ -24,6 +24,7 @@ import org.jclouds.vcloud.director.v1_5.domain.AdminOrg; import org.jclouds.vcloud.director.v1_5.domain.Error; import org.jclouds.vcloud.director.v1_5.domain.Group; import org.jclouds.vcloud.director.v1_5.domain.Checks; +import org.jclouds.vcloud.director.v1_5.domain.OrgGeneralSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgLdapSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgLeaseSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgPasswordPolicySettings; @@ -59,6 +60,7 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { OrgPasswordPolicySettings passwordPolicy; OrgLeaseSettings vAppLeaseSettings; OrgVAppTemplateLeaseSettings vAppTemplateLeaseSettings; + OrgGeneralSettings generalSettings; @Override @BeforeClass(inheritGroups = true) @@ -82,9 +84,66 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { // PUT /admin/org/{id}/settings/email -// GET /admin/org/{id}/settings/general - -// PUT /admin/org/{id}/settings/general + @Test(testName = "GET /admin/org/{id}/settings/generalSettings") + public void testGetGeneralSettings() { + generalSettings = orgClient.getGeneralSettings(orgRef.getURI()); + + Checks.checkGeneralSettings(generalSettings); + } + + @Test(testName = "PUT /admin/org/{id}/settings/generalSettings", + dependsOnMethods = { "testGetGeneralSettings" }, enabled = false ) + public void testUpdateGeneralSettings() { +// boolean canPublishCatalogs = generalSettings.canPublishCatalogs(); // FIXME: did not update + Integer deployedVMQuota = generalSettings.getDeployedVMQuota(); + Integer storedVmQuota = generalSettings.getStoredVmQuota(); + boolean useServerBootSequence = generalSettings.useServerBootSequence(); + Integer delayAfterPowerOnSeconds = generalSettings.getDelayAfterPowerOnSeconds(); + + try { + generalSettings = generalSettings.toBuilder() +// .canPublishCatalogs(!canPublishCatalogs) + .deployedVMQuota(deployedVMQuota+1) + .storedVmQuota(storedVmQuota+1) + .useServerBootSequence(!useServerBootSequence) + .delayAfterPowerOnSeconds(delayAfterPowerOnSeconds+1) + .build(); + + generalSettings = orgClient.updateGeneralSettings( + orgRef.getURI(), generalSettings); + +// assertTrue(equal(generalSettings.canPublishCatalogs(), !canPublishCatalogs), +// String.format(OBJ_FIELD_UPDATABLE, +// "generalSettings", "canPublishCatalogs")); + assertTrue(equal(generalSettings.getDeployedVMQuota(), deployedVMQuota+1), + String.format(OBJ_FIELD_UPDATABLE, + "generalSettings", "deployedVMQuota")); + assertTrue(equal(generalSettings.getStoredVmQuota(), storedVmQuota+1), + String.format(OBJ_FIELD_UPDATABLE, + "generalSettings", "storedVmQuota")); + assertTrue(equal(generalSettings.useServerBootSequence(), !useServerBootSequence), + String.format(OBJ_FIELD_UPDATABLE, + "generalSettings", "useServerBootSequence")); + assertTrue(equal(generalSettings.getDelayAfterPowerOnSeconds(), delayAfterPowerOnSeconds+1), + String.format(OBJ_FIELD_UPDATABLE, + "generalSettings", "delayAfterPowerOnSeconds")); + + //TODO negative tests? + + Checks.checkGeneralSettings(generalSettings); + } finally { + generalSettings = generalSettings.toBuilder() +// .canPublishCatalogs(canPublishCatalogs) + .deployedVMQuota(deployedVMQuota) + .storedVmQuota(storedVmQuota) + .useServerBootSequence(useServerBootSequence) + .delayAfterPowerOnSeconds(delayAfterPowerOnSeconds) + .build(); + + generalSettings = orgClient.updateGeneralSettings( + orgRef.getURI(), generalSettings); + } + } @Test(testName = "GET /admin/org/{id}/settings/ldap") public void getLdapSettings() { From 4077e2d9a4f8b86325411b437ea7577159845249 Mon Sep 17 00:00:00 2001 From: danikov Date: Sun, 11 Mar 2012 18:46:35 +0000 Subject: [PATCH 07/10] get/put emailSettings --- .../v1_5/VCloudDirectorMediaType.java | 4 +- .../v1_5/domain/OrgEmailSettings.java | 14 ++-- .../v1_5/domain/SmtpServerSettings.java | 8 +- .../v1_5/features/AdminOrgAsyncClient.java | 27 +++++- .../v1_5/features/AdminOrgClient.java | 26 +++++- .../features/AdminOrgClientExpectTest.java | 83 +++++++++++++++++-- .../v1_5/features/AdminOrgClientLiveTest.java | 82 +++++++++++++++++- .../resources/org/admin/emailSettings.xml | 14 ++++ .../org/admin/updateEmailSettings.xml | 14 ++++ .../org/admin/updateEmailSettingsSource.xml | 14 ++++ 10 files changed, 258 insertions(+), 28 deletions(-) create mode 100644 labs/vcloud-director/src/test/resources/org/admin/emailSettings.xml create mode 100644 labs/vcloud-director/src/test/resources/org/admin/updateEmailSettings.xml create mode 100644 labs/vcloud-director/src/test/resources/org/admin/updateEmailSettingsSource.xml diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java index 28059c86a7..e3380afe4c 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java @@ -145,6 +145,8 @@ public class VCloudDirectorMediaType { public static final String ORG_GENERAL_SETTINGS = "application/vnd.vmware.admin.organizationGeneralSettings+xml"; + public static final String ORG_EMAIL_SETTINGS = "application/vnd.vmware.admin.organizationEmailSettings+xml"; + /** * * All acceptable media types. @@ -165,6 +167,6 @@ public class VCloudDirectorMediaType { CLONE_MEDIA_PARAMS, LEASE_SETTINGS_SECTION, RELOCATE_TEMPLATE, ENVELOPE, PUBLISH_CATALOG_PARAMS, GROUP, ORG_VAPP_TEMPLATE_LEASE_SETTINGS, ORG_LEASE_SETTINGS, ORG_PASSWORD_POLICY_SETTINGS, ORG_LDAP_SETTINGS, - ORG_GENERAL_SETTINGS + ORG_GENERAL_SETTINGS, ORG_EMAIL_SETTINGS ); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgEmailSettings.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgEmailSettings.java index 64e528a3eb..39c20987ed 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgEmailSettings.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgEmailSettings.java @@ -76,7 +76,7 @@ import com.google.common.collect.ImmutableList; "fromEmailAddress", "defaultSubjectPrefix", "isAlertEmailToAllAdmins", - "alertEmailTo", + "alertEmailsTo", "smtpServerSettings" }) public class OrgEmailSettings extends ResourceType { @@ -142,7 +142,7 @@ public class OrgEmailSettings extends ResourceType { * @see OrgEmailSettings#getAlertEmailTo() */ public Builder alertEmailsTo(List alertEmailsTo) { - this.alertEmailTo = ImmutableList.copyOf(alertEmailsTo); + this.alertEmailTo = alertEmailsTo == null ? null : ImmutableList.copyOf(alertEmailsTo); return this; } @@ -163,7 +163,8 @@ public class OrgEmailSettings extends ResourceType { } public OrgEmailSettings build() { - return new OrgEmailSettings(isDefaultSmtpServer, isDefaultOrgEmail, fromEmailAddress, defaultSubjectPrefix, + return new OrgEmailSettings(href, type, links, isDefaultSmtpServer, + isDefaultOrgEmail, fromEmailAddress, defaultSubjectPrefix, isAlertEmailToAllAdmins, alertEmailTo, smtpServerSettings); } @@ -225,9 +226,11 @@ public class OrgEmailSettings extends ResourceType { // For JAXB } - private OrgEmailSettings(boolean isDefaultSmtpServer, boolean isDefaultOrgEmail, + private OrgEmailSettings(URI href, String type, Set links, + boolean isDefaultSmtpServer, boolean isDefaultOrgEmail, String fromEmailAddress, String defaultSubjectPrefix, boolean isAlertEmailToAllAdmins, List alertEmailTo, SmtpServerSettings smtpServerSettings) { + super(href, type, links); this.isDefaultSmtpServer = isDefaultSmtpServer; this.isDefaultOrgEmail = isDefaultOrgEmail; this.fromEmailAddress = fromEmailAddress; @@ -323,9 +326,6 @@ public class OrgEmailSettings extends ResourceType { * */ public List getAlertEmailsTo() { - if (alertEmailsTo == null) { - alertEmailsTo = new ArrayList(); - } return this.alertEmailsTo; } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/SmtpServerSettings.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/SmtpServerSettings.java index 9c79022acf..4ab6dd17f1 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/SmtpServerSettings.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/SmtpServerSettings.java @@ -61,7 +61,7 @@ import com.google.common.base.Objects.ToStringHelper; */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "SmtpServerSettings", propOrder = { - "isUseAuthentication", + "useAuthentication", "host", "username", "password" @@ -200,8 +200,7 @@ public class SmtpServerSettings { if (o == null || getClass() != o.getClass()) return false; SmtpServerSettings that = SmtpServerSettings.class.cast(o); - return super.equals(that) && - equal(useAuthentication, that.useAuthentication) && + return equal(useAuthentication, that.useAuthentication) && equal(host, that.host) && equal(username, that.username) && equal(password, that.password); @@ -209,8 +208,7 @@ public class SmtpServerSettings { @Override public int hashCode() { - return Objects.hashCode(super.hashCode(), - useAuthentication, + return Objects.hashCode(useAuthentication, host, username, password); diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java index c25497e3bc..8dba6a872d 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java @@ -33,6 +33,7 @@ import org.jclouds.rest.annotations.JAXBResponseParser; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.binders.BindToXMLPayload; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.jclouds.vcloud.director.v1_5.domain.OrgEmailSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgGeneralSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgLdapSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgLeaseSettings; @@ -60,9 +61,29 @@ public interface AdminOrgAsyncClient extends OrgAsyncClient { // PUT /admin/org/{id}/settings -// GET /admin/org/{id}/settings/email - -// PUT /admin/org/{id}/settings/email + /** + * @see AdminOrgClient#getEmailSettings(URI) + */ + @GET + @Path("/settings/email") + @Consumes + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture getEmailSettings( + @EndpointParam URI orgRef); + + /** + * @see AdminOrgClient#updateEmailSettings(URI, OrgEmailSettings) + */ + @PUT + @Path("/settings/email") + @Consumes(VCloudDirectorMediaType.ORG_EMAIL_SETTINGS) + @Produces(VCloudDirectorMediaType.ORG_EMAIL_SETTINGS) + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture updateEmailSettings( + @EndpointParam URI orgRef, + @BinderParam(BindToXMLPayload.class) OrgEmailSettings settings); /** * @see AdminOrgClient#getGeneralSettings(URI) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java index 2c5c9c86d0..9943b6df64 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java @@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; import org.jclouds.vcloud.director.v1_5.domain.Group; +import org.jclouds.vcloud.director.v1_5.domain.OrgEmailSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgGeneralSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgLdapSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgLeaseSettings; @@ -48,9 +49,30 @@ public interface AdminOrgClient extends OrgClient { // PUT /admin/org/{id}/settings -// GET /admin/org/{id}/settings/email + /** + * Retrieves email settings for an organization. + * + *
+    * GET /admin/org/{id}/settings/email
+    * 
+ * + * @param orgRef the reference for the admin org + * @return the email settings + */ + OrgEmailSettings getEmailSettings(URI orgRef); -// PUT /admin/org/{id}/settings/email + /** + * Updates email policy settings for organization. + * + *
+    * PUT /admin/org/{id}/settings/email
+    * 
+ * @param orgRef the reference for the admin org + * @param newSettings the requested updated settings + * @return the resultant settings + */ + OrgEmailSettings updateEmailSettings(URI orgRef, + OrgEmailSettings newSettings); /** * Gets general organization settings. 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 17350e13a1..82b9855ebb 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 @@ -25,12 +25,14 @@ import java.net.URI; import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; import org.jclouds.vcloud.director.v1_5.domain.Link; +import org.jclouds.vcloud.director.v1_5.domain.OrgEmailSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgGeneralSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgLdapSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgLeaseSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgPasswordPolicySettings; 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.internal.BaseVCloudDirectorRestClientExpectTest; import org.testng.annotations.Test; @@ -43,8 +45,6 @@ import org.testng.annotations.Test; public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { private Reference orgRef = Reference.builder() -// .type("application/vnd.vmware.admin.???+xml") - .name("???") .href(URI.create(endpoint + "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) .build(); @@ -58,10 +58,81 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect // PUT /admin/org/{id}/settings -// GET /admin/org/{id}/settings/email - -// PUT /admin/org/{id}/settings/email - + @Test + public void testGetEmailSettings() { + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("GET", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/email") + .acceptAnyMedia() + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/org/admin/emailSettings.xml", + VCloudDirectorMediaType.ORG_GENERAL_SETTINGS) + .httpResponseBuilder().build()); + + OrgEmailSettings expected = emailSettings(); + + assertEquals(client.getAdminOrgClient().getEmailSettings(orgRef.getURI()), expected); + } + + public static final OrgEmailSettings emailSettings() { + return OrgEmailSettings.builder() + .type("application/vnd.vmware.admin.organizationEmailSettings+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/email")) + .link(Link.builder() + .rel("edit") + .type("application/vnd.vmware.admin.organizationEmailSettings+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/email")) + .build()) + .isDefaultSmtpServer(true) + .isDefaultOrgEmail(true) + .fromEmailAddress("") + .defaultSubjectPrefix("") + .isAlertEmailToAllAdmins(true) + .smtpServerSettings(SmtpServerSettings.builder() + .useAuthentication(false) + .host("") + .username("") + .password("") + .build()) + .build(); + } + + @Test + public void testUpdateEmailSettings() { + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("PUT", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/email") + .xmlFilePayload("/org/admin/updateEmailSettingsSource.xml", + VCloudDirectorMediaType.ORG_EMAIL_SETTINGS) + .acceptMedia(VCloudDirectorMediaType.ORG_EMAIL_SETTINGS) + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/org/admin/updateEmailSettings.xml", + VCloudDirectorMediaType.ORG_EMAIL_SETTINGS) + .httpResponseBuilder().build()); + + OrgEmailSettings expected = updateEmailSettings(); + + assertEquals(client.getAdminOrgClient().updateEmailSettings(orgRef.getURI(), expected), expected); + } + + @Test + public static final OrgEmailSettings updateEmailSettings() { + return emailSettings().toBuilder() + .isDefaultSmtpServer(false) + .isDefaultOrgEmail(false) + .fromEmailAddress("test@test.com") + .defaultSubjectPrefix("new") + .isAlertEmailToAllAdmins(false) + .smtpServerSettings(emailSettings().getSmtpServerSettings().toBuilder() + .useAuthentication(true) + .host("new") + .username("new") + .build()) + .build(); + } + @Test(enabled = false) public void testGetGeneralSettings() { VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java index 31ef28692a..cf341ab49b 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java @@ -24,12 +24,14 @@ import org.jclouds.vcloud.director.v1_5.domain.AdminOrg; import org.jclouds.vcloud.director.v1_5.domain.Error; import org.jclouds.vcloud.director.v1_5.domain.Group; import org.jclouds.vcloud.director.v1_5.domain.Checks; +import org.jclouds.vcloud.director.v1_5.domain.OrgEmailSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgGeneralSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgLdapSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgLeaseSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgPasswordPolicySettings; import org.jclouds.vcloud.director.v1_5.domain.OrgVAppTemplateLeaseSettings; import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; +import org.jclouds.vcloud.director.v1_5.domain.SmtpServerSettings; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -57,10 +59,11 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { */ private ReferenceType orgRef; private AdminOrg org; + OrgEmailSettings emailSettings; + OrgGeneralSettings generalSettings; OrgPasswordPolicySettings passwordPolicy; OrgLeaseSettings vAppLeaseSettings; OrgVAppTemplateLeaseSettings vAppTemplateLeaseSettings; - OrgGeneralSettings generalSettings; @Override @BeforeClass(inheritGroups = true) @@ -80,9 +83,80 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { // PUT /admin/org/{id}/settings -// GET /admin/org/{id}/settings/email - -// PUT /admin/org/{id}/settings/email + @Test(testName = "GET /admin/org/{id}/settings/emailSettings") + public void testGetEmailSettings() { + emailSettings = orgClient.getEmailSettings(orgRef.getURI()); + + Checks.checkEmailSettings(emailSettings); + } + + @Test(testName = "PUT /admin/org/{id}/settings/emailSettings", + dependsOnMethods = { "testGetEmailSettings" }) + public void testUpdateEmailSettings() { + boolean isDefaultSmtpServer = emailSettings.isDefaultSmtpServer(); + boolean isDefaultOrgEmail = emailSettings.isDefaultOrgEmail(); + String oldFromEmailAddress = emailSettings.getFromEmailAddress(); + String newFromEmailAddress = "test@test.com"; + String oldDefaultSubjectPrefix = emailSettings.getDefaultSubjectPrefix(); + String newDefaultSubjectPrefix = "new"+oldDefaultSubjectPrefix; + boolean isAlertEmailToAllAdmins = emailSettings.isAlertEmailToAllAdmins(); + SmtpServerSettings oldSmtpServerSettings = emailSettings.getSmtpServerSettings(); + SmtpServerSettings newSmtpServerSettings = oldSmtpServerSettings.toBuilder() + .useAuthentication(!oldSmtpServerSettings.useAuthentication()) + .host("new"+oldSmtpServerSettings.getHost()) + .username("new"+oldSmtpServerSettings.getUsername()) + .password("new"+oldSmtpServerSettings.getPassword()) + .build(); + + try { + emailSettings = emailSettings.toBuilder() + .isDefaultSmtpServer(!isDefaultSmtpServer) + .isDefaultOrgEmail(!isDefaultOrgEmail) + .fromEmailAddress(newFromEmailAddress) + .defaultSubjectPrefix(newDefaultSubjectPrefix) + .isAlertEmailToAllAdmins(!isAlertEmailToAllAdmins) + .smtpServerSettings(newSmtpServerSettings) + .build(); + + emailSettings = orgClient.updateEmailSettings( + orgRef.getURI(), emailSettings); + + assertTrue(equal(emailSettings.isDefaultSmtpServer(), !isDefaultSmtpServer), + String.format(OBJ_FIELD_UPDATABLE, + "emailSettings", "isDefaultSmtpServer")); + assertTrue(equal(emailSettings.isDefaultOrgEmail(), !isDefaultOrgEmail), + String.format(OBJ_FIELD_UPDATABLE, + "emailSettings", "isDefaultOrgEmail")); + assertTrue(equal(emailSettings.getFromEmailAddress(), newFromEmailAddress), + String.format(OBJ_FIELD_UPDATABLE, + "emailSettings", "fromEmailAddress")); + assertTrue(equal(emailSettings.getDefaultSubjectPrefix(), newDefaultSubjectPrefix), + String.format(OBJ_FIELD_UPDATABLE, + "emailSettings", "defaultSubjectPrefix")); + assertTrue(equal(emailSettings.isAlertEmailToAllAdmins(), !isAlertEmailToAllAdmins), + String.format(OBJ_FIELD_UPDATABLE, + "emailSettings", "isAlertEmailToAllAdmins")); + assertTrue(equal(emailSettings.getSmtpServerSettings(), newSmtpServerSettings), + String.format(OBJ_FIELD_UPDATABLE, + "emailSettings", "smtpServerSettings")); + + //TODO negative tests? + + Checks.checkEmailSettings(emailSettings); + } finally { + emailSettings = emailSettings.toBuilder() + .isDefaultSmtpServer(isDefaultSmtpServer) + .isDefaultOrgEmail(isDefaultOrgEmail) + .fromEmailAddress(oldFromEmailAddress) + .defaultSubjectPrefix(oldDefaultSubjectPrefix) + .isAlertEmailToAllAdmins(isAlertEmailToAllAdmins) + .smtpServerSettings(oldSmtpServerSettings) + .build(); + + emailSettings = orgClient.updateEmailSettings( + orgRef.getURI(), emailSettings); + } + } @Test(testName = "GET /admin/org/{id}/settings/generalSettings") public void testGetGeneralSettings() { diff --git a/labs/vcloud-director/src/test/resources/org/admin/emailSettings.xml b/labs/vcloud-director/src/test/resources/org/admin/emailSettings.xml new file mode 100644 index 0000000000..26c61f6eeb --- /dev/null +++ b/labs/vcloud-director/src/test/resources/org/admin/emailSettings.xml @@ -0,0 +1,14 @@ + + + + true + true + + + true + + false + + + + \ No newline at end of file diff --git a/labs/vcloud-director/src/test/resources/org/admin/updateEmailSettings.xml b/labs/vcloud-director/src/test/resources/org/admin/updateEmailSettings.xml new file mode 100644 index 0000000000..c48af09fef --- /dev/null +++ b/labs/vcloud-director/src/test/resources/org/admin/updateEmailSettings.xml @@ -0,0 +1,14 @@ + + + + false + false + test@test.com + new + false + + true + new + new + + \ No newline at end of file diff --git a/labs/vcloud-director/src/test/resources/org/admin/updateEmailSettingsSource.xml b/labs/vcloud-director/src/test/resources/org/admin/updateEmailSettingsSource.xml new file mode 100644 index 0000000000..70b36070e4 --- /dev/null +++ b/labs/vcloud-director/src/test/resources/org/admin/updateEmailSettingsSource.xml @@ -0,0 +1,14 @@ + + + + false + false + test@test.com + new + false + + true + new + new + + \ No newline at end of file From 5817f0446374a5f8f0cc725c70621913d51d7b2d Mon Sep 17 00:00:00 2001 From: danikov Date: Sun, 11 Mar 2012 19:40:04 +0000 Subject: [PATCH 08/10] get/put orgSettings --- .../v1_5/VCloudDirectorMediaType.java | 4 +- .../director/v1_5/domain/OrgSettings.java | 115 +++++++++--------- .../v1_5/features/AdminOrgAsyncClient.java | 27 +++- .../v1_5/features/AdminOrgClient.java | 25 +++- .../vcloud/director/v1_5/domain/Checks.java | 19 ++- .../features/AdminOrgClientExpectTest.java | 70 +++++++++-- .../v1_5/features/AdminOrgClientLiveTest.java | 112 ++++++++++++++--- 7 files changed, 270 insertions(+), 102 deletions(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java index e3380afe4c..354bf95e15 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java @@ -147,6 +147,8 @@ public class VCloudDirectorMediaType { public static final String ORG_EMAIL_SETTINGS = "application/vnd.vmware.admin.organizationEmailSettings+xml"; + public static final String ORG_SETTINGS = "application/vnd.vmware.admin.orgSettings+xml"; + /** * * All acceptable media types. @@ -167,6 +169,6 @@ public class VCloudDirectorMediaType { CLONE_MEDIA_PARAMS, LEASE_SETTINGS_SECTION, RELOCATE_TEMPLATE, ENVELOPE, PUBLISH_CATALOG_PARAMS, GROUP, ORG_VAPP_TEMPLATE_LEASE_SETTINGS, ORG_LEASE_SETTINGS, ORG_PASSWORD_POLICY_SETTINGS, ORG_LDAP_SETTINGS, - ORG_GENERAL_SETTINGS, ORG_EMAIL_SETTINGS + ORG_GENERAL_SETTINGS, ORG_EMAIL_SETTINGS, ORG_SETTINGS ); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgSettings.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgSettings.java index 8a6e88fd4c..f4de180a68 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgSettings.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgSettings.java @@ -69,12 +69,12 @@ import com.google.common.base.Objects.ToStringHelper; @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement(name = "OrgSettings") @XmlType(propOrder = { - "orgGeneralSettings", + "generalSettings", "vAppLeaseSettings", "vAppTemplateLeaseSettings", - "orgLdapSettings", - "orgEmailSettings", - "orgPasswordPolicySettings" + "ldapSettings", + "emailSettings", + "passwordPolicy" }) public class OrgSettings extends ResourceType { public static Builder builder() { @@ -87,18 +87,18 @@ public class OrgSettings extends ResourceType { public static class Builder extends ResourceType.Builder { - private OrgGeneralSettings orgGeneralSettings; + private OrgGeneralSettings generalSettings; private OrgLeaseSettings vAppLeaseSettings; private OrgVAppTemplateLeaseSettings vAppTemplateLeaseSettings; - private OrgLdapSettings orgLdapSettings; - private OrgEmailSettings orgEmailSettings; - private OrgPasswordPolicySettings orgPasswordPolicySettings; + private OrgLdapSettings ldapSettings; + private OrgEmailSettings emailSettings; + private OrgPasswordPolicySettings passwordPolicy; /** - * @see OrgSettings#getOrgGeneralSettings() + * @see OrgSettings#getGeneralSettings() */ - public Builder orgGeneralSettings(OrgGeneralSettings orgGeneralSettings) { - this.orgGeneralSettings = orgGeneralSettings; + public Builder orgGeneralSettings(OrgGeneralSettings generalSettings) { + this.generalSettings = generalSettings; return this; } @@ -119,32 +119,32 @@ public class OrgSettings extends ResourceType { } /** - * @see OrgSettings#getOrgLdapSettings() + * @see OrgSettings#getLdapSettings() */ - public Builder orgLdapSettings(OrgLdapSettings orgLdapSettings) { - this.orgLdapSettings = orgLdapSettings; + public Builder orgLdapSettings(OrgLdapSettings ldapSettings) { + this.ldapSettings = ldapSettings; return this; } /** - * @see OrgSettings#getOrgEmailSettings() + * @see OrgSettings#getEmailSettings() */ - public Builder orgEmailSettings(OrgEmailSettings orgEmailSettings) { - this.orgEmailSettings = orgEmailSettings; + public Builder orgEmailSettings(OrgEmailSettings emailSettings) { + this.emailSettings = emailSettings; return this; } /** - * @see OrgSettings#getOrgPasswordPolicySettings() + * @see OrgSettings#getPasswordPolicy() */ - public Builder orgPasswordPolicySettings(OrgPasswordPolicySettings orgPasswordPolicySettings) { - this.orgPasswordPolicySettings = orgPasswordPolicySettings; + public Builder passwordPolicy(OrgPasswordPolicySettings passwordPolicy) { + this.passwordPolicy = passwordPolicy; return this; } public OrgSettings build() { - return new OrgSettings(href, type, links, orgGeneralSettings, vAppLeaseSettings, - vAppTemplateLeaseSettings, orgLdapSettings, orgEmailSettings, orgPasswordPolicySettings); + return new OrgSettings(href, type, links, generalSettings, vAppLeaseSettings, + vAppTemplateLeaseSettings, ldapSettings, emailSettings, passwordPolicy); } @@ -191,12 +191,12 @@ public class OrgSettings extends ResourceType { } public Builder fromOrgSettings(OrgSettings in) { return fromResourceType(in) - .orgGeneralSettings(in.getOrgGeneralSettings()) + .orgGeneralSettings(in.getGeneralSettings()) .vAppLeaseSettings(in.getVAppLeaseSettings()) .vAppTemplateLeaseSettings(in.getVAppTemplateLeaseSettings()) - .orgLdapSettings(in.getOrgLdapSettings()) - .orgEmailSettings(in.getOrgEmailSettings()) - .orgPasswordPolicySettings(in.getOrgPasswordPolicySettings()); + .orgLdapSettings(in.getLdapSettings()) + .orgEmailSettings(in.getEmailSettings()) + .passwordPolicy(in.getPasswordPolicy()); } } @@ -205,32 +205,33 @@ public class OrgSettings extends ResourceType { // For JAXB } - public OrgSettings(URI href, String type, Set links, - OrgGeneralSettings orgGeneralSettings, + public OrgSettings(URI href, String type, Set links, + OrgGeneralSettings generalSettings, OrgLeaseSettings vAppLeaseSettings, OrgVAppTemplateLeaseSettings vAppTemplateLeaseSettings, - OrgLdapSettings orgLdapSettings, OrgEmailSettings orgEmailSettings, - OrgPasswordPolicySettings orgPasswordPolicySettings) { + OrgLdapSettings ldapSettings, OrgEmailSettings emailSettings, + OrgPasswordPolicySettings passwordPolicy) { super(href, type, links); - this.orgGeneralSettings = orgGeneralSettings; + this.generalSettings = generalSettings; this.vAppLeaseSettings = vAppLeaseSettings; this.vAppTemplateLeaseSettings = vAppTemplateLeaseSettings; - this.orgLdapSettings = orgLdapSettings; - this.orgPasswordPolicySettings = orgPasswordPolicySettings; + this.ldapSettings = ldapSettings; + this.emailSettings = emailSettings; + this.passwordPolicy = passwordPolicy; } @XmlElement(name = "OrgGeneralSettings") - protected OrgGeneralSettings orgGeneralSettings; + protected OrgGeneralSettings generalSettings; @XmlElement(name = "VAppLeaseSettings") protected OrgLeaseSettings vAppLeaseSettings; @XmlElement(name = "VAppTemplateLeaseSettings") protected OrgVAppTemplateLeaseSettings vAppTemplateLeaseSettings; @XmlElement(name = "OrgLdapSettings") - protected OrgLdapSettings orgLdapSettings; + protected OrgLdapSettings ldapSettings; @XmlElement(name = "OrgEmailSettings") - protected OrgEmailSettings orgEmailSettings; + protected OrgEmailSettings emailSettings; @XmlElement(name = "OrgPasswordPolicySettings") - protected OrgPasswordPolicySettings orgPasswordPolicySettings; + protected OrgPasswordPolicySettings passwordPolicy; /** * Gets the value of the orgGeneralSettings property. @@ -240,8 +241,8 @@ public class OrgSettings extends ResourceType { * {@link OrgGeneralSettings } * */ - public OrgGeneralSettings getOrgGeneralSettings() { - return orgGeneralSettings; + public OrgGeneralSettings getGeneralSettings() { + return generalSettings; } /** @@ -276,8 +277,8 @@ public class OrgSettings extends ResourceType { * {@link OrgLdapSettings } * */ - public OrgLdapSettings getOrgLdapSettings() { - return orgLdapSettings; + public OrgLdapSettings getLdapSettings() { + return ldapSettings; } /** @@ -288,8 +289,8 @@ public class OrgSettings extends ResourceType { * {@link OrgEmailSettings } * */ - public OrgEmailSettings getOrgEmailSettings() { - return orgEmailSettings; + public OrgEmailSettings getEmailSettings() { + return emailSettings; } /** @@ -300,8 +301,8 @@ public class OrgSettings extends ResourceType { * {@link OrgPasswordPolicySettings } * */ - public OrgPasswordPolicySettings getOrgPasswordPolicySettings() { - return orgPasswordPolicySettings; + public OrgPasswordPolicySettings getPasswordPolicy() { + return passwordPolicy; } @Override @@ -312,34 +313,34 @@ public class OrgSettings extends ResourceType { return false; OrgSettings that = OrgSettings.class.cast(o); return super.equals(that) && - equal(orgGeneralSettings, that.orgGeneralSettings) && + equal(generalSettings, that.generalSettings) && equal(vAppLeaseSettings, that.vAppLeaseSettings) && equal(vAppTemplateLeaseSettings, that.vAppTemplateLeaseSettings) && - equal(orgLdapSettings, that.orgLdapSettings) && - equal(orgEmailSettings, that.orgEmailSettings) && - equal(orgPasswordPolicySettings, that.orgPasswordPolicySettings); + equal(ldapSettings, that.ldapSettings) && + equal(emailSettings, that.emailSettings) && + equal(passwordPolicy, that.passwordPolicy); } @Override public int hashCode() { return Objects.hashCode(super.hashCode(), - orgGeneralSettings, + generalSettings, vAppLeaseSettings, vAppTemplateLeaseSettings, - orgLdapSettings, - orgEmailSettings, - orgPasswordPolicySettings); + ldapSettings, + emailSettings, + passwordPolicy); } @Override public ToStringHelper string() { return super.string() - .add("orgGeneralSettings", orgGeneralSettings) + .add("generalSettings", generalSettings) .add("vAppLeaseSettings", vAppLeaseSettings) .add("vAppTemplateLeaseSettings", vAppTemplateLeaseSettings) - .add("orgLdapSettings", orgLdapSettings) - .add("orgEmailSettings", orgEmailSettings) - .add("orgPasswordPolicySettings", orgPasswordPolicySettings); + .add("ldapSettings", ldapSettings) + .add("emailSettings", emailSettings) + .add("passwordPolicy", passwordPolicy); } } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java index 8dba6a872d..eda625bd03 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java @@ -38,6 +38,7 @@ import org.jclouds.vcloud.director.v1_5.domain.OrgGeneralSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgLdapSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgLeaseSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgPasswordPolicySettings; +import org.jclouds.vcloud.director.v1_5.domain.OrgSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgVAppTemplateLeaseSettings; import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx; @@ -57,9 +58,29 @@ public interface AdminOrgAsyncClient extends OrgAsyncClient { // POST /admin/org/{id}/groups -// GET /admin/org/{id}/settings - -// PUT /admin/org/{id}/settings + /** + * @see AdminOrgClient#getSettings(URI) + */ + @GET + @Path("/settings") + @Consumes + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture getSettings( + @EndpointParam URI orgRef); + + /** + * @see AdminOrgClient#updateSettings(URI, OrgSettings) + */ + @PUT + @Path("/settings") + @Consumes(VCloudDirectorMediaType.ORG_SETTINGS) + @Produces(VCloudDirectorMediaType.ORG_SETTINGS) + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture updateSettings( + @EndpointParam URI orgRef, + @BinderParam(BindToXMLPayload.class) OrgSettings settings); /** * @see AdminOrgClient#getEmailSettings(URI) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java index 9943b6df64..af752307ce 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java @@ -28,6 +28,7 @@ import org.jclouds.vcloud.director.v1_5.domain.OrgGeneralSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgLdapSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgLeaseSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgPasswordPolicySettings; +import org.jclouds.vcloud.director.v1_5.domain.OrgSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgVAppTemplateLeaseSettings; /** @@ -45,9 +46,29 @@ public interface AdminOrgClient extends OrgClient { // POST /admin/org/{id}/groups -// GET /admin/org/{id}/settings + /** + * Gets organizational settings for this organization. + * + *
+    * GET /admin/org/{id}/settings
+    * 
+ * + * @param orgRef the reference for the admin org + * @return the settings + */ + OrgSettings getSettings(URI orgRef); -// PUT /admin/org/{id}/settings + /** + * Updates organizational settings for this organization. + * + *
+    * PUT /admin/org/{id}/settings
+    * 
+ * @param orgRef the reference for the admin org + * @param newSettings the requested updated settings + * @return the resultant settings + */ + OrgSettings updateSettings(URI orgRef, OrgSettings newSettings); /** * Retrieves email settings for an organization. diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java index c6f07b3735..13c1ba76bc 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java @@ -528,10 +528,10 @@ public class Checks { } } - public static void checkOrgSetting(OrgSettings settings) { + public static void checkOrgSettings(OrgSettings settings) { // Check optional fields - if (settings.getOrgGeneralSettings() != null) { - checkGeneralSettings(settings.getOrgGeneralSettings()); + if (settings.getGeneralSettings() != null) { + checkGeneralSettings(settings.getGeneralSettings()); } if (settings.getVAppLeaseSettings() != null) { checkVAppLeaseSettings(settings.getVAppLeaseSettings()); @@ -539,14 +539,14 @@ public class Checks { if (settings.getVAppTemplateLeaseSettings() != null) { checkVAppTemplateLeaseSettings(settings.getVAppTemplateLeaseSettings()); } - if (settings.getOrgLdapSettings() != null) { - checkLdapSettings(settings.getOrgLdapSettings()); + if (settings.getLdapSettings() != null) { + checkLdapSettings(settings.getLdapSettings()); } - if (settings.getOrgEmailSettings() != null) { - checkEmailSettings(settings.getOrgEmailSettings()); + if (settings.getEmailSettings() != null) { + checkEmailSettings(settings.getEmailSettings()); } - if (settings.getOrgPasswordPolicySettings() != null) { - checkPasswordPolicySettings(settings.getOrgPasswordPolicySettings()); + if (settings.getPasswordPolicy() != null) { + checkPasswordPolicySettings(settings.getPasswordPolicy()); } // parent type @@ -561,7 +561,6 @@ public class Checks { checkEmailAddress(settings.getFromEmailAddress()); assertNotNull(settings.getDefaultSubjectPrefix(), String.format(OBJ_FIELD_REQ, "OrgEmailSettings", "defaultSubjectPrefix")); assertNotNull(settings.isAlertEmailToAllAdmins(), String.format(OBJ_FIELD_REQ, "OrgEmailSettings", "isAlertEmailToAllAdmins")); - assertNotNull(settings.getAlertEmailsTo(), String.format(OBJ_FIELD_REQ, "OrgEmailSettings", "alertEmailsTo")); // optional // NOTE alertEmailsTo cannot be checked 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 82b9855ebb..ddd092a076 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 @@ -30,6 +30,7 @@ import org.jclouds.vcloud.director.v1_5.domain.OrgGeneralSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgLdapSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgLeaseSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgPasswordPolicySettings; +import org.jclouds.vcloud.director.v1_5.domain.OrgSettings; 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; @@ -54,9 +55,60 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect // POST /admin/org/{id}/groups -// GET /admin/org/{id}/settings - -// PUT /admin/org/{id}/settings + @Test + public void testGetSettings() { + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("GET", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/") + .acceptAnyMedia() + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/org/admin/settings.xml", + VCloudDirectorMediaType.ORG_SETTINGS) + .httpResponseBuilder().build()); + + OrgSettings expected = settings(); + + assertEquals(client.getAdminOrgClient().getSettings(orgRef.getURI()), expected); + } + + public static final OrgSettings settings() { + return OrgSettings.builder() + .type("application/vnd.vmware.admin.organizationSettings+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/")) + .link(Link.builder() + .rel("edit") + .type("application/vnd.vmware.admin.organizationSettings+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/")) + .build()) + + .build(); + } + + @Test + public void testUpdateSettings() { + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("PUT", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/") + .xmlFilePayload("/org/admin/updateSettingsSource.xml", + VCloudDirectorMediaType.ORG_SETTINGS) + .acceptMedia(VCloudDirectorMediaType.ORG_SETTINGS) + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/org/admin/updateSettings.xml", + VCloudDirectorMediaType.ORG_SETTINGS) + .httpResponseBuilder().build()); + + OrgSettings expected = updateSettings(); + + assertEquals(client.getAdminOrgClient().updateSettings(orgRef.getURI(), expected), expected); + } + + @Test + public static final OrgSettings updateSettings() { + return settings().toBuilder() + .build(); + } @Test public void testGetEmailSettings() { @@ -239,10 +291,10 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect } @Test - public void testUpdateOrgPasswordPolicy() { + public void testUpdatePasswordPolicy() { VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, new VcloudHttpRequestPrimer() - .apiCommand("PUT", "/admin/org/???/settings/passwordPolicy") + .apiCommand("PUT", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/passwordPolicy") .xmlFilePayload("/org/admin/updatePasswordPolicySource.xml", VCloudDirectorMediaType.ORG_PASSWORD_POLICY_SETTINGS) .acceptMedia(VCloudDirectorMediaType.ORG_PASSWORD_POLICY_SETTINGS) @@ -269,7 +321,7 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect public void testGetVAppLeaseSettings() { VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, new VcloudHttpRequestPrimer() - .apiCommand("GET", "/admin/org/???/settings/vAppLeaseSettings") + .apiCommand("GET", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/vAppLeaseSettings") .acceptAnyMedia() .httpRequestBuilder().build(), new VcloudHttpResponsePrimer() @@ -292,7 +344,7 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect public void testUpdateOrgVAppLeaseSettings() { VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, new VcloudHttpRequestPrimer() - .apiCommand("PUT", "/admin/org/???/settings/vAppLeaseSettings") + .apiCommand("PUT", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/vAppLeaseSettings") .xmlFilePayload("/org/admin/updateVAppLeaseSettingsSource.xml", VCloudDirectorMediaType.ORG_LEASE_SETTINGS) .acceptMedia(VCloudDirectorMediaType.ORG_LEASE_SETTINGS) @@ -317,7 +369,7 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect public void testGetVAppTemplateLeaseSettings() { VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, new VcloudHttpRequestPrimer() - .apiCommand("GET", "/admin/org/???/settings/vAppTemplateLeaseSettings") + .apiCommand("GET", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/vAppTemplateLeaseSettings") .acceptAnyMedia() .httpRequestBuilder().build(), new VcloudHttpResponsePrimer() @@ -340,7 +392,7 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect public void testUpdateOrgVAppTemplateLeaseSettings() { VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, new VcloudHttpRequestPrimer() - .apiCommand("PUT", "/admin/org/???/settings/vAppTemplateLeaseSettings") + .apiCommand("PUT", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/vAppTemplateLeaseSettings") .xmlFilePayload("/org/admin/updateVAppLeaseSettingsSource.xml", VCloudDirectorMediaType.ORG_VAPP_TEMPLATE_LEASE_SETTINGS) .acceptMedia(VCloudDirectorMediaType.ORG_VAPP_TEMPLATE_LEASE_SETTINGS) diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java index cf341ab49b..17d2be7297 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java @@ -29,6 +29,7 @@ import org.jclouds.vcloud.director.v1_5.domain.OrgGeneralSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgLdapSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgLeaseSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgPasswordPolicySettings; +import org.jclouds.vcloud.director.v1_5.domain.OrgSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgVAppTemplateLeaseSettings; import org.jclouds.vcloud.director.v1_5.domain.ReferenceType; import org.jclouds.vcloud.director.v1_5.domain.SmtpServerSettings; @@ -59,11 +60,13 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { */ private ReferenceType orgRef; private AdminOrg org; - OrgEmailSettings emailSettings; - OrgGeneralSettings generalSettings; - OrgPasswordPolicySettings passwordPolicy; - OrgLeaseSettings vAppLeaseSettings; - OrgVAppTemplateLeaseSettings vAppTemplateLeaseSettings; + private OrgSettings settings, newSettings; + private OrgEmailSettings emailSettings, newEmailSettings; + private OrgGeneralSettings generalSettings, newGeneralSettings; + private OrgLdapSettings ldapSettings, newLdapSettings; + private OrgPasswordPolicySettings passwordPolicy, newPasswordPolicy; + private OrgLeaseSettings vAppLeaseSettings, newVAppLeaseSettings; + private OrgVAppTemplateLeaseSettings vAppTemplateLeaseSettings, newVAppTemplateLeaseSettings; @Override @BeforeClass(inheritGroups = true) @@ -79,9 +82,7 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { // POST /admin/org/{id}/groups -// GET /admin/org/{id}/settings - -// PUT /admin/org/{id}/settings + @Test(testName = "GET /admin/org/{id}/settings/emailSettings") public void testGetEmailSettings() { @@ -109,7 +110,7 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { .build(); try { - emailSettings = emailSettings.toBuilder() + newEmailSettings = emailSettings.toBuilder() .isDefaultSmtpServer(!isDefaultSmtpServer) .isDefaultOrgEmail(!isDefaultOrgEmail) .fromEmailAddress(newFromEmailAddress) @@ -119,7 +120,7 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { .build(); emailSettings = orgClient.updateEmailSettings( - orgRef.getURI(), emailSettings); + orgRef.getURI(), newEmailSettings); assertTrue(equal(emailSettings.isDefaultSmtpServer(), !isDefaultSmtpServer), String.format(OBJ_FIELD_UPDATABLE, @@ -175,7 +176,7 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { Integer delayAfterPowerOnSeconds = generalSettings.getDelayAfterPowerOnSeconds(); try { - generalSettings = generalSettings.toBuilder() + newGeneralSettings = generalSettings.toBuilder() // .canPublishCatalogs(!canPublishCatalogs) .deployedVMQuota(deployedVMQuota+1) .storedVmQuota(storedVmQuota+1) @@ -184,7 +185,7 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { .build(); generalSettings = orgClient.updateGeneralSettings( - orgRef.getURI(), generalSettings); + orgRef.getURI(), newGeneralSettings); // assertTrue(equal(generalSettings.canPublishCatalogs(), !canPublishCatalogs), // String.format(OBJ_FIELD_UPDATABLE, @@ -220,8 +221,8 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { } @Test(testName = "GET /admin/org/{id}/settings/ldap") - public void getLdapSettings() { - OrgLdapSettings ldapSettings = orgClient.getLdapSettings(orgRef.getURI()); + public void testGetLdapSettings() { + ldapSettings = orgClient.getLdapSettings(orgRef.getURI()); Checks.checkLdapSettings(ldapSettings); } @@ -241,14 +242,14 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { Integer accountLockoutIntervalMinutes = passwordPolicy.getAccountLockoutIntervalMinutes(); try { - passwordPolicy = passwordPolicy.toBuilder() + newPasswordPolicy = passwordPolicy.toBuilder() .accountLockoutEnabled(!accountLockoutEnabled) .invalidLoginsBeforeLockout(invalidLoginsBeforeLockout+1) .accountLockoutIntervalMinutes(accountLockoutIntervalMinutes+1) .build(); passwordPolicy = orgClient.updatePasswordPolicy( - orgRef.getURI(), passwordPolicy); + orgRef.getURI(), newPasswordPolicy); assertTrue(equal(passwordPolicy.isAccountLockoutEnabled(), !accountLockoutEnabled), String.format(OBJ_FIELD_UPDATABLE, @@ -290,14 +291,14 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { Integer deploymentLeaseSeconds = vAppLeaseSettings.getDeploymentLeaseSeconds(); try { - vAppLeaseSettings = vAppLeaseSettings.toBuilder() + newVAppLeaseSettings = vAppLeaseSettings.toBuilder() .deleteOnStorageLeaseExpiration(!deleteOnStorageLeaseExpiration) .storageLeaseSeconds(storageLeaseSeconds+1) .deploymentLeaseSeconds(deploymentLeaseSeconds+1) .build(); vAppLeaseSettings = orgClient.updateVAppLeaseSettings( - orgRef.getURI(), vAppLeaseSettings); + orgRef.getURI(), newVAppLeaseSettings); assertTrue(equal(vAppLeaseSettings.deleteOnStorageLeaseExpiration(), !deleteOnStorageLeaseExpiration), String.format(OBJ_FIELD_UPDATABLE, @@ -338,13 +339,13 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { Integer storageLeaseSeconds = vAppTemplateLeaseSettings.getStorageLeaseSeconds(); try { - vAppTemplateLeaseSettings = vAppTemplateLeaseSettings.toBuilder() + newVAppTemplateLeaseSettings = vAppTemplateLeaseSettings.toBuilder() .deleteOnStorageLeaseExpiration(!deleteOnStorageLeaseExpiration) .storageLeaseSeconds(storageLeaseSeconds+1) .build(); vAppTemplateLeaseSettings = orgClient.updateVAppTemplateLeaseSettings( - orgRef.getURI(), vAppTemplateLeaseSettings); + orgRef.getURI(), newVAppTemplateLeaseSettings); assertTrue(equal(vAppTemplateLeaseSettings.deleteOnStorageLeaseExpiration(), !deleteOnStorageLeaseExpiration), String.format(OBJ_FIELD_UPDATABLE, @@ -366,4 +367,75 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { orgRef.getURI(), vAppTemplateLeaseSettings); } } + + @Test(testName = "GET /admin/org/{id}/settings/settings", + dependsOnMethods = { "testGetGeneralSettings", + "testGetVAppLeaseSettings", + "testGetVAppTemplateLeaseSettings", + "testGetLdapSettings", + "testGetEmailSettings", + "testGetPasswordPolicy"}) + public void testGetSettings() { + settings = orgClient.getSettings(orgRef.getURI()); + + Checks.checkOrgSettings(settings); + } + + @Test(testName = "PUT /admin/org/{id}/settings/settings", + dependsOnMethods = { "testUpdateGeneralSettings", + "testUpdateVAppLeaseSettings", + "testUpdateVAppTemplateLeaseSettings", + "testUpdateEmailSettings", + "testUpdatePasswordPolicy"}, + enabled = false ) + public void testUpdateSettings() { + try { + newSettings = settings.toBuilder() + .orgGeneralSettings(newGeneralSettings) + .vAppLeaseSettings(newVAppLeaseSettings) + .vAppTemplateLeaseSettings(newVAppTemplateLeaseSettings) + .orgLdapSettings(newLdapSettings) + .orgEmailSettings(newEmailSettings) + .passwordPolicy(newPasswordPolicy) + .build(); + + settings = orgClient.updateSettings( + orgRef.getURI(), newSettings); + + assertTrue(equal(settings.getGeneralSettings(), newGeneralSettings), + String.format(OBJ_FIELD_UPDATABLE, + "orgSettings", "generalSettings")); + assertTrue(equal(settings.getVAppLeaseSettings(), newVAppLeaseSettings), + String.format(OBJ_FIELD_UPDATABLE, + "orgSettings", "vAppLeaseSettings")); + assertTrue(equal(settings.getVAppTemplateLeaseSettings(), newVAppTemplateLeaseSettings), + String.format(OBJ_FIELD_UPDATABLE, + "orgSettings", "vAppTemplateLeaseSettings")); + assertTrue(equal(settings.getLdapSettings(), newLdapSettings), + String.format(OBJ_FIELD_UPDATABLE, + "orgSettings", "ldapSettings")); + assertTrue(equal(settings.getEmailSettings(), newEmailSettings), + String.format(OBJ_FIELD_UPDATABLE, + "orgSettings", "emailSettings")); + assertTrue(equal(settings.getPasswordPolicy(), newPasswordPolicy), + String.format(OBJ_FIELD_UPDATABLE, + "orgSettings", "passwordPolicy")); + + //TODO negative tests? + + Checks.checkOrgSettings(settings); + } finally { + settings = settings.toBuilder() + .orgGeneralSettings(generalSettings) + .vAppLeaseSettings(vAppLeaseSettings) + .vAppTemplateLeaseSettings(vAppTemplateLeaseSettings) + .orgLdapSettings(ldapSettings) + .orgEmailSettings(emailSettings) + .passwordPolicy(passwordPolicy) + .build(); + + settings = orgClient.updateSettings( + orgRef.getURI(), settings); + } + } } From 8e46d9e9ecabb6b4fa8241bcbab46c1c3d3c3f54 Mon Sep 17 00:00:00 2001 From: danikov Date: Sun, 11 Mar 2012 20:34:22 +0000 Subject: [PATCH 09/10] get adminOrg --- .../v1_5/VCloudDirectorMediaType.java | 12 +- .../vcloud/director/v1_5/domain/AdminOrg.java | 11 +- .../director/v1_5/domain/CatalogsList.java | 10 +- .../director/v1_5/domain/GroupsList.java | 2 +- .../vcloud/director/v1_5/domain/Networks.java | 6 +- .../vcloud/director/v1_5/domain/Org.java | 10 +- .../director/v1_5/domain/OrgSettings.java | 12 +- .../director/v1_5/domain/UsersList.java | 6 +- .../vcloud/director/v1_5/domain/Vdcs.java | 4 +- .../v1_5/features/AdminOrgAsyncClient.java | 15 +- .../v1_5/features/AdminOrgClient.java | 19 +- .../v1_5/features/OrgAsyncClient.java | 2 +- .../vcloud/director/v1_5/domain/Checks.java | 40 +++ .../features/AdminOrgClientExpectTest.java | 263 ++++++++++++++++-- .../v1_5/features/AdminOrgClientLiveTest.java | 26 +- .../src/test/resources/org/admin/org.xml | 86 ++++++ 16 files changed, 448 insertions(+), 76 deletions(-) create mode 100644 labs/vcloud-director/src/test/resources/org/admin/org.xml diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java index 354bf95e15..be26e4b8c0 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorMediaType.java @@ -129,7 +129,7 @@ public class VCloudDirectorMediaType { public static final String ADMIN_CATALOG = "application/vnd.vmware.admin.catalog+xml"; - public static final String ADMIN_ORGANIZATION = "application/vnd.vmware.admin.organization+xml"; + public static final String ADMIN_ORG = "application/vnd.vmware.admin.organization+xml"; public static final String PUBLISH_CATALOG_PARAMS = "application/vnd.vmware.admin.publishCatalogParams+xml"; @@ -149,8 +149,11 @@ public class VCloudDirectorMediaType { public static final String ORG_SETTINGS = "application/vnd.vmware.admin.orgSettings+xml"; + public static final String ADMIN_NETWORK = "application/vnd.vmware.admin.network+xml"; + + public static final String ADMIN_ORG_NETWORK = "application/vnd.vmware.admin.orgNetwork+xml"; + /** - * * All acceptable media types. * * This list must be updated whenever a new media type constant is added. @@ -162,13 +165,14 @@ public class VCloudDirectorMediaType { MEDIA, OWNER, VDC, ADMIN_USER, V_APP, V_APP_TEMPLATE, CAPTURE_VAPP_PARAMS, CLONE_V_APP_PARAMS, CLONE_V_APP_TEMPLATE_PARAMS, COMPOSE_VAPP_PARAMS, INSTANTIATE_VAPP_TEMPLATE_PARAMS, - UPLOAD_VAPP_TEMPLATE_PARAMS, ADMIN_CATALOG, ADMIN_ORGANIZATION, + UPLOAD_VAPP_TEMPLATE_PARAMS, ADMIN_CATALOG, ADMIN_ORG, QUERY_RESULT_RECORDS, QUERY_RESULT_REFERENCES, QUERY_RESULT_ID_RECORDS, CONTROL_ACCESS, VAPP_TEMPLATE, CUSTOMIZATION_SECTION, GUEST_CUSTOMIZATION_SECTION, NETWORK_SECTION, NETWORK_CONFIG_SECTION, NETWORK_CONNECTION_SECTION, CLONE_MEDIA_PARAMS, LEASE_SETTINGS_SECTION, RELOCATE_TEMPLATE, ENVELOPE, PUBLISH_CATALOG_PARAMS, GROUP, ORG_VAPP_TEMPLATE_LEASE_SETTINGS, ORG_LEASE_SETTINGS, ORG_PASSWORD_POLICY_SETTINGS, ORG_LDAP_SETTINGS, - ORG_GENERAL_SETTINGS, ORG_EMAIL_SETTINGS, ORG_SETTINGS + ORG_GENERAL_SETTINGS, ORG_EMAIL_SETTINGS, ORG_SETTINGS, ADMIN_NETWORK, + ADMIN_ORG_NETWORK ); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/AdminOrg.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/AdminOrg.java index a940c0cfca..3caf989887 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/AdminOrg.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/AdminOrg.java @@ -21,6 +21,9 @@ package org.jclouds.vcloud.director.v1_5.domain; import static com.google.common.base.Objects.equal; +import java.net.URI; +import java.util.Set; + import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; @@ -145,7 +148,8 @@ public class AdminOrg extends Org { } public AdminOrg build() { - return new AdminOrg(settings, users, groups, catalogs, vdcs, networks); + return new AdminOrg(href, type, links, description, tasksInProgress, id, + name, fullName, isEnabled, settings, users, groups, catalogs, vdcs, networks); } public T fromAdminOrg(AdminOrg in) { @@ -175,8 +179,11 @@ public class AdminOrg extends Org { // For JAXB } - protected AdminOrg(OrgSettings settings, UsersList users, GroupsList groups, + protected AdminOrg(URI href, String type, Set links, String description, + TasksInProgress tasksInProgress, String id, String name, String fullName, + Boolean enabled, OrgSettings settings, UsersList users, GroupsList groups, CatalogsList catalogs, Vdcs vdcs, Networks networks) { + super(href, type, links, description, tasksInProgress, id, name, fullName, enabled); this.settings = settings; this.users = users; this.groups = groups; diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogsList.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogsList.java index 36ff6d9d65..ee0b2af588 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogsList.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogsList.java @@ -67,6 +67,14 @@ public class CatalogsList { this.catalogReferences = checkNotNull(catalogReferences, "catalogReferences"); return this; } + + /** + * @see CatalogsList#getCatalogItems() + */ + public Builder catalog(Reference catalog) { + this.catalogReferences.add(checkNotNull(catalog, "catalog")); + return this; + } public CatalogsList build() { return new CatalogsList(catalogReferences); @@ -81,7 +89,7 @@ public class CatalogsList { // for JAXB } - private CatalogsList(Set tasks) { + private CatalogsList(Set catalogReferences) { this.catalogReferences = ImmutableSet.copyOf(checkNotNull(catalogReferences, "catalogReferences")); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/GroupsList.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/GroupsList.java index f74d9c6d77..7d2bb4ee40 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/GroupsList.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/GroupsList.java @@ -62,7 +62,7 @@ import com.google.common.collect.ImmutableList; @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement(name = "GroupsList") @XmlType(propOrder = { - "groupReference" + "groups" }) public class GroupsList { public static Builder builder() { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Networks.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Networks.java index 01323bf708..a5558238b2 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Networks.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Networks.java @@ -30,6 +30,8 @@ import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlType; +import org.testng.collections.Lists; + import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.ImmutableList; @@ -62,7 +64,7 @@ import com.google.common.collect.ImmutableList; */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "Networks", propOrder = { - "network" + "networks" }) public class Networks { public static Builder builder() { @@ -75,7 +77,7 @@ public class Networks { public static class Builder { - private List networks; + private List networks = Lists.newArrayList(); /** * @see Networks#getNetwork() diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java index 464208023c..06e54d5852 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java @@ -59,8 +59,8 @@ public class Org extends EntityType { public static abstract class NewBuilder> extends EntityType.NewBuilder { - private String fullName; - private Boolean isEnabled; + protected String fullName; + protected Boolean isEnabled; /** * @see Org#getFullName() @@ -232,8 +232,10 @@ public class Org extends EntityType { // for JAXB } - public Org(URI href, String type, Set links, String description, Set tasks, String id, String name, String fullName, Boolean enabled) { - super(href, type, links, description, tasks, id, name); + public Org(URI href, String type, Set links, String description, + TasksInProgress tasksInProgress, String id, String name, + String fullName, Boolean enabled) { + super(href, type, links, description, tasksInProgress, id, name); this.fullName = fullName; isEnabled = enabled; } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgSettings.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgSettings.java index f4de180a68..7bcc9451fa 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgSettings.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgSettings.java @@ -97,7 +97,7 @@ public class OrgSettings extends ResourceType { /** * @see OrgSettings#getGeneralSettings() */ - public Builder orgGeneralSettings(OrgGeneralSettings generalSettings) { + public Builder generalSettings(OrgGeneralSettings generalSettings) { this.generalSettings = generalSettings; return this; } @@ -121,7 +121,7 @@ public class OrgSettings extends ResourceType { /** * @see OrgSettings#getLdapSettings() */ - public Builder orgLdapSettings(OrgLdapSettings ldapSettings) { + public Builder ldapSettings(OrgLdapSettings ldapSettings) { this.ldapSettings = ldapSettings; return this; } @@ -129,7 +129,7 @@ public class OrgSettings extends ResourceType { /** * @see OrgSettings#getEmailSettings() */ - public Builder orgEmailSettings(OrgEmailSettings emailSettings) { + public Builder emailSettings(OrgEmailSettings emailSettings) { this.emailSettings = emailSettings; return this; } @@ -191,11 +191,11 @@ public class OrgSettings extends ResourceType { } public Builder fromOrgSettings(OrgSettings in) { return fromResourceType(in) - .orgGeneralSettings(in.getGeneralSettings()) + .generalSettings(in.getGeneralSettings()) .vAppLeaseSettings(in.getVAppLeaseSettings()) .vAppTemplateLeaseSettings(in.getVAppTemplateLeaseSettings()) - .orgLdapSettings(in.getLdapSettings()) - .orgEmailSettings(in.getEmailSettings()) + .ldapSettings(in.getLdapSettings()) + .emailSettings(in.getEmailSettings()) .passwordPolicy(in.getPasswordPolicy()); } } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/UsersList.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/UsersList.java index 1e949d30fe..3e57b99809 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/UsersList.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/UsersList.java @@ -31,6 +31,8 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import org.testng.collections.Lists; + import com.google.common.base.Objects; import com.google.common.collect.ImmutableList; @@ -62,7 +64,7 @@ import com.google.common.collect.ImmutableList; @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement(name = "UsersList") @XmlType(propOrder = { - "userReference" + "users" }) public class UsersList { public static Builder builder() { @@ -74,7 +76,7 @@ public class UsersList { } public static class Builder { - private List users; + private List users = Lists.newArrayList(); /** * @see UsersList#getUsers() diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Vdcs.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Vdcs.java index 7d2467abf2..a55af00488 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Vdcs.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Vdcs.java @@ -31,6 +31,8 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import org.testng.collections.Lists; + import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.ImmutableList; @@ -76,7 +78,7 @@ public class Vdcs { public static class Builder { - private List vdcs; + private List vdcs = Lists.newArrayList(); /** * @see Vdcs#getVdc() diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java index eda625bd03..fea0a6d155 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgAsyncClient.java @@ -33,6 +33,7 @@ import org.jclouds.rest.annotations.JAXBResponseParser; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.binders.BindToXMLPayload; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.jclouds.vcloud.director.v1_5.domain.AdminOrg; import org.jclouds.vcloud.director.v1_5.domain.OrgEmailSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgGeneralSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgLdapSettings; @@ -52,11 +53,15 @@ import com.google.common.util.concurrent.ListenableFuture; @RequestFilters(AddVCloudAuthorizationToRequest.class) public interface AdminOrgAsyncClient extends OrgAsyncClient { -// GET /admin/org/{id} - -// POST /admin/org/{id}/catalogs - -// POST /admin/org/{id}/groups + /** + * @see AdminOrgClient#getOrg(URI) + */ + @GET + @Consumes + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture getOrg( + @EndpointParam URI orgRef); /** * @see AdminOrgClient#getSettings(URI) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java index af752307ce..471572b512 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClient.java @@ -22,6 +22,7 @@ import java.net.URI; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; +import org.jclouds.vcloud.director.v1_5.domain.AdminOrg; import org.jclouds.vcloud.director.v1_5.domain.Group; import org.jclouds.vcloud.director.v1_5.domain.OrgEmailSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgGeneralSettings; @@ -40,11 +41,19 @@ import org.jclouds.vcloud.director.v1_5.domain.OrgVAppTemplateLeaseSettings; @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) public interface AdminOrgClient extends OrgClient { -// GET /admin/org/{id} - -// POST /admin/org/{id}/catalogs - -// POST /admin/org/{id}/groups + /** + * Retrieves an admin view of an organization. + * The organization might be enabled or disabled. + * If enabled, the organization allows login and all other operations. + * + *
+    * GET /admin/org/{id}
+    * 
+ * + * @param orgRef the reference for the admin org + * @return the admin org + */ + AdminOrg getOrg(URI orgRef); /** * Gets organizational settings for this organization. diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgAsyncClient.java index fa1e7cda69..98dc3bb731 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/OrgAsyncClient.java @@ -60,7 +60,7 @@ public interface OrgAsyncClient { @Consumes @JAXBResponseParser @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture getOrg(@EndpointParam URI orgUri); + ListenableFuture getOrg(@EndpointParam URI orgUri); /** * @return asynchronous access to {@link Metadata.Readable} features diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java index 13c1ba76bc..d6f966d534 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java @@ -232,6 +232,46 @@ public class Checks { checkEntityType(org); } + public static void checkAdminOrg(AdminOrg org) { + // required + assertNotNull(org.getSettings(), String.format(NOT_NULL_OBJECT_FMT, "settings", "AdminOrg")); + + // optional + if (org.getGroups() != null) { + checkGroupsList(org.getGroups()); + } + if (org.getCatalogs() != null) { + checkCatalogsList(org.getCatalogs()); + } + if (org.getVdcs() != null) { + checkVdcs(org.getVdcs()); + } + if (org.getNetworks() != null) { + checkNetworks(org.getNetworks()); + } + + // Check parent type + checkOrg(org); + } + + public static void checkCatalogsList(CatalogsList catalogList) { + for (Reference catalogItem : catalogList.getCatalogItems()) { + checkReferenceType(catalogItem); + } + } + + public static void checkVdcs(Vdcs vdcs) { + for (Reference vdc : vdcs.getVdcs()) { + checkReferenceType(vdc); + } + } + + public static void checkNetworks(Networks networks) { + for (Reference network : networks.getNetwork()) { + checkReferenceType(network); + } + } + public static void checkAdminCatalog(AdminCatalog catalog) { // Check parent type checkCatalogType(catalog); 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 ddd092a076..0ec249dfce 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 @@ -24,7 +24,11 @@ import java.net.URI; import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.jclouds.vcloud.director.v1_5.domain.AdminOrg; +import org.jclouds.vcloud.director.v1_5.domain.CatalogsList; +import org.jclouds.vcloud.director.v1_5.domain.GroupsList; import org.jclouds.vcloud.director.v1_5.domain.Link; +import org.jclouds.vcloud.director.v1_5.domain.Networks; import org.jclouds.vcloud.director.v1_5.domain.OrgEmailSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgGeneralSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgLdapSettings; @@ -34,6 +38,8 @@ import org.jclouds.vcloud.director.v1_5.domain.OrgSettings; 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.domain.UsersList; +import org.jclouds.vcloud.director.v1_5.domain.Vdcs; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; import org.testng.annotations.Test; @@ -49,13 +55,151 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect .href(URI.create(endpoint + "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) .build(); -// GET /admin/org/{id} - -// POST /admin/org/{id}/catalogs - -// POST /admin/org/{id}/groups - @Test + public void testGetOrg() { + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("GET", "/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0") + .acceptAnyMedia() + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/org/admin/org.xml", + VCloudDirectorMediaType.ADMIN_ORG) + .httpResponseBuilder().build()); + + AdminOrg expected = adminOrg(); + + assertEquals(client.getAdminOrgClient().getOrg(orgRef.getURI()), expected); + } + + public static final AdminOrg adminOrg() { + return AdminOrg.builder() + .name("JClouds") + .id("urn:vcloud:org:6f312e42-cd2b-488d-a2bb-97519cd57ed0") + .type("application/vnd.vmware.admin.organization+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.vcloud.tasksList+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/tasksList/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .build()) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.vcloud.metadata+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata")) + .build()) + .link(Link.builder() + .rel("add") + .type("application/vnd.vmware.admin.catalog+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/catalogs")) + .build()) + .link(Link.builder() + .rel("add") + .type("application/vnd.vmware.admin.user+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/users")) + .build()) + .link(Link.builder() + .rel("add") + .type("application/vnd.vmware.admin.group+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/groups")) + .build()) + .link(Link.builder() + .rel("add") + .type("application/vnd.vmware.admin.orgNetwork+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/networks")) + .build()) + .link(Link.builder() + .rel("edit") + .type("application/vnd.vmware.admin.organization+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .build()) + .link(Link.builder() + .rel("remove") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .build()) + .link(Link.builder() + .rel("alternate") + .type("application/vnd.vmware.vcloud.org+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) + .build()) + .description("") + .fullName("JClouds") + .isEnabled(true) + .settings(settings()) + .users(UsersList.builder() + .user(Reference.builder() + .type("application/vnd.vmware.admin.user+xml") + .name("adam.lowe@cloudsoftcorp.com") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/672ebb67-d8ff-4201-9c1b-c1be869e526c")) + .build()) + .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()) + .user(Reference.builder() + .type("application/vnd.vmware.admin.user+xml") + .name("qunying.huang@enstratus.com") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/967d317c-4273-4a95-b8a4-bf63b78e9c69")) + .build()) + .user(Reference.builder() + .type("application/vnd.vmware.admin.user+xml") + .name("dan@cloudsoftcorp.com") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/ae75edd2-12de-414c-8e85-e6ea10442c08")) + .build()) + .user(Reference.builder() + .type("application/vnd.vmware.admin.user+xml") + .name("adk@cloudsoftcorp.com") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/user/e9eb1b29-0404-4c5e-8ef7-e584acc51da9")) + .build()) + .build()) + .groups(GroupsList.builder() + .build()) + .catalogs(CatalogsList.builder() + .catalog(Reference.builder() + .type("application/vnd.vmware.admin.catalog+xml") + .name("QunyingTestCatalog") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4")) + .build()) + .catalog(Reference.builder() + .type("application/vnd.vmware.admin.catalog+xml") + .name("Public") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c")) + .build()) + .catalog(Reference.builder() + .type("application/vnd.vmware.admin.catalog+xml") + .name("dantest") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/catalog/b542aff4-9f97-4f51-a126-4330fbf62f02")) + .build()) + .catalog(Reference.builder() + .type("application/vnd.vmware.admin.catalog+xml") + .name("test") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/catalog/b7289d54-4ca4-497f-9a93-2d4afc97e3da")) + .build()) + .build()) + .vdcs(Vdcs.builder() + .vdc(Reference.builder() + .type("application/vnd.vmware.vcloud.vdc+xml") + .name("Cluster01-JClouds") + .href(URI.create("https://vcloudbeta.bluelock.com/api/vdc/d16d333b-e3c0-4176-845d-a5ee6392df07")) + .build()) + .build()) + .networks(Networks.builder() + .network(Reference.builder() + .type("application/vnd.vmware.admin.network+xml") + .name("ilsolation01-Jclouds") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/network/f3ba8256-6f48-4512-aad6-600e85b4dc38")) + .build()) + .network(Reference.builder() + .type("application/vnd.vmware.admin.network+xml") + .name("internet01-Jclouds") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/network/55a677cf-ab3f-48ae-b880-fab90421980c")) + .build()) + .build()) + .build(); + } + + @Test(enabled = false) public void testGetSettings() { VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, new VcloudHttpRequestPrimer() @@ -74,18 +218,53 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect public static final OrgSettings settings() { return OrgSettings.builder() - .type("application/vnd.vmware.admin.organizationSettings+xml") - .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/")) + .type("application/vnd.vmware.admin.orgSettings+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings")) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.admin.vAppTemplateLeaseSettings+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/vAppTemplateLeaseSettings")) + .build()) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.admin.organizationEmailSettings+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/email")) + .build()) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.admin.vAppLeaseSettings+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/vAppLeaseSettings")) + .build()) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.admin.organizationPasswordPolicySettings+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/passwordPolicy")) + .build()) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.admin.organizationGeneralSettings+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/general")) + .build()) + .link(Link.builder() + .rel("down") + .type("application/vnd.vmware.admin.organizationLdapSettings+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/ldap")) + .build()) .link(Link.builder() .rel("edit") - .type("application/vnd.vmware.admin.organizationSettings+xml") - .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/")) + .type("application/vnd.vmware.admin.orgSettings+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings")) .build()) - + .generalSettings(generalSettings()) + .vAppLeaseSettings(vAppLeaseSettings()) + .vAppTemplateLeaseSettings(vAppTemplateLeaseSettings()) + .ldapSettings(ldapSettings()) + .emailSettings(emailSettings()) + .passwordPolicy(passwordPolicy()) .build(); } - @Test + @Test(enabled = false) public void testUpdateSettings() { VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, new VcloudHttpRequestPrimer() @@ -204,7 +383,18 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect public static final OrgGeneralSettings generalSettings() { return OrgGeneralSettings.builder() - + .type("application/vnd.vmware.admin.organizationGeneralSettings+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/general")) + .link(Link.builder() + .rel("edit") + .type("application/vnd.vmware.admin.organizationGeneralSettings+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/general")) + .build()) + .canPublishCatalogs(false) + .deployedVMQuota(0) + .storedVmQuota(0) + .useServerBootSequence(false) + .delayAfterPowerOnSeconds(0) .build(); } @@ -270,12 +460,12 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect VCloudDirectorMediaType.ORG_PASSWORD_POLICY_SETTINGS) .httpResponseBuilder().build()); - OrgPasswordPolicySettings expected = orgPasswordPolicy(); + OrgPasswordPolicySettings expected = passwordPolicy(); assertEquals(client.getAdminOrgClient().getPasswordPolicy(orgRef.getURI()), expected); } - public static final OrgPasswordPolicySettings orgPasswordPolicy() { + public static final OrgPasswordPolicySettings passwordPolicy() { return OrgPasswordPolicySettings.builder() .type("application/vnd.vmware.admin.organizationPasswordPolicySettings+xml") .link(Link.builder() @@ -310,7 +500,7 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect } public static final OrgPasswordPolicySettings updateOrgPasswordPolicy() { - return orgPasswordPolicy().toBuilder() + return passwordPolicy().toBuilder() .accountLockoutEnabled(true) .invalidLoginsBeforeLockout(6) .accountLockoutIntervalMinutes(11) @@ -329,14 +519,23 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect VCloudDirectorMediaType.ORG_LEASE_SETTINGS) .httpResponseBuilder().build()); - OrgLeaseSettings expected = orgVAppLeaseSettings(); + OrgLeaseSettings expected = vAppLeaseSettings(); assertEquals(client.getAdminOrgClient().getVAppLeaseSettings(orgRef.getURI()), expected); } - public static final OrgLeaseSettings orgVAppLeaseSettings() { + public static final OrgLeaseSettings vAppLeaseSettings() { return OrgLeaseSettings.builder() - + .type("application/vnd.vmware.admin.vAppLeaseSettings+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/vAppLeaseSettings")) + .link(Link.builder() + .rel("edit") + .type("application/vnd.vmware.admin.vAppLeaseSettings+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/vAppLeaseSettings")) + .build()) + .deleteOnStorageLeaseExpiration(false) + .deploymentLeaseSeconds(0) + .storageLeaseSeconds(0) .build(); } @@ -354,13 +553,13 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect VCloudDirectorMediaType.ORG_LEASE_SETTINGS) .httpResponseBuilder().build()); - OrgLeaseSettings expected = updateOrgVAppLeaseSettings(); + OrgLeaseSettings expected = updateVAppLeaseSettings(); assertEquals(client.getAdminOrgClient().updateVAppLeaseSettings(orgRef.getURI(), expected), expected); } - public static final OrgLeaseSettings updateOrgVAppLeaseSettings() { - return orgVAppLeaseSettings().toBuilder() + public static final OrgLeaseSettings updateVAppLeaseSettings() { + return vAppLeaseSettings().toBuilder() .build(); } @@ -377,14 +576,22 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect VCloudDirectorMediaType.ORG_VAPP_TEMPLATE_LEASE_SETTINGS) .httpResponseBuilder().build()); - OrgVAppTemplateLeaseSettings expected = orgVAppTemplateLeaseSettings(); + OrgVAppTemplateLeaseSettings expected = vAppTemplateLeaseSettings(); assertEquals(client.getAdminOrgClient().getVAppTemplateLeaseSettings(orgRef.getURI()), expected); } - public static final OrgVAppTemplateLeaseSettings orgVAppTemplateLeaseSettings() { + public static final OrgVAppTemplateLeaseSettings vAppTemplateLeaseSettings() { return OrgVAppTemplateLeaseSettings.builder() - + .type("application/vnd.vmware.admin.vAppTemplateLeaseSettings+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/vAppTemplateLeaseSettings")) + .link(Link.builder() + .rel("edit") + .type("application/vnd.vmware.admin.vAppTemplateLeaseSettings+xml") + .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/vAppTemplateLeaseSettings")) + .build()) + .deleteOnStorageLeaseExpiration(false) + .storageLeaseSeconds(0) .build(); } @@ -402,13 +609,13 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect VCloudDirectorMediaType.ORG_VAPP_TEMPLATE_LEASE_SETTINGS) .httpResponseBuilder().build()); - OrgVAppTemplateLeaseSettings expected = updateOrgVAppTemplateLeaseSettings(); + OrgVAppTemplateLeaseSettings expected = updateVAppTemplateLeaseSettings(); assertEquals(client.getAdminOrgClient().updateVAppTemplateLeaseSettings(orgRef.getURI(), expected), expected); } - public static final OrgVAppTemplateLeaseSettings updateOrgVAppTemplateLeaseSettings() { - return orgVAppTemplateLeaseSettings().toBuilder() + public static final OrgVAppTemplateLeaseSettings updateVAppTemplateLeaseSettings() { + return vAppTemplateLeaseSettings().toBuilder() .build(); } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java index 17d2be7297..d174978356 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java @@ -59,7 +59,6 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { * Shared state between dependant tests. */ private ReferenceType orgRef; - private AdminOrg org; private OrgSettings settings, newSettings; private OrgEmailSettings emailSettings, newEmailSettings; private OrgGeneralSettings generalSettings, newGeneralSettings; @@ -76,14 +75,13 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { assertNotNull(orgRef, String.format(REF_REQ_LIVE, "admin org")); } -// GET /admin/org/{id} + @Test(testName = "GET /admin/org/{id}") + public void testGetAdminOrg() { + AdminOrg adminOrg = orgClient.getOrg(orgRef.getURI()); + + Checks.checkAdminOrg(adminOrg); + } -// POST /admin/org/{id}/catalogs - -// POST /admin/org/{id}/groups - - - @Test(testName = "GET /admin/org/{id}/settings/emailSettings") public void testGetEmailSettings() { emailSettings = orgClient.getEmailSettings(orgRef.getURI()); @@ -391,11 +389,11 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { public void testUpdateSettings() { try { newSettings = settings.toBuilder() - .orgGeneralSettings(newGeneralSettings) + .generalSettings(newGeneralSettings) .vAppLeaseSettings(newVAppLeaseSettings) .vAppTemplateLeaseSettings(newVAppTemplateLeaseSettings) - .orgLdapSettings(newLdapSettings) - .orgEmailSettings(newEmailSettings) + .ldapSettings(newLdapSettings) + .emailSettings(newEmailSettings) .passwordPolicy(newPasswordPolicy) .build(); @@ -426,11 +424,11 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { Checks.checkOrgSettings(settings); } finally { settings = settings.toBuilder() - .orgGeneralSettings(generalSettings) + .generalSettings(generalSettings) .vAppLeaseSettings(vAppLeaseSettings) .vAppTemplateLeaseSettings(vAppTemplateLeaseSettings) - .orgLdapSettings(ldapSettings) - .orgEmailSettings(emailSettings) + .ldapSettings(ldapSettings) + .emailSettings(emailSettings) .passwordPolicy(passwordPolicy) .build(); diff --git a/labs/vcloud-director/src/test/resources/org/admin/org.xml b/labs/vcloud-director/src/test/resources/org/admin/org.xml new file mode 100644 index 0000000000..5e0ee14a4f --- /dev/null +++ b/labs/vcloud-director/src/test/resources/org/admin/org.xml @@ -0,0 +1,86 @@ + + + + + + + + + + + + + JClouds + true + + + + + + + + + + + false + 0 + 0 + false + 0 + + + + false + 0 + 0 + + + + false + 0 + + + NONE + + + + true + true + + + true + + false + + + + + + + false + 5 + 10 + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 24db1774eb441fddafc55e66133aa1ed0aea147a Mon Sep 17 00:00:00 2001 From: danikov Date: Mon, 12 Mar 2012 03:20:32 +0000 Subject: [PATCH 10/10] org fix --- .../vcloud/director/v1_5/domain/AdminOrg.java | 6 +-- .../vcloud/director/v1_5/domain/Org.java | 2 +- .../features/AdminOrgClientExpectTest.java | 28 +++++------ .../v1_5/features/AdminOrgClientLiveTest.java | 46 ++++++++++--------- 4 files changed, 42 insertions(+), 40 deletions(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/AdminOrg.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/AdminOrg.java index 3caf989887..d515889d09 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/AdminOrg.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/AdminOrg.java @@ -148,7 +148,7 @@ public class AdminOrg extends Org { } public AdminOrg build() { - return new AdminOrg(href, type, links, description, tasksInProgress, id, + return new AdminOrg(href, type, links, description, tasks, id, name, fullName, isEnabled, settings, users, groups, catalogs, vdcs, networks); } @@ -180,10 +180,10 @@ public class AdminOrg extends Org { } protected AdminOrg(URI href, String type, Set links, String description, - TasksInProgress tasksInProgress, String id, String name, String fullName, + Set tasks, String id, String name, String fullName, Boolean enabled, OrgSettings settings, UsersList users, GroupsList groups, CatalogsList catalogs, Vdcs vdcs, Networks networks) { - super(href, type, links, description, tasksInProgress, id, name, fullName, enabled); + super(href, type, links, description, tasks, id, name, fullName, enabled); this.settings = settings; this.users = users; this.groups = groups; diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java index 06e54d5852..368d8024f1 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java @@ -233,7 +233,7 @@ public class Org extends EntityType { } public Org(URI href, String type, Set links, String description, - TasksInProgress tasksInProgress, String id, String name, + Set tasksInProgress, String id, String name, String fullName, Boolean enabled) { super(href, type, links, description, tasksInProgress, id, name); this.fullName = fullName; 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 0ec249dfce..f2cd65ddf8 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 @@ -69,7 +69,7 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect AdminOrg expected = adminOrg(); - assertEquals(client.getAdminOrgClient().getOrg(orgRef.getURI()), expected); + assertEquals(client.getAdminOrgClient().getOrg(orgRef.getHref()), expected); } public static final AdminOrg adminOrg() { @@ -213,7 +213,7 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect OrgSettings expected = settings(); - assertEquals(client.getAdminOrgClient().getSettings(orgRef.getURI()), expected); + assertEquals(client.getAdminOrgClient().getSettings(orgRef.getHref()), expected); } public static final OrgSettings settings() { @@ -280,7 +280,7 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect OrgSettings expected = updateSettings(); - assertEquals(client.getAdminOrgClient().updateSettings(orgRef.getURI(), expected), expected); + assertEquals(client.getAdminOrgClient().updateSettings(orgRef.getHref(), expected), expected); } @Test @@ -303,7 +303,7 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect OrgEmailSettings expected = emailSettings(); - assertEquals(client.getAdminOrgClient().getEmailSettings(orgRef.getURI()), expected); + assertEquals(client.getAdminOrgClient().getEmailSettings(orgRef.getHref()), expected); } public static final OrgEmailSettings emailSettings() { @@ -345,7 +345,7 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect OrgEmailSettings expected = updateEmailSettings(); - assertEquals(client.getAdminOrgClient().updateEmailSettings(orgRef.getURI(), expected), expected); + assertEquals(client.getAdminOrgClient().updateEmailSettings(orgRef.getHref(), expected), expected); } @Test @@ -378,7 +378,7 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect OrgGeneralSettings expected = generalSettings(); - assertEquals(client.getAdminOrgClient().getGeneralSettings(orgRef.getURI()), expected); + assertEquals(client.getAdminOrgClient().getGeneralSettings(orgRef.getHref()), expected); } public static final OrgGeneralSettings generalSettings() { @@ -414,7 +414,7 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect OrgGeneralSettings expected = updateGeneralSettings(); - assertEquals(client.getAdminOrgClient().updateGeneralSettings(orgRef.getURI(), expected), expected); + assertEquals(client.getAdminOrgClient().updateGeneralSettings(orgRef.getHref(), expected), expected); } public static final OrgGeneralSettings updateGeneralSettings() { @@ -437,7 +437,7 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect OrgLdapSettings expected = ldapSettings(); - assertEquals(client.getAdminOrgClient().getLdapSettings(orgRef.getURI()), expected); + assertEquals(client.getAdminOrgClient().getLdapSettings(orgRef.getHref()), expected); } public static final OrgLdapSettings ldapSettings() { @@ -462,7 +462,7 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect OrgPasswordPolicySettings expected = passwordPolicy(); - assertEquals(client.getAdminOrgClient().getPasswordPolicy(orgRef.getURI()), expected); + assertEquals(client.getAdminOrgClient().getPasswordPolicy(orgRef.getHref()), expected); } public static final OrgPasswordPolicySettings passwordPolicy() { @@ -496,7 +496,7 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect OrgPasswordPolicySettings expected = updateOrgPasswordPolicy(); - assertEquals(client.getAdminOrgClient().updatePasswordPolicy(orgRef.getURI(), expected), expected); + assertEquals(client.getAdminOrgClient().updatePasswordPolicy(orgRef.getHref(), expected), expected); } public static final OrgPasswordPolicySettings updateOrgPasswordPolicy() { @@ -521,7 +521,7 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect OrgLeaseSettings expected = vAppLeaseSettings(); - assertEquals(client.getAdminOrgClient().getVAppLeaseSettings(orgRef.getURI()), expected); + assertEquals(client.getAdminOrgClient().getVAppLeaseSettings(orgRef.getHref()), expected); } public static final OrgLeaseSettings vAppLeaseSettings() { @@ -555,7 +555,7 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect OrgLeaseSettings expected = updateVAppLeaseSettings(); - assertEquals(client.getAdminOrgClient().updateVAppLeaseSettings(orgRef.getURI(), expected), expected); + assertEquals(client.getAdminOrgClient().updateVAppLeaseSettings(orgRef.getHref(), expected), expected); } public static final OrgLeaseSettings updateVAppLeaseSettings() { @@ -578,7 +578,7 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect OrgVAppTemplateLeaseSettings expected = vAppTemplateLeaseSettings(); - assertEquals(client.getAdminOrgClient().getVAppTemplateLeaseSettings(orgRef.getURI()), expected); + assertEquals(client.getAdminOrgClient().getVAppTemplateLeaseSettings(orgRef.getHref()), expected); } public static final OrgVAppTemplateLeaseSettings vAppTemplateLeaseSettings() { @@ -611,7 +611,7 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect OrgVAppTemplateLeaseSettings expected = updateVAppTemplateLeaseSettings(); - assertEquals(client.getAdminOrgClient().updateVAppTemplateLeaseSettings(orgRef.getURI(), expected), expected); + assertEquals(client.getAdminOrgClient().updateVAppTemplateLeaseSettings(orgRef.getHref(), expected), expected); } public static final OrgVAppTemplateLeaseSettings updateVAppTemplateLeaseSettings() { diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java index d174978356..5ce9522ec4 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/AdminOrgClientLiveTest.java @@ -18,11 +18,13 @@ */ package org.jclouds.vcloud.director.v1_5.features; +import static com.google.common.base.Objects.equal; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_UPDATABLE; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.REF_REQ_LIVE; import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + import org.jclouds.vcloud.director.v1_5.domain.AdminOrg; -import org.jclouds.vcloud.director.v1_5.domain.Error; -import org.jclouds.vcloud.director.v1_5.domain.Group; import org.jclouds.vcloud.director.v1_5.domain.Checks; import org.jclouds.vcloud.director.v1_5.domain.OrgEmailSettings; import org.jclouds.vcloud.director.v1_5.domain.OrgGeneralSettings; @@ -77,14 +79,14 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { @Test(testName = "GET /admin/org/{id}") public void testGetAdminOrg() { - AdminOrg adminOrg = orgClient.getOrg(orgRef.getURI()); + AdminOrg adminOrg = orgClient.getOrg(orgRef.getHref()); Checks.checkAdminOrg(adminOrg); } @Test(testName = "GET /admin/org/{id}/settings/emailSettings") public void testGetEmailSettings() { - emailSettings = orgClient.getEmailSettings(orgRef.getURI()); + emailSettings = orgClient.getEmailSettings(orgRef.getHref()); Checks.checkEmailSettings(emailSettings); } @@ -118,7 +120,7 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { .build(); emailSettings = orgClient.updateEmailSettings( - orgRef.getURI(), newEmailSettings); + orgRef.getHref(), newEmailSettings); assertTrue(equal(emailSettings.isDefaultSmtpServer(), !isDefaultSmtpServer), String.format(OBJ_FIELD_UPDATABLE, @@ -153,13 +155,13 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { .build(); emailSettings = orgClient.updateEmailSettings( - orgRef.getURI(), emailSettings); + orgRef.getHref(), emailSettings); } } @Test(testName = "GET /admin/org/{id}/settings/generalSettings") public void testGetGeneralSettings() { - generalSettings = orgClient.getGeneralSettings(orgRef.getURI()); + generalSettings = orgClient.getGeneralSettings(orgRef.getHref()); Checks.checkGeneralSettings(generalSettings); } @@ -183,7 +185,7 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { .build(); generalSettings = orgClient.updateGeneralSettings( - orgRef.getURI(), newGeneralSettings); + orgRef.getHref(), newGeneralSettings); // assertTrue(equal(generalSettings.canPublishCatalogs(), !canPublishCatalogs), // String.format(OBJ_FIELD_UPDATABLE, @@ -214,20 +216,20 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { .build(); generalSettings = orgClient.updateGeneralSettings( - orgRef.getURI(), generalSettings); + orgRef.getHref(), generalSettings); } } @Test(testName = "GET /admin/org/{id}/settings/ldap") public void testGetLdapSettings() { - ldapSettings = orgClient.getLdapSettings(orgRef.getURI()); + ldapSettings = orgClient.getLdapSettings(orgRef.getHref()); Checks.checkLdapSettings(ldapSettings); } @Test(testName = "GET /admin/org/{id}/settings/passwordPolicy") public void testGetPasswordPolicy() { - passwordPolicy = orgClient.getPasswordPolicy(orgRef.getURI()); + passwordPolicy = orgClient.getPasswordPolicy(orgRef.getHref()); Checks.checkPasswordPolicySettings(passwordPolicy); } @@ -247,7 +249,7 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { .build(); passwordPolicy = orgClient.updatePasswordPolicy( - orgRef.getURI(), newPasswordPolicy); + orgRef.getHref(), newPasswordPolicy); assertTrue(equal(passwordPolicy.isAccountLockoutEnabled(), !accountLockoutEnabled), String.format(OBJ_FIELD_UPDATABLE, @@ -270,13 +272,13 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { .build(); passwordPolicy = orgClient.updatePasswordPolicy( - orgRef.getURI(), passwordPolicy); + orgRef.getHref(), passwordPolicy); } } @Test(testName = "GET /admin/org/{id}/settings/vAppLeaseSettings") public void testGetVAppLeaseSettings() { - vAppLeaseSettings = orgClient.getVAppLeaseSettings(orgRef.getURI()); + vAppLeaseSettings = orgClient.getVAppLeaseSettings(orgRef.getHref()); Checks.checkVAppLeaseSettings(vAppLeaseSettings); } @@ -296,7 +298,7 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { .build(); vAppLeaseSettings = orgClient.updateVAppLeaseSettings( - orgRef.getURI(), newVAppLeaseSettings); + orgRef.getHref(), newVAppLeaseSettings); assertTrue(equal(vAppLeaseSettings.deleteOnStorageLeaseExpiration(), !deleteOnStorageLeaseExpiration), String.format(OBJ_FIELD_UPDATABLE, @@ -319,13 +321,13 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { .build(); vAppLeaseSettings = orgClient.updateVAppLeaseSettings( - orgRef.getURI(), vAppLeaseSettings); + orgRef.getHref(), vAppLeaseSettings); } } @Test(testName = "GET /admin/org/{id}/settings/vAppTemplateLeaseSettings") public void testGetVAppTemplateLeaseSettings() { - vAppTemplateLeaseSettings = orgClient.getVAppTemplateLeaseSettings(orgRef.getURI()); + vAppTemplateLeaseSettings = orgClient.getVAppTemplateLeaseSettings(orgRef.getHref()); Checks.checkVAppTemplateLeaseSettings(vAppTemplateLeaseSettings); } @@ -343,7 +345,7 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { .build(); vAppTemplateLeaseSettings = orgClient.updateVAppTemplateLeaseSettings( - orgRef.getURI(), newVAppTemplateLeaseSettings); + orgRef.getHref(), newVAppTemplateLeaseSettings); assertTrue(equal(vAppTemplateLeaseSettings.deleteOnStorageLeaseExpiration(), !deleteOnStorageLeaseExpiration), String.format(OBJ_FIELD_UPDATABLE, @@ -362,7 +364,7 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { .build(); vAppTemplateLeaseSettings = orgClient.updateVAppTemplateLeaseSettings( - orgRef.getURI(), vAppTemplateLeaseSettings); + orgRef.getHref(), vAppTemplateLeaseSettings); } } @@ -374,7 +376,7 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { "testGetEmailSettings", "testGetPasswordPolicy"}) public void testGetSettings() { - settings = orgClient.getSettings(orgRef.getURI()); + settings = orgClient.getSettings(orgRef.getHref()); Checks.checkOrgSettings(settings); } @@ -398,7 +400,7 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { .build(); settings = orgClient.updateSettings( - orgRef.getURI(), newSettings); + orgRef.getHref(), newSettings); assertTrue(equal(settings.getGeneralSettings(), newGeneralSettings), String.format(OBJ_FIELD_UPDATABLE, @@ -433,7 +435,7 @@ public class AdminOrgClientLiveTest extends BaseVCloudDirectorClientLiveTest { .build(); settings = orgClient.updateSettings( - orgRef.getURI(), settings); + orgRef.getHref(), settings); } } }