[
https://issues.apache.org/jira/browse/NIFI-1449?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15994232#comment-15994232
]
ASF GitHub Bot commented on NIFI-1449:
--------------------------------------
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.
> PutEmail needs more unit tests
> ------------------------------
>
> Key: NIFI-1449
> URL: https://issues.apache.org/jira/browse/NIFI-1449
> Project: Apache NiFi
> Issue Type: Improvement
> Reporter: Joseph Percivall
> Assignee: Andre F de Miranda
>
> Currently the standard processor PutEmail only has two units. One verifies
> "testHostNotFound" and the other "testEmailPropertyFormatters". Both route to
> failure. There is no checking that the processor actually functions.
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)