You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by jo...@apache.org on 2015/04/27 13:45:14 UTC
[03/16] incubator-nifi git commit: NIFI-271 chipping away - more work
left in standard bundle
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/54818893/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestModifyBytes.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestModifyBytes.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestModifyBytes.java
index 329aace..2c58b80 100644
--- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestModifyBytes.java
+++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestModifyBytes.java
@@ -41,11 +41,14 @@ public class TestModifyBytes {
runner.setProperty(ModifyBytes.START_OFFSET, "1 MB");
runner.setProperty(ModifyBytes.END_OFFSET, "1 MB");
- runner.enqueue(Paths.get("src/test/resources/TestModifyBytes/testFile.txt"));
+ runner.enqueue(Paths.
+ get("src/test/resources/TestModifyBytes/testFile.txt"));
runner.run();
runner.assertAllFlowFilesTransferred(ModifyBytes.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS).
+ get(0);
out.assertContentEquals("".getBytes("UTF-8"));
}
@@ -55,12 +58,16 @@ public class TestModifyBytes {
runner.setProperty(ModifyBytes.START_OFFSET, "0 MB");
runner.setProperty(ModifyBytes.END_OFFSET, "0 MB");
- runner.enqueue(Paths.get("src/test/resources/TestModifyBytes/testFile.txt"));
+ runner.enqueue(Paths.
+ get("src/test/resources/TestModifyBytes/testFile.txt"));
runner.run();
runner.assertAllFlowFilesTransferred(ModifyBytes.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS).get(0);
- out.assertContentEquals(translateNewLines(new File("src/test/resources/TestModifyBytes/testFile.txt")));
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS).
+ get(0);
+ out.
+ assertContentEquals(translateNewLines(new File("src/test/resources/TestModifyBytes/testFile.txt")));
}
@Test
@@ -69,14 +76,18 @@ public class TestModifyBytes {
runner.setProperty(ModifyBytes.START_OFFSET, "12 B"); //REMOVE - '<<<HEADER>>>'
runner.setProperty(ModifyBytes.END_OFFSET, "0 MB");
- runner.enqueue(Paths.get("src/test/resources/TestModifyBytes/testFile.txt"));
+ runner.enqueue(Paths.
+ get("src/test/resources/TestModifyBytes/testFile.txt"));
runner.run();
runner.assertAllFlowFilesTransferred(ModifyBytes.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS).
+ get(0);
final String outContent = new String(out.toByteArray(), StandardCharsets.UTF_8);
System.out.println(outContent);
- out.assertContentEquals(translateNewLines(new File("src/test/resources/TestModifyBytes/noHeader.txt")));
+ out.
+ assertContentEquals(translateNewLines(new File("src/test/resources/TestModifyBytes/noHeader.txt")));
}
@Test
@@ -85,11 +96,14 @@ public class TestModifyBytes {
runner.setProperty(ModifyBytes.START_OFFSET, "181 B");
runner.setProperty(ModifyBytes.END_OFFSET, "0 B");
- runner.enqueue(Paths.get("src/test/resources/TestModifyBytes/testFile.txt"));
+ runner.enqueue(Paths.
+ get("src/test/resources/TestModifyBytes/testFile.txt"));
runner.run();
runner.assertAllFlowFilesTransferred(ModifyBytes.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS).
+ get(0);
final String outContent = new String(out.toByteArray(), StandardCharsets.UTF_8);
System.out.println(outContent);
out.assertContentEquals("<<<FOOTER>>>".getBytes("UTF-8"));
@@ -101,11 +115,14 @@ public class TestModifyBytes {
runner.setProperty(ModifyBytes.START_OFFSET, "0 B");
runner.setProperty(ModifyBytes.END_OFFSET, "181 B");
- runner.enqueue(Paths.get("src/test/resources/TestModifyBytes/testFile.txt"));
+ runner.enqueue(Paths.
+ get("src/test/resources/TestModifyBytes/testFile.txt"));
runner.run();
runner.assertAllFlowFilesTransferred(ModifyBytes.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS).
+ get(0);
out.assertContentEquals("<<<HEADER>>>".getBytes("UTF-8"));
}
@@ -115,14 +132,18 @@ public class TestModifyBytes {
runner.setProperty(ModifyBytes.START_OFFSET, "0 B");
runner.setProperty(ModifyBytes.END_OFFSET, "12 B");
- runner.enqueue(Paths.get("src/test/resources/TestModifyBytes/testFile.txt"));
+ runner.enqueue(Paths.
+ get("src/test/resources/TestModifyBytes/testFile.txt"));
runner.run();
runner.assertAllFlowFilesTransferred(ModifyBytes.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS).
+ get(0);
final String outContent = new String(out.toByteArray(), StandardCharsets.UTF_8);
System.out.println(outContent);
- out.assertContentEquals(translateNewLines(new File("src/test/resources/TestModifyBytes/noFooter.txt")));
+ out.
+ assertContentEquals(translateNewLines(new File("src/test/resources/TestModifyBytes/noFooter.txt")));
}
@Test
@@ -131,14 +152,18 @@ public class TestModifyBytes {
runner.setProperty(ModifyBytes.START_OFFSET, "12 B");
runner.setProperty(ModifyBytes.END_OFFSET, "12 B");
- runner.enqueue(Paths.get("src/test/resources/TestModifyBytes/testFile.txt"));
+ runner.enqueue(Paths.
+ get("src/test/resources/TestModifyBytes/testFile.txt"));
runner.run();
runner.assertAllFlowFilesTransferred(ModifyBytes.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS).
+ get(0);
final String outContent = new String(out.toByteArray(), StandardCharsets.UTF_8);
System.out.println(outContent);
- out.assertContentEquals(translateNewLines(new File("src/test/resources/TestModifyBytes/noFooter_noHeader.txt")));
+ out.
+ assertContentEquals(translateNewLines(new File("src/test/resources/TestModifyBytes/noFooter_noHeader.txt")));
}
@Test
@@ -147,11 +172,14 @@ public class TestModifyBytes {
runner.setProperty(ModifyBytes.START_OFFSET, "97 B");
runner.setProperty(ModifyBytes.END_OFFSET, "97 B");
- runner.enqueue(Paths.get("src/test/resources/TestModifyBytes/testFile.txt"));
+ runner.enqueue(Paths.
+ get("src/test/resources/TestModifyBytes/testFile.txt"));
runner.run();
runner.assertAllFlowFilesTransferred(ModifyBytes.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS).
+ get(0);
out.assertContentEquals("".getBytes("UTF-8"));
}
@@ -161,11 +189,14 @@ public class TestModifyBytes {
runner.setProperty(ModifyBytes.START_OFFSET, "94 B");
runner.setProperty(ModifyBytes.END_OFFSET, "96 B");
- runner.enqueue(Paths.get("src/test/resources/TestModifyBytes/testFile.txt"));
+ runner.enqueue(Paths.
+ get("src/test/resources/TestModifyBytes/testFile.txt"));
runner.run();
runner.assertAllFlowFilesTransferred(ModifyBytes.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS).
+ get(0);
final String outContent = new String(out.toByteArray(), StandardCharsets.UTF_8);
System.out.println(outContent);
out.assertContentEquals("Dew".getBytes("UTF-8"));
@@ -178,13 +209,15 @@ public class TestModifyBytes {
private byte[] translateNewLines(final Path path) throws IOException {
final byte[] data = Files.readAllBytes(path);
final String text = new String(data, StandardCharsets.UTF_8);
- return translateNewLines(text).getBytes(StandardCharsets.UTF_8);
+ return translateNewLines(text).
+ getBytes(StandardCharsets.UTF_8);
}
private String translateNewLines(final String text) {
final String lineSeparator = System.getProperty("line.separator");
final Pattern pattern = Pattern.compile("\n", Pattern.MULTILINE);
- final String translated = pattern.matcher(text).replaceAll(lineSeparator);
+ final String translated = pattern.matcher(text).
+ replaceAll(lineSeparator);
return translated;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/54818893/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMonitorActivity.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMonitorActivity.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMonitorActivity.java
index 1805716..9e970f1 100644
--- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMonitorActivity.java
+++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMonitorActivity.java
@@ -31,7 +31,8 @@ public class TestMonitorActivity {
@Test
public void testFirstMessage() throws InterruptedException, IOException {
- final TestRunner runner = TestRunners.newTestRunner(new MonitorActivity());
+ final TestRunner runner = TestRunners.
+ newTestRunner(new MonitorActivity());
runner.setProperty(MonitorActivity.CONTINUALLY_SEND_MESSAGES, "false");
runner.setProperty(MonitorActivity.THRESHOLD, "100 millis");
@@ -65,9 +66,12 @@ public class TestMonitorActivity {
runner.assertTransferCount(MonitorActivity.REL_SUCCESS, 1);
runner.assertTransferCount(MonitorActivity.REL_ACTIVITY_RESTORED, 1);
- MockFlowFile restoredFlowFile = runner.getFlowFilesForRelationship(MonitorActivity.REL_ACTIVITY_RESTORED).get(0);
+ MockFlowFile restoredFlowFile = runner.
+ getFlowFilesForRelationship(MonitorActivity.REL_ACTIVITY_RESTORED).
+ get(0);
String flowFileContent = new String(restoredFlowFile.toByteArray());
- Assert.assertTrue(Pattern.matches("Activity restored at time: (.*) after being inactive for 0 minutes", flowFileContent));
+ Assert.assertTrue(Pattern.
+ matches("Activity restored at time: (.*) after being inactive for 0 minutes", flowFileContent));
restoredFlowFile.assertAttributeNotExists("key");
restoredFlowFile.assertAttributeNotExists("key1");
@@ -92,16 +96,20 @@ public class TestMonitorActivity {
runner.assertTransferCount(MonitorActivity.REL_ACTIVITY_RESTORED, 1);
runner.assertTransferCount(MonitorActivity.REL_SUCCESS, 1);
- restoredFlowFile = runner.getFlowFilesForRelationship(MonitorActivity.REL_ACTIVITY_RESTORED).get(0);
+ restoredFlowFile = runner.
+ getFlowFilesForRelationship(MonitorActivity.REL_ACTIVITY_RESTORED).
+ get(0);
flowFileContent = new String(restoredFlowFile.toByteArray());
- Assert.assertTrue(Pattern.matches("Activity restored at time: (.*) after being inactive for 0 minutes", flowFileContent));
+ Assert.assertTrue(Pattern.
+ matches("Activity restored at time: (.*) after being inactive for 0 minutes", flowFileContent));
restoredFlowFile.assertAttributeNotExists("key");
restoredFlowFile.assertAttributeNotExists("key1");
}
@Test
public void testFirstMessageWithInherit() throws InterruptedException, IOException {
- final TestRunner runner = TestRunners.newTestRunner(new MonitorActivity());
+ final TestRunner runner = TestRunners.
+ newTestRunner(new MonitorActivity());
runner.setProperty(MonitorActivity.CONTINUALLY_SEND_MESSAGES, "false");
runner.setProperty(MonitorActivity.THRESHOLD, "100 millis");
runner.setProperty(MonitorActivity.COPY_ATTRIBUTES, "true");
@@ -109,7 +117,9 @@ public class TestMonitorActivity {
runner.enqueue(new byte[0]);
runner.run();
runner.assertAllFlowFilesTransferred(MonitorActivity.REL_SUCCESS, 1);
- MockFlowFile originalFlowFile = runner.getFlowFilesForRelationship(MonitorActivity.REL_SUCCESS).get(0);
+ MockFlowFile originalFlowFile = runner.
+ getFlowFilesForRelationship(MonitorActivity.REL_SUCCESS).
+ get(0);
runner.clearTransferState();
Thread.sleep(1000L);
@@ -137,22 +147,33 @@ public class TestMonitorActivity {
runner.assertTransferCount(MonitorActivity.REL_SUCCESS, 1);
runner.assertTransferCount(MonitorActivity.REL_ACTIVITY_RESTORED, 1);
- MockFlowFile restoredFlowFile = runner.getFlowFilesForRelationship(MonitorActivity.REL_ACTIVITY_RESTORED).get(0);
+ MockFlowFile restoredFlowFile = runner.
+ getFlowFilesForRelationship(MonitorActivity.REL_ACTIVITY_RESTORED).
+ get(0);
String flowFileContent = new String(restoredFlowFile.toByteArray());
- Assert.assertTrue(Pattern.matches("Activity restored at time: (.*) after being inactive for 0 minutes", flowFileContent));
+ Assert.assertTrue(Pattern.
+ matches("Activity restored at time: (.*) after being inactive for 0 minutes", flowFileContent));
restoredFlowFile.assertAttributeEquals("key", "value");
restoredFlowFile.assertAttributeEquals("key1", "value1");
// verify the UUIDs are not the same
- restoredFlowFile.assertAttributeNotEquals(CoreAttributes.UUID.key(), originalFlowFile.getAttribute(CoreAttributes.UUID.key()));
- restoredFlowFile.assertAttributeNotEquals(CoreAttributes.FILENAME.key(), originalFlowFile.getAttribute(CoreAttributes.FILENAME.key()));
+ restoredFlowFile.
+ assertAttributeNotEquals(CoreAttributes.UUID.key(), originalFlowFile.
+ getAttribute(CoreAttributes.UUID.key()));
+ restoredFlowFile.
+ assertAttributeNotEquals(CoreAttributes.FILENAME.key(), originalFlowFile.
+ getAttribute(CoreAttributes.FILENAME.key()));
Assert.assertTrue(
- String.format("file sizes match when they shouldn't original=%1$s restored=%2$s",
+ String.
+ format("file sizes match when they shouldn't original=%1$s restored=%2$s",
originalFlowFile.getSize(), restoredFlowFile.getSize()),
restoredFlowFile.getSize() != originalFlowFile.getSize());
- Assert.assertTrue(String.format("lineage start dates match when they shouldn't original=%1$s restored=%2$s",
- originalFlowFile.getLineageStartDate(), restoredFlowFile.getLineageStartDate()),
- restoredFlowFile.getLineageStartDate() != originalFlowFile.getLineageStartDate());
+ Assert.assertTrue(String.
+ format("lineage start dates match when they shouldn't original=%1$s restored=%2$s",
+ originalFlowFile.getLineageStartDate(), restoredFlowFile.
+ getLineageStartDate()),
+ restoredFlowFile.getLineageStartDate() != originalFlowFile.
+ getLineageStartDate());
runner.clearTransferState();
runner.setProperty(MonitorActivity.CONTINUALLY_SEND_MESSAGES, "true");
@@ -175,19 +196,30 @@ public class TestMonitorActivity {
runner.assertTransferCount(MonitorActivity.REL_ACTIVITY_RESTORED, 1);
runner.assertTransferCount(MonitorActivity.REL_SUCCESS, 1);
- restoredFlowFile = runner.getFlowFilesForRelationship(MonitorActivity.REL_ACTIVITY_RESTORED).get(0);
+ restoredFlowFile = runner.
+ getFlowFilesForRelationship(MonitorActivity.REL_ACTIVITY_RESTORED).
+ get(0);
flowFileContent = new String(restoredFlowFile.toByteArray());
- Assert.assertTrue(Pattern.matches("Activity restored at time: (.*) after being inactive for 0 minutes", flowFileContent));
+ Assert.assertTrue(Pattern.
+ matches("Activity restored at time: (.*) after being inactive for 0 minutes", flowFileContent));
restoredFlowFile.assertAttributeEquals("key", "value");
restoredFlowFile.assertAttributeEquals("key1", "value1");
- restoredFlowFile.assertAttributeNotEquals(CoreAttributes.UUID.key(), originalFlowFile.getAttribute(CoreAttributes.UUID.key()));
- restoredFlowFile.assertAttributeNotEquals(CoreAttributes.FILENAME.key(), originalFlowFile.getAttribute(CoreAttributes.FILENAME.key()));
+ restoredFlowFile.
+ assertAttributeNotEquals(CoreAttributes.UUID.key(), originalFlowFile.
+ getAttribute(CoreAttributes.UUID.key()));
+ restoredFlowFile.
+ assertAttributeNotEquals(CoreAttributes.FILENAME.key(), originalFlowFile.
+ getAttribute(CoreAttributes.FILENAME.key()));
Assert.assertTrue(
- String.format("file sizes match when they shouldn't original=%1$s restored=%2$s",
+ String.
+ format("file sizes match when they shouldn't original=%1$s restored=%2$s",
originalFlowFile.getSize(), restoredFlowFile.getSize()),
restoredFlowFile.getSize() != originalFlowFile.getSize());
- Assert.assertTrue(String.format("lineage start dates match when they shouldn't original=%1$s restored=%2$s",
- originalFlowFile.getLineageStartDate(), restoredFlowFile.getLineageStartDate()),
- restoredFlowFile.getLineageStartDate() != originalFlowFile.getLineageStartDate());
+ Assert.assertTrue(String.
+ format("lineage start dates match when they shouldn't original=%1$s restored=%2$s",
+ originalFlowFile.getLineageStartDate(), restoredFlowFile.
+ getLineageStartDate()),
+ restoredFlowFile.getLineageStartDate() != originalFlowFile.
+ getLineageStartDate());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/54818893/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPostHTTP.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPostHTTP.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPostHTTP.java
index dcda136..f4c4367 100644
--- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPostHTTP.java
+++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPostHTTP.java
@@ -34,24 +34,25 @@ import org.junit.After;
import org.junit.Test;
public class TestPostHTTP {
+
private TestServer server;
private TestRunner runner;
private CaptureServlet servlet;
-
+
private void setup(final Map<String, String> sslProperties) throws Exception {
// set up web service
ServletHandler handler = new ServletHandler();
handler.addServletWithMapping(CaptureServlet.class, "/*");
servlet = (CaptureServlet) handler.getServlets()[0].getServlet();
-
+
// create the service
server = new TestServer(sslProperties);
server.addHandler(handler);
server.startServer();
-
+
runner = TestRunners.newTestRunner(PostHTTP.class);
}
-
+
@After
public void cleanup() throws Exception {
if (server != null) {
@@ -59,92 +60,113 @@ public class TestPostHTTP {
server = null;
}
}
-
+
@Test
public void testTruststoreSSLOnly() throws Exception {
final Map<String, String> sslProps = new HashMap<>();
sslProps.put(TestServer.NEED_CLIENT_AUTH, "false");
- sslProps.put(StandardSSLContextService.KEYSTORE.getName(), "src/test/resources/localhost-ks.jks");
- sslProps.put(StandardSSLContextService.KEYSTORE_PASSWORD.getName(), "localtest");
+ sslProps.
+ put(StandardSSLContextService.KEYSTORE.getName(), "src/test/resources/localhost-ks.jks");
+ sslProps.
+ put(StandardSSLContextService.KEYSTORE_PASSWORD.getName(), "localtest");
sslProps.put(StandardSSLContextService.KEYSTORE_TYPE.getName(), "JKS");
setup(sslProps);
-
+
final SSLContextService sslContextService = new StandardSSLContextService();
runner.addControllerService("ssl-context", sslContextService);
- runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE, "src/test/resources/localhost-ts.jks");
- runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE_PASSWORD, "localtest");
- runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE_TYPE, "JKS");
+ runner.
+ setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE, "src/test/resources/localhost-ts.jks");
+ runner.
+ setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE_PASSWORD, "localtest");
+ runner.
+ setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE_TYPE, "JKS");
runner.enableControllerService(sslContextService);
-
+
runner.setProperty(PostHTTP.URL, server.getSecureUrl());
runner.setProperty(PostHTTP.SSL_CONTEXT_SERVICE, "ssl-context");
-
+
runner.enqueue("Hello world".getBytes());
runner.run();
-
+
runner.assertAllFlowFilesTransferred(PostHTTP.REL_SUCCESS, 1);
}
-
-
+
@Test
public void testTwoWaySSL() throws Exception {
final Map<String, String> sslProps = new HashMap<>();
- sslProps.put(StandardSSLContextService.KEYSTORE.getName(), "src/test/resources/localhost-ks.jks");
- sslProps.put(StandardSSLContextService.KEYSTORE_PASSWORD.getName(), "localtest");
+ sslProps.
+ put(StandardSSLContextService.KEYSTORE.getName(), "src/test/resources/localhost-ks.jks");
+ sslProps.
+ put(StandardSSLContextService.KEYSTORE_PASSWORD.getName(), "localtest");
sslProps.put(StandardSSLContextService.KEYSTORE_TYPE.getName(), "JKS");
- sslProps.put(StandardSSLContextService.TRUSTSTORE.getName(), "src/test/resources/localhost-ts.jks");
- sslProps.put(StandardSSLContextService.TRUSTSTORE_PASSWORD.getName(), "localtest");
+ sslProps.
+ put(StandardSSLContextService.TRUSTSTORE.getName(), "src/test/resources/localhost-ts.jks");
+ sslProps.
+ put(StandardSSLContextService.TRUSTSTORE_PASSWORD.getName(), "localtest");
sslProps.put(StandardSSLContextService.TRUSTSTORE_TYPE.getName(), "JKS");
sslProps.put(TestServer.NEED_CLIENT_AUTH, "true");
setup(sslProps);
-
+
final SSLContextService sslContextService = new StandardSSLContextService();
runner.addControllerService("ssl-context", sslContextService);
- runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE, "src/test/resources/localhost-ts.jks");
- runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE_PASSWORD, "localtest");
- runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE_TYPE, "JKS");
- runner.setProperty(sslContextService, StandardSSLContextService.KEYSTORE, "src/test/resources/localhost-ks.jks");
- runner.setProperty(sslContextService, StandardSSLContextService.KEYSTORE_PASSWORD, "localtest");
- runner.setProperty(sslContextService, StandardSSLContextService.KEYSTORE_TYPE, "JKS");
+ runner.
+ setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE, "src/test/resources/localhost-ts.jks");
+ runner.
+ setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE_PASSWORD, "localtest");
+ runner.
+ setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE_TYPE, "JKS");
+ runner.
+ setProperty(sslContextService, StandardSSLContextService.KEYSTORE, "src/test/resources/localhost-ks.jks");
+ runner.
+ setProperty(sslContextService, StandardSSLContextService.KEYSTORE_PASSWORD, "localtest");
+ runner.
+ setProperty(sslContextService, StandardSSLContextService.KEYSTORE_TYPE, "JKS");
runner.enableControllerService(sslContextService);
-
+
runner.setProperty(PostHTTP.URL, server.getSecureUrl());
runner.setProperty(PostHTTP.SSL_CONTEXT_SERVICE, "ssl-context");
-
+
runner.enqueue("Hello world".getBytes());
runner.run();
-
+
runner.assertAllFlowFilesTransferred(PostHTTP.REL_SUCCESS, 1);
}
-
+
@Test
public void testOneWaySSLWhenServerConfiguredForTwoWay() throws Exception {
final Map<String, String> sslProps = new HashMap<>();
- sslProps.put(StandardSSLContextService.KEYSTORE.getName(), "src/test/resources/localhost-ks.jks");
- sslProps.put(StandardSSLContextService.KEYSTORE_PASSWORD.getName(), "localtest");
+ sslProps.
+ put(StandardSSLContextService.KEYSTORE.getName(), "src/test/resources/localhost-ks.jks");
+ sslProps.
+ put(StandardSSLContextService.KEYSTORE_PASSWORD.getName(), "localtest");
sslProps.put(StandardSSLContextService.KEYSTORE_TYPE.getName(), "JKS");
- sslProps.put(StandardSSLContextService.TRUSTSTORE.getName(), "src/test/resources/localhost-ts.jks");
- sslProps.put(StandardSSLContextService.TRUSTSTORE_PASSWORD.getName(), "localtest");
+ sslProps.
+ put(StandardSSLContextService.TRUSTSTORE.getName(), "src/test/resources/localhost-ts.jks");
+ sslProps.
+ put(StandardSSLContextService.TRUSTSTORE_PASSWORD.getName(), "localtest");
sslProps.put(StandardSSLContextService.TRUSTSTORE_TYPE.getName(), "JKS");
sslProps.put(TestServer.NEED_CLIENT_AUTH, "true");
setup(sslProps);
-
+
final SSLContextService sslContextService = new StandardSSLContextService();
runner.addControllerService("ssl-context", sslContextService);
- runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE, "src/test/resources/localhost-ts.jks");
- runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE_PASSWORD, "localtest");
- runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE_TYPE, "JKS");
+ runner.
+ setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE, "src/test/resources/localhost-ts.jks");
+ runner.
+ setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE_PASSWORD, "localtest");
+ runner.
+ setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE_TYPE, "JKS");
runner.enableControllerService(sslContextService);
-
+
runner.setProperty(PostHTTP.URL, server.getSecureUrl());
runner.setProperty(PostHTTP.SSL_CONTEXT_SERVICE, "ssl-context");
-
+
runner.enqueue("Hello world".getBytes());
runner.run();
-
+
runner.assertAllFlowFilesTransferred(PostHTTP.REL_FAILURE, 1);
}
-
+
@Test
public void testSendAsFlowFile() throws Exception {
setup(null);
@@ -153,97 +175,108 @@ public class TestPostHTTP {
final Map<String, String> attrs = new HashMap<>();
attrs.put("abc", "cba");
-
+
runner.enqueue("Hello".getBytes(), attrs);
attrs.put("abc", "abc");
attrs.put("filename", "xyz.txt");
runner.enqueue("World".getBytes(), attrs);
-
+
runner.run(1);
runner.assertAllFlowFilesTransferred(PostHTTP.REL_SUCCESS);
-
+
final byte[] lastPost = servlet.getLastPost();
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final ByteArrayInputStream bais = new ByteArrayInputStream(lastPost);
-
+
FlowFileUnpackagerV3 unpacker = new FlowFileUnpackagerV3();
-
+
// unpack first flowfile received
- Map<String, String> receivedAttrs = unpacker.unpackageFlowFile(bais, baos);
+ Map<String, String> receivedAttrs = unpacker.
+ unpackageFlowFile(bais, baos);
byte[] contentReceived = baos.toByteArray();
assertEquals("Hello", new String(contentReceived));
assertEquals("cba", receivedAttrs.get("abc"));
-
- assertTrue( unpacker.hasMoreData() );
-
+
+ assertTrue(unpacker.hasMoreData());
+
baos.reset();
receivedAttrs = unpacker.unpackageFlowFile(bais, baos);
contentReceived = baos.toByteArray();
-
+
assertEquals("World", new String(contentReceived));
assertEquals("abc", receivedAttrs.get("abc"));
assertEquals("xyz.txt", receivedAttrs.get("filename"));
}
-
-
+
@Test
public void testSendAsFlowFileSecure() throws Exception {
final Map<String, String> sslProps = new HashMap<>();
- sslProps.put(StandardSSLContextService.KEYSTORE.getName(), "src/test/resources/localhost-ks.jks");
- sslProps.put(StandardSSLContextService.KEYSTORE_PASSWORD.getName(), "localtest");
+ sslProps.
+ put(StandardSSLContextService.KEYSTORE.getName(), "src/test/resources/localhost-ks.jks");
+ sslProps.
+ put(StandardSSLContextService.KEYSTORE_PASSWORD.getName(), "localtest");
sslProps.put(StandardSSLContextService.KEYSTORE_TYPE.getName(), "JKS");
- sslProps.put(StandardSSLContextService.TRUSTSTORE.getName(), "src/test/resources/localhost-ts.jks");
- sslProps.put(StandardSSLContextService.TRUSTSTORE_PASSWORD.getName(), "localtest");
+ sslProps.
+ put(StandardSSLContextService.TRUSTSTORE.getName(), "src/test/resources/localhost-ts.jks");
+ sslProps.
+ put(StandardSSLContextService.TRUSTSTORE_PASSWORD.getName(), "localtest");
sslProps.put(StandardSSLContextService.TRUSTSTORE_TYPE.getName(), "JKS");
sslProps.put(TestServer.NEED_CLIENT_AUTH, "true");
setup(sslProps);
-
+
final SSLContextService sslContextService = new StandardSSLContextService();
runner.addControllerService("ssl-context", sslContextService);
- runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE, "src/test/resources/localhost-ts.jks");
- runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE_PASSWORD, "localtest");
- runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE_TYPE, "JKS");
- runner.setProperty(sslContextService, StandardSSLContextService.KEYSTORE, "src/test/resources/localhost-ks.jks");
- runner.setProperty(sslContextService, StandardSSLContextService.KEYSTORE_PASSWORD, "localtest");
- runner.setProperty(sslContextService, StandardSSLContextService.KEYSTORE_TYPE, "JKS");
+ runner.
+ setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE, "src/test/resources/localhost-ts.jks");
+ runner.
+ setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE_PASSWORD, "localtest");
+ runner.
+ setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE_TYPE, "JKS");
+ runner.
+ setProperty(sslContextService, StandardSSLContextService.KEYSTORE, "src/test/resources/localhost-ks.jks");
+ runner.
+ setProperty(sslContextService, StandardSSLContextService.KEYSTORE_PASSWORD, "localtest");
+ runner.
+ setProperty(sslContextService, StandardSSLContextService.KEYSTORE_TYPE, "JKS");
runner.enableControllerService(sslContextService);
-
+
runner.setProperty(PostHTTP.URL, server.getSecureUrl());
runner.setProperty(PostHTTP.SEND_AS_FLOWFILE, "true");
runner.setProperty(PostHTTP.SSL_CONTEXT_SERVICE, "ssl-context");
final Map<String, String> attrs = new HashMap<>();
attrs.put("abc", "cba");
-
+
runner.enqueue("Hello".getBytes(), attrs);
attrs.put("abc", "abc");
attrs.put("filename", "xyz.txt");
runner.enqueue("World".getBytes(), attrs);
-
+
runner.run(1);
runner.assertAllFlowFilesTransferred(PostHTTP.REL_SUCCESS);
-
+
final byte[] lastPost = servlet.getLastPost();
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final ByteArrayInputStream bais = new ByteArrayInputStream(lastPost);
-
+
FlowFileUnpackagerV3 unpacker = new FlowFileUnpackagerV3();
-
+
// unpack first flowfile received
- Map<String, String> receivedAttrs = unpacker.unpackageFlowFile(bais, baos);
+ Map<String, String> receivedAttrs = unpacker.
+ unpackageFlowFile(bais, baos);
byte[] contentReceived = baos.toByteArray();
assertEquals("Hello", new String(contentReceived));
assertEquals("cba", receivedAttrs.get("abc"));
-
- assertTrue( unpacker.hasMoreData() );
-
+
+ assertTrue(unpacker.hasMoreData());
+
baos.reset();
receivedAttrs = unpacker.unpackageFlowFile(bais, baos);
contentReceived = baos.toByteArray();
-
+
assertEquals("World", new String(contentReceived));
assertEquals("abc", receivedAttrs.get("abc"));
assertEquals("xyz.txt", receivedAttrs.get("filename"));
}
-
+
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/54818893/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutEmail.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutEmail.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutEmail.java
index b0ce477..313790e 100644
--- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutEmail.java
+++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutEmail.java
@@ -19,19 +19,18 @@ package org.apache.nifi.processors.standard;
import java.util.HashMap;
import java.util.Map;
-import org.apache.nifi.flowfile.FlowFile;
-import org.apache.nifi.processor.ProcessContext;
-import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
+import static org.junit.Assert.assertEquals;
import org.junit.Test;
-import static org.junit.Assert.*;
-
public class TestPutEmail {
@Test
- public void testHostNotFound() {
+ public void testHostNotFound() {
// verifies that files are routed to failure when the SMTP host doesn't exist
final TestRunner runner = TestRunners.newTestRunner(new PutEmail());
runner.setProperty(PutEmail.SMTP_HOSTNAME, "host-doesnt-exist123");
@@ -47,37 +46,44 @@ public class TestPutEmail {
runner.assertQueueEmpty();
runner.assertAllFlowFilesTransferred(PutEmail.REL_FAILURE);
}
-
- @Test
- public void testEmailPropertyFormatters() {
- // verifies that files are routed to failure when the SMTP host doesn't exist
- final TestRunner runner = TestRunners.newTestRunner(new PutEmail());
- runner.setProperty(PutEmail.HEADER_XMAILER, "TestingNiFi");
- runner.setProperty(PutEmail.SMTP_HOSTNAME, "smtp-host");
- runner.setProperty(PutEmail.SMTP_SOCKET_FACTORY, "${dynamicSocketFactory}");
- runner.setProperty(PutEmail.HEADER_XMAILER, "TestingNiFi");
- runner.setProperty(PutEmail.FROM, "test@apache.org");
- runner.setProperty(PutEmail.MESSAGE, "Message Body");
- runner.setProperty(PutEmail.TO, "recipient@apache.org");
-
- ProcessSession session = runner.getProcessSessionFactory().createSession();
- FlowFile ff = session.create();
- ff = session.putAttribute(ff, "dynamicSocketFactory", "testingSocketFactory");
- ProcessContext context = runner.getProcessContext();
-
- String xmailer = context.getProperty(PutEmail.HEADER_XMAILER).evaluateAttributeExpressions(ff).getValue();
- assertEquals("X-Mailer Header", "TestingNiFi", xmailer);
-
- String socketFactory = context.getProperty(PutEmail.SMTP_SOCKET_FACTORY).evaluateAttributeExpressions(ff).getValue();
- assertEquals("Socket Factory", "testingSocketFactory", socketFactory);
-
- final Map<String, String> attributes = new HashMap<>();
- runner.enqueue("Some Text".getBytes(), attributes);
-
- runner.run();
-
- runner.assertQueueEmpty();
- runner.assertAllFlowFilesTransferred(PutEmail.REL_FAILURE);
- }
-
+
+ @Test
+ public void testEmailPropertyFormatters() {
+ // verifies that files are routed to failure when the SMTP host doesn't exist
+ final TestRunner runner = TestRunners.newTestRunner(new PutEmail());
+ runner.setProperty(PutEmail.HEADER_XMAILER, "TestingNiFi");
+ runner.setProperty(PutEmail.SMTP_HOSTNAME, "smtp-host");
+ runner.
+ setProperty(PutEmail.SMTP_SOCKET_FACTORY, "${dynamicSocketFactory}");
+ runner.setProperty(PutEmail.HEADER_XMAILER, "TestingNiFi");
+ runner.setProperty(PutEmail.FROM, "test@apache.org");
+ runner.setProperty(PutEmail.MESSAGE, "Message Body");
+ runner.setProperty(PutEmail.TO, "recipient@apache.org");
+
+ ProcessSession session = runner.getProcessSessionFactory().
+ createSession();
+ FlowFile ff = session.create();
+ ff = session.
+ putAttribute(ff, "dynamicSocketFactory", "testingSocketFactory");
+ ProcessContext context = runner.getProcessContext();
+
+ String xmailer = context.getProperty(PutEmail.HEADER_XMAILER).
+ evaluateAttributeExpressions(ff).
+ getValue();
+ assertEquals("X-Mailer Header", "TestingNiFi", xmailer);
+
+ String socketFactory = context.getProperty(PutEmail.SMTP_SOCKET_FACTORY).
+ evaluateAttributeExpressions(ff).
+ getValue();
+ assertEquals("Socket Factory", "testingSocketFactory", socketFactory);
+
+ final Map<String, String> attributes = new HashMap<>();
+ runner.enqueue("Some Text".getBytes(), attributes);
+
+ runner.run();
+
+ runner.assertQueueEmpty();
+ runner.assertAllFlowFilesTransferred(PutEmail.REL_FAILURE);
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/54818893/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceText.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceText.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceText.java
index e340468..4722a84 100644
--- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceText.java
+++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceText.java
@@ -42,7 +42,9 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).
+ get(0);
out.assertContentEquals("Hlleo, World!".getBytes("UTF-8"));
}
@@ -57,7 +59,9 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).
+ get(0);
out.assertContentEquals("H[ell]o, World!");
}
@@ -74,7 +78,9 @@ public class TestReplaceText {
runner.enqueue(Paths.get("src/test/resources/hello.txt"), attributes);
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).
+ get(0);
final String actual = new String(out.toByteArray(), StandardCharsets.UTF_8);
System.out.println(actual);
Assert.assertEquals(expected, actual);
@@ -92,7 +98,9 @@ public class TestReplaceText {
runner.enqueue(Paths.get("src/test/resources/hello.txt"), attributes);
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).
+ get(0);
final String actual = new String(out.toByteArray(), StandardCharsets.UTF_8);
Assert.assertEquals("Hell123o, World!", actual);
}
@@ -111,7 +119,9 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).
+ get(0);
out.assertContentEquals("Hello, World!");
}
@@ -129,7 +139,9 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).
+ get(0);
out.assertContentEquals("H[$1]o, World!");
}
@@ -148,7 +160,9 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).
+ get(0);
out.assertContentEquals("Good-bye, World!");
}
@@ -167,7 +181,9 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).
+ get(0);
out.assertContentEquals("Hello, World!");
}
@@ -186,7 +202,9 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).
+ get(0);
out.assertContentEquals("Hell$2o, World!");
}
@@ -205,7 +223,9 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).
+ get(0);
out.assertContentEquals("H$do, World!");
}
@@ -224,7 +244,9 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).
+ get(0);
out.assertContentEquals("H$1o, World!");
}
@@ -239,7 +261,9 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).
+ get(0);
out.assertContentEquals("Ho, World!");
}
@@ -254,7 +278,9 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).
+ get(0);
out.assertContentEquals("Hello, World!");
}
@@ -269,7 +295,9 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).
+ get(0);
out.assertContentEquals("HeRRo, WorRd!");
}
@@ -287,7 +315,9 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).
+ get(0);
out.assertContentEquals("Good");
}
@@ -323,7 +353,9 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).
+ get(0);
out.assertContentEquals("Good");
}
@@ -332,7 +364,8 @@ public class TestReplaceText {
final TestRunner runner = TestRunners.newTestRunner(new ReplaceText());
runner.setValidateExpressionUsage(false);
runner.setProperty(ReplaceText.REGEX, ".*");
- runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "${filename}\t${now():format(\"yyyy/MM/dd'T'HHmmss'Z'\")}\t${fileSize}\n");
+ runner.
+ setProperty(ReplaceText.REPLACEMENT_VALUE, "${filename}\t${now():format(\"yyyy/MM/dd'T'HHmmss'Z'\")}\t${fileSize}\n");
final Map<String, String> attributes = new HashMap<>();
attributes.put("filename", "abc.txt");
@@ -341,7 +374,9 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).
+ get(0);
final String outContent = new String(out.toByteArray(), StandardCharsets.UTF_8);
Assert.assertTrue(outContent.startsWith("abc.txt\t"));
System.out.println(outContent);
@@ -353,7 +388,8 @@ public class TestReplaceText {
final TestRunner runner = TestRunners.newTestRunner(new ReplaceText());
runner.setValidateExpressionUsage(false);
runner.setProperty(ReplaceText.REGEX, "(?s)(^.*)");
- runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "attribute header\n\n${filename}\n\ndata header\n\n$1\n\nfooter");
+ runner.
+ setProperty(ReplaceText.REPLACEMENT_VALUE, "attribute header\n\n${filename}\n\ndata header\n\n$1\n\nfooter");
final Map<String, String> attributes = new HashMap<>();
attributes.put("filename", "abc.txt");
@@ -362,9 +398,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).
+ get(0);
final String outContent = new String(out.toByteArray(), StandardCharsets.UTF_8);
- Assert.assertTrue(outContent.equals("attribute header\n\nabc.txt\n\ndata header\n\nHello\nWorld!\n\nfooter"));
+ Assert.assertTrue(outContent.
+ equals("attribute header\n\nabc.txt\n\ndata header\n\nHello\nWorld!\n\nfooter"));
System.out.println(outContent);
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/54818893/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceTextLineByLine.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceTextLineByLine.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceTextLineByLine.java
index 1c0ea57..9c19369 100644
--- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceTextLineByLine.java
+++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceTextLineByLine.java
@@ -40,236 +40,300 @@ public class TestReplaceTextLineByLine {
public void testSimple() throws IOException {
final TestRunner runner = TestRunners.newTestRunner(new ReplaceText());
runner.setValidateExpressionUsage(false);
- runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
+ runner.
+ setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.REGEX, "odo");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "ood");
- runner.enqueue(translateNewLines(Paths.get("src/test/resources/TestReplaceTextLineByLine/testFile.txt")));
+ runner.enqueue(translateNewLines(Paths.
+ get("src/test/resources/TestReplaceTextLineByLine/testFile.txt")));
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
- out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/food.txt")));
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).
+ get(0);
+ out.
+ assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/food.txt")));
}
@Test
public void testBackReference() throws IOException {
final TestRunner runner = TestRunners.newTestRunner(new ReplaceText());
runner.setValidateExpressionUsage(false);
- runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
+ runner.
+ setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.REGEX, "(DODO)");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "[$1]");
- runner.enqueue(translateNewLines(Paths.get("src/test/resources/TestReplaceTextLineByLine/testFile.txt")));
+ runner.enqueue(translateNewLines(Paths.
+ get("src/test/resources/TestReplaceTextLineByLine/testFile.txt")));
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
- out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/[DODO].txt")));
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).
+ get(0);
+ out.
+ assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/[DODO].txt")));
}
@Test
public void testReplacementWithExpressionLanguageIsEscaped() throws IOException {
final TestRunner runner = TestRunners.newTestRunner(new ReplaceText());
runner.setValidateExpressionUsage(false);
- runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
+ runner.
+ setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.REGEX, "(jo)");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "[${abc}]");
final Map<String, String> attributes = new HashMap<>();
attributes.put("abc", "$1");
- runner.enqueue(translateNewLines(Paths.get("src/test/resources/TestReplaceTextLineByLine/testFile.txt")), attributes);
+ runner.enqueue(translateNewLines(Paths.
+ get("src/test/resources/TestReplaceTextLineByLine/testFile.txt")), attributes);
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
- out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/cu[$1]_Po[$1].txt")));
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).
+ get(0);
+ out.
+ assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/cu[$1]_Po[$1].txt")));
}
@Test
public void testRegexWithExpressionLanguage() throws IOException {
final TestRunner runner = TestRunners.newTestRunner(new ReplaceText());
runner.setValidateExpressionUsage(false);
- runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
+ runner.
+ setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.REGEX, "${replaceKey}");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "${replaceValue}");
final Map<String, String> attributes = new HashMap<>();
attributes.put("replaceKey", "Riley");
attributes.put("replaceValue", "Spider");
- runner.enqueue(translateNewLines(Paths.get("src/test/resources/TestReplaceTextLineByLine/testFile.txt")), attributes);
+ runner.enqueue(translateNewLines(Paths.
+ get("src/test/resources/TestReplaceTextLineByLine/testFile.txt")), attributes);
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
- out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/Spider.txt")));
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).
+ get(0);
+ out.
+ assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/Spider.txt")));
}
@Test
public void testRegexWithExpressionLanguageIsEscaped() throws IOException {
final TestRunner runner = TestRunners.newTestRunner(new ReplaceText());
runner.setValidateExpressionUsage(false);
- runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
+ runner.
+ setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.REGEX, "${replaceKey}");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "${replaceValue}");
final Map<String, String> attributes = new HashMap<>();
attributes.put("replaceKey", "R.*y");
attributes.put("replaceValue", "Spider");
- runner.enqueue(translateNewLines(Paths.get("src/test/resources/TestReplaceTextLineByLine/testFile.txt")), attributes);
+ runner.enqueue(translateNewLines(Paths.
+ get("src/test/resources/TestReplaceTextLineByLine/testFile.txt")), attributes);
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
- out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/testFile.txt")));
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).
+ get(0);
+ out.
+ assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/testFile.txt")));
}
@Test
public void testBackReferenceWithTooLargeOfIndexIsEscaped() throws IOException {
final TestRunner runner = TestRunners.newTestRunner(new ReplaceText());
runner.setValidateExpressionUsage(false);
- runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
+ runner.
+ setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.REGEX, "(lu)");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "$1$2");
final Map<String, String> attributes = new HashMap<>();
attributes.put("replaceKey", "R.*y");
attributes.put("replaceValue", "Spiderman");
- runner.enqueue(translateNewLines(Paths.get("src/test/resources/TestReplaceTextLineByLine/testFile.txt")), attributes);
+ runner.enqueue(translateNewLines(Paths.
+ get("src/test/resources/TestReplaceTextLineByLine/testFile.txt")), attributes);
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
- out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/Blu$2e_clu$2e.txt")));
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).
+ get(0);
+ out.
+ assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/Blu$2e_clu$2e.txt")));
}
@Test
public void testBackReferenceWithInvalidReferenceIsEscaped() throws IOException {
final TestRunner runner = TestRunners.newTestRunner(new ReplaceText());
runner.setValidateExpressionUsage(false);
- runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
+ runner.
+ setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.REGEX, "(ew)");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "$d");
final Map<String, String> attributes = new HashMap<>();
attributes.put("replaceKey", "H.*o");
attributes.put("replaceValue", "Good-bye");
- runner.enqueue(translateNewLines(Paths.get("src/test/resources/TestReplaceTextLineByLine/testFile.txt")), attributes);
+ runner.enqueue(translateNewLines(Paths.
+ get("src/test/resources/TestReplaceTextLineByLine/testFile.txt")), attributes);
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
- out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/D$d_h$d.txt")));
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).
+ get(0);
+ out.
+ assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/D$d_h$d.txt")));
}
@Test
public void testEscapingDollarSign() throws IOException {
final TestRunner runner = TestRunners.newTestRunner(new ReplaceText());
runner.setValidateExpressionUsage(false);
- runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
+ runner.
+ setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.REGEX, "(DO)");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "\\$1");
final Map<String, String> attributes = new HashMap<>();
attributes.put("replaceKey", "H.*o");
attributes.put("replaceValue", "Good-bye");
- runner.enqueue(translateNewLines(Paths.get("src/test/resources/TestReplaceTextLineByLine/testFile.txt")), attributes);
+ runner.enqueue(translateNewLines(Paths.
+ get("src/test/resources/TestReplaceTextLineByLine/testFile.txt")), attributes);
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
- out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/$1$1.txt")));
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).
+ get(0);
+ out.
+ assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/$1$1.txt")));
}
@Test
public void testReplaceWithEmptyString() throws IOException {
final TestRunner runner = TestRunners.newTestRunner(new ReplaceText());
runner.setValidateExpressionUsage(false);
- runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
+ runner.
+ setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.REGEX, "(jo)");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "");
- runner.enqueue(translateNewLines(Paths.get("src/test/resources/TestReplaceTextLineByLine/testFile.txt")));
+ runner.enqueue(translateNewLines(Paths.
+ get("src/test/resources/TestReplaceTextLineByLine/testFile.txt")));
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
- out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/cu_Po.txt")));
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).
+ get(0);
+ out.
+ assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/cu_Po.txt")));
}
@Test
public void testWithNoMatch() throws IOException {
final TestRunner runner = TestRunners.newTestRunner(new ReplaceText());
runner.setValidateExpressionUsage(false);
- runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
+ runner.
+ setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.REGEX, "Z");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "Morning");
- runner.enqueue(translateNewLines(Paths.get("src/test/resources/TestReplaceTextLineByLine/testFile.txt")));
+ runner.enqueue(translateNewLines(Paths.
+ get("src/test/resources/TestReplaceTextLineByLine/testFile.txt")));
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
- out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/testFile.txt")));
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).
+ get(0);
+ out.
+ assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/testFile.txt")));
}
@Test
public void testWithMultipleMatches() throws IOException {
final TestRunner runner = TestRunners.newTestRunner(new ReplaceText());
runner.setValidateExpressionUsage(false);
- runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
+ runner.
+ setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.REGEX, "l");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "R");
- runner.enqueue(translateNewLines(Paths.get("src/test/resources/TestReplaceTextLineByLine/testFile.txt")));
+ runner.enqueue(translateNewLines(Paths.
+ get("src/test/resources/TestReplaceTextLineByLine/testFile.txt")));
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
- out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/BRue_cRue_RiRey.txt")));
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).
+ get(0);
+ out.
+ assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/BRue_cRue_RiRey.txt")));
}
@Test
public void testAttributeToContent() throws IOException {
final TestRunner runner = TestRunners.newTestRunner(new ReplaceText());
runner.setValidateExpressionUsage(false);
- runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
+ runner.
+ setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.REGEX, ".*");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "${abc}");
final Map<String, String> attributes = new HashMap<>();
attributes.put("abc", "Good");
- runner.enqueue(translateNewLines(Paths.get("src/test/resources/TestReplaceTextLineByLine/testFile.txt")), attributes);
+ runner.enqueue(translateNewLines(Paths.
+ get("src/test/resources/TestReplaceTextLineByLine/testFile.txt")), attributes);
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
- out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/Good.txt")));
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).
+ get(0);
+ out.
+ assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/Good.txt")));
}
@Test
public void testAttributeToContentWindows() throws IOException {
final TestRunner runner = TestRunners.newTestRunner(new ReplaceText());
runner.setValidateExpressionUsage(false);
- runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
+ runner.
+ setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.REGEX, ".*");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "${abc}");
final Map<String, String> attributes = new HashMap<>();
attributes.put("abc", "Good");
- runner.enqueue("<<<HEADER>>>\r\n<<BODY>>\r\n<<<FOOTER>>>\r".getBytes(), attributes);
+ runner.
+ enqueue("<<<HEADER>>>\r\n<<BODY>>\r\n<<<FOOTER>>>\r".getBytes(), attributes);
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).
+ get(0);
out.assertContentEquals("GoodGoodGood");
}
@@ -277,31 +341,39 @@ public class TestReplaceTextLineByLine {
public void testProblematicCase1() throws IOException {
final TestRunner runner = TestRunners.newTestRunner(new ReplaceText());
runner.setValidateExpressionUsage(false);
- runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
+ runner.
+ setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.REGEX, ".*");
- runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "${filename}\t${now():format(\"yyyy/MM/dd'T'HHmmss'Z'\")}\t${fileSize}\n");
+ runner.
+ setProperty(ReplaceText.REPLACEMENT_VALUE, "${filename}\t${now():format(\"yyyy/MM/dd'T'HHmmss'Z'\")}\t${fileSize}\n");
final Map<String, String> attributes = new HashMap<>();
attributes.put("filename", "abc.txt");
- runner.enqueue(translateNewLines(Paths.get("src/test/resources/TestReplaceTextLineByLine/testFile.txt")), attributes);
+ runner.enqueue(translateNewLines(Paths.
+ get("src/test/resources/TestReplaceTextLineByLine/testFile.txt")), attributes);
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).
+ get(0);
final String outContent = translateNewLines(new String(out.toByteArray(), StandardCharsets.UTF_8));
Assert.assertTrue(outContent.startsWith("abc.txt\t"));
System.out.println(outContent);
- Assert.assertTrue(outContent.endsWith("193\n") || outContent.endsWith("203\r\n"));
+ Assert.assertTrue(outContent.endsWith("193\n") || outContent.
+ endsWith("203\r\n"));
}
@Test
public void testGetExistingContent() throws IOException {
final TestRunner runner = TestRunners.newTestRunner(new ReplaceText());
runner.setValidateExpressionUsage(false);
- runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
+ runner.
+ setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.REGEX, "(?s)(^.*)");
- runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "attribute header\n\n${filename}\n\ndata header\n\n$1\n\nfooter\n");
+ runner.
+ setProperty(ReplaceText.REPLACEMENT_VALUE, "attribute header\n\n${filename}\n\ndata header\n\n$1\n\nfooter\n");
final Map<String, String> attributes = new HashMap<>();
attributes.put("filename", "abc.txt");
@@ -310,11 +382,14 @@ public class TestReplaceTextLineByLine {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.
+ getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).
+ get(0);
final String outContent = new String(out.toByteArray(), StandardCharsets.UTF_8);
System.out.println(outContent);
- Assert.assertTrue(outContent.equals("attribute header\n\nabc.txt\n\ndata header\n\nHello\n\n\nfooter\n"
- + "attribute header\n\nabc.txt\n\ndata header\n\nWorld!\n\nfooter\n"));
+ Assert.assertTrue(outContent.
+ equals("attribute header\n\nabc.txt\n\ndata header\n\nHello\n\n\nfooter\n"
+ + "attribute header\n\nabc.txt\n\ndata header\n\nWorld!\n\nfooter\n"));
}
@@ -325,13 +400,15 @@ public class TestReplaceTextLineByLine {
private byte[] translateNewLines(final Path path) throws IOException {
final byte[] data = Files.readAllBytes(path);
final String text = new String(data, StandardCharsets.UTF_8);
- return translateNewLines(text).getBytes(StandardCharsets.UTF_8);
+ return translateNewLines(text).
+ getBytes(StandardCharsets.UTF_8);
}
private String translateNewLines(final String text) {
final String lineSeparator = System.getProperty("line.separator");
final Pattern pattern = Pattern.compile("\n", Pattern.MULTILINE);
- final String translated = pattern.matcher(text).replaceAll(lineSeparator);
+ final String translated = pattern.matcher(text).
+ replaceAll(lineSeparator);
return translated;
}
}