Search in sources :

Example 31 with Relationship

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

Example 32 with Relationship

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

Example 33 with Relationship

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

Example 34 with Relationship

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));
}
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 35 with Relationship

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