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/TestReplaceTextWithMapping.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceTextWithMapping.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceTextWithMapping.java index 080f4b2..89f330b 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceTextWithMapping.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceTextWithMapping.java @@ -36,15 +36,23 @@ public class TestReplaceTextWithMapping { @Test public void testSimple() throws IOException { - final TestRunner runner = TestRunners.newTestRunner(new ReplaceTextWithMapping()); - final String mappingFile = Paths.get("src/test/resources/TestReplaceTextWithMapping/color-fruit-mapping.txt").toFile().getAbsolutePath(); + final TestRunner runner = TestRunners. + newTestRunner(new ReplaceTextWithMapping()); + final String mappingFile = Paths. + get("src/test/resources/TestReplaceTextWithMapping/color-fruit-mapping.txt"). + toFile(). + getAbsolutePath(); runner.setProperty(ReplaceTextWithMapping.MAPPING_FILE, mappingFile); - runner.enqueue(Paths.get("src/test/resources/TestReplaceTextWithMapping/colors-without-dashes.txt")); + runner.enqueue(Paths. + get("src/test/resources/TestReplaceTextWithMapping/colors-without-dashes.txt")); runner.run(); - runner.assertAllFlowFilesTransferred(ReplaceTextWithMapping.REL_SUCCESS, 1); - final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceTextWithMapping.REL_SUCCESS).get(0); + runner. + assertAllFlowFilesTransferred(ReplaceTextWithMapping.REL_SUCCESS, 1); + final MockFlowFile out = runner. + getFlowFilesForRelationship(ReplaceTextWithMapping.REL_SUCCESS). + get(0); String outputString = new String(out.toByteArray()); String expected = "roses are apple\n" + "violets are blueberry\n" @@ -55,8 +63,12 @@ public class TestReplaceTextWithMapping { @Test public void testExpressionLanguageInText() throws IOException { - final TestRunner runner = TestRunners.newTestRunner(new ReplaceTextWithMapping()); - final String mappingFile = Paths.get("src/test/resources/TestReplaceTextWithMapping/color-fruit-mapping.txt").toFile().getAbsolutePath(); + final TestRunner runner = TestRunners. + newTestRunner(new ReplaceTextWithMapping()); + final String mappingFile = Paths. + get("src/test/resources/TestReplaceTextWithMapping/color-fruit-mapping.txt"). + toFile(). + getAbsolutePath(); runner.setProperty(ReplaceTextWithMapping.MAPPING_FILE, mappingFile); String text = "${foo} red ${baz}"; @@ -64,8 +76,11 @@ public class TestReplaceTextWithMapping { runner.enqueue(text.getBytes()); runner.run(); - runner.assertAllFlowFilesTransferred(ReplaceTextWithMapping.REL_SUCCESS, 1); - final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceTextWithMapping.REL_SUCCESS).get(0); + runner. + assertAllFlowFilesTransferred(ReplaceTextWithMapping.REL_SUCCESS, 1); + final MockFlowFile out = runner. + getFlowFilesForRelationship(ReplaceTextWithMapping.REL_SUCCESS). + get(0); String outputString = new String(out.toByteArray()); String expected = "${foo} apple ${baz}"; assertEquals(expected, outputString); @@ -73,19 +88,27 @@ public class TestReplaceTextWithMapping { @Test public void testExpressionLanguageInText2() throws IOException { - final TestRunner runner = TestRunners.newTestRunner(new ReplaceTextWithMapping()); - final String mappingFile = Paths.get("src/test/resources/TestReplaceTextWithMapping/color-fruit-mapping.txt").toFile().getAbsolutePath(); + final TestRunner runner = TestRunners. + newTestRunner(new ReplaceTextWithMapping()); + final String mappingFile = Paths. + get("src/test/resources/TestReplaceTextWithMapping/color-fruit-mapping.txt"). + toFile(). + getAbsolutePath(); runner.setProperty(ReplaceTextWithMapping.MAPPING_FILE, mappingFile); runner.setProperty(ReplaceTextWithMapping.REGEX, "\\|(.*?)\\|"); - runner.setProperty(ReplaceTextWithMapping.MATCHING_GROUP_FOR_LOOKUP_KEY, "1"); + runner. + setProperty(ReplaceTextWithMapping.MATCHING_GROUP_FOR_LOOKUP_KEY, "1"); String text = "${foo}|red|${baz}"; runner.enqueue(text.getBytes()); runner.run(); - runner.assertAllFlowFilesTransferred(ReplaceTextWithMapping.REL_SUCCESS, 1); - final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceTextWithMapping.REL_SUCCESS).get(0); + runner. + assertAllFlowFilesTransferred(ReplaceTextWithMapping.REL_SUCCESS, 1); + final MockFlowFile out = runner. + getFlowFilesForRelationship(ReplaceTextWithMapping.REL_SUCCESS). + get(0); String outputString = new String(out.toByteArray()); String expected = "${foo}|apple|${baz}"; assertEquals(expected, outputString); @@ -93,19 +116,27 @@ public class TestReplaceTextWithMapping { @Test public void testExpressionLanguageInText3() throws IOException { - final TestRunner runner = TestRunners.newTestRunner(new ReplaceTextWithMapping()); - final String mappingFile = Paths.get("src/test/resources/TestReplaceTextWithMapping/color-fruit-mapping.txt").toFile().getAbsolutePath(); + final TestRunner runner = TestRunners. + newTestRunner(new ReplaceTextWithMapping()); + final String mappingFile = Paths. + get("src/test/resources/TestReplaceTextWithMapping/color-fruit-mapping.txt"). + toFile(). + getAbsolutePath(); runner.setProperty(ReplaceTextWithMapping.MAPPING_FILE, mappingFile); runner.setProperty(ReplaceTextWithMapping.REGEX, ".*\\|(.*?)\\|.*"); - runner.setProperty(ReplaceTextWithMapping.MATCHING_GROUP_FOR_LOOKUP_KEY, "1"); + runner. + setProperty(ReplaceTextWithMapping.MATCHING_GROUP_FOR_LOOKUP_KEY, "1"); String text = "${foo}|red|${baz}"; runner.enqueue(text.getBytes()); runner.run(); - runner.assertAllFlowFilesTransferred(ReplaceTextWithMapping.REL_SUCCESS, 1); - final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceTextWithMapping.REL_SUCCESS).get(0); + runner. + assertAllFlowFilesTransferred(ReplaceTextWithMapping.REL_SUCCESS, 1); + final MockFlowFile out = runner. + getFlowFilesForRelationship(ReplaceTextWithMapping.REL_SUCCESS). + get(0); String outputString = new String(out.toByteArray()); String expected = "${foo}|apple|${baz}"; assertEquals(expected, outputString); @@ -113,16 +144,25 @@ public class TestReplaceTextWithMapping { @Test public void testWithMatchingGroupAndContext() throws IOException { - final TestRunner runner = TestRunners.newTestRunner(new ReplaceTextWithMapping()); + final TestRunner runner = TestRunners. + newTestRunner(new ReplaceTextWithMapping()); runner.setProperty(ReplaceTextWithMapping.REGEX, "-(.*?)-"); - runner.setProperty(ReplaceTextWithMapping.MATCHING_GROUP_FOR_LOOKUP_KEY, "1"); - runner.setProperty(ReplaceTextWithMapping.MAPPING_FILE, Paths.get("src/test/resources/TestReplaceTextWithMapping/color-fruit-mapping.txt").toFile().getAbsolutePath()); - - runner.enqueue(Paths.get("src/test/resources/TestReplaceTextWithMapping/colors.txt")); + runner. + setProperty(ReplaceTextWithMapping.MATCHING_GROUP_FOR_LOOKUP_KEY, "1"); + runner.setProperty(ReplaceTextWithMapping.MAPPING_FILE, Paths. + get("src/test/resources/TestReplaceTextWithMapping/color-fruit-mapping.txt"). + toFile(). + getAbsolutePath()); + + runner.enqueue(Paths. + get("src/test/resources/TestReplaceTextWithMapping/colors.txt")); runner.run(); - runner.assertAllFlowFilesTransferred(ReplaceTextWithMapping.REL_SUCCESS, 1); - final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceTextWithMapping.REL_SUCCESS).get(0); + runner. + assertAllFlowFilesTransferred(ReplaceTextWithMapping.REL_SUCCESS, 1); + final MockFlowFile out = runner. + getFlowFilesForRelationship(ReplaceTextWithMapping.REL_SUCCESS). + get(0); String outputString = new String(out.toByteArray()); String expected = "-roses- are -apple-\n" + "violets are -blueberry-\n" @@ -133,16 +173,25 @@ public class TestReplaceTextWithMapping { @Test public void testBackReference() throws IOException { - final TestRunner runner = TestRunners.newTestRunner(new ReplaceTextWithMapping()); + final TestRunner runner = TestRunners. + newTestRunner(new ReplaceTextWithMapping()); runner.setProperty(ReplaceTextWithMapping.REGEX, "(\\S+)"); - runner.setProperty(ReplaceTextWithMapping.MATCHING_GROUP_FOR_LOOKUP_KEY, "1"); - runner.setProperty(ReplaceTextWithMapping.MAPPING_FILE, Paths.get("src/test/resources/TestReplaceTextWithMapping/color-fruit-backreference-mapping.txt").toFile().getAbsolutePath()); - - runner.enqueue(Paths.get("src/test/resources/TestReplaceTextWithMapping/colors-without-dashes.txt")); + runner. + setProperty(ReplaceTextWithMapping.MATCHING_GROUP_FOR_LOOKUP_KEY, "1"); + runner.setProperty(ReplaceTextWithMapping.MAPPING_FILE, Paths. + get("src/test/resources/TestReplaceTextWithMapping/color-fruit-backreference-mapping.txt"). + toFile(). + getAbsolutePath()); + + runner.enqueue(Paths. + get("src/test/resources/TestReplaceTextWithMapping/colors-without-dashes.txt")); runner.run(); - runner.assertAllFlowFilesTransferred(ReplaceTextWithMapping.REL_SUCCESS, 1); - final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceTextWithMapping.REL_SUCCESS).get(0); + runner. + assertAllFlowFilesTransferred(ReplaceTextWithMapping.REL_SUCCESS, 1); + final MockFlowFile out = runner. + getFlowFilesForRelationship(ReplaceTextWithMapping.REL_SUCCESS). + get(0); String outputString = new String(out.toByteArray()); String expected = "roses are red apple\n" + "violets are blue blueberry\n" @@ -153,32 +202,47 @@ public class TestReplaceTextWithMapping { @Test public void testRoutesToFailureIfTooLarge() throws IOException { - final TestRunner runner = TestRunners.newTestRunner(new ReplaceTextWithMapping()); + final TestRunner runner = TestRunners. + newTestRunner(new ReplaceTextWithMapping()); runner.setProperty(ReplaceTextWithMapping.REGEX, "[123]"); runner.setProperty(ReplaceTextWithMapping.MAX_BUFFER_SIZE, "1 b"); - runner.setProperty(ReplaceTextWithMapping.MAPPING_FILE, Paths.get("src/test/resources/TestReplaceTextWithMapping/color-fruit-mapping.txt").toFile().getAbsolutePath()); + runner.setProperty(ReplaceTextWithMapping.MAPPING_FILE, Paths. + get("src/test/resources/TestReplaceTextWithMapping/color-fruit-mapping.txt"). + toFile(). + getAbsolutePath()); final Map<String, String> attributes = new HashMap<>(); attributes.put("abc", "Good"); - runner.enqueue(Paths.get("src/test/resources/TestReplaceTextWithMapping/colors.txt")); + runner.enqueue(Paths. + get("src/test/resources/TestReplaceTextWithMapping/colors.txt")); runner.run(); - runner.assertAllFlowFilesTransferred(ReplaceTextWithMapping.REL_FAILURE, 1); + runner. + assertAllFlowFilesTransferred(ReplaceTextWithMapping.REL_FAILURE, 1); } @Test public void testBackReferenceWithTooLargeOfIndexIsEscaped() throws IOException { - final TestRunner runner = TestRunners.newTestRunner(new ReplaceTextWithMapping()); + final TestRunner runner = TestRunners. + newTestRunner(new ReplaceTextWithMapping()); runner.setProperty(ReplaceTextWithMapping.REGEX, "-(.*?)-"); - runner.setProperty(ReplaceTextWithMapping.MATCHING_GROUP_FOR_LOOKUP_KEY, "1"); - runner.setProperty(ReplaceTextWithMapping.MAPPING_FILE, Paths.get("src/test/resources/TestReplaceTextWithMapping/color-fruit-excessive-backreference-mapping.txt").toFile().getAbsolutePath()); - - runner.enqueue(Paths.get("src/test/resources/TestReplaceTextWithMapping/colors.txt")); + runner. + setProperty(ReplaceTextWithMapping.MATCHING_GROUP_FOR_LOOKUP_KEY, "1"); + runner.setProperty(ReplaceTextWithMapping.MAPPING_FILE, Paths. + get("src/test/resources/TestReplaceTextWithMapping/color-fruit-excessive-backreference-mapping.txt"). + toFile(). + getAbsolutePath()); + + runner.enqueue(Paths. + get("src/test/resources/TestReplaceTextWithMapping/colors.txt")); runner.run(); - runner.assertAllFlowFilesTransferred(ReplaceTextWithMapping.REL_SUCCESS, 1); - final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceTextWithMapping.REL_SUCCESS).get(0); + runner. + assertAllFlowFilesTransferred(ReplaceTextWithMapping.REL_SUCCESS, 1); + final MockFlowFile out = runner. + getFlowFilesForRelationship(ReplaceTextWithMapping.REL_SUCCESS). + get(0); String outputString = new String(out.toByteArray()); String expected = "-roses- are -red$2 apple-\n" + "violets are -blue$2 blueberry-\n" @@ -189,14 +253,23 @@ public class TestReplaceTextWithMapping { @Test public void testBackReferenceWithTooLargeOfIndexIsEscapedSimple() throws IOException { - final TestRunner runner = TestRunners.newTestRunner(new ReplaceTextWithMapping()); - runner.setProperty(ReplaceTextWithMapping.MAPPING_FILE, Paths.get("src/test/resources/TestReplaceTextWithMapping/color-fruit-excessive-backreference-mapping-simple.txt").toFile().getAbsolutePath()); - - runner.enqueue(Paths.get("src/test/resources/TestReplaceTextWithMapping/colors-without-dashes.txt")); + final TestRunner runner = TestRunners. + newTestRunner(new ReplaceTextWithMapping()); + runner.setProperty(ReplaceTextWithMapping.MAPPING_FILE, + Paths. + get("src/test/resources/TestReplaceTextWithMapping/color-fruit-excessive-backreference-mapping-simple.txt"). + toFile(). + getAbsolutePath()); + + runner.enqueue(Paths. + get("src/test/resources/TestReplaceTextWithMapping/colors-without-dashes.txt")); runner.run(); - runner.assertAllFlowFilesTransferred(ReplaceTextWithMapping.REL_SUCCESS, 1); - final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceTextWithMapping.REL_SUCCESS).get(0); + runner. + assertAllFlowFilesTransferred(ReplaceTextWithMapping.REL_SUCCESS, 1); + final MockFlowFile out = runner. + getFlowFilesForRelationship(ReplaceTextWithMapping.REL_SUCCESS). + get(0); String outputString = new String(out.toByteArray()); String expected = "roses are red$1 apple\n" + "violets are blue$1 blueberry\n" @@ -207,16 +280,25 @@ public class TestReplaceTextWithMapping { @Test public void testBackReferenceWithInvalidReferenceIsEscaped() throws IOException { - final TestRunner runner = TestRunners.newTestRunner(new ReplaceTextWithMapping()); + final TestRunner runner = TestRunners. + newTestRunner(new ReplaceTextWithMapping()); runner.setProperty(ReplaceTextWithMapping.REGEX, "(\\S+)"); - runner.setProperty(ReplaceTextWithMapping.MATCHING_GROUP_FOR_LOOKUP_KEY, "1"); - runner.setProperty(ReplaceTextWithMapping.MAPPING_FILE, Paths.get("src/test/resources/TestReplaceTextWithMapping/color-fruit-invalid-backreference-mapping.txt").toFile().getAbsolutePath()); - - runner.enqueue(Paths.get("src/test/resources/TestReplaceTextWithMapping/colors-without-dashes.txt")); + runner. + setProperty(ReplaceTextWithMapping.MATCHING_GROUP_FOR_LOOKUP_KEY, "1"); + runner.setProperty(ReplaceTextWithMapping.MAPPING_FILE, Paths. + get("src/test/resources/TestReplaceTextWithMapping/color-fruit-invalid-backreference-mapping.txt"). + toFile(). + getAbsolutePath()); + + runner.enqueue(Paths. + get("src/test/resources/TestReplaceTextWithMapping/colors-without-dashes.txt")); runner.run(); - runner.assertAllFlowFilesTransferred(ReplaceTextWithMapping.REL_SUCCESS, 1); - final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceTextWithMapping.REL_SUCCESS).get(0); + runner. + assertAllFlowFilesTransferred(ReplaceTextWithMapping.REL_SUCCESS, 1); + final MockFlowFile out = runner. + getFlowFilesForRelationship(ReplaceTextWithMapping.REL_SUCCESS). + get(0); String outputString = new String(out.toByteArray()); String expected = "roses are red$d apple\n" + "violets are blue$d blueberry\n" @@ -227,16 +309,25 @@ public class TestReplaceTextWithMapping { @Test public void testEscapingDollarSign() throws IOException { - final TestRunner runner = TestRunners.newTestRunner(new ReplaceTextWithMapping()); + final TestRunner runner = TestRunners. + newTestRunner(new ReplaceTextWithMapping()); runner.setProperty(ReplaceTextWithMapping.REGEX, "-(.*?)-"); - runner.setProperty(ReplaceTextWithMapping.MATCHING_GROUP_FOR_LOOKUP_KEY, "1"); - runner.setProperty(ReplaceTextWithMapping.MAPPING_FILE, Paths.get("src/test/resources/TestReplaceTextWithMapping/color-fruit-escaped-dollar-mapping.txt").toFile().getAbsolutePath()); - - runner.enqueue(Paths.get("src/test/resources/TestReplaceTextWithMapping/colors.txt")); + runner. + setProperty(ReplaceTextWithMapping.MATCHING_GROUP_FOR_LOOKUP_KEY, "1"); + runner.setProperty(ReplaceTextWithMapping.MAPPING_FILE, Paths. + get("src/test/resources/TestReplaceTextWithMapping/color-fruit-escaped-dollar-mapping.txt"). + toFile(). + getAbsolutePath()); + + runner.enqueue(Paths. + get("src/test/resources/TestReplaceTextWithMapping/colors.txt")); runner.run(); - runner.assertAllFlowFilesTransferred(ReplaceTextWithMapping.REL_SUCCESS, 1); - final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceTextWithMapping.REL_SUCCESS).get(0); + runner. + assertAllFlowFilesTransferred(ReplaceTextWithMapping.REL_SUCCESS, 1); + final MockFlowFile out = runner. + getFlowFilesForRelationship(ReplaceTextWithMapping.REL_SUCCESS). + get(0); String outputString = new String(out.toByteArray()); String expected = "-roses- are -$1 apple-\n" + "violets are -$1 blueberry-\n" @@ -247,14 +338,22 @@ public class TestReplaceTextWithMapping { @Test public void testEscapingDollarSignSimple() throws IOException { - final TestRunner runner = TestRunners.newTestRunner(new ReplaceTextWithMapping()); - runner.setProperty(ReplaceTextWithMapping.MAPPING_FILE, Paths.get("src/test/resources/TestReplaceTextWithMapping/color-fruit-escaped-dollar-mapping.txt").toFile().getAbsolutePath()); - - runner.enqueue(Paths.get("src/test/resources/TestReplaceTextWithMapping/colors-without-dashes.txt")); + final TestRunner runner = TestRunners. + newTestRunner(new ReplaceTextWithMapping()); + runner.setProperty(ReplaceTextWithMapping.MAPPING_FILE, Paths. + get("src/test/resources/TestReplaceTextWithMapping/color-fruit-escaped-dollar-mapping.txt"). + toFile(). + getAbsolutePath()); + + runner.enqueue(Paths. + get("src/test/resources/TestReplaceTextWithMapping/colors-without-dashes.txt")); runner.run(); - runner.assertAllFlowFilesTransferred(ReplaceTextWithMapping.REL_SUCCESS, 1); - final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceTextWithMapping.REL_SUCCESS).get(0); + runner. + assertAllFlowFilesTransferred(ReplaceTextWithMapping.REL_SUCCESS, 1); + final MockFlowFile out = runner. + getFlowFilesForRelationship(ReplaceTextWithMapping.REL_SUCCESS). + get(0); String outputString = new String(out.toByteArray()); String expected = "roses are $1 apple\n" + "violets are $1 blueberry\n" @@ -265,14 +364,22 @@ public class TestReplaceTextWithMapping { @Test public void testReplaceWithEmptyString() throws IOException { - final TestRunner runner = TestRunners.newTestRunner(new ReplaceTextWithMapping()); - runner.setProperty(ReplaceTextWithMapping.MAPPING_FILE, Paths.get("src/test/resources/TestReplaceTextWithMapping/color-fruit-blank-mapping.txt").toFile().getAbsolutePath()); - - runner.enqueue(Paths.get("src/test/resources/TestReplaceTextWithMapping/colors-without-dashes.txt")); + final TestRunner runner = TestRunners. + newTestRunner(new ReplaceTextWithMapping()); + runner.setProperty(ReplaceTextWithMapping.MAPPING_FILE, Paths. + get("src/test/resources/TestReplaceTextWithMapping/color-fruit-blank-mapping.txt"). + toFile(). + getAbsolutePath()); + + runner.enqueue(Paths. + get("src/test/resources/TestReplaceTextWithMapping/colors-without-dashes.txt")); runner.run(); - runner.assertAllFlowFilesTransferred(ReplaceTextWithMapping.REL_SUCCESS, 1); - final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceTextWithMapping.REL_SUCCESS).get(0); + runner. + assertAllFlowFilesTransferred(ReplaceTextWithMapping.REL_SUCCESS, 1); + final MockFlowFile out = runner. + getFlowFilesForRelationship(ReplaceTextWithMapping.REL_SUCCESS). + get(0); String outputString = new String(out.toByteArray()); String expected = "roses are \n" + "violets are \n" @@ -283,14 +390,22 @@ public class TestReplaceTextWithMapping { @Test public void testReplaceWithSpaceInString() throws IOException { - final TestRunner runner = TestRunners.newTestRunner(new ReplaceTextWithMapping()); - runner.setProperty(ReplaceTextWithMapping.MAPPING_FILE, Paths.get("src/test/resources/TestReplaceTextWithMapping/color-fruit-space-mapping.txt").toFile().getAbsolutePath()); - - runner.enqueue(Paths.get("src/test/resources/TestReplaceTextWithMapping/colors-without-dashes.txt")); + final TestRunner runner = TestRunners. + newTestRunner(new ReplaceTextWithMapping()); + runner.setProperty(ReplaceTextWithMapping.MAPPING_FILE, Paths. + get("src/test/resources/TestReplaceTextWithMapping/color-fruit-space-mapping.txt"). + toFile(). + getAbsolutePath()); + + runner.enqueue(Paths. + get("src/test/resources/TestReplaceTextWithMapping/colors-without-dashes.txt")); runner.run(); - runner.assertAllFlowFilesTransferred(ReplaceTextWithMapping.REL_SUCCESS, 1); - final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceTextWithMapping.REL_SUCCESS).get(0); + runner. + assertAllFlowFilesTransferred(ReplaceTextWithMapping.REL_SUCCESS, 1); + final MockFlowFile out = runner. + getFlowFilesForRelationship(ReplaceTextWithMapping.REL_SUCCESS). + get(0); String outputString = new String(out.toByteArray()); String expected = "roses are really red\n" + "violets are super blue\n" @@ -301,17 +416,26 @@ public class TestReplaceTextWithMapping { @Test public void testWithNoMatch() throws IOException { - final TestRunner runner = TestRunners.newTestRunner(new ReplaceTextWithMapping()); + final TestRunner runner = TestRunners. + newTestRunner(new ReplaceTextWithMapping()); runner.setProperty(ReplaceTextWithMapping.REGEX, "-(.*?)-"); - runner.setProperty(ReplaceTextWithMapping.MATCHING_GROUP_FOR_LOOKUP_KEY, "1"); - runner.setProperty(ReplaceTextWithMapping.MAPPING_FILE, Paths.get("src/test/resources/TestReplaceTextWithMapping/color-fruit-no-match-mapping.txt").toFile().getAbsolutePath()); - - final Path path = Paths.get("src/test/resources/TestReplaceTextWithMapping/colors.txt"); + runner. + setProperty(ReplaceTextWithMapping.MATCHING_GROUP_FOR_LOOKUP_KEY, "1"); + runner.setProperty(ReplaceTextWithMapping.MAPPING_FILE, Paths. + get("src/test/resources/TestReplaceTextWithMapping/color-fruit-no-match-mapping.txt"). + toFile(). + getAbsolutePath()); + + final Path path = Paths. + get("src/test/resources/TestReplaceTextWithMapping/colors.txt"); runner.enqueue(path); runner.run(); - runner.assertAllFlowFilesTransferred(ReplaceTextWithMapping.REL_SUCCESS, 1); - final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceTextWithMapping.REL_SUCCESS).get(0); + runner. + assertAllFlowFilesTransferred(ReplaceTextWithMapping.REL_SUCCESS, 1); + final MockFlowFile out = runner. + getFlowFilesForRelationship(ReplaceTextWithMapping.REL_SUCCESS). + get(0); String outputString = new String(out.toByteArray()); String expected = new String(Files.readAllBytes(path)); assertEquals(expected, outputString); @@ -319,12 +443,18 @@ public class TestReplaceTextWithMapping { @Test(expected = java.lang.AssertionError.class) public void testMatchingGroupForLookupKeyTooLarge() throws IOException { - final TestRunner runner = TestRunners.newTestRunner(new ReplaceTextWithMapping()); + final TestRunner runner = TestRunners. + newTestRunner(new ReplaceTextWithMapping()); runner.setProperty(ReplaceTextWithMapping.REGEX, "-(.*?)-"); - runner.setProperty(ReplaceTextWithMapping.MATCHING_GROUP_FOR_LOOKUP_KEY, "2"); - runner.setProperty(ReplaceTextWithMapping.MAPPING_FILE, Paths.get("src/test/resources/TestReplaceTextWithMapping/color-mapping.txt").toFile().getAbsolutePath()); - - final Path path = Paths.get("src/test/resources/TestReplaceTextWithMapping/colors.txt"); + runner. + setProperty(ReplaceTextWithMapping.MATCHING_GROUP_FOR_LOOKUP_KEY, "2"); + runner.setProperty(ReplaceTextWithMapping.MAPPING_FILE, Paths. + get("src/test/resources/TestReplaceTextWithMapping/color-mapping.txt"). + toFile(). + getAbsolutePath()); + + final Path path = Paths. + get("src/test/resources/TestReplaceTextWithMapping/colors.txt"); runner.enqueue(path); runner.run(); }
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/TestRouteOnAttribute.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestRouteOnAttribute.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestRouteOnAttribute.java index 7c2ea8b..56996fe 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestRouteOnAttribute.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestRouteOnAttribute.java @@ -40,7 +40,8 @@ public class TestRouteOnAttribute { public void testInvalidOnMisconfiguredProperty() { final RouteOnAttribute proc = new RouteOnAttribute(); final MockProcessContext ctx = new MockProcessContext(proc); - final ValidationResult validationResult = ctx.setProperty("RouteA", "${a:equals('b')"); // Missing closing brace + final ValidationResult validationResult = ctx. + setProperty("RouteA", "${a:equals('b')"); // Missing closing brace assertFalse(validationResult.isValid()); } @@ -48,13 +49,15 @@ public class TestRouteOnAttribute { public void testInvalidOnNonBooleanProperty() { final RouteOnAttribute proc = new RouteOnAttribute(); final MockProcessContext ctx = new MockProcessContext(proc); - final ValidationResult validationResult = ctx.setProperty("RouteA", "${a:length()"); // Should be boolean + final ValidationResult validationResult = ctx. + setProperty("RouteA", "${a:length()"); // Should be boolean assertFalse(validationResult.isValid()); } @Test public void testSimpleEquals() { - final TestRunner runner = TestRunners.newTestRunner(new RouteOnAttribute()); + final TestRunner runner = TestRunners. + newTestRunner(new RouteOnAttribute()); runner.setProperty("RouteA", "${a:equals('b')}"); final Map<String, String> attributes = new HashMap<>(); @@ -63,16 +66,24 @@ public class TestRouteOnAttribute { runner.run(); - runner.assertAllFlowFilesTransferred(new Relationship.Builder().name("RouteA").build(), 1); - final List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship("RouteA"); - flowFiles.get(0).assertAttributeEquals("a", "b"); - flowFiles.get(0).assertAttributeEquals(RouteOnAttribute.ROUTE_ATTRIBUTE_KEY, "RouteA"); + runner.assertAllFlowFilesTransferred(new Relationship.Builder(). + name("RouteA"). + build(), 1); + final List<MockFlowFile> flowFiles = runner. + getFlowFilesForRelationship("RouteA"); + flowFiles.get(0). + assertAttributeEquals("a", "b"); + flowFiles.get(0). + assertAttributeEquals(RouteOnAttribute.ROUTE_ATTRIBUTE_KEY, "RouteA"); } @Test public void testMatchAll() { - final TestRunner runner = TestRunners.newTestRunner(new RouteOnAttribute()); - runner.setProperty(RouteOnAttribute.ROUTE_STRATEGY, RouteOnAttribute.ROUTE_ALL_MATCH.getValue()); + final TestRunner runner = TestRunners. + newTestRunner(new RouteOnAttribute()); + runner. + setProperty(RouteOnAttribute.ROUTE_STRATEGY, RouteOnAttribute.ROUTE_ALL_MATCH. + getValue()); runner.setProperty("RouteA", "${a:equals('b')}"); runner.setProperty("RouteB", "${b:equals('a')}"); @@ -92,27 +103,36 @@ public class TestRouteOnAttribute { runner.run(4); - final List<MockFlowFile> match = runner.getFlowFilesForRelationship(RouteOnAttribute.REL_MATCH); - final List<MockFlowFile> noMatch = runner.getFlowFilesForRelationship(RouteOnAttribute.REL_NO_MATCH); + final List<MockFlowFile> match = runner. + getFlowFilesForRelationship(RouteOnAttribute.REL_MATCH); + final List<MockFlowFile> noMatch = runner. + getFlowFilesForRelationship(RouteOnAttribute.REL_NO_MATCH); assertEquals(1, match.size()); assertEquals(3, noMatch.size()); for (final MockFlowFile ff : noMatch) { - ff.assertAttributeEquals(RouteOnAttribute.ROUTE_ATTRIBUTE_KEY, "unmatched"); + ff. + assertAttributeEquals(RouteOnAttribute.ROUTE_ATTRIBUTE_KEY, "unmatched"); } - final Map<String, String> matchedAttrs = match.iterator().next().getAttributes(); + final Map<String, String> matchedAttrs = match.iterator(). + next(). + getAttributes(); assertEquals("b", matchedAttrs.get("a")); assertEquals("a", matchedAttrs.get("b")); - assertEquals("matched", matchedAttrs.get(RouteOnAttribute.ROUTE_ATTRIBUTE_KEY)); + assertEquals("matched", matchedAttrs. + get(RouteOnAttribute.ROUTE_ATTRIBUTE_KEY)); } @Test public void testMatchAny() { - final TestRunner runner = TestRunners.newTestRunner(new RouteOnAttribute()); + final TestRunner runner = TestRunners. + newTestRunner(new RouteOnAttribute()); runner.setThreadCount(4); - runner.setProperty(RouteOnAttribute.ROUTE_STRATEGY, RouteOnAttribute.ROUTE_ANY_MATCHES.getValue()); + runner. + setProperty(RouteOnAttribute.ROUTE_STRATEGY, RouteOnAttribute.ROUTE_ANY_MATCHES. + getValue()); runner.setProperty("RouteA", "${a:equals('b')}"); runner.setProperty("RouteB", "${b:equals('a')}"); @@ -132,16 +152,20 @@ public class TestRouteOnAttribute { runner.run(4); - final List<MockFlowFile> match = runner.getFlowFilesForRelationship(RouteOnAttribute.REL_MATCH); - final List<MockFlowFile> noMatch = runner.getFlowFilesForRelationship(RouteOnAttribute.REL_NO_MATCH); + final List<MockFlowFile> match = runner. + getFlowFilesForRelationship(RouteOnAttribute.REL_MATCH); + final List<MockFlowFile> noMatch = runner. + getFlowFilesForRelationship(RouteOnAttribute.REL_NO_MATCH); assertEquals(2, match.size()); assertEquals(2, noMatch.size()); // Get attributes for both matching FlowFiles final Iterator<MockFlowFile> itr = match.iterator(); - final Map<String, String> attrs1 = itr.next().getAttributes(); - final Map<String, String> attrs2 = itr.next().getAttributes(); + final Map<String, String> attrs1 = itr.next(). + getAttributes(); + final Map<String, String> attrs2 = itr.next(). + getAttributes(); // Both matches should map a -> b assertEquals("b", attrs1.get("a")); 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/TestRouteOnContent.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestRouteOnContent.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestRouteOnContent.java index f42dbbd..96c281a 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestRouteOnContent.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestRouteOnContent.java @@ -31,8 +31,10 @@ public class TestRouteOnContent { @Test public void testCloning() throws IOException { - final TestRunner runner = TestRunners.newTestRunner(new RouteOnContent()); - runner.setProperty(RouteOnContent.MATCH_REQUIREMENT, RouteOnContent.MATCH_SUBSEQUENCE); + final TestRunner runner = TestRunners. + newTestRunner(new RouteOnContent()); + runner. + setProperty(RouteOnContent.MATCH_REQUIREMENT, RouteOnContent.MATCH_SUBSEQUENCE); runner.setProperty("hello", "Hello"); runner.setProperty("world", "World"); @@ -46,8 +48,10 @@ public class TestRouteOnContent { @Test public void testSubstituteAttributes() throws IOException { - final TestRunner runner = TestRunners.newTestRunner(new RouteOnContent()); - runner.setProperty(RouteOnContent.MATCH_REQUIREMENT, RouteOnContent.MATCH_SUBSEQUENCE); + final TestRunner runner = TestRunners. + newTestRunner(new RouteOnContent()); + runner. + setProperty(RouteOnContent.MATCH_REQUIREMENT, RouteOnContent.MATCH_SUBSEQUENCE); runner.setProperty("attr", "Hel${highLow}"); final Map<String, String> attributes = new HashMap<>(); @@ -60,8 +64,10 @@ public class TestRouteOnContent { @Test public void testBufferSize() throws IOException { - final TestRunner runner = TestRunners.newTestRunner(new RouteOnContent()); - runner.setProperty(RouteOnContent.MATCH_REQUIREMENT, RouteOnContent.MATCH_ALL); + final TestRunner runner = TestRunners. + newTestRunner(new RouteOnContent()); + runner. + setProperty(RouteOnContent.MATCH_REQUIREMENT, RouteOnContent.MATCH_ALL); runner.setProperty(RouteOnContent.BUFFER_SIZE, "3 B"); runner.setProperty("rel", "Hel"); 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/TestScanAttribute.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestScanAttribute.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestScanAttribute.java index 6317131..982cf57 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestScanAttribute.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestScanAttribute.java @@ -30,7 +30,8 @@ public class TestScanAttribute { @Test public void testSingleMatch() { final TestRunner runner = TestRunners.newTestRunner(new ScanAttribute()); - runner.setProperty(ScanAttribute.DICTIONARY_FILE, "src/test/resources/ScanAttribute/dictionary1"); + runner. + setProperty(ScanAttribute.DICTIONARY_FILE, "src/test/resources/ScanAttribute/dictionary1"); final Map<String, String> attributes = new HashMap<>(); attributes.put("abc", "world"); @@ -66,8 +67,10 @@ public class TestScanAttribute { @Test public void testAllMatch() { final TestRunner runner = TestRunners.newTestRunner(new ScanAttribute()); - runner.setProperty(ScanAttribute.DICTIONARY_FILE, "src/test/resources/ScanAttribute/dictionary1"); - runner.setProperty(ScanAttribute.MATCHING_CRITERIA, ScanAttribute.MATCH_CRITERIA_ALL); + runner. + setProperty(ScanAttribute.DICTIONARY_FILE, "src/test/resources/ScanAttribute/dictionary1"); + runner. + setProperty(ScanAttribute.MATCHING_CRITERIA, ScanAttribute.MATCH_CRITERIA_ALL); runner.setProperty(ScanAttribute.ATTRIBUTE_PATTERN, "a.*"); final Map<String, String> attributes = new HashMap<>(); @@ -103,7 +106,8 @@ public class TestScanAttribute { @Test public void testWithEmptyEntries() { final TestRunner runner = TestRunners.newTestRunner(new ScanAttribute()); - runner.setProperty(ScanAttribute.DICTIONARY_FILE, "src/test/resources/ScanAttribute/dictionary-with-empty-new-lines"); + runner. + setProperty(ScanAttribute.DICTIONARY_FILE, "src/test/resources/ScanAttribute/dictionary-with-empty-new-lines"); final Map<String, String> attributes = new HashMap<>(); attributes.put("abc", ""); @@ -123,7 +127,8 @@ public class TestScanAttribute { @Test public void testWithDictionaryFilter() { final TestRunner runner = TestRunners.newTestRunner(new ScanAttribute()); - runner.setProperty(ScanAttribute.DICTIONARY_FILE, "src/test/resources/ScanAttribute/dictionary-with-extra-info"); + runner. + setProperty(ScanAttribute.DICTIONARY_FILE, "src/test/resources/ScanAttribute/dictionary-with-extra-info"); runner.setProperty(ScanAttribute.DICTIONARY_FILTER, "(.*)<greeting>"); final Map<String, String> attributes = new HashMap<>(); 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/TestScanContent.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestScanContent.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestScanContent.java index 8c36845..442aa63 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestScanContent.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestScanContent.java @@ -50,15 +50,22 @@ public class TestScanContent { final byte[] termBytes = baos.toByteArray(); final Path dictionaryPath = Paths.get("target/dictionary"); - Files.write(dictionaryPath, termBytes, StandardOpenOption.CREATE, StandardOpenOption.WRITE); + Files. + write(dictionaryPath, termBytes, StandardOpenOption.CREATE, StandardOpenOption.WRITE); - final TestRunner runner = TestRunners.newTestRunner(new ScanContent()); + final TestRunner runner = TestRunners. + newTestRunner(new ScanContent()); runner.setThreadCount(1); - runner.setProperty(ScanContent.DICTIONARY, dictionaryPath.toString()); - runner.setProperty(ScanContent.DICTIONARY_ENCODING, ScanContent.BINARY_ENCODING); + runner. + setProperty(ScanContent.DICTIONARY, dictionaryPath. + toString()); + runner. + setProperty(ScanContent.DICTIONARY_ENCODING, ScanContent.BINARY_ENCODING); - runner.enqueue(Paths.get("src/test/resources/TestScanContent/helloWorld")); - runner.enqueue(Paths.get("src/test/resources/TestScanContent/wellthengood-bye")); + runner.enqueue(Paths. + get("src/test/resources/TestScanContent/helloWorld")); + runner.enqueue(Paths. + get("src/test/resources/TestScanContent/wellthengood-bye")); runner.enqueue(new byte[0]); while (!runner.isQueueEmpty()) { @@ -72,13 +79,18 @@ public class TestScanContent { runner.assertTransferCount(ScanContent.REL_MATCH, 2); runner.assertTransferCount(ScanContent.REL_NO_MATCH, 1); - final List<MockFlowFile> matched = runner.getFlowFilesForRelationship(ScanContent.REL_MATCH); - final List<MockFlowFile> unmatched = runner.getFlowFilesForRelationship(ScanContent.REL_NO_MATCH); + final List<MockFlowFile> matched = runner. + getFlowFilesForRelationship(ScanContent.REL_MATCH); + final List<MockFlowFile> unmatched = runner. + getFlowFilesForRelationship(ScanContent.REL_NO_MATCH); - matched.get(0).assertAttributeEquals(ScanContent.MATCH_ATTRIBUTE_KEY, "hello"); - matched.get(1).assertAttributeEquals(ScanContent.MATCH_ATTRIBUTE_KEY, "good-bye"); + matched.get(0). + assertAttributeEquals(ScanContent.MATCH_ATTRIBUTE_KEY, "hello"); + matched.get(1). + assertAttributeEquals(ScanContent.MATCH_ATTRIBUTE_KEY, "good-bye"); - unmatched.get(0).assertAttributeNotExists(ScanContent.MATCH_ATTRIBUTE_KEY); + unmatched.get(0). + assertAttributeNotExists(ScanContent.MATCH_ATTRIBUTE_KEY); } } 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/TestSegmentContent.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSegmentContent.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSegmentContent.java index a712f7c..7a6001c 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSegmentContent.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSegmentContent.java @@ -32,13 +32,15 @@ public class TestSegmentContent { @Test public void test() throws IOException { - final TestRunner testRunner = TestRunners.newTestRunner(new SegmentContent()); + final TestRunner testRunner = TestRunners. + newTestRunner(new SegmentContent()); testRunner.setProperty(SegmentContent.SIZE, "4 B"); testRunner.enqueue(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9}); testRunner.run(); - final List<MockFlowFile> flowFiles = testRunner.getFlowFilesForRelationship(SegmentContent.REL_SEGMENTS); + final List<MockFlowFile> flowFiles = testRunner. + getFlowFilesForRelationship(SegmentContent.REL_SEGMENTS); assertEquals(3, flowFiles.size()); final MockFlowFile out1 = flowFiles.get(0); @@ -52,14 +54,17 @@ public class TestSegmentContent { @Test public void testTransferSmall() throws IOException { - final TestRunner testRunner = TestRunners.newTestRunner(new SegmentContent()); + final TestRunner testRunner = TestRunners. + newTestRunner(new SegmentContent()); testRunner.setProperty(SegmentContent.SIZE, "4 KB"); testRunner.enqueue(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9}); testRunner.run(); testRunner.assertTransferCount(SegmentContent.REL_SEGMENTS, 1); - final MockFlowFile out1 = testRunner.getFlowFilesForRelationship(SegmentContent.REL_SEGMENTS).get(0); + final MockFlowFile out1 = testRunner. + getFlowFilesForRelationship(SegmentContent.REL_SEGMENTS). + get(0); out1.assertContentEquals(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9}); } } 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/TestServer.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestServer.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestServer.java index abdff6e..b9c623e 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestServer.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestServer.java @@ -28,8 +28,9 @@ import org.eclipse.jetty.util.ssl.SslContextFactory; * Test server to assist with unit tests that requires a server to be stood up. */ public class TestServer { + public static final String NEED_CLIENT_AUTH = "clientAuth"; - + private Server jetty; private boolean secure = false; @@ -39,29 +40,23 @@ public class TestServer { public TestServer() { createServer(null); } - + /** * Creates the test server. * - * @param sslProperties SSLProps to be used in the secure connection. The keys - * should should use the StandardSSLContextService properties. + * @param sslProperties SSLProps to be used in the secure connection. The + * keys should should use the StandardSSLContextService properties. */ public TestServer(final Map<String, String> sslProperties) { createServer(sslProperties); } - /** - * Creates the server. - * - * @param webappContext - * @return - */ private void createServer(final Map<String, String> sslProperties) { jetty = new Server(); // create the unsecure connector createConnector(); - + // create the secure connector if sslProperties are specified if (sslProperties != null) { createSecureConnector(sslProperties); @@ -78,29 +73,30 @@ public class TestServer { http.setPort(0); jetty.addConnector(http); } - - /** - * Creates the https connector. - * - * @return - */ + private void createSecureConnector(final Map<String, String> sslProperties) { SslContextFactory ssl = new SslContextFactory(); - - if ( sslProperties.get(StandardSSLContextService.KEYSTORE.getName()) != null ) { - ssl.setKeyStorePath(sslProperties.get(StandardSSLContextService.KEYSTORE.getName())); - ssl.setKeyStorePassword(sslProperties.get(StandardSSLContextService.KEYSTORE_PASSWORD.getName())); - ssl.setKeyStoreType(sslProperties.get(StandardSSLContextService.KEYSTORE_TYPE.getName())); + + if (sslProperties.get(StandardSSLContextService.KEYSTORE.getName()) != null) { + ssl.setKeyStorePath(sslProperties. + get(StandardSSLContextService.KEYSTORE.getName())); + ssl.setKeyStorePassword(sslProperties. + get(StandardSSLContextService.KEYSTORE_PASSWORD.getName())); + ssl.setKeyStoreType(sslProperties. + get(StandardSSLContextService.KEYSTORE_TYPE.getName())); } - - if ( sslProperties.get(StandardSSLContextService.TRUSTSTORE.getName()) != null ) { - ssl.setTrustStorePath(sslProperties.get(StandardSSLContextService.TRUSTSTORE.getName())); - ssl.setTrustStorePassword(sslProperties.get(StandardSSLContextService.TRUSTSTORE_PASSWORD.getName())); - ssl.setTrustStoreType(sslProperties.get(StandardSSLContextService.TRUSTSTORE_TYPE.getName())); + + if (sslProperties.get(StandardSSLContextService.TRUSTSTORE.getName()) != null) { + ssl.setTrustStorePath(sslProperties. + get(StandardSSLContextService.TRUSTSTORE.getName())); + ssl.setTrustStorePassword(sslProperties. + get(StandardSSLContextService.TRUSTSTORE_PASSWORD.getName())); + ssl.setTrustStoreType(sslProperties. + get(StandardSSLContextService.TRUSTSTORE_TYPE.getName())); } - + final String clientAuth = sslProperties.get(NEED_CLIENT_AUTH); - if ( clientAuth == null ) { + if (clientAuth == null) { ssl.setNeedClientAuth(true); } else { ssl.setNeedClientAuth(Boolean.parseBoolean(clientAuth)); @@ -114,7 +110,7 @@ public class TestServer { // add the connector jetty.addConnector(https); - + // mark secure as enabled secure = true; } @@ -128,25 +124,15 @@ public class TestServer { } } } - + public void addHandler(Handler handler) { ((HandlerCollection) jetty.getHandler()).addHandler(handler); } - - /** - * Starts the server. - * - * @throws Exception - */ + public void startServer() throws Exception { jetty.start(); } - /** - * Stops the server. - * - * @throws Exception - */ public void shutdownServer() throws Exception { jetty.stop(); jetty.destroy(); @@ -158,7 +144,7 @@ public class TestServer { } return ((ServerConnector) jetty.getConnectors()[0]).getLocalPort(); } - + private int getSecurePort() { if (!jetty.isStarted()) { throw new IllegalStateException("Jetty server not started"); @@ -166,20 +152,10 @@ public class TestServer { return ((ServerConnector) jetty.getConnectors()[1]).getLocalPort(); } - /** - * Returns the url for the server. - * - * @return - */ public String getUrl() { return "http://localhost:" + getPort(); } - - /** - * Returns the secure url for the server. - * - * @return - */ + public String getSecureUrl() { String url = null; if (secure) { 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/TestSplitContent.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitContent.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitContent.java index 07c255b..ea3da22 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitContent.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitContent.java @@ -32,10 +32,13 @@ public class TestSplitContent { @Test public void testTextFormatLeadingPosition() { final TestRunner runner = TestRunners.newTestRunner(new SplitContent()); - runner.setProperty(SplitContent.FORMAT, SplitContent.UTF8_FORMAT.getValue()); + runner.setProperty(SplitContent.FORMAT, SplitContent.UTF8_FORMAT. + getValue()); runner.setProperty(SplitContent.BYTE_SEQUENCE, "ub"); runner.setProperty(SplitContent.KEEP_SEQUENCE, "true"); - runner.setProperty(SplitContent.BYTE_SEQUENCE_LOCATION, SplitContent.LEADING_POSITION.getValue()); + runner. + setProperty(SplitContent.BYTE_SEQUENCE_LOCATION, SplitContent.LEADING_POSITION. + getValue()); runner.enqueue("rub-a-dub-dub".getBytes()); runner.run(); @@ -44,23 +47,31 @@ public class TestSplitContent { runner.assertTransferCount(SplitContent.REL_SPLITS, 4); runner.assertQueueEmpty(); - final List<MockFlowFile> splits = runner.getFlowFilesForRelationship(SplitContent.REL_SPLITS); - splits.get(0).assertContentEquals("r"); - splits.get(1).assertContentEquals("ub-a-d"); - splits.get(2).assertContentEquals("ub-d"); - splits.get(3).assertContentEquals("ub"); + final List<MockFlowFile> splits = runner. + getFlowFilesForRelationship(SplitContent.REL_SPLITS); + splits.get(0). + assertContentEquals("r"); + splits.get(1). + assertContentEquals("ub-a-d"); + splits.get(2). + assertContentEquals("ub-d"); + splits.get(3). + assertContentEquals("ub"); } - - + @Test public void testTextFormatSplits() { final TestRunner runner = TestRunners.newTestRunner(new SplitContent()); - runner.setProperty(SplitContent.FORMAT, SplitContent.UTF8_FORMAT.getValue()); + runner.setProperty(SplitContent.FORMAT, SplitContent.UTF8_FORMAT. + getValue()); runner.setProperty(SplitContent.BYTE_SEQUENCE, "test"); runner.setProperty(SplitContent.KEEP_SEQUENCE, "true"); - runner.setProperty(SplitContent.BYTE_SEQUENCE_LOCATION, SplitContent.LEADING_POSITION.getValue()); + runner. + setProperty(SplitContent.BYTE_SEQUENCE_LOCATION, SplitContent.LEADING_POSITION. + getValue()); - final byte[] input = "This is a test. This is another test. And this is yet another test. Finally this is the last Test.".getBytes(); + final byte[] input = "This is a test. This is another test. And this is yet another test. Finally this is the last Test.". + getBytes(); runner.enqueue(input); runner.run(); @@ -68,75 +79,109 @@ public class TestSplitContent { runner.assertTransferCount(SplitContent.REL_SPLITS, 4); runner.assertQueueEmpty(); - List<MockFlowFile> splits = runner.getFlowFilesForRelationship(SplitContent.REL_SPLITS); - splits.get(0).assertContentEquals("This is a "); - splits.get(1).assertContentEquals("test. This is another "); - splits.get(2).assertContentEquals("test. And this is yet another "); - splits.get(3).assertContentEquals("test. Finally this is the last Test."); + List<MockFlowFile> splits = runner. + getFlowFilesForRelationship(SplitContent.REL_SPLITS); + splits.get(0). + assertContentEquals("This is a "); + splits.get(1). + assertContentEquals("test. This is another "); + splits.get(2). + assertContentEquals("test. And this is yet another "); + splits.get(3). + assertContentEquals("test. Finally this is the last Test."); runner.clearTransferState(); - + runner.setProperty(SplitContent.KEEP_SEQUENCE, "false"); runner.enqueue(input); runner.run(); runner.assertTransferCount(SplitContent.REL_ORIGINAL, 1); runner.assertTransferCount(SplitContent.REL_SPLITS, 4); splits = runner.getFlowFilesForRelationship(SplitContent.REL_SPLITS); - splits.get(0).assertContentEquals("This is a "); - splits.get(1).assertContentEquals(". This is another "); - splits.get(2).assertContentEquals(". And this is yet another "); - splits.get(3).assertContentEquals(". Finally this is the last Test."); + splits.get(0). + assertContentEquals("This is a "); + splits.get(1). + assertContentEquals(". This is another "); + splits.get(2). + assertContentEquals(". And this is yet another "); + splits.get(3). + assertContentEquals(". Finally this is the last Test."); runner.clearTransferState(); - + runner.setProperty(SplitContent.KEEP_SEQUENCE, "true"); - runner.setProperty(SplitContent.BYTE_SEQUENCE_LOCATION, SplitContent.TRAILING_POSITION.getValue()); + runner. + setProperty(SplitContent.BYTE_SEQUENCE_LOCATION, SplitContent.TRAILING_POSITION. + getValue()); runner.enqueue(input); runner.run(); runner.assertTransferCount(SplitContent.REL_ORIGINAL, 1); runner.assertTransferCount(SplitContent.REL_SPLITS, 4); splits = runner.getFlowFilesForRelationship(SplitContent.REL_SPLITS); - splits.get(0).assertContentEquals("This is a test"); - splits.get(1).assertContentEquals(". This is another test"); - splits.get(2).assertContentEquals(". And this is yet another test"); - splits.get(3).assertContentEquals(". Finally this is the last Test."); + splits.get(0). + assertContentEquals("This is a test"); + splits.get(1). + assertContentEquals(". This is another test"); + splits.get(2). + assertContentEquals(". And this is yet another test"); + splits.get(3). + assertContentEquals(". Finally this is the last Test."); runner.clearTransferState(); - + runner.setProperty(SplitContent.KEEP_SEQUENCE, "true"); - runner.setProperty(SplitContent.BYTE_SEQUENCE_LOCATION, SplitContent.TRAILING_POSITION.getValue()); - runner.enqueue("This is a test. This is another test. And this is yet another test. Finally this is the last test".getBytes()); + runner. + setProperty(SplitContent.BYTE_SEQUENCE_LOCATION, SplitContent.TRAILING_POSITION. + getValue()); + runner. + enqueue("This is a test. This is another test. And this is yet another test. Finally this is the last test". + getBytes()); runner.run(); runner.assertTransferCount(SplitContent.REL_ORIGINAL, 1); runner.assertTransferCount(SplitContent.REL_SPLITS, 4); splits = runner.getFlowFilesForRelationship(SplitContent.REL_SPLITS); - splits.get(0).assertContentEquals("This is a test"); - splits.get(1).assertContentEquals(". This is another test"); - splits.get(2).assertContentEquals(". And this is yet another test"); - splits.get(3).assertContentEquals(". Finally this is the last test"); + splits.get(0). + assertContentEquals("This is a test"); + splits.get(1). + assertContentEquals(". This is another test"); + splits.get(2). + assertContentEquals(". And this is yet another test"); + splits.get(3). + assertContentEquals(". Finally this is the last test"); runner.clearTransferState(); - + runner.setProperty(SplitContent.KEEP_SEQUENCE, "true"); - runner.setProperty(SplitContent.BYTE_SEQUENCE_LOCATION, SplitContent.LEADING_POSITION.getValue()); - runner.enqueue("This is a test. This is another test. And this is yet another test. Finally this is the last test".getBytes()); + runner. + setProperty(SplitContent.BYTE_SEQUENCE_LOCATION, SplitContent.LEADING_POSITION. + getValue()); + runner. + enqueue("This is a test. This is another test. And this is yet another test. Finally this is the last test". + getBytes()); runner.run(); runner.assertTransferCount(SplitContent.REL_ORIGINAL, 1); runner.assertTransferCount(SplitContent.REL_SPLITS, 5); splits = runner.getFlowFilesForRelationship(SplitContent.REL_SPLITS); - splits.get(0).assertContentEquals("This is a "); - splits.get(1).assertContentEquals("test. This is another "); - splits.get(2).assertContentEquals("test. And this is yet another "); - splits.get(3).assertContentEquals("test. Finally this is the last "); - splits.get(4).assertContentEquals("test"); - + splits.get(0). + assertContentEquals("This is a "); + splits.get(1). + assertContentEquals("test. This is another "); + splits.get(2). + assertContentEquals("test. And this is yet another "); + splits.get(3). + assertContentEquals("test. Finally this is the last "); + splits.get(4). + assertContentEquals("test"); + runner.clearTransferState(); } - - + @Test public void testTextFormatTrailingPosition() { final TestRunner runner = TestRunners.newTestRunner(new SplitContent()); - runner.setProperty(SplitContent.FORMAT, SplitContent.UTF8_FORMAT.getValue()); + runner.setProperty(SplitContent.FORMAT, SplitContent.UTF8_FORMAT. + getValue()); runner.setProperty(SplitContent.BYTE_SEQUENCE, "ub"); runner.setProperty(SplitContent.KEEP_SEQUENCE, "true"); - runner.setProperty(SplitContent.BYTE_SEQUENCE_LOCATION, SplitContent.TRAILING_POSITION.getValue()); + runner. + setProperty(SplitContent.BYTE_SEQUENCE_LOCATION, SplitContent.TRAILING_POSITION. + getValue()); runner.enqueue("rub-a-dub-dub".getBytes()); runner.run(); @@ -145,27 +190,32 @@ public class TestSplitContent { runner.assertTransferCount(SplitContent.REL_SPLITS, 3); runner.assertQueueEmpty(); - final List<MockFlowFile> splits = runner.getFlowFilesForRelationship(SplitContent.REL_SPLITS); - splits.get(0).assertContentEquals("rub"); - splits.get(1).assertContentEquals("-a-dub"); - splits.get(2).assertContentEquals("-dub"); + final List<MockFlowFile> splits = runner. + getFlowFilesForRelationship(SplitContent.REL_SPLITS); + splits.get(0). + assertContentEquals("rub"); + splits.get(1). + assertContentEquals("-a-dub"); + splits.get(2). + assertContentEquals("-dub"); } - - + @Test public void testSmallSplits() throws IOException { final TestRunner runner = TestRunners.newTestRunner(new SplitContent()); runner.setProperty(SplitContent.KEEP_SEQUENCE, "false"); runner.setProperty(SplitContent.BYTE_SEQUENCE.getName(), "FFFF"); - runner.enqueue(new byte[]{1, 2, 3, 4, 5, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, 5, 4, 3, 2, 1}); + runner. + enqueue(new byte[]{1, 2, 3, 4, 5, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, 5, 4, 3, 2, 1}); runner.run(); runner.assertTransferCount(SplitContent.REL_ORIGINAL, 1); runner.assertTransferCount(SplitContent.REL_SPLITS, 2); runner.assertQueueEmpty(); - final List<MockFlowFile> splits = runner.getFlowFilesForRelationship(SplitContent.REL_SPLITS); + final List<MockFlowFile> splits = runner. + getFlowFilesForRelationship(SplitContent.REL_SPLITS); final MockFlowFile split1 = splits.get(0); final MockFlowFile split2 = splits.get(1); @@ -186,7 +236,8 @@ public class TestSplitContent { runner.assertTransferCount(SplitContent.REL_SPLITS, 2); runner.assertQueueEmpty(); - final List<MockFlowFile> splits = runner.getFlowFilesForRelationship(SplitContent.REL_SPLITS); + final List<MockFlowFile> splits = runner. + getFlowFilesForRelationship(SplitContent.REL_SPLITS); final MockFlowFile split1 = splits.get(0); final MockFlowFile split2 = splits.get(1); @@ -210,7 +261,8 @@ public class TestSplitContent { runner.assertTransferCount(SplitContent.REL_SPLITS, 2); runner.assertQueueEmpty(); - final List<MockFlowFile> splits = runner.getFlowFilesForRelationship(SplitContent.REL_SPLITS); + final List<MockFlowFile> splits = runner. + getFlowFilesForRelationship(SplitContent.REL_SPLITS); final MockFlowFile split1 = splits.get(0); final MockFlowFile split2 = splits.get(1); @@ -235,7 +287,8 @@ public class TestSplitContent { runner.assertTransferCount(SplitContent.REL_SPLITS, 2); runner.assertQueueEmpty(); - final List<MockFlowFile> splits = runner.getFlowFilesForRelationship(SplitContent.REL_SPLITS); + final List<MockFlowFile> splits = runner. + getFlowFilesForRelationship(SplitContent.REL_SPLITS); final MockFlowFile split1 = splits.get(0); final MockFlowFile split2 = splits.get(1); @@ -257,7 +310,8 @@ public class TestSplitContent { runner.assertTransferCount(SplitContent.REL_SPLITS, 1); runner.assertQueueEmpty(); - final List<MockFlowFile> splits = runner.getFlowFilesForRelationship(SplitContent.REL_SPLITS); + final List<MockFlowFile> splits = runner. + getFlowFilesForRelationship(SplitContent.REL_SPLITS); final MockFlowFile split1 = splits.get(0); split1.assertContentEquals(new byte[]{1, 2, 3, 4}); @@ -277,7 +331,8 @@ public class TestSplitContent { runner.assertTransferCount(SplitContent.REL_SPLITS, 1); runner.assertQueueEmpty(); - final List<MockFlowFile> splits = runner.getFlowFilesForRelationship(SplitContent.REL_SPLITS); + final List<MockFlowFile> splits = runner. + getFlowFilesForRelationship(SplitContent.REL_SPLITS); final MockFlowFile split1 = splits.get(0); split1.assertContentEquals(new byte[]{1, 2, 3, 4, 5, 5, 5, 5}); @@ -297,7 +352,8 @@ public class TestSplitContent { runner.assertTransferCount(SplitContent.REL_SPLITS, 1); runner.assertQueueEmpty(); - final List<MockFlowFile> splits = runner.getFlowFilesForRelationship(SplitContent.REL_SPLITS); + final List<MockFlowFile> splits = runner. + getFlowFilesForRelationship(SplitContent.REL_SPLITS); final MockFlowFile split1 = splits.get(0); split1.assertContentEquals(new byte[]{1, 2, 3, 4}); @@ -317,9 +373,12 @@ public class TestSplitContent { runner.assertTransferCount(SplitContent.REL_SPLITS, 2); runner.assertQueueEmpty(); - final List<MockFlowFile> splits = runner.getFlowFilesForRelationship(SplitContent.REL_SPLITS); - splits.get(0).assertContentEquals(new byte[]{5, 5, 5, 5}); - splits.get(1).assertContentEquals(new byte[]{1, 2, 3, 4}); + final List<MockFlowFile> splits = runner. + getFlowFilesForRelationship(SplitContent.REL_SPLITS); + splits.get(0). + assertContentEquals(new byte[]{5, 5, 5, 5}); + splits.get(1). + assertContentEquals(new byte[]{1, 2, 3, 4}); } @Test @@ -328,23 +387,29 @@ public class TestSplitContent { runner.setProperty(SplitContent.KEEP_SEQUENCE, "true"); runner.setProperty(SplitContent.BYTE_SEQUENCE.getName(), "FFFF"); - runner.enqueue(new byte[]{1, 2, 3, 4, 5, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, 5, 4, 3, 2, 1}); + runner. + enqueue(new byte[]{1, 2, 3, 4, 5, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, 5, 4, 3, 2, 1}); runner.run(); runner.assertTransferCount(SplitContent.REL_ORIGINAL, 1); runner.assertTransferCount(SplitContent.REL_SPLITS, 2); runner.assertQueueEmpty(); - final List<MockFlowFile> splits = runner.getFlowFilesForRelationship(SplitContent.REL_SPLITS); + final List<MockFlowFile> splits = runner. + getFlowFilesForRelationship(SplitContent.REL_SPLITS); final MockFlowFile split1 = splits.get(0); final MockFlowFile split2 = splits.get(1); - split1.assertContentEquals(new byte[]{1, 2, 3, 4, 5, (byte) 0xFF, (byte) 0xFF}); + split1. + assertContentEquals(new byte[]{1, 2, 3, 4, 5, (byte) 0xFF, (byte) 0xFF}); split2.assertContentEquals(new byte[]{(byte) 0xFF, 5, 4, 3, 2, 1}); - final TestRunner mergeRunner = TestRunners.newTestRunner(new MergeContent()); - mergeRunner.setProperty(MergeContent.MERGE_FORMAT, MergeContent.MERGE_FORMAT_CONCAT); - mergeRunner.setProperty(MergeContent.MERGE_STRATEGY, MergeContent.MERGE_STRATEGY_DEFRAGMENT); + final TestRunner mergeRunner = TestRunners. + newTestRunner(new MergeContent()); + mergeRunner. + setProperty(MergeContent.MERGE_FORMAT, MergeContent.MERGE_FORMAT_CONCAT); + mergeRunner. + setProperty(MergeContent.MERGE_STRATEGY, MergeContent.MERGE_STRATEGY_DEFRAGMENT); mergeRunner.enqueue(splits.toArray(new MockFlowFile[0])); mergeRunner.run(); @@ -352,7 +417,9 @@ public class TestSplitContent { mergeRunner.assertTransferCount(MergeContent.REL_ORIGINAL, 2); mergeRunner.assertTransferCount(MergeContent.REL_FAILURE, 0); - final List<MockFlowFile> packed = mergeRunner.getFlowFilesForRelationship(MergeContent.REL_MERGED); - packed.get(0).assertContentEquals(new byte[]{1, 2, 3, 4, 5, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, 5, 4, 3, 2, 1}); + final List<MockFlowFile> packed = mergeRunner. + getFlowFilesForRelationship(MergeContent.REL_MERGED); + packed.get(0). + assertContentEquals(new byte[]{1, 2, 3, 4, 5, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, 5, 4, 3, 2, 1}); } } 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/TestSplitJson.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitJson.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitJson.java index fc07386..9503182 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitJson.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitJson.java @@ -35,15 +35,18 @@ import java.nio.file.Paths; public class TestSplitJson { - private static final Path JSON_SNIPPET = Paths.get("src/test/resources/TestJson/json-sample.json"); - private static final Path XML_SNIPPET = Paths.get("src/test/resources/TestXml/xml-snippet.xml"); + private static final Path JSON_SNIPPET = Paths. + get("src/test/resources/TestJson/json-sample.json"); + private static final Path XML_SNIPPET = Paths. + get("src/test/resources/TestXml/xml-snippet.xml"); @Test(expected = AssertionError.class) public void testInvalidJsonPath() { final TestRunner testRunner = TestRunners.newTestRunner(new SplitJson()); testRunner.setProperty(SplitJson.ARRAY_JSON_PATH_EXPRESSION, "$.."); - Assert.fail("An improper JsonPath expression was not detected as being invalid."); + Assert. + fail("An improper JsonPath expression was not detected as being invalid."); } @Test @@ -55,7 +58,9 @@ public class TestSplitJson { testRunner.run(); testRunner.assertAllFlowFilesTransferred(SplitJson.REL_FAILURE, 1); - final MockFlowFile out = testRunner.getFlowFilesForRelationship(SplitJson.REL_FAILURE).get(0); + final MockFlowFile out = testRunner. + getFlowFilesForRelationship(SplitJson.REL_FAILURE). + get(0); // Verify that the content was unchanged out.assertContentEquals(XML_SNIPPET); } @@ -71,28 +76,36 @@ public class TestSplitJson { Relationship expectedRel = SplitJson.REL_FAILURE; testRunner.assertAllFlowFilesTransferred(expectedRel, 1); - final MockFlowFile out = testRunner.getFlowFilesForRelationship(expectedRel).get(0); + final MockFlowFile out = testRunner. + getFlowFilesForRelationship(expectedRel). + get(0); out.assertContentEquals(JSON_SNIPPET); } @Test public void testSplit_arrayResult_oneValue() throws Exception { final TestRunner testRunner = TestRunners.newTestRunner(new SplitJson()); - testRunner.setProperty(SplitJson.ARRAY_JSON_PATH_EXPRESSION, "$[0].range[?(@ == 0)]"); + testRunner. + setProperty(SplitJson.ARRAY_JSON_PATH_EXPRESSION, "$[0].range[?(@ == 0)]"); testRunner.enqueue(JSON_SNIPPET); testRunner.run(); testRunner.assertTransferCount(SplitJson.REL_ORIGINAL, 1); testRunner.assertTransferCount(SplitJson.REL_SPLIT, 1); - testRunner.getFlowFilesForRelationship(SplitJson.REL_ORIGINAL).get(0).assertContentEquals(JSON_SNIPPET); - testRunner.getFlowFilesForRelationship(SplitJson.REL_SPLIT).get(0).assertContentEquals("0"); + testRunner.getFlowFilesForRelationship(SplitJson.REL_ORIGINAL). + get(0). + assertContentEquals(JSON_SNIPPET); + testRunner.getFlowFilesForRelationship(SplitJson.REL_SPLIT). + get(0). + assertContentEquals("0"); } @Test public void testSplit_arrayResult_multipleValues() throws Exception { final TestRunner testRunner = TestRunners.newTestRunner(new SplitJson()); - testRunner.setProperty(SplitJson.ARRAY_JSON_PATH_EXPRESSION, "$[0].range"); + testRunner. + setProperty(SplitJson.ARRAY_JSON_PATH_EXPRESSION, "$[0].range"); testRunner.enqueue(JSON_SNIPPET); testRunner.run(); @@ -101,49 +114,63 @@ public class TestSplitJson { testRunner.assertTransferCount(SplitJson.REL_ORIGINAL, 1); testRunner.assertTransferCount(SplitJson.REL_SPLIT, numSplitsExpected); - final MockFlowFile originalOut = testRunner.getFlowFilesForRelationship(SplitJson.REL_ORIGINAL).get(0); + final MockFlowFile originalOut = testRunner. + getFlowFilesForRelationship(SplitJson.REL_ORIGINAL). + get(0); originalOut.assertContentEquals(JSON_SNIPPET); } @Test public void testSplit_arrayResult_nonScalarValues() throws Exception { final TestRunner testRunner = TestRunners.newTestRunner(new SplitJson()); - testRunner.setProperty(SplitJson.ARRAY_JSON_PATH_EXPRESSION, "$[*].name"); + testRunner. + setProperty(SplitJson.ARRAY_JSON_PATH_EXPRESSION, "$[*].name"); testRunner.enqueue(JSON_SNIPPET); testRunner.run(); testRunner.assertTransferCount(SplitJson.REL_ORIGINAL, 1); testRunner.assertTransferCount(SplitJson.REL_SPLIT, 7); - testRunner.getFlowFilesForRelationship(SplitJson.REL_ORIGINAL).get(0).assertContentEquals(JSON_SNIPPET); - testRunner.getFlowFilesForRelationship(SplitJson.REL_SPLIT).get(0).assertContentEquals("{\"first\":\"Shaffer\",\"last\":\"Pearson\"}"); + testRunner.getFlowFilesForRelationship(SplitJson.REL_ORIGINAL). + get(0). + assertContentEquals(JSON_SNIPPET); + testRunner.getFlowFilesForRelationship(SplitJson.REL_SPLIT). + get(0). + assertContentEquals("{\"first\":\"Shaffer\",\"last\":\"Pearson\"}"); } @Test public void testSplit_pathNotFound() throws Exception { final TestRunner testRunner = TestRunners.newTestRunner(new SplitJson()); - testRunner.setProperty(SplitJson.ARRAY_JSON_PATH_EXPRESSION, "$.nonexistent"); + testRunner. + setProperty(SplitJson.ARRAY_JSON_PATH_EXPRESSION, "$.nonexistent"); testRunner.enqueue(JSON_SNIPPET); testRunner.run(); testRunner.assertTransferCount(SplitJson.REL_FAILURE, 1); - testRunner.getFlowFilesForRelationship(SplitJson.REL_FAILURE).get(0).assertContentEquals(JSON_SNIPPET); + testRunner.getFlowFilesForRelationship(SplitJson.REL_FAILURE). + get(0). + assertContentEquals(JSON_SNIPPET); } @Test public void testSplit_pathToNullValue() throws Exception { final TestRunner testRunner = TestRunners.newTestRunner(new SplitJson()); - testRunner.setProperty(SplitJson.ARRAY_JSON_PATH_EXPRESSION, "$.nullField"); + testRunner. + setProperty(SplitJson.ARRAY_JSON_PATH_EXPRESSION, "$.nullField"); - ProcessSession session = testRunner.getProcessSessionFactory().createSession(); + ProcessSession session = testRunner.getProcessSessionFactory(). + createSession(); FlowFile ff = session.create(); ff = session.write(ff, new OutputStreamCallback() { @Override public void process(OutputStream out) throws IOException { try (OutputStream outputStream = new BufferedOutputStream(out)) { - outputStream.write("{\"stringField\": \"String Value\", \"nullField\": null}".getBytes(StandardCharsets.UTF_8)); + outputStream. + write("{\"stringField\": \"String Value\", \"nullField\": null}". + getBytes(StandardCharsets.UTF_8)); } } }); @@ -157,16 +184,20 @@ public class TestSplitJson { @Test public void testSplit_pathToArrayWithNulls_emptyStringRepresentation() throws Exception { final TestRunner testRunner = TestRunners.newTestRunner(new SplitJson()); - testRunner.setProperty(SplitJson.ARRAY_JSON_PATH_EXPRESSION, "$.arrayOfNulls"); + testRunner. + setProperty(SplitJson.ARRAY_JSON_PATH_EXPRESSION, "$.arrayOfNulls"); - ProcessSession session = testRunner.getProcessSessionFactory().createSession(); + ProcessSession session = testRunner.getProcessSessionFactory(). + createSession(); FlowFile ff = session.create(); ff = session.write(ff, new OutputStreamCallback() { @Override public void process(OutputStream out) throws IOException { try (OutputStream outputStream = new BufferedOutputStream(out)) { - outputStream.write("{\"stringField\": \"String Value\", \"arrayOfNulls\": [null, null, null]}".getBytes(StandardCharsets.UTF_8)); + outputStream. + write("{\"stringField\": \"String Value\", \"arrayOfNulls\": [null, null, null]}". + getBytes(StandardCharsets.UTF_8)); } } }); @@ -178,25 +209,31 @@ public class TestSplitJson { int expectedFiles = 3; testRunner.assertTransferCount(SplitJson.REL_SPLIT, expectedFiles); for (int i = 0; i < expectedFiles; i++) { - testRunner.getFlowFilesForRelationship(SplitJson.REL_SPLIT).get(i).assertContentEquals(""); + testRunner.getFlowFilesForRelationship(SplitJson.REL_SPLIT). + get(i). + assertContentEquals(""); } } @Test public void testSplit_pathToArrayWithNulls_nullStringRepresentation() throws Exception { final TestRunner testRunner = TestRunners.newTestRunner(new SplitJson()); - testRunner.setProperty(SplitJson.ARRAY_JSON_PATH_EXPRESSION, "$.arrayOfNulls"); + testRunner. + setProperty(SplitJson.ARRAY_JSON_PATH_EXPRESSION, "$.arrayOfNulls"); testRunner.setProperty(SplitJson.NULL_VALUE_DEFAULT_REPRESENTATION, AbstractJsonPathProcessor.NULL_STRING_OPTION); - ProcessSession session = testRunner.getProcessSessionFactory().createSession(); + ProcessSession session = testRunner.getProcessSessionFactory(). + createSession(); FlowFile ff = session.create(); ff = session.write(ff, new OutputStreamCallback() { @Override public void process(OutputStream out) throws IOException { try (OutputStream outputStream = new BufferedOutputStream(out)) { - outputStream.write("{\"stringField\": \"String Value\", \"arrayOfNulls\": [null, null, null]}".getBytes(StandardCharsets.UTF_8)); + outputStream. + write("{\"stringField\": \"String Value\", \"arrayOfNulls\": [null, null, null]}". + getBytes(StandardCharsets.UTF_8)); } } }); @@ -208,7 +245,9 @@ public class TestSplitJson { int expectedFiles = 3; testRunner.assertTransferCount(SplitJson.REL_SPLIT, expectedFiles); for (int i = 0; i < expectedFiles; i++) { - testRunner.getFlowFilesForRelationship(SplitJson.REL_SPLIT).get(i).assertContentEquals("null"); + testRunner.getFlowFilesForRelationship(SplitJson.REL_SPLIT). + get(i). + assertContentEquals("null"); } } }