use of org.apache.nifi.util.TestRunner in project nifi by apache.
the class TestConsumeEmail method validateUrl.
@Test
public void validateUrl() throws Exception {
Field displayUrlField = AbstractEmailProcessor.class.getDeclaredField("displayUrl");
displayUrlField.setAccessible(true);
AbstractEmailProcessor<? extends AbstractMailReceiver> consume = new ConsumeIMAP();
TestRunner runner = TestRunners.newTestRunner(consume);
runner.setProperty(ConsumeIMAP.HOST, "foo.bar.com");
runner.setProperty(ConsumeIMAP.PORT, "1234");
runner.setProperty(ConsumeIMAP.USER, "jon");
runner.setProperty(ConsumeIMAP.PASSWORD, "qhgwjgehr");
runner.setProperty(ConsumeIMAP.FOLDER, "MYBOX");
runner.setProperty(ConsumeIMAP.USE_SSL, "false");
assertEquals("imap://jon:qhgwjgehr@foo.bar.com:1234/MYBOX", consume.buildUrl(runner.getProcessContext()));
assertEquals("imap://jon:[password]@foo.bar.com:1234/MYBOX", displayUrlField.get(consume));
}
use of org.apache.nifi.util.TestRunner in project nifi by apache.
the class TestExtractEmailAttachments method testValidEmailWithoutAttachments.
@Test
public void testValidEmailWithoutAttachments() throws Exception {
final TestRunner runner = TestRunners.newTestRunner(new ExtractEmailAttachments());
// Create the message dynamically
byte[] simpleEmail = attachmentGenerator.SimpleEmail();
runner.enqueue(simpleEmail);
runner.run();
runner.assertTransferCount(ExtractEmailAttachments.REL_ORIGINAL, 1);
runner.assertTransferCount(ExtractEmailAttachments.REL_FAILURE, 0);
runner.assertTransferCount(ExtractEmailAttachments.REL_ATTACHMENTS, 0);
}
use of org.apache.nifi.util.TestRunner in project nifi by apache.
the class TestExtractEmailAttachments method testValidEmailWithMultipleAttachments.
@Test
public void testValidEmailWithMultipleAttachments() throws Exception {
Random rnd = new Random();
final TestRunner runner = TestRunners.newTestRunner(new ExtractEmailAttachments());
// Create the message dynamically
int amount = rnd.nextInt(10) + 1;
byte[] withAttachment = attachmentGenerator.WithAttachments(amount);
runner.enqueue(withAttachment);
runner.run();
runner.assertTransferCount(ExtractEmailAttachments.REL_ORIGINAL, 1);
runner.assertTransferCount(ExtractEmailAttachments.REL_FAILURE, 0);
runner.assertTransferCount(ExtractEmailAttachments.REL_ATTACHMENTS, amount);
// Have a look at the attachments...
final List<MockFlowFile> splits = runner.getFlowFilesForRelationship(ExtractEmailAttachments.REL_ATTACHMENTS);
List<String> filenames = new ArrayList<>();
for (int a = 0; a < amount; a++) {
filenames.add(splits.get(a).getAttribute("filename").toString());
}
Assert.assertTrue(filenames.containsAll(Arrays.asList("pom.xml1", "pom.xml" + amount)));
}
use of org.apache.nifi.util.TestRunner in project nifi by apache.
the class TestExtractEmailAttachments method testValidEmailWithAttachments.
@Test
public void testValidEmailWithAttachments() throws Exception {
final TestRunner runner = TestRunners.newTestRunner(new ExtractEmailAttachments());
// Create the message dynamically
byte[] withAttachment = attachmentGenerator.WithAttachments(1);
runner.enqueue(withAttachment);
runner.run();
runner.assertTransferCount(ExtractEmailAttachments.REL_ORIGINAL, 1);
runner.assertTransferCount(ExtractEmailAttachments.REL_FAILURE, 0);
runner.assertTransferCount(ExtractEmailAttachments.REL_ATTACHMENTS, 1);
// Have a look at the attachments...
final List<MockFlowFile> splits = runner.getFlowFilesForRelationship(ExtractEmailAttachments.REL_ATTACHMENTS);
splits.get(0).assertAttributeEquals("filename", "pom.xml1");
}
use of org.apache.nifi.util.TestRunner in project nifi by apache.
the class TestExtractEmailHeaders method testStrictParsingFailsForInvalidAddresses.
/**
* NIFI-4326 adds a new feature to disable strict address parsing for
* mailbox list header fields. This is a test case that asserts that
* strict address parsing fails (when set to "strict=true") for malformed
* addresses.
*/
@Test
public void testStrictParsingFailsForInvalidAddresses() throws Exception {
final TestRunner runner = TestRunners.newTestRunner(new ExtractEmailHeaders());
runner.setProperty(ExtractEmailHeaders.STRICT_PARSING, "true");
MimeMessage simpleEmailMimeMessage = attachmentGenerator.SimpleEmailMimeMessage();
simpleEmailMimeMessage.setHeader("From", "<bad_email>");
simpleEmailMimeMessage.setHeader("To", "<>, Joe, <invalid>");
ByteArrayOutputStream messageBytes = new ByteArrayOutputStream();
try {
simpleEmailMimeMessage.writeTo(messageBytes);
} catch (IOException | MessagingException e) {
e.printStackTrace();
}
runner.enqueue(messageBytes.toByteArray());
runner.run();
runner.assertTransferCount(ExtractEmailHeaders.REL_SUCCESS, 0);
runner.assertTransferCount(ExtractEmailHeaders.REL_FAILURE, 1);
}
Aggregations