Search in sources :

Example 1 with IEmailConfiguration

use of org.pentaho.platform.api.email.IEmailConfiguration in project pentaho-platform by pentaho.

the class EmailServiceIT method testEmailConfig.

public void testEmailConfig() throws Exception {
    assertTrue(defaultConfigFile.delete());
    assertFalse(defaultConfigFile.exists());
    final EmailResource emailResource = new EmailResource();
    final IEmailConfiguration emptyEmailConfig = emailResource.getEmailConfig();
    assertTrue(new EmailConfiguration().equals(emptyEmailConfig));
    // Create an email config to save
    assertFalse(defaultConfigFile.exists());
    final EmailConfiguration newEmailConfig = new EmailConfiguration();
    newEmailConfig.setSmtpProtocol("smtp");
    newEmailConfig.setSmtpPort(35);
    newEmailConfig.setAuthenticate(true);
    newEmailConfig.setUserId("test_user");
    final Response OK_RESPONSE = Response.ok().build();
    final Response actual = emailResource.setEmailConfig(newEmailConfig);
    assertEquals(OK_RESPONSE.getStatus(), actual.getStatus());
    // Get the email config and compare the values
    assertTrue(defaultConfigFile.exists());
    final IEmailConfiguration actualEmailConfig = emailResource.getEmailConfig();
    assertTrue(newEmailConfig.equals(actualEmailConfig));
    // Update the config
    newEmailConfig.setSmtpPort(36);
    newEmailConfig.setUserId("");
    newEmailConfig.setPassword("password");
    assertEquals(OK_RESPONSE.getStatus(), emailResource.setEmailConfig(newEmailConfig).getStatus());
    assertTrue(newEmailConfig.equals(emailResource.getEmailConfig()));
}
Also used : Response(javax.ws.rs.core.Response) IEmailConfiguration(org.pentaho.platform.api.email.IEmailConfiguration) IEmailConfiguration(org.pentaho.platform.api.email.IEmailConfiguration) EmailResource(org.pentaho.platform.web.http.api.resources.EmailResource)

Example 2 with IEmailConfiguration

use of org.pentaho.platform.api.email.IEmailConfiguration in project pentaho-platform by pentaho.

the class EmailResourceTest method testEmailConfig.

public void testEmailConfig() throws Exception {
    try {
        new EmailResource(null);
        fail("Exception should be thrown when a null EmailService is provided");
    } catch (IllegalArgumentException success) {
    // ignore
    }
    try {
        new EmailResource(new EmailService(new File(defaultConfigFile, "cannot.exist")));
        fail("Exception should be thrown when an invalid EmailService is provided");
    } catch (IllegalArgumentException success) {
    // ignore
    }
    IEmailConfiguration emptyConfig = emailResource.getEmailConfig();
    assertTrue(BLANK_CONFIG.equals(emptyConfig));
    Response response = emailResource.setEmailConfig(new EmailConfiguration());
    assertEquals(OK_STATUS, response.getStatus());
    emptyConfig = emailResource.getEmailConfig();
    assertTrue(BLANK_CONFIG.equals(emptyConfig));
    final EmailConfiguration emailConfigOriginal = new EmailConfiguration(true, false, "test@pentaho.com", "Pentaho Scheduler", null, 36, "", true, "user", null, false, true);
    response = emailResource.setEmailConfig(emailConfigOriginal);
    assertEquals(OK_STATUS, response.getStatus());
    final IEmailConfiguration emailConfigNew = emailResource.getEmailConfig();
    assertTrue(emailConfigOriginal.equals(emailConfigNew));
}
Also used : Response(javax.ws.rs.core.Response) IEmailConfiguration(org.pentaho.platform.api.email.IEmailConfiguration) EmailConfiguration(org.pentaho.platform.plugin.services.email.EmailConfiguration) IEmailConfiguration(org.pentaho.platform.api.email.IEmailConfiguration) EmailService(org.pentaho.platform.plugin.services.email.EmailService) File(java.io.File)

Aggregations

Response (javax.ws.rs.core.Response)2 IEmailConfiguration (org.pentaho.platform.api.email.IEmailConfiguration)2 File (java.io.File)1 EmailConfiguration (org.pentaho.platform.plugin.services.email.EmailConfiguration)1 EmailService (org.pentaho.platform.plugin.services.email.EmailService)1 EmailResource (org.pentaho.platform.web.http.api.resources.EmailResource)1