[
https://issues.apache.org/jira/browse/NIFI-16609?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18147673#comment-18147673
]
Joe Witt commented on NIFI-16609:
---------------------------------
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.
> MockValidationContext does not propagate Parameter Context values from
> MockProcessContext
> -----------------------------------------------------------------------------------------
>
> Key: NIFI-16609
> URL: https://issues.apache.org/jira/browse/NIFI-16609
> Project: Apache NiFi
> Issue Type: Bug
> Components: NiFi API
> Affects Versions: nifi-api-2.12.0
> Reporter: Devin Fisher
> Priority: Minor
>
> {{MockValidationContext}} receives a {{MockProcessContext}} in its
> constructor, but it appears that the {{contextParameters}} from the
> {{MockProcessContext}} are not being carried over.
> Minimal Test to reproduce:
> {code:java}
> @Test
> void resolvesParameterContextValue() {
> var testRunner = TestRunners.newTestRunner( UpdateAttribute.class);
> testRunner.setParameterContextValue("test-param", "resolved-value");
> testRunner.setProperty("param_based_attr", "#{test-param}");
> testRunner.enqueue(new byte[0]);
> testRunner.run();
> }
> {code}
> Specifically it seem to be here:
> https://github.com/apache/nifi/blob/rel/nifi-2.12.0/nifi-mock/src/main/java/org/apache/nifi/util/MockProcessContext.java#L289
> that calls here:
> https://github.com/apache/nifi/blob/rel/nifi-2.12.0/nifi-mock/src/main/java/org/apache/nifi/util/MockValidationContext.java#L58
> which sets the {{parameterLookup}} to {{ParameterLookup.EMPTY}}
> Seems like it should get the parameterLookup from the passed in
> MockProcessContext
>
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)