Adding a test for a destination of attributes and only one JsonPath expression evaluates to a found result.

This commit is contained in:
Aldrin Piri 2015-02-16 18:26:35 -05:00
parent d4a94c37ee
commit 6897090771
1 changed files with 22 additions and 0 deletions

View File

@ -139,6 +139,28 @@ public class TestEvaluateJsonPath {
Assert.assertEquals("Transferred flow file did not have the correct result for name attribute", "", out.getAttribute(jsonPathNameAttrKey)); 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 @Test
public void testExtractPath_destinationContent() throws Exception { public void testExtractPath_destinationContent() throws Exception {
String jsonPathAttrKey = "JsonPath"; String jsonPathAttrKey = "JsonPath";