mirror of https://github.com/apache/nifi.git
NIFI-5230: Fixed NPE in InvokeScriptedProcessor on customValidate
This closes #2734 Signed-off-by: Mike Thomsen <mikerthomsen@gmail.com>
This commit is contained in:
parent
3a29c1e4ca
commit
23feb8f429
|
@ -237,7 +237,7 @@ public class InvokeScriptedProcessor extends AbstractSessionFactoryProcessor {
|
||||||
@Override
|
@Override
|
||||||
public void onPropertyModified(final PropertyDescriptor descriptor, final String oldValue, final String newValue) {
|
public void onPropertyModified(final PropertyDescriptor descriptor, final String oldValue, final String newValue) {
|
||||||
|
|
||||||
validationResults.set(null);
|
validationResults.set(new HashSet<>());
|
||||||
|
|
||||||
final ComponentLog logger = getLogger();
|
final ComponentLog logger = getLogger();
|
||||||
final Processor instance = processor.get();
|
final Processor instance = processor.get();
|
||||||
|
@ -455,7 +455,7 @@ public class InvokeScriptedProcessor extends AbstractSessionFactoryProcessor {
|
||||||
|
|
||||||
// do not try to build processor/compile/etc until onPropertyModified clear the validation error/s
|
// do not try to build processor/compile/etc until onPropertyModified clear the validation error/s
|
||||||
// and don't print anything into log.
|
// and don't print anything into log.
|
||||||
if (validationResults.get() != null){
|
if (!validationResults.get().isEmpty()) {
|
||||||
return validationResults.get();
|
return validationResults.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,6 @@ public class TestInvokeGroovy extends BaseScriptTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testReadFlowFileContentAndStoreInFlowFileAttribute() throws Exception {
|
public void testReadFlowFileContentAndStoreInFlowFileAttribute() throws Exception {
|
||||||
runner.setValidateExpressionUsage(false);
|
|
||||||
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy");
|
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy");
|
||||||
runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "target/test/resources/groovy/test_reader.groovy");
|
runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "target/test/resources/groovy/test_reader.groovy");
|
||||||
runner.setProperty(ScriptingComponentUtils.MODULES, "target/test/resources/groovy");
|
runner.setProperty(ScriptingComponentUtils.MODULES, "target/test/resources/groovy");
|
||||||
|
@ -140,7 +139,6 @@ public class TestInvokeGroovy extends BaseScriptTest {
|
||||||
@Test(expected = AssertionError.class)
|
@Test(expected = AssertionError.class)
|
||||||
public void testInvokeScriptCausesException() throws Exception {
|
public void testInvokeScriptCausesException() throws Exception {
|
||||||
final TestRunner runner = TestRunners.newTestRunner(new InvokeScriptedProcessor());
|
final TestRunner runner = TestRunners.newTestRunner(new InvokeScriptedProcessor());
|
||||||
runner.setValidateExpressionUsage(false);
|
|
||||||
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy");
|
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy");
|
||||||
runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, getFileContentsAsString(
|
runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, getFileContentsAsString(
|
||||||
TEST_RESOURCE_LOCATION + "groovy/testInvokeScriptCausesException.groovy")
|
TEST_RESOURCE_LOCATION + "groovy/testInvokeScriptCausesException.groovy")
|
||||||
|
@ -158,7 +156,6 @@ public class TestInvokeGroovy extends BaseScriptTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testScriptRoutesToFailure() throws Exception {
|
public void testScriptRoutesToFailure() throws Exception {
|
||||||
runner.setValidateExpressionUsage(false);
|
|
||||||
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy");
|
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy");
|
||||||
runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, getFileContentsAsString(
|
runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, getFileContentsAsString(
|
||||||
TEST_RESOURCE_LOCATION + "groovy/testScriptRoutesToFailure.groovy")
|
TEST_RESOURCE_LOCATION + "groovy/testScriptRoutesToFailure.groovy")
|
||||||
|
@ -171,4 +168,15 @@ public class TestInvokeGroovy extends BaseScriptTest {
|
||||||
final List<MockFlowFile> result = runner.getFlowFilesForRelationship("FAILURE");
|
final List<MockFlowFile> result = runner.getFlowFilesForRelationship("FAILURE");
|
||||||
assertFalse(result.isEmpty());
|
assertFalse(result.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testValidationResultsReset() throws Exception {
|
||||||
|
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy");
|
||||||
|
runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "target/test/resources/groovy/test_reader.groovy");
|
||||||
|
runner.setProperty(ScriptingComponentUtils.MODULES, "target/test/resources/groovy");
|
||||||
|
|
||||||
|
runner.assertValid();
|
||||||
|
runner.setProperty("test-attribute", "test");
|
||||||
|
runner.assertValid();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue