mgaido91 commented on a change in pull request #3615: NIFI-6500 Support Padding
functions in Expression Language
URL: https://github.com/apache/nifi/pull/3615#discussion_r309375721
##########
File path:
nifi-commons/nifi-expression-language/src/test/java/org/apache/nifi/attribute/expression/language/TestQuery.java
##########
@@ -1822,6 +1826,63 @@ public void testThread() {
verifyEquals("${thread()}", attributes, "main");
}
+ @Test
+ public void testPadLeft() {
+ final Map<String, String> attributes = new HashMap<>();
+ attributes.put("attr", "hello");
+ attributes.put("emptyString", "");
+ attributes.put("nullString", null);
+
+ verifyEquals("${attr:padLeft(10, '@')}", attributes, "@@@@@hello");
+ verifyEquals("${attr:padLeft(10)}", attributes, "_____hello");
+ verifyEquals("${attr:padLeft(10, \"abc\")}", attributes, "aaaaahello");
+ verifyEquals("${attr:padLeft(1, \"a\")}", attributes, "hello");
+ verifyEquals("${attr:padLeft(-10, \"a\")}", attributes, "hello");
+ verifyEquals("${emptyString:padLeft(10, '@')}", attributes,
"@@@@@@@@@@");
+
+ // Cannot pass by verifyEquals
+ final Query notExistingAttrQuery =
Query.compile("${nonExistingAttr:padLeft(10, \"abc\")}");
+ final QueryResult<?> notExistingAttrResult =
notExistingAttrQuery.evaluate(attributes, null);
+ assertTrue(notExistingAttrResult.getValue() == null);
+
+ final Query overflowLengthQuery =
Query.compile("${nonExistingAttr:padLeft(9999999999, \"abc\")}");
+ final QueryResult<?> overflowLengthResult =
overflowLengthQuery.evaluate(attributes, null);
+ assertTrue(overflowLengthResult.getValue() == null);
+
+ final Query nullStringQuery = Query.compile("${nullString:padLeft(10,
\"@\")}");
+ final QueryResult<?> nullStringResult =
nullStringQuery.evaluate(attributes, null);
+ assertTrue(nullStringResult.getValue() == null);
+
Review comment:
nit:remove empty line
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services