You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by JPercivall <gi...@git.apache.org> on 2017/05/03 03:37:51 UTC

[GitHub] nifi pull request #1553: NIFI-1449 - Migrate PutEmail tests from Mock class ...

Github user JPercivall commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1553#discussion_r114464910
  
    --- Diff: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutEmail.java ---
    @@ -17,83 +17,64 @@
     package org.apache.nifi.processors.standard;
     
     import static org.junit.Assert.assertEquals;
    -import static org.junit.Assert.assertNull;
    +
     import static org.junit.Assert.assertTrue;
     
    -import java.io.InputStream;
    -import java.util.ArrayList;
     import java.util.HashMap;
     import java.util.List;
     import java.util.Map;
     
    -import javax.mail.BodyPart;
    -import javax.mail.Message;
    -import javax.mail.MessagingException;
    -import javax.mail.internet.MimeMessage.RecipientType;
    -import javax.mail.internet.MimeMultipart;
    -
     import org.apache.commons.codec.binary.Base64;
     import org.apache.commons.codec.binary.StringUtils;
    -import org.apache.commons.io.IOUtils;
    +import org.apache.nifi.processors.email.ExtractEmailAttachments;
    +import org.apache.nifi.processors.email.ExtractEmailHeaders;
    +import org.apache.nifi.processors.email.ListenSMTP;
    +import org.apache.nifi.remote.io.socket.NetworkUtils;
     import org.apache.nifi.util.LogMessage;
    +import org.apache.nifi.util.MockFlowFile;
     import org.apache.nifi.util.TestRunner;
     import org.apache.nifi.util.TestRunners;
    +import org.hamcrest.CoreMatchers;
    +import org.junit.Assert;
     import org.junit.Before;
     import org.junit.Test;
     
    -public class TestPutEmail {
     
    -    /**
    -     * Extension to PutEmail that stubs out the calls to
    -     * Transport.sendMessage().
    -     *
    -     * <p>
    -     * All sent messages are records in a list available via the
    -     * {@link #getMessages()} method.</p>
    -     * <p> Calling
    -     * {@link #setException(MessagingException)} will cause the supplied exception to be
    -     * thrown when sendMessage is invoked.
    -     * </p>
    -     */
    -    private static final class PutEmailExtension extends PutEmail {
    -        private MessagingException e;
    -        private ArrayList<Message> messages = new ArrayList<>();
    -
    -        @Override
    -        protected void send(Message msg) throws MessagingException {
    -            messages.add(msg);
    -            if (this.e != null) {
    -                throw e;
    -            }
    -        }
    -
    -        void setException(final MessagingException e) {
    -            this.e = e;
    -        }
    -
    -        List<Message> getMessages() {
    -            return messages;
    -        }
    -    }
     
    -    PutEmailExtension processor;
    +public class TestPutEmail {
    +
         TestRunner runner;
    +    TestRunner smtpRunner;
    +    TestRunner extractHeadersRunner;
    +    TestRunner extractAttachmentsRunner;
    +    int port;
     
         @Before
         public void setup() {
    -        processor = new PutEmailExtension();
    -        runner = TestRunners.newTestRunner(processor);
    +        runner = TestRunners.newTestRunner(PutEmail.class);
    +        smtpRunner = TestRunners.newTestRunner(ListenSMTP.class);
    +        extractHeadersRunner = TestRunners.newTestRunner(ExtractEmailHeaders.class);
    +        extractAttachmentsRunner = TestRunners.newTestRunner(ExtractEmailAttachments.class);
    +
    +        port = NetworkUtils.availablePort();
    +        smtpRunner.setProperty("SMTP_PORT", String.valueOf(port));
    +        smtpRunner.setProperty("SMTP_MAXIMUM_CONNECTIONS", "3");
    +        smtpRunner.setProperty("SMTP_TIMEOUT", "10 seconds");
    +        smtpRunner.run(1,false);
    --- End diff --
    
    I believe this line is the only one that needs to be run before each method and the rest can be run before the class, specifically the network port.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---