get/put emailSettings

This commit is contained in:
danikov 2012-03-11 18:46:35 +00:00
parent 8e5ec325ae
commit 4077e2d9a4
10 changed files with 258 additions and 28 deletions

View File

@ -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
);
}

View File

@ -76,7 +76,7 @@ import com.google.common.collect.ImmutableList;
"fromEmailAddress",
"defaultSubjectPrefix",
"isAlertEmailToAllAdmins",
"alertEmailTo",
"alertEmailsTo",
"smtpServerSettings"
})
public class OrgEmailSettings extends ResourceType<OrgEmailSettings> {
@ -142,7 +142,7 @@ public class OrgEmailSettings extends ResourceType<OrgEmailSettings> {
* @see OrgEmailSettings#getAlertEmailTo()
*/
public Builder alertEmailsTo(List<String> 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<OrgEmailSettings> {
}
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<OrgEmailSettings> {
// For JAXB
}
private OrgEmailSettings(boolean isDefaultSmtpServer, boolean isDefaultOrgEmail,
private OrgEmailSettings(URI href, String type, Set<Link> links,
boolean isDefaultSmtpServer, boolean isDefaultOrgEmail,
String fromEmailAddress, String defaultSubjectPrefix, boolean isAlertEmailToAllAdmins,
List<String> 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<OrgEmailSettings> {
*
*/
public List<String> getAlertEmailsTo() {
if (alertEmailsTo == null) {
alertEmailsTo = new ArrayList<String>();
}
return this.alertEmailsTo;
}

View File

@ -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);

View File

@ -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
/**
* @see AdminOrgClient#getEmailSettings(URI)
*/
@GET
@Path("/settings/email")
@Consumes
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<OrgEmailSettings> getEmailSettings(
@EndpointParam URI orgRef);
// PUT /admin/org/{id}/settings/email
/**
* @see AdminOrgClient#updateEmailSettings(URI, OrgEmailSettings)
*/
@PUT
@Path("/settings/email")
@Consumes(VCloudDirectorMediaType.ORG_EMAIL_SETTINGS)
@Produces(VCloudDirectorMediaType.ORG_EMAIL_SETTINGS)
@JAXBResponseParser
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<OrgEmailSettings> updateEmailSettings(
@EndpointParam URI orgRef,
@BinderParam(BindToXMLPayload.class) OrgEmailSettings settings);
/**
* @see AdminOrgClient#getGeneralSettings(URI)

View File

@ -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.
*
* <pre>
* GET /admin/org/{id}/settings/email
* </pre>
*
* @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.
*
* <pre>
* PUT /admin/org/{id}/settings/email
* </pre>
* @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.

View File

@ -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,9 +58,80 @@ public class AdminOrgClientExpectTest extends BaseVCloudDirectorRestClientExpect
// PUT /admin/org/{id}/settings
// GET /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());
// PUT /admin/org/{id}/settings/email
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() {

View File

@ -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
@Test(testName = "GET /admin/org/{id}/settings/emailSettings")
public void testGetEmailSettings() {
emailSettings = orgClient.getEmailSettings(orgRef.getURI());
// PUT /admin/org/{id}/settings/email
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() {

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<OrgEmailSettings xmlns="http://www.vmware.com/vcloud/v1.5" type="application/vnd.vmware.admin.organizationEmailSettings+xml" href="https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/email" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://vcloudbeta.bluelock.com/api/v1.5/schema/master.xsd">
<Link rel="edit" type="application/vnd.vmware.admin.organizationEmailSettings+xml" href="https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/email"/>
<IsDefaultSmtpServer>true</IsDefaultSmtpServer>
<IsDefaultOrgEmail>true</IsDefaultOrgEmail>
<FromEmailAddress/>
<DefaultSubjectPrefix/>
<IsAlertEmailToAllAdmins>true</IsAlertEmailToAllAdmins>
<SmtpServerSettings>
<IsUseAuthentication>false</IsUseAuthentication>
<Host/>
<Username/>
</SmtpServerSettings>
</OrgEmailSettings>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<OrgEmailSettings xmlns="http://www.vmware.com/vcloud/v1.5" type="application/vnd.vmware.admin.organizationEmailSettings+xml" href="https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/email" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://vcloudbeta.bluelock.com/api/v1.5/schema/master.xsd">
<Link rel="edit" type="application/vnd.vmware.admin.organizationEmailSettings+xml" href="https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/email"/>
<IsDefaultSmtpServer>false</IsDefaultSmtpServer>
<IsDefaultOrgEmail>false</IsDefaultOrgEmail>
<FromEmailAddress>test@test.com</FromEmailAddress>
<DefaultSubjectPrefix>new</DefaultSubjectPrefix>
<IsAlertEmailToAllAdmins>false</IsAlertEmailToAllAdmins>
<SmtpServerSettings>
<IsUseAuthentication>true</IsUseAuthentication>
<Host>new</Host>
<Username>new</Username>
</SmtpServerSettings>
</OrgEmailSettings>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<OrgEmailSettings type="application/vnd.vmware.admin.organizationEmailSettings+xml" href="https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/email" xmlns="http://www.vmware.com/vcloud/v1.5">
<Link rel="edit" type="application/vnd.vmware.admin.organizationEmailSettings+xml" href="https://vcloudbeta.bluelock.com/api/admin/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/settings/email"/>
<IsDefaultSmtpServer>false</IsDefaultSmtpServer>
<IsDefaultOrgEmail>false</IsDefaultOrgEmail>
<FromEmailAddress>test@test.com</FromEmailAddress>
<DefaultSubjectPrefix>new</DefaultSubjectPrefix>
<IsAlertEmailToAllAdmins>false</IsAlertEmailToAllAdmins>
<SmtpServerSettings>
<IsUseAuthentication>true</IsUseAuthentication>
<Host>new</Host>
<Username>new</Username>
</SmtpServerSettings>
</OrgEmailSettings>