Github user mattyb149 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/303#discussion_r64142194
  
    --- Diff: 
nifi-commons/nifi-expression-language/src/test/java/org/apache/nifi/attribute/expression/language/TestQuery.java
 ---
    @@ -233,6 +233,24 @@ public void testEmbeddedExpressionsAndQuotes() {
         }
     
         @Test
    +    public void testJsonPath() {
    +        final Map<String, String> attributes = new HashMap<>();
    +        attributes.put("json",
    +                "{" + "\n  \"firstName\": \"John\"," + "\n  \"lastName\": 
\"Smith\"," + "\n  \"isAlive\": true," + "\n  \"age\": 25," + "\n  \"address\": 
{"
    +                        + "\n    \"streetAddress\": \"21 2nd Street\"," + 
"\n    \"city\": \"New York\"," + "\n    \"state\": \"NY\","
    +                        + "\n    \"postalCode\": \"10021-3100\"" + "\n  
}," + "\n  \"phoneNumbers\": [" + "\n    {" + "\n      \"type\": \"home\","
    +                        + "\n      \"number\": \"212 555-1234\"" + "\n    
}," + "\n    {" + "\n      \"type\": \"office\","
    +                        + "\n      \"number\": \"646 555-4567\"" + "\n    
}" + "\n  ]," + "\n  \"children\": []," + "\n  \"spouse\": null" + "\n}");
    +        verifyEquals("${json:jsonPath('$.firstName')}", attributes, 
"John");
    +        verifyEquals("${json:jsonPath('$.address.postalCode')}", 
attributes, "10021-3100");
    +        
verifyEquals("${json:jsonPath(\"$.phoneNumbers[?(@.type=='home')].number\")}", 
attributes, "212 555-1234");
    +        verifyEquals("${json:jsonPath('$.phoneNumbers')}", attributes,
    +                "[{\"type\":\"home\",\"number\":\"212 
555-1234\"},{\"type\":\"office\",\"number\":\"646 555-4567\"}]");
    +        verifyEquals("${json:jsonPath('$.missing-path')}", attributes, "");
    +        verifyEquals("${missing:jsonPath('$.bad@expression')}", 
attributes, "");
    +    }
    --- End diff --
    
    Perhaps add a test for an existing attribute containing invalid JSON.  If 
the behavior on bad JSON is changed to throw an exception (see above comment), 
a test could verify that; otherwise it should be tested for null.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to