From 6897090771434fc1553b722b835c3b67e8dd14a9 Mon Sep 17 00:00:00 2001 From: Aldrin Piri Date: Mon, 16 Feb 2015 18:26:35 -0500 Subject: [PATCH] Adding a test for a destination of attributes and only one JsonPath expression evaluates to a found result. --- .../standard/TestEvaluateJsonPath.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEvaluateJsonPath.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEvaluateJsonPath.java index 6a1fbad460..fc125c2e8b 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEvaluateJsonPath.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEvaluateJsonPath.java @@ -139,6 +139,28 @@ public class TestEvaluateJsonPath { Assert.assertEquals("Transferred flow file did not have the correct result for name attribute", "", out.getAttribute(jsonPathNameAttrKey)); } + @Test + public void testExtractPath_destinationAttributes_twoPaths_oneFound() throws Exception { + final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateJsonPath()); + testRunner.setProperty(EvaluateJsonPath.DESTINATION, EvaluateJsonPath.DESTINATION_ATTRIBUTE); + + String jsonPathIdAttrKey = "evaluatejson.id"; + String jsonPathNameAttrKey = "evaluatejson.name"; + + testRunner.setProperty(jsonPathIdAttrKey, "$[0]._id"); + testRunner.setProperty(jsonPathNameAttrKey, "$[0].name.nonexistent"); + + testRunner.enqueue(JSON_SNIPPET); + testRunner.run(); + + Relationship expectedRel = EvaluateJsonPath.REL_MATCH; + + testRunner.assertAllFlowFilesTransferred(expectedRel, 1); + final MockFlowFile out = testRunner.getFlowFilesForRelationship(expectedRel).get(0); + Assert.assertEquals("Transferred flow file did not have the correct result for id attribute", "54df94072d5dbf7dc6340cc5", out.getAttribute(jsonPathIdAttrKey)); + Assert.assertEquals("Transferred flow file did not have the correct result for name attribute", "", out.getAttribute(jsonPathNameAttrKey)); + } + @Test public void testExtractPath_destinationContent() throws Exception { String jsonPathAttrKey = "JsonPath";