You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "exceptionfactory (via GitHub)" <gi...@apache.org> on 2023/05/16 02:50:23 UTC

[GitHub] [nifi] exceptionfactory commented on a diff in pull request #7250: [NIFI-11550] Refactored Groovy tests to Java.

exceptionfactory commented on code in PR #7250:
URL: https://github.com/apache/nifi/pull/7250#discussion_r1194544215


##########
nifi-commons/nifi-expression-language/src/test/java/org/apache/nifi/attribute/expression/language/TestQuery.java:
##########
@@ -1177,6 +1179,99 @@ public void testReplaceAllWithMatchingGroup() {
         verifyEquals("${attr:replaceAll('.*?(l+).*', '$1')}", attributes, "ll");
     }
 
+    @Test
+    public void testReplaceShouldReplaceAllLiteralMatches() {
+        int n = 3;
+        final String ORIGINAL_VALUE = "Hello World";
+        final Map<String, String> attributes = Map.of("single", ORIGINAL_VALUE,
+                "repeating", StringUtils.repeat(ORIGINAL_VALUE, " ", n));
+        final String REPLACEMENT_VALUE = "Goodbye Planet";
+        final String EXPECTED_REPEATING_RESULT = StringUtils.repeat(REPLACEMENT_VALUE, " ", n);
+        final String REPLACE_SINGLE_EXPRESSION = "${single:replace('" + ORIGINAL_VALUE + "', '" + REPLACEMENT_VALUE + "')}";
+        final String REPLACE_REPEATING_EXPRESSION = "${repeating:replace('" + ORIGINAL_VALUE + "', '" + REPLACEMENT_VALUE + "')}";
+        Query replaceSingleQuery = Query.compile(REPLACE_SINGLE_EXPRESSION);
+        Query replaceRepeatingQuery = Query.compile(REPLACE_REPEATING_EXPRESSION);
+
+        QueryResult<?> replaceSingleResult = replaceSingleQuery.evaluate(new StandardEvaluationContext(attributes));
+        QueryResult<?> replaceRepeatingResult = replaceRepeatingQuery.evaluate(new StandardEvaluationContext(attributes));
+
+        assertEquals(REPLACEMENT_VALUE, replaceSingleResult.getValue());
+        assertEquals(AttributeExpression.ResultType.STRING, replaceSingleResult.getResultType());
+        assertEquals(EXPECTED_REPEATING_RESULT, replaceRepeatingResult.getValue());
+        assertEquals(AttributeExpression.ResultType.STRING, replaceRepeatingResult.getResultType());
+    }
+
+    @Test
+    public void testReplaceFirstShouldOnlyReplaceFirstRegexMatch() {
+        // Arrange

Review Comment:
   ```suggestion
   ```



##########
nifi-commons/nifi-expression-language/src/test/java/org/apache/nifi/attribute/expression/language/TestQuery.java:
##########
@@ -1177,6 +1179,99 @@ public void testReplaceAllWithMatchingGroup() {
         verifyEquals("${attr:replaceAll('.*?(l+).*', '$1')}", attributes, "ll");
     }
 
+    @Test
+    public void testReplaceShouldReplaceAllLiteralMatches() {
+        int n = 3;
+        final String ORIGINAL_VALUE = "Hello World";

Review Comment:
   Understanding that this is a migration, can you correct the style of these methods variables to use camelCase instead of all capital letters?
   ```suggestion
           final String originalValue = "Hello World";
   ```



-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org