Search in sources :

Example 96 with Relationship

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));
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) TestRunner(org.apache.nifi.util.TestRunner) Relationship(org.apache.nifi.processor.Relationship) Test(org.junit.Test)

Example 97 with Relationship

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]");
}
Also used : TestRunner(org.apache.nifi.util.TestRunner) Relationship(org.apache.nifi.processor.Relationship) Test(org.junit.Test)

Example 98 with Relationship

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));
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) TestRunner(org.apache.nifi.util.TestRunner) Relationship(org.apache.nifi.processor.Relationship) Test(org.junit.Test)

Example 99 with Relationship

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);
}
Also used : TestRunner(org.apache.nifi.util.TestRunner) Relationship(org.apache.nifi.processor.Relationship) Test(org.junit.Test)

Example 100 with Relationship

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();
}
Also used : TestRunner(org.apache.nifi.util.TestRunner) Relationship(org.apache.nifi.processor.Relationship) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Relationship (org.apache.nifi.processor.Relationship)106 ArrayList (java.util.ArrayList)41 HashSet (java.util.HashSet)40 HashMap (java.util.HashMap)32 FlowFile (org.apache.nifi.flowfile.FlowFile)32 Map (java.util.Map)31 IOException (java.io.IOException)26 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)26 Test (org.junit.Test)23 List (java.util.List)20 Set (java.util.Set)19 Connection (org.apache.nifi.connectable.Connection)18 TestRunner (org.apache.nifi.util.TestRunner)18 ProcessException (org.apache.nifi.processor.exception.ProcessException)17 ProcessSession (org.apache.nifi.processor.ProcessSession)15 InputStream (java.io.InputStream)14 DynamicRelationship (org.apache.nifi.annotation.behavior.DynamicRelationship)12 Processor (org.apache.nifi.processor.Processor)12 Collections (java.util.Collections)11 AtomicLong (java.util.concurrent.atomic.AtomicLong)10