use of org.apache.nifi.processor.Relationship in project nifi by apache.
the class TestEvaluateJsonPath method testExtractPath_destinationAttribute.
@Test
public void testExtractPath_destinationAttribute() throws Exception {
String jsonPathAttrKey = "JsonPath";
final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateJsonPath());
testRunner.setProperty(EvaluateJsonPath.DESTINATION, EvaluateJsonPath.DESTINATION_ATTRIBUTE);
testRunner.setProperty(jsonPathAttrKey, "$[0]._id");
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", "54df94072d5dbf7dc6340cc5", out.getAttribute(jsonPathAttrKey));
}
use of org.apache.nifi.processor.Relationship in project nifi by apache.
the class TestEvaluateJsonPath method testExtractPath_destinationContent_indefiniteResult_operators.
@Test
public void testExtractPath_destinationContent_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]");
}
use of org.apache.nifi.processor.Relationship in project nifi by apache.
the class TestEvaluateJsonPath method testExtractPath_destinationAttributes_twoPaths_notFound.
@Test
public void testExtractPath_destinationAttributes_twoPaths_notFound() 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.nonexistent");
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", "", out.getAttribute(jsonPathIdAttrKey));
Assert.assertEquals("Transferred flow file did not have the correct result for name attribute", "", out.getAttribute(jsonPathNameAttrKey));
}
use of org.apache.nifi.processor.Relationship in project nifi by apache.
the class TestEvaluateJsonPath method testRouteFailure_returnTypeScalar_resultArray.
@Test
public void testRouteFailure_returnTypeScalar_resultArray() throws Exception {
String jsonPathAttrKey = "friends.indefinite.id.list";
final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateJsonPath());
testRunner.setProperty(EvaluateJsonPath.RETURN_TYPE, EvaluateJsonPath.RETURN_TYPE_SCALAR);
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_FAILURE;
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 TestRouteText method testRelationships.
@Test
public void testRelationships() throws IOException {
final TestRunner runner = TestRunners.newTestRunner(new RouteText());
runner.setProperty(RouteText.MATCH_STRATEGY, RouteText.STARTS_WITH);
runner.setProperty(RouteText.ROUTE_STRATEGY, RouteText.ROUTE_TO_MATCHED_WHEN_ANY_PROPERTY_MATCHES);
runner.setProperty("simple", "start");
runner.run();
Set<Relationship> relationshipSet = runner.getProcessor().getRelationships();
Set<String> expectedRelationships = new HashSet<>(Arrays.asList("matched", "unmatched", "original"));
assertEquals(expectedRelationships.size(), relationshipSet.size());
for (Relationship relationship : relationshipSet) {
assertTrue(expectedRelationships.contains(relationship.getName()));
}
runner.setProperty(RouteText.ROUTE_STRATEGY, RouteText.ROUTE_TO_MATCHING_PROPERTY_NAME);
relationshipSet = runner.getProcessor().getRelationships();
expectedRelationships = new HashSet<>(Arrays.asList("simple", "unmatched", "original"));
assertEquals(expectedRelationships.size(), relationshipSet.size());
for (Relationship relationship : relationshipSet) {
assertTrue(expectedRelationships.contains(relationship.getName()));
}
runner.run();
}
Aggregations