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/TestEvaluateXQuery.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEvaluateXQuery.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEvaluateXQuery.java index aae4411..99d5858 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEvaluateXQuery.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEvaluateXQuery.java @@ -43,7 +43,8 @@ import org.junit.Test; public class TestEvaluateXQuery { - private static final Path XML_SNIPPET = Paths.get("src/test/resources/TestXml/fruit.xml"); + private static final Path XML_SNIPPET = Paths. + get("src/test/resources/TestXml/fruit.xml"); private static final String[] fruitNames = {"apple", "apple", "banana", "orange", "blueberry", "raspberry", "none"}; private static final String[] methods = {EvaluateXQuery.OUTPUT_METHOD_XML, EvaluateXQuery.OUTPUT_METHOD_HTML, EvaluateXQuery.OUTPUT_METHOD_TEXT}; @@ -55,11 +56,15 @@ public class TestEvaluateXQuery { for (int i = 0; i < methods.length; i++) { for (int j = 0; j < booleans.length; j++) { for (int k = 0; k < booleans.length; k++) { - Properties props = EvaluateXQuery.getTransformerProperties(methods[i], booleans[j], booleans[k]); + Properties props = EvaluateXQuery. + getTransformerProperties(methods[i], booleans[j], booleans[k]); assertEquals(3, props.size()); - assertEquals(methods[i], props.getProperty(OutputKeys.METHOD)); - assertEquals(booleans[j] ? "yes" : "no", props.getProperty(OutputKeys.INDENT)); - assertEquals(booleans[k] ? "yes" : "no", props.getProperty(OutputKeys.OMIT_XML_DECLARATION)); + assertEquals(methods[i], props. + getProperty(OutputKeys.METHOD)); + assertEquals(booleans[j] ? "yes" : "no", props. + getProperty(OutputKeys.INDENT)); + assertEquals(booleans[k] ? "yes" : "no", props. + getProperty(OutputKeys.OMIT_XML_DECLARATION)); } } } @@ -157,10 +162,14 @@ public class TestEvaluateXQuery { List<String> resultStrings = new ArrayList<>(); runnerProps.clear(); - runnerProps.put(EvaluateXQuery.DESTINATION.getName(), EvaluateXQuery.DESTINATION_CONTENT); + runnerProps. + put(EvaluateXQuery.DESTINATION.getName(), EvaluateXQuery.DESTINATION_CONTENT); runnerProps.put(EvaluateXQuery.XML_OUTPUT_METHOD.getName(), method); - runnerProps.put(EvaluateXQuery.XML_OUTPUT_INDENT.getName(), Boolean.toString(indent)); - runnerProps.put(EvaluateXQuery.XML_OUTPUT_OMIT_XML_DECLARATION.getName(), Boolean.toString(omitDeclaration)); + runnerProps.put(EvaluateXQuery.XML_OUTPUT_INDENT.getName(), Boolean. + toString(indent)); + runnerProps. + put(EvaluateXQuery.XML_OUTPUT_OMIT_XML_DECLARATION.getName(), Boolean. + toString(omitDeclaration)); runnerProps.put("xquery", xQuery); resultFlowFiles = runXquery(xml, runnerProps); @@ -176,22 +185,26 @@ public class TestEvaluateXQuery { @Test(expected = java.lang.AssertionError.class) public void testBadXQuery() throws Exception { - doXqueryTest(XML_SNIPPET, "counttttttt(*:fruitbasket/fruit)", Arrays.asList("7")); + doXqueryTest(XML_SNIPPET, "counttttttt(*:fruitbasket/fruit)", Arrays. + asList("7")); } @Test public void testXQueries() throws Exception { /* count matches */ - doXqueryTest(XML_SNIPPET, "count(*:fruitbasket/fruit)", Arrays.asList("7")); + doXqueryTest(XML_SNIPPET, "count(*:fruitbasket/fruit)", Arrays. + asList("7")); doXqueryTest(XML_SNIPPET, "count(//fruit)", Arrays.asList("7")); /* Using a namespace */ - doXqueryTest(XML_SNIPPET, "declare namespace fb = \"http://namespace/1\"; count(fb:fruitbasket/fruit)", Arrays.asList("7")); + doXqueryTest(XML_SNIPPET, "declare namespace fb = \"http://namespace/1\"; count(fb:fruitbasket/fruit)", Arrays. + asList("7")); /* determine if node exists */ doXqueryTest(XML_SNIPPET, "boolean(//fruit[1])", Arrays.asList("true")); - doXqueryTest(XML_SNIPPET, "boolean(//fruit[100])", Arrays.asList("false")); + doXqueryTest(XML_SNIPPET, "boolean(//fruit[100])", Arrays. + asList("false")); /* XML first match */ doXqueryTest(XML_SNIPPET, "//fruit[1]", Arrays.asList( @@ -229,13 +242,16 @@ public class TestEvaluateXQuery { + "</wrap>")); /* String all matches fruit names*/ - doXqueryTest(XML_SNIPPET, "for $x in //fruit return $x/name/text()", Arrays.asList(fruitNames)); + doXqueryTest(XML_SNIPPET, "for $x in //fruit return $x/name/text()", Arrays. + asList(fruitNames)); /* String first match fruit name (XPath)*/ - doXqueryTest(XML_SNIPPET, "//fruit[1]/name/text()", Arrays.asList("apple")); + doXqueryTest(XML_SNIPPET, "//fruit[1]/name/text()", Arrays. + asList("apple")); /* String first match fruit color (XPath)*/ - doXqueryTest(XML_SNIPPET, "//fruit[1]/color/text()", Arrays.asList("red")); + doXqueryTest(XML_SNIPPET, "//fruit[1]/color/text()", Arrays. + asList("red")); /* String first match fruit name (XQuery)*/ doXqueryTest(XML_SNIPPET, "for $x in //fruit[1] return string-join(($x/name/text() , $x/color/text()), ' - ')", @@ -280,25 +296,31 @@ public class TestEvaluateXQuery { /* String all matches name only, comma delimited (one result)*/ doXqueryTest(XML_SNIPPET, "string-join((for $x in //fruit return $x/name/text()), ', ')", - Arrays.asList("apple, apple, banana, orange, blueberry, raspberry, none")); + Arrays. + asList("apple, apple, banana, orange, blueberry, raspberry, none")); /* String all matches color and name, comma delimited (one result)*/ doXqueryTest(XML_SNIPPET, "string-join((for $y in (for $x in //fruit return string-join(($x/color/text() , $x/name/text()), ' ')) return $y), ', ')", - Arrays.asList("red apple, green apple, yellow banana, orange orange, blue blueberry, red raspberry, none")); + Arrays. + asList("red apple, green apple, yellow banana, orange orange, blue blueberry, red raspberry, none")); /* String all matches color and name, comma delimited using let(one result)*/ doXqueryTest(XML_SNIPPET, "string-join((for $y in (for $x in //fruit let $d := string-join(($x/color/text() , $x/name/text()), ' ') return $d) return $y), ', ')", - Arrays.asList("red apple, green apple, yellow banana, orange orange, blue blueberry, red raspberry, none")); + Arrays. + asList("red apple, green apple, yellow banana, orange orange, blue blueberry, red raspberry, none")); /* Query for attribute */ - doXqueryTest(XML_SNIPPET, "string(//fruit[1]/@taste)", Arrays.asList("crisp")); + doXqueryTest(XML_SNIPPET, "string(//fruit[1]/@taste)", Arrays. + asList("crisp")); /* Query for comment */ - doXqueryTest(XML_SNIPPET, "//fruit/comment()", Arrays.asList(" Apples are my favorite ")); + doXqueryTest(XML_SNIPPET, "//fruit/comment()", Arrays. + asList(" Apples are my favorite ")); /* Query for processing instruction */ - doXqueryTest(XML_SNIPPET, "//processing-instruction()[name()='xml-stylesheet']", Arrays.asList("type=\"text/xsl\" href=\"foo.xsl\"")); + doXqueryTest(XML_SNIPPET, "//processing-instruction()[name()='xml-stylesheet']", Arrays. + asList("type=\"text/xsl\" href=\"foo.xsl\"")); } @@ -310,7 +332,8 @@ public class TestEvaluateXQuery { // test read from content, write to attribute { runnerProps.clear(); - runnerProps.put(EvaluateXQuery.DESTINATION.getName(), EvaluateXQuery.DESTINATION_ATTRIBUTE); + runnerProps. + put(EvaluateXQuery.DESTINATION.getName(), EvaluateXQuery.DESTINATION_ATTRIBUTE); runnerProps.put("xquery", xQuery); resultFlowFiles = runXquery(xml, runnerProps); @@ -323,8 +346,10 @@ public class TestEvaluateXQuery { if (expectedResults.size() > 1) { key += "." + ((int) i + 1); } - final String actual = out.getAttribute(key).replaceAll(">\\s+<", "><"); - final String expected = expectedResults.get(i).replaceAll(">\\s+<", "><"); + final String actual = out.getAttribute(key). + replaceAll(">\\s+<", "><"); + final String expected = expectedResults.get(i). + replaceAll(">\\s+<", "><"); assertEquals(expected, actual); } } @@ -332,7 +357,8 @@ public class TestEvaluateXQuery { // test read from content, write to content { runnerProps.clear(); - runnerProps.put(EvaluateXQuery.DESTINATION.getName(), EvaluateXQuery.DESTINATION_CONTENT); + runnerProps. + put(EvaluateXQuery.DESTINATION.getName(), EvaluateXQuery.DESTINATION_CONTENT); runnerProps.put("xquery", xQuery); resultFlowFiles = runXquery(xml, runnerProps); @@ -342,9 +368,11 @@ public class TestEvaluateXQuery { final MockFlowFile out = resultFlowFiles.get(i); final byte[] outData = out.toByteArray(); - final String outXml = new String(outData, "UTF-8").replaceAll(">\\s+<", "><"); + final String outXml = new String(outData, "UTF-8"). + replaceAll(">\\s+<", "><"); final String actual = outXml; - final String expected = expectedResults.get(i).replaceAll(">\\s+<", "><"); + final String expected = expectedResults.get(i). + replaceAll(">\\s+<", "><"); assertEquals(expected, actual); } } @@ -356,7 +384,8 @@ public class TestEvaluateXQuery { private List<MockFlowFile> runXquery(Path xml, Map<String, String> runnerProps, Map<String, String> flowFileAttributes) throws Exception { - final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateXQuery()); + final TestRunner testRunner = TestRunners. + newTestRunner(new EvaluateXQuery()); for (Entry<String, String> entry : runnerProps.entrySet()) { testRunner.setProperty(entry.getKey(), entry.getValue()); @@ -372,81 +401,109 @@ public class TestEvaluateXQuery { @Test public void testRootPath() throws XPathFactoryConfigurationException, IOException { - final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateXQuery()); - testRunner.setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_ATTRIBUTE); + final TestRunner testRunner = TestRunners. + newTestRunner(new EvaluateXQuery()); + testRunner. + setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_ATTRIBUTE); testRunner.setProperty("xquery.result1", "/"); testRunner.enqueue(XML_SNIPPET); testRunner.run(); testRunner.assertAllFlowFilesTransferred(EvaluateXQuery.REL_MATCH, 1); - final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).get(0); - final String attributeString = out.getAttribute("xquery.result1").replaceAll(">\\s+<", "><"); - final String xmlSnippetString = new String(Files.readAllBytes(XML_SNIPPET), "UTF-8").replaceAll(">\\s+<", "><"); + final MockFlowFile out = testRunner. + getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH). + get(0); + final String attributeString = out.getAttribute("xquery.result1"). + replaceAll(">\\s+<", "><"); + final String xmlSnippetString = new String(Files. + readAllBytes(XML_SNIPPET), "UTF-8").replaceAll(">\\s+<", "><"); assertEquals(xmlSnippetString, attributeString); } @Test public void testCheckIfElementExists() throws XPathFactoryConfigurationException, IOException { - final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateXQuery()); - testRunner.setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_ATTRIBUTE); - testRunner.setProperty("xquery.result.exist.1", "boolean(/*:fruitbasket/fruit[1])"); - testRunner.setProperty("xquery.result.exist.2", "boolean(/*:fruitbasket/fruit[100])"); + final TestRunner testRunner = TestRunners. + newTestRunner(new EvaluateXQuery()); + testRunner. + setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_ATTRIBUTE); + testRunner. + setProperty("xquery.result.exist.1", "boolean(/*:fruitbasket/fruit[1])"); + testRunner. + setProperty("xquery.result.exist.2", "boolean(/*:fruitbasket/fruit[100])"); testRunner.enqueue(XML_SNIPPET); testRunner.run(); testRunner.assertAllFlowFilesTransferred(EvaluateXQuery.REL_MATCH, 1); - final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).get(0); + final MockFlowFile out = testRunner. + getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH). + get(0); out.assertAttributeEquals("xquery.result.exist.1", "true"); out.assertAttributeEquals("xquery.result.exist.2", "false"); } @Test public void testUnmatchedContent() throws XPathFactoryConfigurationException, IOException { - final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateXQuery()); - testRunner.setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_CONTENT); + final TestRunner testRunner = TestRunners. + newTestRunner(new EvaluateXQuery()); + testRunner. + setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_CONTENT); testRunner.setProperty("xquery.result.exist.2", "/*:fruitbasket/node2"); testRunner.enqueue(XML_SNIPPET); testRunner.run(); testRunner.assertAllFlowFilesTransferred(EvaluateXQuery.REL_NO_MATCH, 1); - testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_NO_MATCH).get(0).assertContentEquals(XML_SNIPPET); + testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_NO_MATCH). + get(0). + assertContentEquals(XML_SNIPPET); } @Test public void testUnmatchedAttribute() throws XPathFactoryConfigurationException, IOException { - final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateXQuery()); - testRunner.setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_ATTRIBUTE); + final TestRunner testRunner = TestRunners. + newTestRunner(new EvaluateXQuery()); + testRunner. + setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_ATTRIBUTE); testRunner.setProperty("xquery.result.exist.2", "/*:fruitbasket/node2"); testRunner.enqueue(XML_SNIPPET); testRunner.run(); testRunner.assertAllFlowFilesTransferred(EvaluateXQuery.REL_NO_MATCH, 1); - final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_NO_MATCH).get(0); + final MockFlowFile out = testRunner. + getFlowFilesForRelationship(EvaluateXQuery.REL_NO_MATCH). + get(0); out.assertAttributeEquals("xquery.result.exist.2", null); - testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_NO_MATCH).get(0).assertContentEquals(XML_SNIPPET); + testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_NO_MATCH). + get(0). + assertContentEquals(XML_SNIPPET); } @Test public void testNoXQueryAttribute() throws XPathFactoryConfigurationException, IOException { - final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateXQuery()); - testRunner.setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_ATTRIBUTE); + final TestRunner testRunner = TestRunners. + newTestRunner(new EvaluateXQuery()); + testRunner. + setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_ATTRIBUTE); testRunner.enqueue(XML_SNIPPET); testRunner.run(); testRunner.assertAllFlowFilesTransferred(EvaluateXQuery.REL_NO_MATCH, 1); - testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_NO_MATCH).get(0).assertContentEquals(XML_SNIPPET); + testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_NO_MATCH). + get(0). + assertContentEquals(XML_SNIPPET); } @Test(expected = java.lang.AssertionError.class) public void testNoXQueryContent() throws XPathFactoryConfigurationException, IOException { - final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateXQuery()); - testRunner.setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_CONTENT); + final TestRunner testRunner = TestRunners. + newTestRunner(new EvaluateXQuery()); + testRunner. + setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_CONTENT); testRunner.enqueue(XML_SNIPPET); testRunner.run(); @@ -454,8 +511,10 @@ public class TestEvaluateXQuery { @Test public void testOneMatchOneUnmatchAttribute() throws XPathFactoryConfigurationException, IOException { - final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateXQuery()); - testRunner.setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_ATTRIBUTE); + final TestRunner testRunner = TestRunners. + newTestRunner(new EvaluateXQuery()); + testRunner. + setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_ATTRIBUTE); testRunner.setProperty("some.property", "//fruit/name/text()"); testRunner.setProperty("xquery.result.exist.2", "/*:fruitbasket/node2"); @@ -464,37 +523,51 @@ public class TestEvaluateXQuery { testRunner.assertAllFlowFilesTransferred(EvaluateXQuery.REL_MATCH, 1); - final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).get(0); + final MockFlowFile out = testRunner. + getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH). + get(0); for (int i = 0; i < fruitNames.length; i++) { - final String outXml = out.getAttribute("some.property." + ((int) i + 1)); + final String outXml = out. + getAttribute("some.property." + ((int) i + 1)); assertEquals(fruitNames[i], outXml.trim()); } out.assertAttributeEquals("xquery.result.exist.2", null); - testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).get(0).assertContentEquals(XML_SNIPPET); + testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH). + get(0). + assertContentEquals(XML_SNIPPET); } @Test public void testMatchedEmptyStringAttribute() throws XPathFactoryConfigurationException, IOException { - final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateXQuery()); - testRunner.setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_ATTRIBUTE); - testRunner.setProperty("xquery.result.exist.2", "/*:fruitbasket/*[name='none']/color/text()"); + final TestRunner testRunner = TestRunners. + newTestRunner(new EvaluateXQuery()); + testRunner. + setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_ATTRIBUTE); + testRunner. + setProperty("xquery.result.exist.2", "/*:fruitbasket/*[name='none']/color/text()"); testRunner.enqueue(XML_SNIPPET); testRunner.run(); testRunner.assertAllFlowFilesTransferred(EvaluateXQuery.REL_NO_MATCH, 1); - final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_NO_MATCH).get(0); + final MockFlowFile out = testRunner. + getFlowFilesForRelationship(EvaluateXQuery.REL_NO_MATCH). + get(0); out.assertAttributeEquals("xquery.result.exist.2", null); - testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_NO_MATCH).get(0).assertContentEquals(XML_SNIPPET); + testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_NO_MATCH). + get(0). + assertContentEquals(XML_SNIPPET); } @Test(expected = java.lang.AssertionError.class) public void testMultipleXPathForContent() throws IOException { - final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateXQuery()); - testRunner.setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_CONTENT); + final TestRunner testRunner = TestRunners. + newTestRunner(new EvaluateXQuery()); + testRunner. + setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_CONTENT); testRunner.setProperty("some.property.1", "/*:fruitbasket/fruit[1]"); testRunner.setProperty("some.property.2", "/*:fruitbasket/fruit[2]"); @@ -504,71 +577,98 @@ public class TestEvaluateXQuery { @Test public void testWriteStringToAttribute() throws XPathFactoryConfigurationException, IOException { - final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateXQuery()); - testRunner.setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_ATTRIBUTE); - testRunner.setProperty("xquery.result2", "/*:fruitbasket/fruit[1]/name/text()"); + final TestRunner testRunner = TestRunners. + newTestRunner(new EvaluateXQuery()); + testRunner. + setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_ATTRIBUTE); + testRunner. + setProperty("xquery.result2", "/*:fruitbasket/fruit[1]/name/text()"); testRunner.enqueue(XML_SNIPPET); testRunner.run(); testRunner.assertAllFlowFilesTransferred(EvaluateXQuery.REL_MATCH, 1); - final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).get(0); + final MockFlowFile out = testRunner. + getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH). + get(0); out.assertAttributeEquals("xquery.result2", "apple"); - testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).get(0).assertContentEquals(XML_SNIPPET); + testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH). + get(0). + assertContentEquals(XML_SNIPPET); } @Test public void testWriteStringToContent() throws XPathFactoryConfigurationException, IOException { - final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateXQuery()); - testRunner.setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_CONTENT); - testRunner.setProperty("some.property", "/*:fruitbasket/fruit[1]/name/text()"); + final TestRunner testRunner = TestRunners. + newTestRunner(new EvaluateXQuery()); + testRunner. + setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_CONTENT); + testRunner. + setProperty("some.property", "/*:fruitbasket/fruit[1]/name/text()"); testRunner.enqueue(XML_SNIPPET); testRunner.run(); testRunner.assertAllFlowFilesTransferred(EvaluateXQuery.REL_MATCH, 1); - final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).get(0); + final MockFlowFile out = testRunner. + getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH). + get(0); final byte[] outData = testRunner.getContentAsByteArray(out); final String outXml = new String(outData, "UTF-8"); - assertTrue(outXml.trim().equals("apple")); + assertTrue(outXml.trim(). + equals("apple")); } @Test public void testWriteXmlToAttribute() throws XPathFactoryConfigurationException, IOException { - final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateXQuery()); - testRunner.setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_ATTRIBUTE); + final TestRunner testRunner = TestRunners. + newTestRunner(new EvaluateXQuery()); + testRunner. + setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_ATTRIBUTE); testRunner.setProperty("some.property", "/*:fruitbasket/fruit[1]/name"); testRunner.enqueue(XML_SNIPPET); testRunner.run(); testRunner.assertAllFlowFilesTransferred(EvaluateXQuery.REL_MATCH, 1); - final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).get(0); + final MockFlowFile out = testRunner. + getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH). + get(0); final String outXml = out.getAttribute("some.property"); - assertTrue(outXml.contains("<name xmlns:ns=\"http://namespace/1\">apple</name>")); - testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).get(0).assertContentEquals(XML_SNIPPET); + assertTrue(outXml. + contains("<name xmlns:ns=\"http://namespace/1\">apple</name>")); + testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH). + get(0). + assertContentEquals(XML_SNIPPET); } @Test public void testWriteXmlToContent() throws XPathFactoryConfigurationException, IOException { - final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateXQuery()); - testRunner.setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_CONTENT); + final TestRunner testRunner = TestRunners. + newTestRunner(new EvaluateXQuery()); + testRunner. + setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_CONTENT); testRunner.setProperty("some.property", "/*:fruitbasket/fruit[1]/name"); testRunner.enqueue(XML_SNIPPET); testRunner.run(); testRunner.assertAllFlowFilesTransferred(EvaluateXQuery.REL_MATCH, 1); - final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).get(0); + final MockFlowFile out = testRunner. + getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH). + get(0); final byte[] outData = testRunner.getContentAsByteArray(out); final String outXml = new String(outData, "UTF-8"); - assertTrue(outXml.contains("<name xmlns:ns=\"http://namespace/1\">apple</name>")); + assertTrue(outXml. + contains("<name xmlns:ns=\"http://namespace/1\">apple</name>")); } @Test public void testMatchesMultipleStringContent() throws XPathFactoryConfigurationException, IOException { - final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateXQuery()); - testRunner.setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_CONTENT); + final TestRunner testRunner = TestRunners. + newTestRunner(new EvaluateXQuery()); + testRunner. + setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_CONTENT); testRunner.setProperty("some.property", "//fruit/name/text()"); testRunner.enqueue(XML_SNIPPET); @@ -576,7 +676,8 @@ public class TestEvaluateXQuery { testRunner.assertAllFlowFilesTransferred(EvaluateXQuery.REL_MATCH, 7); - final List<MockFlowFile> flowFilesForRelMatch = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH); + final List<MockFlowFile> flowFilesForRelMatch = testRunner. + getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH); for (int i = 0; i < flowFilesForRelMatch.size(); i++) { final MockFlowFile out = flowFilesForRelMatch.get(i); @@ -588,8 +689,10 @@ public class TestEvaluateXQuery { @Test public void testMatchesMultipleStringAttribute() throws XPathFactoryConfigurationException, IOException { - final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateXQuery()); - testRunner.setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_ATTRIBUTE); + final TestRunner testRunner = TestRunners. + newTestRunner(new EvaluateXQuery()); + testRunner. + setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_ATTRIBUTE); testRunner.setProperty("some.property", "//fruit/name/text()"); testRunner.enqueue(XML_SNIPPET); @@ -597,19 +700,26 @@ public class TestEvaluateXQuery { testRunner.assertAllFlowFilesTransferred(EvaluateXQuery.REL_MATCH, 1); - final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).get(0); + final MockFlowFile out = testRunner. + getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH). + get(0); for (int i = 0; i < fruitNames.length; i++) { - final String outXml = out.getAttribute("some.property." + ((int) i + 1)); + final String outXml = out. + getAttribute("some.property." + ((int) i + 1)); assertEquals(fruitNames[i], outXml.trim()); } - testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).get(0).assertContentEquals(XML_SNIPPET); + testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH). + get(0). + assertContentEquals(XML_SNIPPET); } @Test public void testMatchesMultipleXmlContent() throws XPathFactoryConfigurationException, IOException { - final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateXQuery()); - testRunner.setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_CONTENT); + final TestRunner testRunner = TestRunners. + newTestRunner(new EvaluateXQuery()); + testRunner. + setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_CONTENT); testRunner.setProperty("some.property", "//fruit/name"); testRunner.enqueue(XML_SNIPPET); @@ -617,7 +727,8 @@ public class TestEvaluateXQuery { testRunner.assertAllFlowFilesTransferred(EvaluateXQuery.REL_MATCH, 7); - final List<MockFlowFile> flowFilesForRelMatch = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH); + final List<MockFlowFile> flowFilesForRelMatch = testRunner. + getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH); for (int i = 0; i < flowFilesForRelMatch.size(); i++) { final MockFlowFile out = flowFilesForRelMatch.get(i); @@ -630,8 +741,10 @@ public class TestEvaluateXQuery { @Test public void testMatchesMultipleXmlAttribute() throws XPathFactoryConfigurationException, IOException { - final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateXQuery()); - testRunner.setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_ATTRIBUTE); + final TestRunner testRunner = TestRunners. + newTestRunner(new EvaluateXQuery()); + testRunner. + setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_ATTRIBUTE); testRunner.setProperty("some.property", "//fruit/name"); testRunner.enqueue(XML_SNIPPET); @@ -639,13 +752,18 @@ public class TestEvaluateXQuery { testRunner.assertAllFlowFilesTransferred(EvaluateXQuery.REL_MATCH, 1); - final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).get(0); + final MockFlowFile out = testRunner. + getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH). + get(0); for (int i = 0; i < fruitNames.length; i++) { - final String outXml = out.getAttribute("some.property." + ((int) i + 1)); + final String outXml = out. + getAttribute("some.property." + ((int) i + 1)); String expectedXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><name xmlns:ns=\"http://namespace/1\">" + fruitNames[i] + "</name>"; assertEquals(expectedXml, outXml.trim()); } - testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).get(0).assertContentEquals(XML_SNIPPET); + testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH). + get(0). + assertContentEquals(XML_SNIPPET); } }
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/TestExecuteProcess.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteProcess.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteProcess.java index 897973c..0907f38 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteProcess.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteProcess.java @@ -34,43 +34,49 @@ public class TestExecuteProcess { final List<String> nullArgs = ExecuteProcess.splitArgs(null); assertNotNull(nullArgs); assertTrue(nullArgs.isEmpty()); - + final List<String> zeroArgs = ExecuteProcess.splitArgs(" "); assertNotNull(zeroArgs); assertTrue(zeroArgs.isEmpty()); - + final List<String> singleArg = ExecuteProcess.splitArgs(" hello "); assertEquals(1, singleArg.size()); assertEquals("hello", singleArg.get(0)); - - final List<String> twoArg = ExecuteProcess.splitArgs(" hello good-bye "); + + final List<String> twoArg = ExecuteProcess. + splitArgs(" hello good-bye "); assertEquals(2, twoArg.size()); assertEquals("hello", twoArg.get(0)); assertEquals("good-bye", twoArg.get(1)); - - final List<String> singleQuotedArg = ExecuteProcess.splitArgs(" \"hello\" "); + + final List<String> singleQuotedArg = ExecuteProcess. + splitArgs(" \"hello\" "); assertEquals(1, singleQuotedArg.size()); assertEquals("hello", singleQuotedArg.get(0)); - - final List<String> twoQuotedArg = ExecuteProcess.splitArgs(" hello \"good bye\""); + + final List<String> twoQuotedArg = ExecuteProcess. + splitArgs(" hello \"good bye\""); assertEquals(2, twoQuotedArg.size()); assertEquals("hello", twoQuotedArg.get(0)); assertEquals("good bye", twoQuotedArg.get(1)); } - + @Test public void testEcho() { - System.setProperty("org.slf4j.simpleLogger.log.org.apache.nifi", "TRACE"); - - final TestRunner runner = TestRunners.newTestRunner(ExecuteProcess.class); + System. + setProperty("org.slf4j.simpleLogger.log.org.apache.nifi", "TRACE"); + + final TestRunner runner = TestRunners. + newTestRunner(ExecuteProcess.class); runner.setProperty(ExecuteProcess.COMMAND, "echo"); runner.setProperty(ExecuteProcess.COMMAND_ARGUMENTS, "test-args"); runner.setProperty(ExecuteProcess.BATCH_DURATION, "500 millis"); - + runner.run(); - final List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(ExecuteProcess.REL_SUCCESS); - for ( final MockFlowFile flowFile : flowFiles ) { + final List<MockFlowFile> flowFiles = runner. + getFlowFilesForRelationship(ExecuteProcess.REL_SUCCESS); + for (final MockFlowFile flowFile : flowFiles) { System.out.println(flowFile); System.out.println(new String(flowFile.toByteArray())); } 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/TestExecuteStreamCommand.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteStreamCommand.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteStreamCommand.java index 755637a..f95d644 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteStreamCommand.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteStreamCommand.java @@ -48,8 +48,10 @@ public class TestExecuteStreamCommand { public static void init() { System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "info"); System.setProperty("org.slf4j.simpleLogger.showDateTime", "true"); - System.setProperty("org.slf4j.simpleLogger.log.nifi.processors.standard.ExecuteStreamCommand", "debug"); - System.setProperty("org.slf4j.simpleLogger.log.nifi.processors.standard.TestExecuteStreamCommand", "debug"); + System. + setProperty("org.slf4j.simpleLogger.log.nifi.processors.standard.ExecuteStreamCommand", "debug"); + System. + setProperty("org.slf4j.simpleLogger.log.nifi.processors.standard.TestExecuteStreamCommand", "debug"); LOGGER = LoggerFactory.getLogger(TestExecuteStreamCommand.class); } @@ -59,32 +61,46 @@ public class TestExecuteStreamCommand { File dummy = new File("src/test/resources/ExecuteCommand/1000bytes.txt"); String jarPath = exJar.getAbsolutePath(); exJar.setExecutable(true); - final TestRunner controller = TestRunners.newTestRunner(ExecuteStreamCommand.class); + final TestRunner controller = TestRunners. + newTestRunner(ExecuteStreamCommand.class); controller.setValidateExpressionUsage(false); controller.enqueue(dummy.toPath()); controller.setProperty(ExecuteStreamCommand.EXECUTION_COMMAND, "java"); - controller.setProperty(ExecuteStreamCommand.EXECUTION_ARGUMENTS, "-jar;" + jarPath); + controller. + setProperty(ExecuteStreamCommand.EXECUTION_ARGUMENTS, "-jar;" + jarPath); controller.run(1); - controller.assertTransferCount(ExecuteStreamCommand.ORIGINAL_RELATIONSHIP, 1); - controller.assertTransferCount(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP, 1); + controller. + assertTransferCount(ExecuteStreamCommand.ORIGINAL_RELATIONSHIP, 1); + controller. + assertTransferCount(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP, 1); - List<MockFlowFile> flowFiles = controller.getFlowFilesForRelationship(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP); + List<MockFlowFile> flowFiles = controller. + getFlowFilesForRelationship(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP); MockFlowFile outputFlowFile = flowFiles.get(0); byte[] byteArray = outputFlowFile.toByteArray(); String result = new String(byteArray); - assertTrue("Test was a success\r\n".equals(result) || "Test was a success\n".equals(result)); + assertTrue("Test was a success\r\n".equals(result) || "Test was a success\n". + equals(result)); assertEquals("0", outputFlowFile.getAttribute("execution.status")); assertEquals("java", outputFlowFile.getAttribute("execution.command")); - assertEquals("-jar;", outputFlowFile.getAttribute("execution.command.args").substring(0, 5)); + assertEquals("-jar;", outputFlowFile. + getAttribute("execution.command.args"). + substring(0, 5)); String attribute = outputFlowFile.getAttribute("execution.command.args"); String expected = "src" + File.separator + "test" + File.separator + "resources" + File.separator + "ExecuteCommand" + File.separator + "TestSuccess.jar"; - assertEquals(expected, attribute.substring(attribute.length() - expected.length())); - - MockFlowFile originalFlowFile = controller.getFlowFilesForRelationship(ExecuteStreamCommand.ORIGINAL_RELATIONSHIP).get(0); - assertEquals(outputFlowFile.getAttribute("execution.status"), originalFlowFile.getAttribute("execution.status")); - assertEquals(outputFlowFile.getAttribute("execution.command"), originalFlowFile.getAttribute("execution.command")); - assertEquals(outputFlowFile.getAttribute("execution.command.args"), originalFlowFile.getAttribute("execution.command.args")); + assertEquals(expected, attribute. + substring(attribute.length() - expected.length())); + + MockFlowFile originalFlowFile = controller. + getFlowFilesForRelationship(ExecuteStreamCommand.ORIGINAL_RELATIONSHIP). + get(0); + assertEquals(outputFlowFile.getAttribute("execution.status"), originalFlowFile. + getAttribute("execution.status")); + assertEquals(outputFlowFile.getAttribute("execution.command"), originalFlowFile. + getAttribute("execution.command")); + assertEquals(outputFlowFile.getAttribute("execution.command.args"), originalFlowFile. + getAttribute("execution.command.args")); } @Test @@ -93,17 +109,25 @@ public class TestExecuteStreamCommand { File dummy = new File("src/test/resources/ExecuteCommand/1000bytes.txt"); String jarPath = exJar.getAbsolutePath(); exJar.setExecutable(true); - final TestRunner controller = TestRunners.newTestRunner(ExecuteStreamCommand.class); + final TestRunner controller = TestRunners. + newTestRunner(ExecuteStreamCommand.class); controller.setValidateExpressionUsage(false); controller.enqueue(dummy.toPath()); controller.setProperty(ExecuteStreamCommand.EXECUTION_COMMAND, "java"); - controller.setProperty(ExecuteStreamCommand.EXECUTION_ARGUMENTS, "-jar;" + jarPath); + controller. + setProperty(ExecuteStreamCommand.EXECUTION_ARGUMENTS, "-jar;" + jarPath); controller.run(1); - controller.assertTransferCount(ExecuteStreamCommand.ORIGINAL_RELATIONSHIP, 1); - controller.assertTransferCount(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP, 1); - List<MockFlowFile> flowFiles = controller.getFlowFilesForRelationship(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP); - assertEquals(0, flowFiles.get(0).getSize()); - assertEquals("Error: Unable to access jarfile", flowFiles.get(0).getAttribute("execution.error").substring(0, 31)); + controller. + assertTransferCount(ExecuteStreamCommand.ORIGINAL_RELATIONSHIP, 1); + controller. + assertTransferCount(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP, 1); + List<MockFlowFile> flowFiles = controller. + getFlowFilesForRelationship(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP); + assertEquals(0, flowFiles.get(0). + getSize()); + assertEquals("Error: Unable to access jarfile", flowFiles.get(0). + getAttribute("execution.error"). + substring(0, 31)); } @Test @@ -122,20 +146,28 @@ public class TestExecuteStreamCommand { fos.close(); String jarPath = exJar.getAbsolutePath(); exJar.setExecutable(true); - final TestRunner controller = TestRunners.newTestRunner(ExecuteStreamCommand.class); + final TestRunner controller = TestRunners. + newTestRunner(ExecuteStreamCommand.class); controller.setValidateExpressionUsage(false); controller.enqueue(dummy100MBytes.toPath()); controller.setProperty(ExecuteStreamCommand.EXECUTION_COMMAND, "java"); - controller.setProperty(ExecuteStreamCommand.EXECUTION_ARGUMENTS, "-jar;" + jarPath); + controller. + setProperty(ExecuteStreamCommand.EXECUTION_ARGUMENTS, "-jar;" + jarPath); controller.run(1); - controller.assertTransferCount(ExecuteStreamCommand.ORIGINAL_RELATIONSHIP, 1); - controller.assertTransferCount(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP, 1); - List<MockFlowFile> flowFiles = controller.getFlowFilesForRelationship(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP); - byte[] byteArray = flowFiles.get(0).toByteArray(); + controller. + assertTransferCount(ExecuteStreamCommand.ORIGINAL_RELATIONSHIP, 1); + controller. + assertTransferCount(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP, 1); + List<MockFlowFile> flowFiles = controller. + getFlowFilesForRelationship(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP); + byte[] byteArray = flowFiles.get(0). + toByteArray(); String result = new String(byteArray); - assertTrue(result.contains(File.separator + "nifi-standard-processors:ModifiedResult\r\n") - || result.contains(File.separator + "nifi-standard-processors:ModifiedResult\n")); + assertTrue(result. + contains(File.separator + "nifi-standard-processors:ModifiedResult\r\n") + || result. + contains(File.separator + "nifi-standard-processors:ModifiedResult\n")); } @Test @@ -144,20 +176,28 @@ public class TestExecuteStreamCommand { File dummy = new File("src/test/resources/ExecuteCommand/1000bytes.txt"); String jarPath = exJar.getAbsolutePath(); exJar.setExecutable(true); - final TestRunner controller = TestRunners.newTestRunner(ExecuteStreamCommand.class); + final TestRunner controller = TestRunners. + newTestRunner(ExecuteStreamCommand.class); controller.setValidateExpressionUsage(false); controller.enqueue(dummy.toPath()); controller.setProperty(ExecuteStreamCommand.WORKING_DIR, "target"); controller.setProperty(ExecuteStreamCommand.EXECUTION_COMMAND, "java"); - controller.setProperty(ExecuteStreamCommand.EXECUTION_ARGUMENTS, "-jar;" + jarPath); + controller. + setProperty(ExecuteStreamCommand.EXECUTION_ARGUMENTS, "-jar;" + jarPath); controller.run(1); - controller.assertTransferCount(ExecuteStreamCommand.ORIGINAL_RELATIONSHIP, 1); - controller.assertTransferCount(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP, 1); - List<MockFlowFile> flowFiles = controller.getFlowFilesForRelationship(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP); - byte[] byteArray = flowFiles.get(0).toByteArray(); + controller. + assertTransferCount(ExecuteStreamCommand.ORIGINAL_RELATIONSHIP, 1); + controller. + assertTransferCount(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP, 1); + List<MockFlowFile> flowFiles = controller. + getFlowFilesForRelationship(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP); + byte[] byteArray = flowFiles.get(0). + toByteArray(); String result = new String(byteArray); - assertTrue(result.contains(File.separator + "nifi-standard-processors" + File.separator + "target:ModifiedResult\r\n") - || result.contains(File.separator + "nifi-standard-processors" + File.separator + "target:ModifiedResult\n")); + assertTrue(result. + contains(File.separator + "nifi-standard-processors" + File.separator + "target:ModifiedResult\r\n") + || result. + contains(File.separator + "nifi-standard-processors" + File.separator + "target:ModifiedResult\n")); } // this is dependent on window with cygwin...so it's not enabled @@ -167,7 +207,8 @@ public class TestExecuteStreamCommand { File testFile = new File("target/test.txt"); testFile.delete(); File dummy = new File("src/test/resources/ExecuteCommand/1000bytes.txt"); - final TestRunner controller = TestRunners.newTestRunner(ExecuteStreamCommand.class); + final TestRunner controller = TestRunners. + newTestRunner(ExecuteStreamCommand.class); controller.setValidateExpressionUsage(false); controller.enqueue(dummy.toPath()); controller.enqueue(dummy.toPath()); @@ -176,13 +217,17 @@ public class TestExecuteStreamCommand { controller.enqueue(dummy.toPath()); controller.setProperty(ExecuteStreamCommand.WORKING_DIR, "target/xx1"); controller.setThreadCount(6); - controller.setProperty(ExecuteStreamCommand.EXECUTION_COMMAND, "c:\\cygwin\\bin\\touch"); - controller.setProperty(ExecuteStreamCommand.EXECUTION_ARGUMENTS, "test.txt"); + controller. + setProperty(ExecuteStreamCommand.EXECUTION_COMMAND, "c:\\cygwin\\bin\\touch"); + controller. + setProperty(ExecuteStreamCommand.EXECUTION_ARGUMENTS, "test.txt"); controller.assertValid(); controller.run(6); - List<MockFlowFile> flowFiles = controller.getFlowFilesForRelationship(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP); + List<MockFlowFile> flowFiles = controller. + getFlowFilesForRelationship(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP); assertEquals(5, flowFiles.size()); - assertEquals(0, flowFiles.get(0).getSize()); + assertEquals(0, flowFiles.get(0). + getSize()); } } 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/TestExtractText.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExtractText.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExtractText.java index 2025767..045a4f9 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExtractText.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExtractText.java @@ -37,13 +37,15 @@ public class TestExtractText { @Test public void testProcessor() throws Exception { - final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText()); + final TestRunner testRunner = TestRunners. + newTestRunner(new ExtractText()); testRunner.setProperty("regex.result1", "(?s)(.*)"); testRunner.setProperty("regex.result2", "(?s).*(bar1).*"); - testRunner.setProperty("regex.result3", "(?s).*?(bar\\d).*"); // reluctant gets first - testRunner.setProperty("regex.result4", "(?s).*?(?:bar\\d).*?(bar\\d).*?(bar3).*"); // reluctant w/ repeated pattern gets second - testRunner.setProperty("regex.result5", "(?s).*(bar\\d).*"); // greedy gets last + testRunner.setProperty("regex.result3", "(?s).*?(bar\\d).*"); // reluctant gets first + testRunner. + setProperty("regex.result4", "(?s).*?(?:bar\\d).*?(bar\\d).*?(bar3).*"); // reluctant w/ repeated pattern gets second + testRunner.setProperty("regex.result5", "(?s).*(bar\\d).*"); // greedy gets last testRunner.setProperty("regex.result6", "(?s)^(.*)$"); testRunner.setProperty("regex.result7", "(?s)(XXX)"); @@ -51,7 +53,9 @@ public class TestExtractText { testRunner.run(); testRunner.assertAllFlowFilesTransferred(ExtractText.REL_MATCH, 1); - final MockFlowFile out = testRunner.getFlowFilesForRelationship(ExtractText.REL_MATCH).get(0); + final MockFlowFile out = testRunner. + getFlowFilesForRelationship(ExtractText.REL_MATCH). + get(0); out.assertAttributeEquals("regex.result1", SAMPLE_STRING); out.assertAttributeEquals("regex.result2", "bar1"); out.assertAttributeEquals("regex.result3", "bar1"); @@ -68,15 +72,16 @@ public class TestExtractText { @Test public void testProcessorWithDotall() throws Exception { - final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText()); + final TestRunner testRunner = TestRunners. + newTestRunner(new ExtractText()); testRunner.setProperty(ExtractText.DOTALL, "true"); testRunner.setProperty("regex.result1", "(.*)"); testRunner.setProperty("regex.result2", ".*(bar1).*"); - testRunner.setProperty("regex.result3", ".*?(bar\\d).*"); // reluctant gets first + testRunner.setProperty("regex.result3", ".*?(bar\\d).*"); // reluctant gets first testRunner.setProperty("regex.result4", ".*?(?:bar\\d).*?(bar\\d).*"); // reluctant w/ repeated pattern gets second - testRunner.setProperty("regex.result5", ".*(bar\\d).*"); // greedy gets last + testRunner.setProperty("regex.result5", ".*(bar\\d).*"); // greedy gets last testRunner.setProperty("regex.result6", "^(.*)$"); testRunner.setProperty("regex.result7", "^(XXX)$"); @@ -84,7 +89,9 @@ public class TestExtractText { testRunner.run(); testRunner.assertAllFlowFilesTransferred(ExtractText.REL_MATCH, 1); - final MockFlowFile out = testRunner.getFlowFilesForRelationship(ExtractText.REL_MATCH).get(0); + final MockFlowFile out = testRunner. + getFlowFilesForRelationship(ExtractText.REL_MATCH). + get(0); out.assertAttributeEquals("regex.result1", SAMPLE_STRING); out.assertAttributeEquals("regex.result2", "bar1"); out.assertAttributeEquals("regex.result3", "bar1"); @@ -98,7 +105,8 @@ public class TestExtractText { @Test public void testProcessorWithMultiline() throws Exception { - final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText()); + final TestRunner testRunner = TestRunners. + newTestRunner(new ExtractText()); testRunner.setProperty(ExtractText.MULTILINE, "true"); @@ -116,22 +124,25 @@ public class TestExtractText { testRunner.run(); testRunner.assertAllFlowFilesTransferred(ExtractText.REL_MATCH, 1); - final MockFlowFile out = testRunner.getFlowFilesForRelationship(ExtractText.REL_MATCH).get(0); - out.assertAttributeEquals("regex.result1", "foo"); // matches everything on the first line + final MockFlowFile out = testRunner. + getFlowFilesForRelationship(ExtractText.REL_MATCH). + get(0); + out.assertAttributeEquals("regex.result1", "foo"); // matches everything on the first line out.assertAttributeEquals("regex.result2", "bar1"); out.assertAttributeEquals("regex.result3", "bar1"); - out.assertAttributeEquals("regex.result4", null); // null because no line has two bar's + out.assertAttributeEquals("regex.result4", null); // null because no line has two bar's out.assertAttributeEquals("regex.result4b", "bar2"); // included newlines in regex - out.assertAttributeEquals("regex.result5", "bar1"); //still gets first because no lines with multiple bar's - out.assertAttributeEquals("regex.result5b", "bar3");// included newlines in regex - out.assertAttributeEquals("regex.result6", "foo"); // matches all of first line - out.assertAttributeEquals("regex.result7", null); // no match + out.assertAttributeEquals("regex.result5", "bar1"); //still gets first because no lines with multiple bar's + out.assertAttributeEquals("regex.result5b", "bar3"); // included newlines in regex + out.assertAttributeEquals("regex.result6", "foo"); // matches all of first line + out.assertAttributeEquals("regex.result7", null); // no match } @Test public void testProcessorWithMultilineAndDotall() throws Exception { - final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText()); + final TestRunner testRunner = TestRunners. + newTestRunner(new ExtractText()); testRunner.setProperty(ExtractText.MULTILINE, "true"); testRunner.setProperty(ExtractText.DOTALL, "true"); @@ -150,7 +161,9 @@ public class TestExtractText { testRunner.run(); testRunner.assertAllFlowFilesTransferred(ExtractText.REL_MATCH, 1); - final MockFlowFile out = testRunner.getFlowFilesForRelationship(ExtractText.REL_MATCH).get(0); + final MockFlowFile out = testRunner. + getFlowFilesForRelationship(ExtractText.REL_MATCH). + get(0); out.assertAttributeEquals("regex.result1", SAMPLE_STRING); out.assertAttributeEquals("regex.result2", "bar1"); @@ -166,7 +179,8 @@ public class TestExtractText { @Test public void testProcessorWithNoMatches() throws Exception { - final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText()); + final TestRunner testRunner = TestRunners. + newTestRunner(new ExtractText()); testRunner.setProperty(ExtractText.MULTILINE, "true"); testRunner.setProperty(ExtractText.DOTALL, "true"); @@ -183,7 +197,9 @@ public class TestExtractText { testRunner.run(); testRunner.assertAllFlowFilesTransferred(ExtractText.REL_NO_MATCH, 1); - final MockFlowFile out = testRunner.getFlowFilesForRelationship(ExtractText.REL_NO_MATCH).get(0); + final MockFlowFile out = testRunner. + getFlowFilesForRelationship(ExtractText.REL_NO_MATCH). + get(0); out.assertAttributeEquals("regex.result1", null); out.assertAttributeEquals("regex.result2", null); @@ -198,7 +214,8 @@ public class TestExtractText { @Test(expected = java.lang.AssertionError.class) public void testNoCaptureGroups() throws UnsupportedEncodingException { - final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText()); + final TestRunner testRunner = TestRunners. + newTestRunner(new ExtractText()); testRunner.setProperty("regex.result1", ".*"); testRunner.enqueue(SAMPLE_STRING.getBytes("UTF-8")); testRunner.run(); @@ -206,7 +223,8 @@ public class TestExtractText { @Test public void testNoFlowFile() throws UnsupportedEncodingException { - final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText()); + final TestRunner testRunner = TestRunners. + newTestRunner(new ExtractText()); testRunner.run(); testRunner.assertAllFlowFilesTransferred(ExtractText.REL_MATCH, 0); @@ -214,7 +232,8 @@ public class TestExtractText { @Test public void testMatchOutsideBuffer() throws Exception { - final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText()); + final TestRunner testRunner = TestRunners. + newTestRunner(new ExtractText()); testRunner.setProperty(ExtractText.MAX_BUFFER_SIZE, "3 B");//only read the first 3 chars ("foo") @@ -225,10 +244,12 @@ public class TestExtractText { testRunner.run(); testRunner.assertAllFlowFilesTransferred(ExtractText.REL_MATCH, 1); - final MockFlowFile out = testRunner.getFlowFilesForRelationship(ExtractText.REL_MATCH).get(0); + final MockFlowFile out = testRunner. + getFlowFilesForRelationship(ExtractText.REL_MATCH). + get(0); out.assertAttributeEquals("regex.result1", "foo"); - out.assertAttributeEquals("regex.result2", null); // null because outsk + out.assertAttributeEquals("regex.result2", null); // null because outsk } @Test @@ -246,53 +267,63 @@ public class TestExtractText { // UNIX_LINES testRunner = TestRunners.newTestRunner(processor); testRunner.setProperty(ExtractText.UNIX_LINES, "true"); - assertEquals(Pattern.UNIX_LINES, processor.getCompileFlags(testRunner.getProcessContext())); + assertEquals(Pattern.UNIX_LINES, processor.getCompileFlags(testRunner. + getProcessContext())); // CASE_INSENSITIVE testRunner = TestRunners.newTestRunner(processor); testRunner.setProperty(ExtractText.CASE_INSENSITIVE, "true"); - assertEquals(Pattern.CASE_INSENSITIVE, processor.getCompileFlags(testRunner.getProcessContext())); + assertEquals(Pattern.CASE_INSENSITIVE, processor. + getCompileFlags(testRunner.getProcessContext())); // COMMENTS testRunner = TestRunners.newTestRunner(processor); testRunner.setProperty(ExtractText.COMMENTS, "true"); - assertEquals(Pattern.COMMENTS, processor.getCompileFlags(testRunner.getProcessContext())); + assertEquals(Pattern.COMMENTS, processor.getCompileFlags(testRunner. + getProcessContext())); // MULTILINE testRunner = TestRunners.newTestRunner(processor); testRunner.setProperty(ExtractText.MULTILINE, "true"); - assertEquals(Pattern.MULTILINE, processor.getCompileFlags(testRunner.getProcessContext())); + assertEquals(Pattern.MULTILINE, processor.getCompileFlags(testRunner. + getProcessContext())); // LITERAL testRunner = TestRunners.newTestRunner(processor); testRunner.setProperty(ExtractText.LITERAL, "true"); - assertEquals(Pattern.LITERAL, processor.getCompileFlags(testRunner.getProcessContext())); + assertEquals(Pattern.LITERAL, processor.getCompileFlags(testRunner. + getProcessContext())); // DOTALL testRunner = TestRunners.newTestRunner(processor); testRunner.setProperty(ExtractText.DOTALL, "true"); - assertEquals(Pattern.DOTALL, processor.getCompileFlags(testRunner.getProcessContext())); + assertEquals(Pattern.DOTALL, processor.getCompileFlags(testRunner. + getProcessContext())); // UNICODE_CASE testRunner = TestRunners.newTestRunner(processor); testRunner.setProperty(ExtractText.UNICODE_CASE, "true"); - assertEquals(Pattern.UNICODE_CASE, processor.getCompileFlags(testRunner.getProcessContext())); + assertEquals(Pattern.UNICODE_CASE, processor.getCompileFlags(testRunner. + getProcessContext())); // CANON_EQ testRunner = TestRunners.newTestRunner(processor); testRunner.setProperty(ExtractText.CANON_EQ, "true"); - assertEquals(Pattern.CANON_EQ, processor.getCompileFlags(testRunner.getProcessContext())); + assertEquals(Pattern.CANON_EQ, processor.getCompileFlags(testRunner. + getProcessContext())); // UNICODE_CHARACTER_CLASS testRunner = TestRunners.newTestRunner(processor); testRunner.setProperty(ExtractText.UNICODE_CHARACTER_CLASS, "true"); - assertEquals(Pattern.UNICODE_CHARACTER_CLASS, processor.getCompileFlags(testRunner.getProcessContext())); + assertEquals(Pattern.UNICODE_CHARACTER_CLASS, processor. + getCompileFlags(testRunner.getProcessContext())); // DOTALL and MULTILINE testRunner = TestRunners.newTestRunner(processor); testRunner.setProperty(ExtractText.DOTALL, "true"); testRunner.setProperty(ExtractText.MULTILINE, "true"); - assertEquals(Pattern.DOTALL | Pattern.MULTILINE, processor.getCompileFlags(testRunner.getProcessContext())); + assertEquals(Pattern.DOTALL | Pattern.MULTILINE, processor. + getCompileFlags(testRunner.getProcessContext())); } @Test @@ -301,7 +332,6 @@ public class TestExtractText { final ExtractText processor = new ExtractText(); final TestRunner testRunner = TestRunners.newTestRunner(processor); -// testRunner.setProperty("regex.result1", "(.*)"); testRunner.enqueue("foo".getBytes("UTF-8")); testRunner.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/TestGetFile.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetFile.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetFile.java index 018cbdc..f0526d9 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetFile.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetFile.java @@ -46,7 +46,8 @@ public class TestGetFile { public void testFilePickedUp() throws IOException { final File directory = new File("target/test/data/in"); deleteDirectory(directory); - assertTrue("Unable to create test data directory " + directory.getAbsolutePath(), directory.exists() || directory.mkdirs()); + assertTrue("Unable to create test data directory " + directory. + getAbsolutePath(), directory.exists() || directory.mkdirs()); final File inFile = new File("src/test/resources/hello.txt"); final Path inPath = inFile.toPath(); @@ -61,12 +62,16 @@ public class TestGetFile { runner.run(); runner.assertAllFlowFilesTransferred(GetFile.REL_SUCCESS, 1); - final List<MockFlowFile> successFiles = runner.getFlowFilesForRelationship(GetFile.REL_SUCCESS); - successFiles.get(0).assertContentEquals("Hello, World!".getBytes("UTF-8")); + final List<MockFlowFile> successFiles = runner. + getFlowFilesForRelationship(GetFile.REL_SUCCESS); + successFiles.get(0). + assertContentEquals("Hello, World!".getBytes("UTF-8")); - final String path = successFiles.get(0).getAttribute("path"); + final String path = successFiles.get(0). + getAttribute("path"); assertEquals("/", path); - final String absolutePath = successFiles.get(0).getAttribute(CoreAttributes.ABSOLUTE_PATH.key()); + final String absolutePath = successFiles.get(0). + getAttribute(CoreAttributes.ABSOLUTE_PATH.key()); assertEquals(absTargetPathStr, absolutePath); } @@ -77,7 +82,8 @@ public class TestGetFile { deleteDirectory(file); } - assertTrue("Could not delete " + file.getAbsolutePath(), file.delete()); + assertTrue("Could not delete " + file.getAbsolutePath(), file. + delete()); } } } @@ -89,7 +95,8 @@ public class TestGetFile { final File directory = new File("target/test/data/in/" + dirStruc); deleteDirectory(directory); - assertTrue("Unable to create test data directory " + directory.getAbsolutePath(), directory.exists() || directory.mkdirs()); + assertTrue("Unable to create test data directory " + directory. + getAbsolutePath(), directory.exists() || directory.mkdirs()); final File inFile = new File("src/test/resources/hello.txt"); final Path inPath = inFile.toPath(); @@ -98,12 +105,15 @@ public class TestGetFile { Files.copy(inPath, targetPath); final TestRunner runner = TestRunners.newTestRunner(new GetFile()); - runner.setProperty(GetFile.DIRECTORY, "target/test/data/in/${now():format('yyyy/MM/dd')}"); + runner. + setProperty(GetFile.DIRECTORY, "target/test/data/in/${now():format('yyyy/MM/dd')}"); runner.run(); runner.assertAllFlowFilesTransferred(GetFile.REL_SUCCESS, 1); - final List<MockFlowFile> successFiles = runner.getFlowFilesForRelationship(GetFile.REL_SUCCESS); - successFiles.get(0).assertContentEquals("Hello, World!".getBytes("UTF-8")); + final List<MockFlowFile> successFiles = runner. + getFlowFilesForRelationship(GetFile.REL_SUCCESS); + successFiles.get(0). + assertContentEquals("Hello, World!".getBytes("UTF-8")); } @Test @@ -113,14 +123,16 @@ public class TestGetFile { final File directory = new File("target/test/data/in/" + dirStruc); deleteDirectory(new File("target/test/data/in")); - assertTrue("Unable to create test data directory " + directory.getAbsolutePath(), directory.exists() || directory.mkdirs()); + assertTrue("Unable to create test data directory " + directory. + getAbsolutePath(), directory.exists() || directory.mkdirs()); final File inFile = new File("src/test/resources/hello.txt"); final Path inPath = inFile.toPath(); final File destFile = new File(directory, inFile.getName()); final Path targetPath = destFile.toPath(); final Path absTargetPath = targetPath.toAbsolutePath(); - final String absTargetPathStr = absTargetPath.getParent().toString() + "/"; + final String absTargetPathStr = absTargetPath.getParent(). + toString() + "/"; Files.copy(inPath, targetPath); final TestRunner runner = TestRunners.newTestRunner(new GetFile()); @@ -128,12 +140,16 @@ public class TestGetFile { runner.run(); runner.assertAllFlowFilesTransferred(GetFile.REL_SUCCESS, 1); - final List<MockFlowFile> successFiles = runner.getFlowFilesForRelationship(GetFile.REL_SUCCESS); - successFiles.get(0).assertContentEquals("Hello, World!".getBytes("UTF-8")); + final List<MockFlowFile> successFiles = runner. + getFlowFilesForRelationship(GetFile.REL_SUCCESS); + successFiles.get(0). + assertContentEquals("Hello, World!".getBytes("UTF-8")); - final String path = successFiles.get(0).getAttribute("path"); + final String path = successFiles.get(0). + getAttribute("path"); assertEquals(dirStruc, path.replace('\\', '/')); - final String absolutePath = successFiles.get(0).getAttribute(CoreAttributes.ABSOLUTE_PATH.key()); + final String absolutePath = successFiles.get(0). + getAttribute(CoreAttributes.ABSOLUTE_PATH.key()); assertEquals(absTargetPathStr, absolutePath); } @@ -141,7 +157,8 @@ public class TestGetFile { public void testAttributes() throws IOException { final File directory = new File("target/test/data/in/"); deleteDirectory(directory); - assertTrue("Unable to create test data directory " + directory.getAbsolutePath(), directory.exists() || directory.mkdirs()); + assertTrue("Unable to create test data directory " + directory. + getAbsolutePath(), directory.exists() || directory.mkdirs()); final File inFile = new File("src/test/resources/hello.txt"); final Path inPath = inFile.toPath(); @@ -158,7 +175,8 @@ public class TestGetFile { boolean verifyPermissions = false; try { - Files.setPosixFilePermissions(targetPath, PosixFilePermissions.fromString("r--r-----")); + Files.setPosixFilePermissions(targetPath, PosixFilePermissions. + fromString("r--r-----")); verifyPermissions = true; } catch (Exception donothing) { } @@ -168,19 +186,22 @@ public class TestGetFile { runner.run(); runner.assertAllFlowFilesTransferred(GetFile.REL_SUCCESS, 1); - final List<MockFlowFile> successFiles = runner.getFlowFilesForRelationship(GetFile.REL_SUCCESS); + final List<MockFlowFile> successFiles = runner. + getFlowFilesForRelationship(GetFile.REL_SUCCESS); if (verifyLastModified) { try { final DateFormat formatter = new SimpleDateFormat(GetFile.FILE_MODIFY_DATE_ATTR_FORMAT, Locale.US); - final Date fileModifyTime = formatter.parse(successFiles.get(0).getAttribute("file.lastModifiedTime")); + final Date fileModifyTime = formatter.parse(successFiles.get(0). + getAttribute("file.lastModifiedTime")); assertEquals(new Date(1000000000), fileModifyTime); } catch (ParseException e) { fail(); } } if (verifyPermissions) { - successFiles.get(0).assertAttributeEquals("file.permissions", "r--r-----"); + successFiles.get(0). + assertAttributeEquals("file.permissions", "r--r-----"); } } } 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/TestGetHTTP.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetHTTP.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetHTTP.java index f52b212..7a76ffd 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetHTTP.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetHTTP.java @@ -48,13 +48,15 @@ import org.junit.Test; public class TestGetHTTP { private TestRunner controller; - + @BeforeClass public static void before() { System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "info"); System.setProperty("org.slf4j.simpleLogger.showDateTime", "true"); - System.setProperty("org.slf4j.simpleLogger.log.nifi.processors.standard.GetHTTP", "debug"); - System.setProperty("org.slf4j.simpleLogger.log.nifi.processors.standard.TestGetHTTP", "debug"); + System. + setProperty("org.slf4j.simpleLogger.log.nifi.processors.standard.GetHTTP", "debug"); + System. + setProperty("org.slf4j.simpleLogger.log.nifi.processors.standard.TestGetHTTP", "debug"); File confDir = new File("conf"); if (!confDir.exists()) { confDir.mkdir(); @@ -73,43 +75,47 @@ public class TestGetHTTP { assertTrue(confDir.delete()); } - @Test public final void testContentModified() throws Exception { // set up web service ServletHandler handler = new ServletHandler(); handler.addServletWithMapping(RESTServiceContentModified.class, "/*"); - + // create the service TestServer server = new TestServer(); server.addHandler(handler); - + try { server.startServer(); - + // this is the base url with the random port String destination = server.getUrl(); - + // set up NiFi mock controller controller = TestRunners.newTestRunner(GetHTTP.class); controller.setProperty(GetHTTP.CONNECTION_TIMEOUT, "5 secs"); controller.setProperty(GetHTTP.URL, destination); controller.setProperty(GetHTTP.FILENAME, "testFile"); - controller.setProperty(GetHTTP.ACCEPT_CONTENT_TYPE, "application/json"); - + controller. + setProperty(GetHTTP.ACCEPT_CONTENT_TYPE, "application/json"); + GetHTTP getHTTPProcessor = (GetHTTP) controller.getProcessor(); assertEquals("", getHTTPProcessor.entityTagRef.get()); - assertEquals("Thu, 01 Jan 1970 00:00:00 GMT", getHTTPProcessor.lastModifiedRef.get()); + assertEquals("Thu, 01 Jan 1970 00:00:00 GMT", getHTTPProcessor.lastModifiedRef. + get()); controller.run(2); // verify the lastModified and entityTag are updated assertFalse("".equals(getHTTPProcessor.entityTagRef.get())); - assertFalse("Thu, 01 Jan 1970 00:00:00 GMT".equals(getHTTPProcessor.lastModifiedRef.get())); + assertFalse("Thu, 01 Jan 1970 00:00:00 GMT". + equals(getHTTPProcessor.lastModifiedRef.get())); // ran twice, but got one...which is good controller.assertTransferCount(GetHTTP.REL_SUCCESS, 1); // verify remote.source flowfile attribute - controller.getFlowFilesForRelationship(GetHTTP.REL_SUCCESS).get(0).assertAttributeEquals("gethttp.remote.source", "localhost"); + controller.getFlowFilesForRelationship(GetHTTP.REL_SUCCESS). + get(0). + assertAttributeEquals("gethttp.remote.source", "localhost"); controller.clearTransferState(); @@ -147,7 +153,8 @@ public class TestGetHTTP { // turn off checking for Etag, turn on checking for lastModified, but change value RESTServiceContentModified.IGNORE_LAST_MODIFIED = false; RESTServiceContentModified.IGNORE_ETAG = true; - RESTServiceContentModified.modificationDate = System.currentTimeMillis() / 1000 * 1000 + 5000; + RESTServiceContentModified.modificationDate = System. + currentTimeMillis() / 1000 * 1000 + 5000; String lastMod = getHTTPProcessor.lastModifiedRef.get(); controller.run(2); // ran twice, got 1...but should have new cached etag @@ -169,32 +176,34 @@ public class TestGetHTTP { for (File file : files) { assertTrue("Failed to delete " + file.getName(), file.delete()); } - + // set up web service ServletHandler handler = new ServletHandler(); handler.addServletWithMapping(RESTServiceContentModified.class, "/*"); - + // create the service TestServer server = new TestServer(); server.addHandler(handler); - + try { server.startServer(); - + // get the server url String destination = server.getUrl(); - + // set up NiFi mock controller controller = TestRunners.newTestRunner(GetHTTP.class); controller.setProperty(GetHTTP.CONNECTION_TIMEOUT, "5 secs"); controller.setProperty(GetHTTP.FILENAME, "testFile"); controller.setProperty(GetHTTP.URL, destination); - controller.setProperty(GetHTTP.ACCEPT_CONTENT_TYPE, "application/json"); - + controller. + setProperty(GetHTTP.ACCEPT_CONTENT_TYPE, "application/json"); + GetHTTP getHTTPProcessor = (GetHTTP) controller.getProcessor(); - + assertEquals("", getHTTPProcessor.entityTagRef.get()); - assertEquals("Thu, 01 Jan 1970 00:00:00 GMT", getHTTPProcessor.lastModifiedRef.get()); + assertEquals("Thu, 01 Jan 1970 00:00:00 GMT", getHTTPProcessor.lastModifiedRef. + get()); controller.run(2); // verify the lastModified and entityTag are updated @@ -217,7 +226,8 @@ public class TestGetHTTP { assertEquals(etag, props.getProperty(GetHTTP.ETAG)); assertEquals(lastMod, props.getProperty(GetHTTP.LAST_MODIFIED)); - ProcessorInitializationContext pic = new MockProcessorInitializationContext(controller.getProcessor(), + ProcessorInitializationContext pic = new MockProcessorInitializationContext(controller. + getProcessor(), (MockProcessContext) controller.getProcessContext()); // init causes read from file getHTTPProcessor.init(pic); @@ -249,14 +259,14 @@ public class TestGetHTTP { // set up web service ServletHandler handler = new ServletHandler(); handler.addServletWithMapping(UserAgentTestingServlet.class, "/*"); - + // create the service TestServer server = new TestServer(); server.addHandler(handler); - + try { server.startServer(); - + String destination = server.getUrl(); // set up NiFi mock controller @@ -264,8 +274,9 @@ public class TestGetHTTP { controller.setProperty(GetHTTP.CONNECTION_TIMEOUT, "5 secs"); controller.setProperty(GetHTTP.URL, destination); controller.setProperty(GetHTTP.FILENAME, "testFile"); - controller.setProperty(GetHTTP.ACCEPT_CONTENT_TYPE, "application/json"); - + controller. + setProperty(GetHTTP.ACCEPT_CONTENT_TYPE, "application/json"); + controller.run(); controller.assertTransferCount(GetHTTP.REL_SUCCESS, 0); @@ -278,63 +289,70 @@ public class TestGetHTTP { server.shutdownServer(); } } - + private Map<String, String> getSslProperties() { Map<String, String> props = new HashMap<String, String>(); - props.put(StandardSSLContextService.KEYSTORE.getName(), "src/test/resources/localhost-ks.jks"); - props.put(StandardSSLContextService.KEYSTORE_PASSWORD.getName(), "localtest"); + props. + put(StandardSSLContextService.KEYSTORE.getName(), "src/test/resources/localhost-ks.jks"); + props. + put(StandardSSLContextService.KEYSTORE_PASSWORD.getName(), "localtest"); props.put(StandardSSLContextService.KEYSTORE_TYPE.getName(), "JKS"); - props.put(StandardSSLContextService.TRUSTSTORE.getName(), "src/test/resources/localhost-ts.jks"); - props.put(StandardSSLContextService.TRUSTSTORE_PASSWORD.getName(), "localtest"); + props. + put(StandardSSLContextService.TRUSTSTORE.getName(), "src/test/resources/localhost-ts.jks"); + props. + put(StandardSSLContextService.TRUSTSTORE_PASSWORD.getName(), "localtest"); props.put(StandardSSLContextService.TRUSTSTORE_TYPE.getName(), "JKS"); return props; } - + private void useSSLContextService() { final SSLContextService service = new StandardSSLContextService(); try { - controller.addControllerService("ssl-service", service, getSslProperties()); + controller. + addControllerService("ssl-service", service, getSslProperties()); controller.enableControllerService(service); } catch (InitializationException ex) { ex.printStackTrace(); Assert.fail("Could not create SSL Context Service"); } - + controller.setProperty(GetHTTP.SSL_CONTEXT_SERVICE, "ssl-service"); } - + @Test public final void testSecure() throws Exception { // set up web service ServletHandler handler = new ServletHandler(); handler.addServletWithMapping(HelloWorldServlet.class, "/*"); - + // create the service TestServer server = new TestServer(getSslProperties()); server.addHandler(handler); - + try { server.startServer(); - + String destination = server.getSecureUrl(); // set up NiFi mock controller controller = TestRunners.newTestRunner(GetHTTP.class); useSSLContextService(); - + controller.setProperty(GetHTTP.CONNECTION_TIMEOUT, "5 secs"); controller.setProperty(GetHTTP.URL, destination); controller.setProperty(GetHTTP.FILENAME, "testFile"); - controller.setProperty(GetHTTP.ACCEPT_CONTENT_TYPE, "application/json"); - + controller. + setProperty(GetHTTP.ACCEPT_CONTENT_TYPE, "application/json"); + controller.run(); controller.assertAllFlowFilesTransferred(GetHTTP.REL_SUCCESS, 1); - final MockFlowFile mff = controller.getFlowFilesForRelationship(GetHTTP.REL_SUCCESS).get(0); + final MockFlowFile mff = controller. + getFlowFilesForRelationship(GetHTTP.REL_SUCCESS). + get(0); mff.assertContentEquals("Hello, World!"); } finally { server.shutdownServer(); } } - - + }
