This is an automated email from the ASF dual-hosted git repository. lordgamez pushed a commit to branch NIFI-9058 in repository https://gitbox.apache.org/repos/asf/nifi.git
commit 0cc4fa4628d5de5425afe71990a8b632c0762062 Author: Gabor Gyimesi <[email protected]> AuthorDate: Wed Aug 18 15:51:54 2021 +0200 NIFI-9058 Core attributes shall not be filtered from Attributes List --- .../nifi/processors/standard/AttributesToJSON.java | 5 +--- .../processors/standard/TestAttributesToJSON.java | 29 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AttributesToJSON.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AttributesToJSON.java index eb1b52a..3e9fd61 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AttributesToJSON.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AttributesToJSON.java @@ -212,10 +212,7 @@ public class AttributesToJSON extends AbstractProcessor { if (ats != null) { Set<String> result = new HashSet<>(ats.length); for (String str : ats) { - String trim = str.trim(); - if (!atrsToExclude.contains(trim)) { - result.add(trim); - } + result.add(str.trim()); } return result; } diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestAttributesToJSON.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestAttributesToJSON.java index 84f5c7d..40352fe 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestAttributesToJSON.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestAttributesToJSON.java @@ -310,6 +310,35 @@ public class TestAttributesToJSON { ObjectMapper mapper = new ObjectMapper(); Map<String, String> val = mapper.readValue(json, HashMap.class); assertEquals(TEST_ATTRIBUTE_VALUE, val.get(TEST_ATTRIBUTE_KEY)); + assertEquals(TEST_ATTRIBUTE_VALUE, val.get(CoreAttributes.PATH.key())); + assertEquals(2, val.size()); + } + + @Test + public void testAttribute_noIncludeCoreAttributesRegex() throws IOException { + final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToJSON()); + testRunner.setProperty(AttributesToJSON.ATTRIBUTES_REGEX, CoreAttributes.PATH.key() + ".*"); + testRunner.setProperty(AttributesToJSON.INCLUDE_CORE_ATTRIBUTES, "false"); + + ProcessSession session = testRunner.getProcessSessionFactory().createSession(); + FlowFile ff = session.create(); + ff = session.putAttribute(ff, TEST_ATTRIBUTE_KEY, TEST_ATTRIBUTE_VALUE); + ff = session.putAttribute(ff, CoreAttributes.PATH.key(), TEST_ATTRIBUTE_VALUE); + + testRunner.enqueue(ff); + testRunner.run(); + + testRunner.getFlowFilesForRelationship(AttributesToJSON.REL_SUCCESS).get(0) + .assertAttributeExists(AttributesToJSON.JSON_ATTRIBUTE_NAME); + testRunner.assertTransferCount(AttributesToJSON.REL_SUCCESS, 1); + testRunner.assertTransferCount(AttributesToJSON.REL_FAILURE, 0); + + String json = testRunner.getFlowFilesForRelationship(AttributesToJSON.REL_SUCCESS) + .get(0).getAttribute(AttributesToJSON.JSON_ATTRIBUTE_NAME); + + ObjectMapper mapper = new ObjectMapper(); + Map<String, String> val = mapper.readValue(json, HashMap.class); + assertEquals(TEST_ATTRIBUTE_VALUE, val.get(CoreAttributes.PATH.key())); assertEquals(1, val.size()); }
