Joe Witt created NIFI-16612:
-------------------------------

             Summary: MockValidationContext ignores TestRunner parameter 
context values during validation
                 Key: NIFI-16612
                 URL: https://issues.apache.org/jira/browse/NIFI-16612
             Project: Apache NiFi
          Issue Type: Test
          Components: Core Framework
    Affects Versions: 2.12.0
            Reporter: Joe Witt
            Assignee: Joe Witt



TestRunner.setParameterContextValue() stores parameters on MockProcessContext, 
but validation still uses ParameterLookup.EMPTY.

MockProcessContext.setProperty() and MockProcessContext.validate() both 
construct:

  new MockValidationContext(this, stateManager)

The two-argument MockValidationContext constructor then does:

  this(processContext, stateManager, ParameterLookup.EMPTY)

So MockValidationContext.getProperties() / evaluateParameters() substitute 
#{param} against an empty lookup. The configured value becomes null even when 
the parameter was set on the TestRunner.

This is still true on main.

Reproduction (UpdateAttribute, same as community report):

  TestRunner runner = TestRunners.newTestRunner(UpdateAttribute.class);
  runner.setParameterContextValue("test-param", "resolved-value");
  runner.setProperty("param_based_attr", "#{test-param}");
  runner.enqueue(new byte[0]);
  runner.run();

Actual:
  Processor has 1 validation failures:
  'param_based_attr' is invalid because Dynamic Property param_based_attr is 
null. Does it reference an unset parameter?

Expected:
  Processor is valid. After run(), param_based_attr is "resolved-value".

Runtime evaluation on MockProcessContext already uses MockParameterLookup over 
the TestRunner map. Only the validation path is wrong.

Fix: the two-argument constructor should pass 
processContext.getParameterLookup() instead of ParameterLookup.EMPTY.

Do not change the three-argument constructor's null fallback. NIFI-15251 
already set that to processContext.getParameterLookup(). Reverting it to EMPTY 
would drop parameters again when a null lookup is passed.

Keep TestUpdateAttribute.testDynamicPropertyWithUnsetParameter: a missing 
parameter must still fail validation.

Introduced by NIFI-14808 (#10159). NIFI-15251 (#10577) taught 
isParameterDefined / isParameterSet to read the context map but left the 
two-argument constructor on EMPTY.

Reported on Apache NiFi Slack #users by Devin Fisher against 2.12.0.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to