NIFI-14016 Resolved issue for onPropertyModified() where oldValue was always null (#9560)

NIFI-14016 Resolved issue for onPropertyModified() where oldValue was always null (#9560)
This commit is contained in:
NissimShiman 2024-12-03 15:34:09 +00:00 committed by GitHub
parent 82fe051413
commit 39aa106943
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 1 deletions

View File

@ -555,10 +555,11 @@ public abstract class AbstractComponentNode implements ComponentNode {
// Keep setProperty/removeProperty private so that all calls go through setProperties
private void setProperty(final PropertyDescriptor descriptor, final PropertyConfiguration propertyConfiguration, final Function<PropertyDescriptor, PropertyConfiguration> valueToCompareFunction) {
final PropertyConfiguration propertyModComparisonValue = valueToCompareFunction.apply(descriptor);
// Remove current PropertyDescriptor to force updated instance references
final PropertyConfiguration removed = properties.remove(descriptor);
final PropertyConfiguration propertyModComparisonValue = valueToCompareFunction.apply(descriptor);
properties.put(descriptor, propertyConfiguration);
final String effectiveValue = propertyConfiguration.getEffectiveValue(getParameterContext());
final String resolvedValue = resolveAllowableValue(effectiveValue, descriptor);

View File

@ -306,6 +306,37 @@ public class TestAbstractComponentNode {
assertFalse(updatedPropertyDescriptor.isSensitive());
}
@Test
public void testSetPropertiesPropertyModified() {
final String propertyValueModified = PROPERTY_VALUE + "-modified";
final List<PropertyModification> propertyModifications = new ArrayList<>();
final AbstractComponentNode node = new LocalComponentNode() {
@Override
protected void onPropertyModified(final PropertyDescriptor descriptor, final String oldValue, final String newValue) {
propertyModifications.add(new PropertyModification(descriptor, oldValue, newValue));
super.onPropertyModified(descriptor, oldValue, newValue);
}
};
final Map<String, String> properties = new HashMap<>();
properties.put(PROPERTY_NAME, PROPERTY_VALUE);
node.setProperties(properties);
assertEquals(1, propertyModifications.size());
PropertyModification mod = propertyModifications.get(0);
assertNull(mod.getPreviousValue());
assertEquals(PROPERTY_VALUE, mod.getUpdatedValue());
propertyModifications.clear();
properties.put(PROPERTY_NAME, propertyValueModified);
node.setProperties(properties);
assertEquals(1, propertyModifications.size());
mod = propertyModifications.get(0);
assertEquals(PROPERTY_VALUE, mod.getPreviousValue());
assertEquals(propertyValueModified, mod.getUpdatedValue());
}
@Test
public void testSetPropertiesSensitiveDynamicPropertyNames() {
final AbstractComponentNode node = new LocalComponentNode();