From 219e0e96fbcdbab7903641a584bd52f7f3dca7ad Mon Sep 17 00:00:00 2001 From: devin fisher Date: Wed, 27 Jul 2016 22:18:50 -0600 Subject: [PATCH] Added more test for escape and unescape functions Signed-off-by: Matt Burgess --- .../expression/language/TestQuery.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/nifi-commons/nifi-expression-language/src/test/java/org/apache/nifi/attribute/expression/language/TestQuery.java b/nifi-commons/nifi-expression-language/src/test/java/org/apache/nifi/attribute/expression/language/TestQuery.java index dd81b3bede..29dbcc0177 100644 --- a/nifi-commons/nifi-expression-language/src/test/java/org/apache/nifi/attribute/expression/language/TestQuery.java +++ b/nifi-commons/nifi-expression-language/src/test/java/org/apache/nifi/attribute/expression/language/TestQuery.java @@ -1320,8 +1320,40 @@ public class TestQuery { attributes.put("string", "making air \"QUOTES\"."); verifyEquals("${string:escapeJson()}", attributes, "making air \\\"QUOTES\\\"."); + + attributes.put("string", "M & M"); + verifyEquals("${string:escapeXml()}", attributes, "M & M"); + + attributes.put("string", "making air \"QUOTES\"."); + verifyEquals("${string:escapeCsv()}", attributes, "\"making air \"\"QUOTES\"\".\""); + + attributes.put("string", "special ¡"); + verifyEquals("${string:escapeHtml3()}", attributes, "special ¡"); + + attributes.put("string", "special ♣"); + verifyEquals("${string:escapeHtml4()}", attributes, "special ♣"); } + @Test + public void testUnescapeFunctions() { + final Map attributes = new HashMap<>(); + + attributes.put("string", "making air \\\"QUOTES\\\"."); + verifyEquals("${string:unescapeJson()}", attributes, "making air \"QUOTES\"."); + + attributes.put("string", "M & M"); + verifyEquals("${string:unescapeXml()}", attributes, "M & M"); + + attributes.put("string", "\"making air \"\"QUOTES\"\".\""); + verifyEquals("${string:unescapeCsv()}", attributes, "making air \"QUOTES\"."); + + attributes.put("string", "special ¡"); + verifyEquals("${string:unescapeHtml3()}", attributes, "special ¡"); + + attributes.put("string", "special ♣"); + verifyEquals("${string:unescapeHtml4()}", attributes, "special ♣"); + } + private void verifyEquals(final String expression, final Map attributes, final Object expectedResult) { Query.validateExpression(expression, false); assertEquals(String.valueOf(expectedResult), Query.evaluateExpressions(expression, attributes, null));