use of org.apache.nifi.processor.Relationship in project nifi by apache.
the class TestEvaluateJsonPath method testExtractPath_destinationContent.
@Test
public void testExtractPath_destinationContent() throws Exception {
String jsonPathAttrKey = "JsonPath";
final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateJsonPath());
testRunner.setProperty(EvaluateJsonPath.DESTINATION, EvaluateJsonPath.DESTINATION_CONTENT);
testRunner.setProperty(jsonPathAttrKey, "$[0]._id");
testRunner.enqueue(JSON_SNIPPET);
testRunner.run();
Relationship expectedRel = EvaluateJsonPath.REL_MATCH;
testRunner.assertAllFlowFilesTransferred(expectedRel, 1);
testRunner.getFlowFilesForRelationship(expectedRel).get(0).assertContentEquals("54df94072d5dbf7dc6340cc5");
}
use of org.apache.nifi.processor.Relationship in project nifi by apache.
the class TestEvaluateJsonPath method testExtractPath_destinationContent_indefiniteResult.
@Test
public void testExtractPath_destinationContent_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]");
}
use of org.apache.nifi.processor.Relationship in project nifi by apache.
the class TestEvaluateJsonPath method testRouteUnmatched_destinationContent_noMatch.
@Test
public void testRouteUnmatched_destinationContent_noMatch() throws Exception {
final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateJsonPath());
testRunner.setProperty(EvaluateJsonPath.DESTINATION, EvaluateJsonPath.DESTINATION_CONTENT);
testRunner.setProperty("jsonPath", "$[0].nonexistent.key");
testRunner.enqueue(JSON_SNIPPET);
testRunner.run();
Relationship expectedRel = EvaluateJsonPath.REL_NO_MATCH;
testRunner.assertAllFlowFilesTransferred(expectedRel, 1);
testRunner.getFlowFilesForRelationship(expectedRel).get(0).assertContentEquals(JSON_SNIPPET);
}
use of org.apache.nifi.processor.Relationship in project nifi by apache.
the class TestEvaluateJsonPath method testExtractPath_destinationAttributes_twoPaths.
@Test
public void testExtractPath_destinationAttributes_twoPaths() throws Exception {
final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateJsonPath());
testRunner.setProperty(EvaluateJsonPath.DESTINATION, EvaluateJsonPath.DESTINATION_ATTRIBUTE);
testRunner.setProperty(EvaluateJsonPath.RETURN_TYPE, EvaluateJsonPath.RETURN_TYPE_JSON);
String jsonPathIdAttrKey = "evaluatejson.id";
String jsonPathNameAttrKey = "evaluatejson.name";
testRunner.setProperty(jsonPathIdAttrKey, "$[0]._id");
testRunner.setProperty(jsonPathNameAttrKey, "$[0].name");
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", "{\"first\":\"Shaffer\",\"last\":\"Pearson\"}", out.getAttribute(jsonPathNameAttrKey));
}
use of org.apache.nifi.processor.Relationship in project nifi by apache.
the class TestExtractText method testGetRelationShips.
@Test
public void testGetRelationShips() throws Exception {
final ExtractText processor = new ExtractText();
final TestRunner testRunner = TestRunners.newTestRunner(processor);
testRunner.enqueue("foo".getBytes("UTF-8"));
testRunner.run();
Set<Relationship> relationships = processor.getRelationships();
assertTrue(relationships.contains(ExtractText.REL_MATCH));
assertTrue(relationships.contains(ExtractText.REL_NO_MATCH));
assertEquals(2, relationships.size());
}
Aggregations