From 7e581307b7d65da79464914b09fe8a90dd5046e9 Mon Sep 17 00:00:00 2001 From: Aldrin Piri Date: Mon, 16 Feb 2015 18:33:48 -0500 Subject: [PATCH] Adding tests for indefinite results with and without the usage of operators. --- .../standard/TestEvaluateJsonPath.java | 35 +++++++++++++++++++ 1 file changed, 35 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 fc125c2e8b..bece3da175 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 @@ -177,4 +177,39 @@ public class TestEvaluateJsonPath { testRunner.assertAllFlowFilesTransferred(expectedRel, 1); testRunner.getFlowFilesForRelationship(expectedRel).get(0).assertContentEquals("54df94072d5dbf7dc6340cc5"); } + + + @Test + public void testExtractPath_destinationAttribute_indefiniteResult() throws Exception { + String jsonPathAttrKey = "friends.indefinite.id.list"; + + final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateJsonPath()); + testRunner.setProperty(EvaluateJsonPath.DESTINATION, EvaluateJsonPath.DESTINATION_CONTENT); + testRunner.setProperty(jsonPathAttrKey, "$[0].friends.[*].id"); + + testRunner.enqueue(JSON_SNIPPET); + testRunner.run(); + + Relationship expectedRel = EvaluateJsonPath.REL_MATCH; + + testRunner.assertAllFlowFilesTransferred(expectedRel, 1); + testRunner.getFlowFilesForRelationship(expectedRel).get(0).assertContentEquals("[0,1,2]"); + } + + @Test + public void testExtractPath_destinationAttribute_indefiniteResult_operators() throws Exception { + String jsonPathAttrKey = "friends.indefinite.id.list"; + + final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateJsonPath()); + testRunner.setProperty(EvaluateJsonPath.DESTINATION, EvaluateJsonPath.DESTINATION_CONTENT); + testRunner.setProperty(jsonPathAttrKey, "$[0].friends[?(@.id < 3)].id"); + + testRunner.enqueue(JSON_SNIPPET); + testRunner.run(); + + Relationship expectedRel = EvaluateJsonPath.REL_MATCH; + + testRunner.assertAllFlowFilesTransferred(expectedRel, 1); + testRunner.getFlowFilesForRelationship(expectedRel).get(0).assertContentEquals("[0,1,2]"); + } }