Package org.pentaho.platform.web.http.api.resources

Examples of org.pentaho.platform.web.http.api.resources.EmailResource


  }

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

  }
View Full Code Here


  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() ) );
  }
View Full Code Here

    assertTrue( newEmailConfig.equals( emailResource.getEmailConfig() ) );
  }

  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
    }
  }
View Full Code Here

TOP

Related Classes of org.pentaho.platform.web.http.api.resources.EmailResource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.