NIFI-4798 allow empty value for UpdateAttribute property

Signed-off-by: Matthew Burgess <mattyb149@apache.org>

This closes #6585
This commit is contained in:
Mark Bean 2022-10-24 20:33:57 -04:00 committed by Matthew Burgess
parent 19658df52b
commit 4e4f6437ee
No known key found for this signature in database
GPG Key ID: 05D3DEB8126DAD24
2 changed files with 28 additions and 1 deletions

View File

@ -246,7 +246,6 @@ public class UpdateAttribute extends AbstractProcessor implements Searchable {
.build();
} else {
return propertyBuilder
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
.build();
}
}

View File

@ -107,6 +107,34 @@ public class TestUpdateAttribute {
result.get(0).assertAttributeEquals("attribute.2", "new.value.2");
}
@Test
public void testSetEmptyString() throws Exception {
final TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute());
runner.setProperty("attribute.1", "");
runner.assertValid();
// No attributes on flowfile
runner.enqueue(new byte[0]);
runner.run();
runner.assertAllFlowFilesTransferred(UpdateAttribute.REL_SUCCESS, 1);
List<MockFlowFile> result = runner.getFlowFilesForRelationship(UpdateAttribute.REL_SUCCESS);
assertTrue(result.get(0).getAttribute("attribute.1").isEmpty());
runner.clearTransferState();
final Map<String, String> attributes = new HashMap<>();
attributes.put("attribute.1", "old.value.1");
// Existing attribute to be replaced on flowfile
runner.enqueue(new byte[0], attributes);
runner.run();
runner.assertAllFlowFilesTransferred(UpdateAttribute.REL_SUCCESS, 1);
result = runner.getFlowFilesForRelationship(UpdateAttribute.REL_SUCCESS);
assertTrue(result.get(0).getAttribute("attribute.1").isEmpty());
}
@Test
public void testDefaultAddAttribute() throws Exception {
final TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute());