Search in sources :

Example 1 with EmailResource

use of org.pentaho.platform.web.http.api.resources.EmailResource 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 EmailResource

use of org.pentaho.platform.web.http.api.resources.EmailResource in project pentaho-platform by pentaho.

the class EmailServiceIT method testSendTestEmail.

public void testSendTestEmail() throws Exception {
    // Testing with a blank config should fail
    final EmailResource emailResource = new EmailResource();
    final EmailConfiguration blankEmailConfig = new EmailConfiguration();
    try {
        emailResource.sendEmailTest(blankEmailConfig);
        fail("Testing with a blank email config should fail");
    } catch (Throwable success) {
    // ignore
    }
}
Also used : IEmailConfiguration(org.pentaho.platform.api.email.IEmailConfiguration) EmailResource(org.pentaho.platform.web.http.api.resources.EmailResource)

Example 3 with EmailResource

use of org.pentaho.platform.web.http.api.resources.EmailResource in project pentaho-platform by pentaho.

the class EmailServiceIT method testConstruction.

public void testConstruction() throws Exception {
    // null File parameter
    try {
        new EmailResource(null);
        fail("Null file should throw an exception");
    } catch (IllegalArgumentException success) {
    // ignore
    }
    // Parent directory doesn't exist
    try {
        final File tempFile = new File(tempDir, "EmailResourceTest1");
        new EmailService(new File(tempFile, "email_config.xml"));
        fail("Exception should be thrown when parent directory of file provided doesn't exist");
    } catch (IllegalArgumentException success) {
    // ignore
    }
    // File exists but is a directory
    try {
        new EmailService(tempDir);
        fail("Exception should be thrown when providing a filename that is a directory");
    } catch (IllegalArgumentException success) {
    // ignore
    }
    // Parent exists, but is not a directory
    try {
        final File tempFile = new File(tempDir, "EmailResourceTest2");
        assertTrue("Testing scenario could not be setup correctly", tempFile.createNewFile());
        new EmailService(new File(tempFile, "email_config.xml"));
        fail("Exception should be thrown when parent directory exists but is a file");
    } catch (IllegalArgumentException success) {
    // ignore
    }
    // File doesn't exist (but is ok)
    final File tempFile = new File(tempDir, "temp.xml");
    assertFalse("Testing scenario not setup correctly", tempFile.exists());
    new EmailService(tempFile);
    // File exists (but it is ok)
    assertTrue("Testing scenario could not be setup correctly", tempFile.createNewFile());
    new EmailService(tempFile);
    // Default parameters
    // This should work
    new EmailResource();
}
Also used : EmailResource(org.pentaho.platform.web.http.api.resources.EmailResource) File(java.io.File)

Aggregations

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