Package org.springframework.xd.shell.command

Source Code of org.springframework.xd.shell.command.MailCommandTests

/*
* Copyright 2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.xd.shell.command;

import static org.springframework.xd.shell.command.fixtures.XDMatchers.eventually;
import static org.springframework.xd.shell.command.fixtures.XDMatchers.hasContentsThat;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

import javax.mail.internet.MimeMessage;

import org.junit.Assert;
import org.junit.Test;

import org.springframework.xd.shell.command.fixtures.HttpSource;
import org.springframework.xd.test.fixtures.FileSink;
import org.springframework.xd.test.fixtures.MailSink;
import org.springframework.xd.test.fixtures.NonPollingImapSource;
import org.springframework.xd.test.fixtures.PollingMailSource;


/**
* Tests for the mail related sources and sink.
*
* @author Eric Bottard
*/
public class MailCommandTests extends AbstractStreamIntegrationTest {

  @Test
  public void testImapPoll() throws Exception {
    PollingMailSource pollingMailSource = newPollingMailSource();
    FileSink fileSink = newFileSink().binary(true);

    pollingMailSource.ensureStarted();

    stream().create(generateStreamName(), "%s | %s", pollingMailSource, fileSink);

    pollingMailSource.sendEmail("from@foo.com", "The Subject", "My body is slim!");

    assertThat(fileSink, eventually(hasContentsThat(equalTo("My body is slim!\r\n"))));
  }

  @Test
  public void testImapIdle() throws Exception {
    NonPollingImapSource mailSource = newNonPollingMailSource();
    FileSink fileSink = newFileSink().binary(true);

    mailSource.ensureStarted();

    stream().create(generateStreamName(), "%s | %s", mailSource, fileSink);

    mailSource.sendEmail("from@foo.com", "The Subject", "My body is slim!");

    assertThat(fileSink, eventually(hasContentsThat(equalTo("My body is slim!\r\n"))));
  }

  @Test
  public void testMailSink() throws Exception {
    HttpSource httpSource = newHttpSource();
    MailSink mailSink = newMailSink();

    mailSink.ensureStarted()
        .to("'\"some.one@domain.com\"'")
        .subject("payload");


    stream().create(generateStreamName(), "%s | %s", httpSource, mailSink);

    httpSource.ensureReady().postData("Woohoo!");
    MimeMessage result = mailSink.waitForEmail();

    Assert.assertEquals("Woohoo!\r\n", result.getContent());
    Assert.assertEquals("Woohoo!", result.getSubject());

  }

}
TOP

Related Classes of org.springframework.xd.shell.command.MailCommandTests

TOP
Copyright © 2018 www.massapi.com. 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.