timeabarna commented on a change in pull request #4948:
URL: https://github.com/apache/nifi/pull/4948#discussion_r639552943



##########
File path: 
nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestScriptedFilterRecord.java
##########
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.script;
+
+import org.apache.nifi.processor.Processor;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.util.MockFlowFile;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestScriptedFilterRecord extends TestScriptedRouterProcessor {
+    private static final String SCRIPT = "return record.getValue(\"first\") == 
1";
+
+    private static final Object[] MATCHING_RECORD_1 = new Object[] {1, 
"lorem"};
+    private static final Object[] MATCHING_RECORD_2 = new Object[] {1, 
"ipsum"};
+    private static final Object[] NON_MATCHING_RECORD_1 = new Object[] {2, 
"lorem"};
+    private static final Object[] NON_MATCHING_RECORD_2 = new Object[] {2, 
"ipsum"};
+
+    @Test
+    public void testIncomingFlowFileContainsMatchingRecordsOnly() throws 
Exception {
+        // given
+        recordReader.addRecord(MATCHING_RECORD_1);
+        recordReader.addRecord(MATCHING_RECORD_2);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenMatchingFlowFileContains(new Object[][]{MATCHING_RECORD_1, 
MATCHING_RECORD_2});
+    }
+
+    @Test
+    public void testIncomingFlowFileContainsNonMatchingRecordsOnly() throws 
Exception {
+        // given
+        recordReader.addRecord(NON_MATCHING_RECORD_1);
+        recordReader.addRecord(NON_MATCHING_RECORD_2);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenMatchingFlowFileIsEmpty();
+    }
+
+    @Test
+    public void testIncomingFlowFileContainsMatchingAndNonMatchingRecords() 
throws Exception {
+        // given
+        recordReader.addRecord(MATCHING_RECORD_1);
+        recordReader.addRecord(NON_MATCHING_RECORD_1);
+        recordReader.addRecord(MATCHING_RECORD_2);
+        recordReader.addRecord(NON_MATCHING_RECORD_2);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenMatchingFlowFileContains(new Object[][]{MATCHING_RECORD_1, 
MATCHING_RECORD_2});
+    }
+
+    @Test
+    public void testIncomingFlowFileContainsNoRecords() throws Exception {

Review comment:
       Exception is never thrown, it can be removed.

##########
File path: 
nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestScriptedValidateRecord.java
##########
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.script;
+
+import org.apache.nifi.processor.Processor;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.util.MockFlowFile;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestScriptedValidateRecord extends TestScriptedRouterProcessor {
+    private static final String SCRIPT = "return record.getValue(\"first\") == 
1";
+
+    private static final Object[] VALID_RECORD_1 = new Object[] {1, "lorem"};
+    private static final Object[] VALID_RECORD_2 = new Object[] {1, "ipsum"};
+    private static final Object[] INVALID_RECORD_1 = new Object[] {2, "lorem"};
+    private static final Object[] INVALID_RECORD_2 = new Object[] {2, "ipsum"};
+
+    @Test
+    public void testIncomingFlowFileContainsValidRecordsOnly() throws 
Exception {

Review comment:
       Exception is never thrown, it can be removed.

##########
File path: 
nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestScriptedValidateRecord.java
##########
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.script;
+
+import org.apache.nifi.processor.Processor;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.util.MockFlowFile;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestScriptedValidateRecord extends TestScriptedRouterProcessor {
+    private static final String SCRIPT = "return record.getValue(\"first\") == 
1";
+
+    private static final Object[] VALID_RECORD_1 = new Object[] {1, "lorem"};
+    private static final Object[] VALID_RECORD_2 = new Object[] {1, "ipsum"};
+    private static final Object[] INVALID_RECORD_1 = new Object[] {2, "lorem"};
+    private static final Object[] INVALID_RECORD_2 = new Object[] {2, "ipsum"};
+
+    @Test
+    public void testIncomingFlowFileContainsValidRecordsOnly() throws 
Exception {
+        // given
+        recordReader.addRecord(VALID_RECORD_1);
+        recordReader.addRecord(VALID_RECORD_2);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenValidFlowFileContains(new Object[][]{VALID_RECORD_1, 
VALID_RECORD_2});
+        thenNoInvalidFlowFile();
+    }
+
+    @Test
+    public void testIncomingFlowFileContainsInvalidRecordsOnly() throws 
Exception {
+        // given
+        recordReader.addRecord(INVALID_RECORD_1);
+        recordReader.addRecord(INVALID_RECORD_2);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenInvalidFlowFileContains(new Object[][]{INVALID_RECORD_1, 
INVALID_RECORD_2});
+        thenNoValidFlowFile();
+    }
+
+    @Test
+    public void testIncomingFlowFileContainsBothValidAndInvalidRecords() 
throws Exception {
+        // given
+        recordReader.addRecord(VALID_RECORD_1);
+        recordReader.addRecord(INVALID_RECORD_1);
+        recordReader.addRecord(VALID_RECORD_2);
+        recordReader.addRecord(INVALID_RECORD_2);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenValidFlowFileContains(new Object[][]{VALID_RECORD_1, 
VALID_RECORD_2});
+        thenInvalidFlowFileContains(new Object[][]{INVALID_RECORD_1, 
INVALID_RECORD_2});
+    }
+
+    @Test
+    public void testIncomingFlowFileContainsNoRecords() throws Exception {

Review comment:
       Exception is never thrown, it can be removed.

##########
File path: 
nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestScriptedPartitionRecord.java
##########
@@ -0,0 +1,249 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.script;
+
+import org.apache.nifi.processor.Processor;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.util.MockFlowFile;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Set;
+import java.util.stream.Collectors;
+
+public class TestScriptedPartitionRecord extends TestScriptedRouterProcessor {
+    private static final String SCRIPT =
+        "if (record.getValue(\"first\") == 1) {\n" +
+        "   return \"partition1\";\n" +
+        "} else if (record.getValue(\"first\") == 2) {\n" +
+        "   return \"partition2\";\n" +
+        "} else {\n" +
+        "   return \"partition3\";\n" +
+        "}\n";
+
+    private static final Object[] PARTITION_1_RECORD_1 = new Object[] {1, 
"lorem"};
+    private static final Object[] PARTITION_1_RECORD_2 = new Object[] {1, 
"ipsum"};
+    private static final Object[] PARTITION_2_RECORD_1 = new Object[] {2, 
"lorem"};
+    private static final Object[] PARTITION_3_RECORD_1 = new Object[] {3, 
"lorem"};
+    private static final String PARTITION_1 = "partition1";
+    private static final String PARTITION_2 = "partition2";
+    private static final String PARTITION_3 = "partition3";
+    private static final String RELATIONSHIP_1 = "relationship1";
+    private static final String RELATIONSHIP_2 = "relationship2";
+
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        testRunner.setProperty(PARTITION_1, RELATIONSHIP_1);
+        testRunner.setProperty(PARTITION_2, RELATIONSHIP_2);
+    }
+
+    @Test
+    public void testIncomingFlowFilesContainsRecordForOneRoute() throws 
Exception {
+        // given
+        recordReader.addRecord(PARTITION_1_RECORD_1);
+        recordReader.addRecord(PARTITION_1_RECORD_2);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenGivenRouteContains(RELATIONSHIP_1, new 
Object[][]{PARTITION_1_RECORD_1, PARTITION_1_RECORD_2});
+        thenGivenRouteIsEmpty(RELATIONSHIP_2);
+        thenNonMatchingIsEmpty();
+    }
+
+    @Test
+    public void testIncomingFlowFilesContainsRecordForMultipleRoutes() throws 
Exception {
+        // given
+        recordReader.addRecord(PARTITION_1_RECORD_1);
+        recordReader.addRecord(PARTITION_2_RECORD_1);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenGivenRouteContains(RELATIONSHIP_1, new 
Object[][]{PARTITION_1_RECORD_1});
+        thenGivenRouteContains(RELATIONSHIP_2, new 
Object[][]{PARTITION_2_RECORD_1});
+        thenNonMatchingIsEmpty();
+    }
+
+    @Test
+    public void testIncomingFlowFilesContainsNonMatchingRecord() throws 
Exception {

Review comment:
       Exception is never thrown, it can be removed.

##########
File path: 
nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestScriptedValidateRecord.java
##########
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.script;
+
+import org.apache.nifi.processor.Processor;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.util.MockFlowFile;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestScriptedValidateRecord extends TestScriptedRouterProcessor {
+    private static final String SCRIPT = "return record.getValue(\"first\") == 
1";
+
+    private static final Object[] VALID_RECORD_1 = new Object[] {1, "lorem"};
+    private static final Object[] VALID_RECORD_2 = new Object[] {1, "ipsum"};
+    private static final Object[] INVALID_RECORD_1 = new Object[] {2, "lorem"};
+    private static final Object[] INVALID_RECORD_2 = new Object[] {2, "ipsum"};
+
+    @Test
+    public void testIncomingFlowFileContainsValidRecordsOnly() throws 
Exception {
+        // given
+        recordReader.addRecord(VALID_RECORD_1);
+        recordReader.addRecord(VALID_RECORD_2);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenValidFlowFileContains(new Object[][]{VALID_RECORD_1, 
VALID_RECORD_2});
+        thenNoInvalidFlowFile();
+    }
+
+    @Test
+    public void testIncomingFlowFileContainsInvalidRecordsOnly() throws 
Exception {

Review comment:
       Exception is never thrown, it can be removed.

##########
File path: 
nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestScriptedFilterRecord.java
##########
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.script;
+
+import org.apache.nifi.processor.Processor;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.util.MockFlowFile;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestScriptedFilterRecord extends TestScriptedRouterProcessor {
+    private static final String SCRIPT = "return record.getValue(\"first\") == 
1";
+
+    private static final Object[] MATCHING_RECORD_1 = new Object[] {1, 
"lorem"};
+    private static final Object[] MATCHING_RECORD_2 = new Object[] {1, 
"ipsum"};
+    private static final Object[] NON_MATCHING_RECORD_1 = new Object[] {2, 
"lorem"};
+    private static final Object[] NON_MATCHING_RECORD_2 = new Object[] {2, 
"ipsum"};
+
+    @Test
+    public void testIncomingFlowFileContainsMatchingRecordsOnly() throws 
Exception {
+        // given
+        recordReader.addRecord(MATCHING_RECORD_1);
+        recordReader.addRecord(MATCHING_RECORD_2);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenMatchingFlowFileContains(new Object[][]{MATCHING_RECORD_1, 
MATCHING_RECORD_2});
+    }
+
+    @Test
+    public void testIncomingFlowFileContainsNonMatchingRecordsOnly() throws 
Exception {
+        // given
+        recordReader.addRecord(NON_MATCHING_RECORD_1);
+        recordReader.addRecord(NON_MATCHING_RECORD_2);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenMatchingFlowFileIsEmpty();
+    }
+
+    @Test
+    public void testIncomingFlowFileContainsMatchingAndNonMatchingRecords() 
throws Exception {

Review comment:
       Exception is never thrown, it can be removed.

##########
File path: 
nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestScriptedPartitionRecord.java
##########
@@ -0,0 +1,249 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.script;
+
+import org.apache.nifi.processor.Processor;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.util.MockFlowFile;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Set;
+import java.util.stream.Collectors;
+
+public class TestScriptedPartitionRecord extends TestScriptedRouterProcessor {
+    private static final String SCRIPT =
+        "if (record.getValue(\"first\") == 1) {\n" +
+        "   return \"partition1\";\n" +
+        "} else if (record.getValue(\"first\") == 2) {\n" +
+        "   return \"partition2\";\n" +
+        "} else {\n" +
+        "   return \"partition3\";\n" +
+        "}\n";
+
+    private static final Object[] PARTITION_1_RECORD_1 = new Object[] {1, 
"lorem"};
+    private static final Object[] PARTITION_1_RECORD_2 = new Object[] {1, 
"ipsum"};
+    private static final Object[] PARTITION_2_RECORD_1 = new Object[] {2, 
"lorem"};
+    private static final Object[] PARTITION_3_RECORD_1 = new Object[] {3, 
"lorem"};
+    private static final String PARTITION_1 = "partition1";
+    private static final String PARTITION_2 = "partition2";
+    private static final String PARTITION_3 = "partition3";
+    private static final String RELATIONSHIP_1 = "relationship1";
+    private static final String RELATIONSHIP_2 = "relationship2";
+
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        testRunner.setProperty(PARTITION_1, RELATIONSHIP_1);
+        testRunner.setProperty(PARTITION_2, RELATIONSHIP_2);
+    }
+
+    @Test
+    public void testIncomingFlowFilesContainsRecordForOneRoute() throws 
Exception {
+        // given
+        recordReader.addRecord(PARTITION_1_RECORD_1);
+        recordReader.addRecord(PARTITION_1_RECORD_2);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenGivenRouteContains(RELATIONSHIP_1, new 
Object[][]{PARTITION_1_RECORD_1, PARTITION_1_RECORD_2});
+        thenGivenRouteIsEmpty(RELATIONSHIP_2);
+        thenNonMatchingIsEmpty();
+    }
+
+    @Test
+    public void testIncomingFlowFilesContainsRecordForMultipleRoutes() throws 
Exception {

Review comment:
       Exception is never thrown, it can be removed.

##########
File path: 
nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestScriptedValidateRecord.java
##########
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.script;
+
+import org.apache.nifi.processor.Processor;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.util.MockFlowFile;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestScriptedValidateRecord extends TestScriptedRouterProcessor {
+    private static final String SCRIPT = "return record.getValue(\"first\") == 
1";
+
+    private static final Object[] VALID_RECORD_1 = new Object[] {1, "lorem"};
+    private static final Object[] VALID_RECORD_2 = new Object[] {1, "ipsum"};
+    private static final Object[] INVALID_RECORD_1 = new Object[] {2, "lorem"};
+    private static final Object[] INVALID_RECORD_2 = new Object[] {2, "ipsum"};
+
+    @Test
+    public void testIncomingFlowFileContainsValidRecordsOnly() throws 
Exception {
+        // given
+        recordReader.addRecord(VALID_RECORD_1);
+        recordReader.addRecord(VALID_RECORD_2);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenValidFlowFileContains(new Object[][]{VALID_RECORD_1, 
VALID_RECORD_2});
+        thenNoInvalidFlowFile();
+    }
+
+    @Test
+    public void testIncomingFlowFileContainsInvalidRecordsOnly() throws 
Exception {
+        // given
+        recordReader.addRecord(INVALID_RECORD_1);
+        recordReader.addRecord(INVALID_RECORD_2);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenInvalidFlowFileContains(new Object[][]{INVALID_RECORD_1, 
INVALID_RECORD_2});
+        thenNoValidFlowFile();
+    }
+
+    @Test
+    public void testIncomingFlowFileContainsBothValidAndInvalidRecords() 
throws Exception {

Review comment:
       Exception is never thrown, it can be removed.

##########
File path: 
nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestScriptedPartitionRecord.java
##########
@@ -0,0 +1,249 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.script;
+
+import org.apache.nifi.processor.Processor;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.util.MockFlowFile;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Set;
+import java.util.stream.Collectors;
+
+public class TestScriptedPartitionRecord extends TestScriptedRouterProcessor {
+    private static final String SCRIPT =
+        "if (record.getValue(\"first\") == 1) {\n" +
+        "   return \"partition1\";\n" +
+        "} else if (record.getValue(\"first\") == 2) {\n" +
+        "   return \"partition2\";\n" +
+        "} else {\n" +
+        "   return \"partition3\";\n" +
+        "}\n";
+
+    private static final Object[] PARTITION_1_RECORD_1 = new Object[] {1, 
"lorem"};
+    private static final Object[] PARTITION_1_RECORD_2 = new Object[] {1, 
"ipsum"};
+    private static final Object[] PARTITION_2_RECORD_1 = new Object[] {2, 
"lorem"};
+    private static final Object[] PARTITION_3_RECORD_1 = new Object[] {3, 
"lorem"};
+    private static final String PARTITION_1 = "partition1";
+    private static final String PARTITION_2 = "partition2";
+    private static final String PARTITION_3 = "partition3";
+    private static final String RELATIONSHIP_1 = "relationship1";
+    private static final String RELATIONSHIP_2 = "relationship2";
+
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        testRunner.setProperty(PARTITION_1, RELATIONSHIP_1);
+        testRunner.setProperty(PARTITION_2, RELATIONSHIP_2);
+    }
+
+    @Test
+    public void testIncomingFlowFilesContainsRecordForOneRoute() throws 
Exception {
+        // given
+        recordReader.addRecord(PARTITION_1_RECORD_1);
+        recordReader.addRecord(PARTITION_1_RECORD_2);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenGivenRouteContains(RELATIONSHIP_1, new 
Object[][]{PARTITION_1_RECORD_1, PARTITION_1_RECORD_2});
+        thenGivenRouteIsEmpty(RELATIONSHIP_2);
+        thenNonMatchingIsEmpty();
+    }
+
+    @Test
+    public void testIncomingFlowFilesContainsRecordForMultipleRoutes() throws 
Exception {
+        // given
+        recordReader.addRecord(PARTITION_1_RECORD_1);
+        recordReader.addRecord(PARTITION_2_RECORD_1);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenGivenRouteContains(RELATIONSHIP_1, new 
Object[][]{PARTITION_1_RECORD_1});
+        thenGivenRouteContains(RELATIONSHIP_2, new 
Object[][]{PARTITION_2_RECORD_1});
+        thenNonMatchingIsEmpty();
+    }
+
+    @Test
+    public void testIncomingFlowFilesContainsNonMatchingRecord() throws 
Exception {
+        // given
+        recordReader.addRecord(PARTITION_1_RECORD_1);
+        recordReader.addRecord(PARTITION_2_RECORD_1);
+        recordReader.addRecord(PARTITION_3_RECORD_1);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenGivenRouteContains(RELATIONSHIP_1, new 
Object[][]{PARTITION_1_RECORD_1});
+        thenGivenRouteContains(RELATIONSHIP_2, new 
Object[][]{PARTITION_2_RECORD_1});
+        thenNonMatchingContains(new Object[][]{PARTITION_3_RECORD_1});
+    }
+
+    @Test
+    public void testIncomingFlowFilesContainsOnlyNonMatchingRecord() throws 
Exception {
+        // given
+        recordReader.addRecord(PARTITION_3_RECORD_1);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenGivenRouteIsEmpty(RELATIONSHIP_1);
+        thenGivenRouteIsEmpty(RELATIONSHIP_2);
+        thenNonMatchingContains(new Object[][]{PARTITION_3_RECORD_1});
+    }
+
+    @Test
+    public void testIncomingFlowFileContainsNoRecords() throws Exception {

Review comment:
       Exception is never thrown, it can be removed.

##########
File path: 
nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestScriptedValidateRecord.java
##########
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.script;
+
+import org.apache.nifi.processor.Processor;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.util.MockFlowFile;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestScriptedValidateRecord extends TestScriptedRouterProcessor {
+    private static final String SCRIPT = "return record.getValue(\"first\") == 
1";
+
+    private static final Object[] VALID_RECORD_1 = new Object[] {1, "lorem"};
+    private static final Object[] VALID_RECORD_2 = new Object[] {1, "ipsum"};
+    private static final Object[] INVALID_RECORD_1 = new Object[] {2, "lorem"};
+    private static final Object[] INVALID_RECORD_2 = new Object[] {2, "ipsum"};
+
+    @Test
+    public void testIncomingFlowFileContainsValidRecordsOnly() throws 
Exception {
+        // given
+        recordReader.addRecord(VALID_RECORD_1);
+        recordReader.addRecord(VALID_RECORD_2);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenValidFlowFileContains(new Object[][]{VALID_RECORD_1, 
VALID_RECORD_2});
+        thenNoInvalidFlowFile();
+    }
+
+    @Test
+    public void testIncomingFlowFileContainsInvalidRecordsOnly() throws 
Exception {
+        // given
+        recordReader.addRecord(INVALID_RECORD_1);
+        recordReader.addRecord(INVALID_RECORD_2);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenInvalidFlowFileContains(new Object[][]{INVALID_RECORD_1, 
INVALID_RECORD_2});
+        thenNoValidFlowFile();
+    }
+
+    @Test
+    public void testIncomingFlowFileContainsBothValidAndInvalidRecords() 
throws Exception {
+        // given
+        recordReader.addRecord(VALID_RECORD_1);
+        recordReader.addRecord(INVALID_RECORD_1);
+        recordReader.addRecord(VALID_RECORD_2);
+        recordReader.addRecord(INVALID_RECORD_2);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenValidFlowFileContains(new Object[][]{VALID_RECORD_1, 
VALID_RECORD_2});
+        thenInvalidFlowFileContains(new Object[][]{INVALID_RECORD_1, 
INVALID_RECORD_2});
+    }
+
+    @Test
+    public void testIncomingFlowFileContainsNoRecords() throws Exception {
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenNoValidFlowFile();
+        thenNoInvalidFlowFile();
+    }
+
+    @Test
+    public void testIncomingFlowFileCannotBeRead() throws Exception {

Review comment:
       Exception is never thrown, it can be removed.

##########
File path: 
nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestScriptedFilterRecord.java
##########
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.script;
+
+import org.apache.nifi.processor.Processor;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.util.MockFlowFile;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestScriptedFilterRecord extends TestScriptedRouterProcessor {
+    private static final String SCRIPT = "return record.getValue(\"first\") == 
1";
+
+    private static final Object[] MATCHING_RECORD_1 = new Object[] {1, 
"lorem"};
+    private static final Object[] MATCHING_RECORD_2 = new Object[] {1, 
"ipsum"};
+    private static final Object[] NON_MATCHING_RECORD_1 = new Object[] {2, 
"lorem"};
+    private static final Object[] NON_MATCHING_RECORD_2 = new Object[] {2, 
"ipsum"};
+
+    @Test
+    public void testIncomingFlowFileContainsMatchingRecordsOnly() throws 
Exception {
+        // given
+        recordReader.addRecord(MATCHING_RECORD_1);
+        recordReader.addRecord(MATCHING_RECORD_2);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenMatchingFlowFileContains(new Object[][]{MATCHING_RECORD_1, 
MATCHING_RECORD_2});
+    }
+
+    @Test
+    public void testIncomingFlowFileContainsNonMatchingRecordsOnly() throws 
Exception {
+        // given
+        recordReader.addRecord(NON_MATCHING_RECORD_1);
+        recordReader.addRecord(NON_MATCHING_RECORD_2);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenMatchingFlowFileIsEmpty();
+    }
+
+    @Test
+    public void testIncomingFlowFileContainsMatchingAndNonMatchingRecords() 
throws Exception {
+        // given
+        recordReader.addRecord(MATCHING_RECORD_1);
+        recordReader.addRecord(NON_MATCHING_RECORD_1);
+        recordReader.addRecord(MATCHING_RECORD_2);
+        recordReader.addRecord(NON_MATCHING_RECORD_2);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenMatchingFlowFileContains(new Object[][]{MATCHING_RECORD_1, 
MATCHING_RECORD_2});
+    }
+
+    @Test
+    public void testIncomingFlowFileContainsNoRecords() throws Exception {
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenMatchingFlowFileIsEmpty();
+    }
+
+    @Test
+    public void testIncomingFlowFileCannotBeRead() throws Exception {

Review comment:
       Exception is never thrown, it can be removed.

##########
File path: 
nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestScriptedPartitionRecord.java
##########
@@ -0,0 +1,249 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.script;
+
+import org.apache.nifi.processor.Processor;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.util.MockFlowFile;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Set;
+import java.util.stream.Collectors;
+
+public class TestScriptedPartitionRecord extends TestScriptedRouterProcessor {
+    private static final String SCRIPT =
+        "if (record.getValue(\"first\") == 1) {\n" +
+        "   return \"partition1\";\n" +
+        "} else if (record.getValue(\"first\") == 2) {\n" +
+        "   return \"partition2\";\n" +
+        "} else {\n" +
+        "   return \"partition3\";\n" +
+        "}\n";
+
+    private static final Object[] PARTITION_1_RECORD_1 = new Object[] {1, 
"lorem"};
+    private static final Object[] PARTITION_1_RECORD_2 = new Object[] {1, 
"ipsum"};
+    private static final Object[] PARTITION_2_RECORD_1 = new Object[] {2, 
"lorem"};
+    private static final Object[] PARTITION_3_RECORD_1 = new Object[] {3, 
"lorem"};
+    private static final String PARTITION_1 = "partition1";
+    private static final String PARTITION_2 = "partition2";
+    private static final String PARTITION_3 = "partition3";
+    private static final String RELATIONSHIP_1 = "relationship1";
+    private static final String RELATIONSHIP_2 = "relationship2";
+
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        testRunner.setProperty(PARTITION_1, RELATIONSHIP_1);
+        testRunner.setProperty(PARTITION_2, RELATIONSHIP_2);
+    }
+
+    @Test
+    public void testIncomingFlowFilesContainsRecordForOneRoute() throws 
Exception {
+        // given
+        recordReader.addRecord(PARTITION_1_RECORD_1);
+        recordReader.addRecord(PARTITION_1_RECORD_2);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenGivenRouteContains(RELATIONSHIP_1, new 
Object[][]{PARTITION_1_RECORD_1, PARTITION_1_RECORD_2});
+        thenGivenRouteIsEmpty(RELATIONSHIP_2);
+        thenNonMatchingIsEmpty();
+    }
+
+    @Test
+    public void testIncomingFlowFilesContainsRecordForMultipleRoutes() throws 
Exception {
+        // given
+        recordReader.addRecord(PARTITION_1_RECORD_1);
+        recordReader.addRecord(PARTITION_2_RECORD_1);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenGivenRouteContains(RELATIONSHIP_1, new 
Object[][]{PARTITION_1_RECORD_1});
+        thenGivenRouteContains(RELATIONSHIP_2, new 
Object[][]{PARTITION_2_RECORD_1});
+        thenNonMatchingIsEmpty();
+    }
+
+    @Test
+    public void testIncomingFlowFilesContainsNonMatchingRecord() throws 
Exception {
+        // given
+        recordReader.addRecord(PARTITION_1_RECORD_1);
+        recordReader.addRecord(PARTITION_2_RECORD_1);
+        recordReader.addRecord(PARTITION_3_RECORD_1);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenGivenRouteContains(RELATIONSHIP_1, new 
Object[][]{PARTITION_1_RECORD_1});
+        thenGivenRouteContains(RELATIONSHIP_2, new 
Object[][]{PARTITION_2_RECORD_1});
+        thenNonMatchingContains(new Object[][]{PARTITION_3_RECORD_1});
+    }
+
+    @Test
+    public void testIncomingFlowFilesContainsOnlyNonMatchingRecord() throws 
Exception {
+        // given
+        recordReader.addRecord(PARTITION_3_RECORD_1);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenGivenRouteIsEmpty(RELATIONSHIP_1);
+        thenGivenRouteIsEmpty(RELATIONSHIP_2);
+        thenNonMatchingContains(new Object[][]{PARTITION_3_RECORD_1});
+    }
+
+    @Test
+    public void testIncomingFlowFileContainsNoRecords() throws Exception {
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenGivenRouteIsEmpty(RELATIONSHIP_1);
+        thenGivenRouteIsEmpty(RELATIONSHIP_2);
+        thenNonMatchingIsEmpty();
+    }
+
+    @Test
+    public void testIncomingFlowFileCannotBeRead() throws Exception {

Review comment:
       Exception is never thrown, it can be removed.

##########
File path: 
nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestScriptedFilterRecord.java
##########
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.script;
+
+import org.apache.nifi.processor.Processor;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.util.MockFlowFile;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestScriptedFilterRecord extends TestScriptedRouterProcessor {
+    private static final String SCRIPT = "return record.getValue(\"first\") == 
1";
+
+    private static final Object[] MATCHING_RECORD_1 = new Object[] {1, 
"lorem"};
+    private static final Object[] MATCHING_RECORD_2 = new Object[] {1, 
"ipsum"};
+    private static final Object[] NON_MATCHING_RECORD_1 = new Object[] {2, 
"lorem"};
+    private static final Object[] NON_MATCHING_RECORD_2 = new Object[] {2, 
"ipsum"};
+
+    @Test
+    public void testIncomingFlowFileContainsMatchingRecordsOnly() throws 
Exception {

Review comment:
       Exception is never thrown, it can be removed.

##########
File path: 
nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestScriptedPartitionRecord.java
##########
@@ -0,0 +1,249 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.script;
+
+import org.apache.nifi.processor.Processor;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.util.MockFlowFile;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Set;
+import java.util.stream.Collectors;
+
+public class TestScriptedPartitionRecord extends TestScriptedRouterProcessor {
+    private static final String SCRIPT =
+        "if (record.getValue(\"first\") == 1) {\n" +
+        "   return \"partition1\";\n" +
+        "} else if (record.getValue(\"first\") == 2) {\n" +
+        "   return \"partition2\";\n" +
+        "} else {\n" +
+        "   return \"partition3\";\n" +
+        "}\n";
+
+    private static final Object[] PARTITION_1_RECORD_1 = new Object[] {1, 
"lorem"};
+    private static final Object[] PARTITION_1_RECORD_2 = new Object[] {1, 
"ipsum"};
+    private static final Object[] PARTITION_2_RECORD_1 = new Object[] {2, 
"lorem"};
+    private static final Object[] PARTITION_3_RECORD_1 = new Object[] {3, 
"lorem"};
+    private static final String PARTITION_1 = "partition1";
+    private static final String PARTITION_2 = "partition2";
+    private static final String PARTITION_3 = "partition3";
+    private static final String RELATIONSHIP_1 = "relationship1";
+    private static final String RELATIONSHIP_2 = "relationship2";
+
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        testRunner.setProperty(PARTITION_1, RELATIONSHIP_1);
+        testRunner.setProperty(PARTITION_2, RELATIONSHIP_2);
+    }
+
+    @Test
+    public void testIncomingFlowFilesContainsRecordForOneRoute() throws 
Exception {
+        // given
+        recordReader.addRecord(PARTITION_1_RECORD_1);
+        recordReader.addRecord(PARTITION_1_RECORD_2);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenGivenRouteContains(RELATIONSHIP_1, new 
Object[][]{PARTITION_1_RECORD_1, PARTITION_1_RECORD_2});
+        thenGivenRouteIsEmpty(RELATIONSHIP_2);
+        thenNonMatchingIsEmpty();
+    }
+
+    @Test
+    public void testIncomingFlowFilesContainsRecordForMultipleRoutes() throws 
Exception {
+        // given
+        recordReader.addRecord(PARTITION_1_RECORD_1);
+        recordReader.addRecord(PARTITION_2_RECORD_1);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenGivenRouteContains(RELATIONSHIP_1, new 
Object[][]{PARTITION_1_RECORD_1});
+        thenGivenRouteContains(RELATIONSHIP_2, new 
Object[][]{PARTITION_2_RECORD_1});
+        thenNonMatchingIsEmpty();
+    }
+
+    @Test
+    public void testIncomingFlowFilesContainsNonMatchingRecord() throws 
Exception {
+        // given
+        recordReader.addRecord(PARTITION_1_RECORD_1);
+        recordReader.addRecord(PARTITION_2_RECORD_1);
+        recordReader.addRecord(PARTITION_3_RECORD_1);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenGivenRouteContains(RELATIONSHIP_1, new 
Object[][]{PARTITION_1_RECORD_1});
+        thenGivenRouteContains(RELATIONSHIP_2, new 
Object[][]{PARTITION_2_RECORD_1});
+        thenNonMatchingContains(new Object[][]{PARTITION_3_RECORD_1});
+    }
+
+    @Test
+    public void testIncomingFlowFilesContainsOnlyNonMatchingRecord() throws 
Exception {
+        // given
+        recordReader.addRecord(PARTITION_3_RECORD_1);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenGivenRouteIsEmpty(RELATIONSHIP_1);
+        thenGivenRouteIsEmpty(RELATIONSHIP_2);
+        thenNonMatchingContains(new Object[][]{PARTITION_3_RECORD_1});
+    }
+
+    @Test
+    public void testIncomingFlowFileContainsNoRecords() throws Exception {
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenGivenRouteIsEmpty(RELATIONSHIP_1);
+        thenGivenRouteIsEmpty(RELATIONSHIP_2);
+        thenNonMatchingIsEmpty();
+    }
+
+    @Test
+    public void testIncomingFlowFileCannotBeRead() throws Exception {
+        // given
+        recordReader.failAfter(0);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToFailed();
+        thenGivenRouteIsEmpty(RELATIONSHIP_1);
+        thenGivenRouteIsEmpty(RELATIONSHIP_2);
+        thenNonMatchingIsEmpty();
+    }
+
+    @Test
+    public void testMultiplePartitionPointToTheSameRelationship() throws 
Exception {

Review comment:
       Exception is never thrown, it can be removed.

##########
File path: 
nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestScriptedPartitionRecord.java
##########
@@ -0,0 +1,249 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.script;
+
+import org.apache.nifi.processor.Processor;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.util.MockFlowFile;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Set;
+import java.util.stream.Collectors;
+
+public class TestScriptedPartitionRecord extends TestScriptedRouterProcessor {
+    private static final String SCRIPT =
+        "if (record.getValue(\"first\") == 1) {\n" +
+        "   return \"partition1\";\n" +
+        "} else if (record.getValue(\"first\") == 2) {\n" +
+        "   return \"partition2\";\n" +
+        "} else {\n" +
+        "   return \"partition3\";\n" +
+        "}\n";
+
+    private static final Object[] PARTITION_1_RECORD_1 = new Object[] {1, 
"lorem"};
+    private static final Object[] PARTITION_1_RECORD_2 = new Object[] {1, 
"ipsum"};
+    private static final Object[] PARTITION_2_RECORD_1 = new Object[] {2, 
"lorem"};
+    private static final Object[] PARTITION_3_RECORD_1 = new Object[] {3, 
"lorem"};
+    private static final String PARTITION_1 = "partition1";
+    private static final String PARTITION_2 = "partition2";
+    private static final String PARTITION_3 = "partition3";
+    private static final String RELATIONSHIP_1 = "relationship1";
+    private static final String RELATIONSHIP_2 = "relationship2";
+
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        testRunner.setProperty(PARTITION_1, RELATIONSHIP_1);
+        testRunner.setProperty(PARTITION_2, RELATIONSHIP_2);
+    }
+
+    @Test
+    public void testIncomingFlowFilesContainsRecordForOneRoute() throws 
Exception {
+        // given
+        recordReader.addRecord(PARTITION_1_RECORD_1);
+        recordReader.addRecord(PARTITION_1_RECORD_2);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenGivenRouteContains(RELATIONSHIP_1, new 
Object[][]{PARTITION_1_RECORD_1, PARTITION_1_RECORD_2});
+        thenGivenRouteIsEmpty(RELATIONSHIP_2);
+        thenNonMatchingIsEmpty();
+    }
+
+    @Test
+    public void testIncomingFlowFilesContainsRecordForMultipleRoutes() throws 
Exception {
+        // given
+        recordReader.addRecord(PARTITION_1_RECORD_1);
+        recordReader.addRecord(PARTITION_2_RECORD_1);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenGivenRouteContains(RELATIONSHIP_1, new 
Object[][]{PARTITION_1_RECORD_1});
+        thenGivenRouteContains(RELATIONSHIP_2, new 
Object[][]{PARTITION_2_RECORD_1});
+        thenNonMatchingIsEmpty();
+    }
+
+    @Test
+    public void testIncomingFlowFilesContainsNonMatchingRecord() throws 
Exception {
+        // given
+        recordReader.addRecord(PARTITION_1_RECORD_1);
+        recordReader.addRecord(PARTITION_2_RECORD_1);
+        recordReader.addRecord(PARTITION_3_RECORD_1);
+
+        // when
+        whenTriggerProcessor();
+
+        // then
+        thenIncomingFlowFileIsRoutedToOriginal();
+        thenGivenRouteContains(RELATIONSHIP_1, new 
Object[][]{PARTITION_1_RECORD_1});
+        thenGivenRouteContains(RELATIONSHIP_2, new 
Object[][]{PARTITION_2_RECORD_1});
+        thenNonMatchingContains(new Object[][]{PARTITION_3_RECORD_1});
+    }
+
+    @Test
+    public void testIncomingFlowFilesContainsOnlyNonMatchingRecord() throws 
Exception {

Review comment:
       Exception is never thrown, it can be removed.

##########
File path: 
nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestScriptedPartitionRecord.java
##########
@@ -0,0 +1,249 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.script;
+
+import org.apache.nifi.processor.Processor;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.util.MockFlowFile;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Set;
+import java.util.stream.Collectors;
+
+public class TestScriptedPartitionRecord extends TestScriptedRouterProcessor {
+    private static final String SCRIPT =
+        "if (record.getValue(\"first\") == 1) {\n" +
+        "   return \"partition1\";\n" +
+        "} else if (record.getValue(\"first\") == 2) {\n" +
+        "   return \"partition2\";\n" +
+        "} else {\n" +
+        "   return \"partition3\";\n" +
+        "}\n";
+
+    private static final Object[] PARTITION_1_RECORD_1 = new Object[] {1, 
"lorem"};
+    private static final Object[] PARTITION_1_RECORD_2 = new Object[] {1, 
"ipsum"};
+    private static final Object[] PARTITION_2_RECORD_1 = new Object[] {2, 
"lorem"};
+    private static final Object[] PARTITION_3_RECORD_1 = new Object[] {3, 
"lorem"};
+    private static final String PARTITION_1 = "partition1";
+    private static final String PARTITION_2 = "partition2";
+    private static final String PARTITION_3 = "partition3";
+    private static final String RELATIONSHIP_1 = "relationship1";
+    private static final String RELATIONSHIP_2 = "relationship2";
+
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        testRunner.setProperty(PARTITION_1, RELATIONSHIP_1);
+        testRunner.setProperty(PARTITION_2, RELATIONSHIP_2);
+    }
+
+    @Test
+    public void testIncomingFlowFilesContainsRecordForOneRoute() throws 
Exception {

Review comment:
       Exception is never thrown, it can be removed.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to