Search in sources :

Example 11 with BufferedOutputStream

use of org.apache.nifi.stream.io.BufferedOutputStream in project nifi by apache.

the class TestSplitJson method testSplit_pathToArrayWithNulls_emptyStringRepresentation.

@Test
public void testSplit_pathToArrayWithNulls_emptyStringRepresentation() throws Exception {
    final TestRunner testRunner = TestRunners.newTestRunner(new SplitJson());
    testRunner.setProperty(SplitJson.ARRAY_JSON_PATH_EXPRESSION, "$.arrayOfNulls");
    ProcessSession session = testRunner.getProcessSessionFactory().createSession();
    FlowFile ff = session.create();
    ff = session.write(ff, new OutputStreamCallback() {

        @Override
        public void process(OutputStream out) throws IOException {
            try (OutputStream outputStream = new BufferedOutputStream(out)) {
                outputStream.write("{\"stringField\": \"String Value\", \"arrayOfNulls\": [null, null, null]}".getBytes(StandardCharsets.UTF_8));
            }
        }
    });
    testRunner.enqueue(ff);
    testRunner.run();
    /* assert that three files were transferred to split and each is empty */
    int expectedFiles = 3;
    testRunner.assertTransferCount(SplitJson.REL_SPLIT, expectedFiles);
    for (int i = 0; i < expectedFiles; i++) {
        testRunner.getFlowFilesForRelationship(SplitJson.REL_SPLIT).get(i).assertContentEquals("");
    }
}
Also used : ProcessSession(org.apache.nifi.processor.ProcessSession) FlowFile(org.apache.nifi.flowfile.FlowFile) MockFlowFile(org.apache.nifi.util.MockFlowFile) TestRunner(org.apache.nifi.util.TestRunner) OutputStream(java.io.OutputStream) BufferedOutputStream(org.apache.nifi.stream.io.BufferedOutputStream) OutputStreamCallback(org.apache.nifi.processor.io.OutputStreamCallback) BufferedOutputStream(org.apache.nifi.stream.io.BufferedOutputStream) Test(org.junit.Test)

Aggregations

OutputStream (java.io.OutputStream)11 FlowFile (org.apache.nifi.flowfile.FlowFile)11 BufferedOutputStream (org.apache.nifi.stream.io.BufferedOutputStream)11 OutputStreamCallback (org.apache.nifi.processor.io.OutputStreamCallback)10 ProcessSession (org.apache.nifi.processor.ProcessSession)6 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5 ProcessException (org.apache.nifi.processor.exception.ProcessException)5 MockFlowFile (org.apache.nifi.util.MockFlowFile)5 TestRunner (org.apache.nifi.util.TestRunner)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)4 Map (java.util.Map)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 ComponentLog (org.apache.nifi.logging.ComponentLog)3 InputStreamCallback (org.apache.nifi.processor.io.InputStreamCallback)3 BufferedInputStream (org.apache.nifi.stream.io.BufferedInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 StringReader (java.io.StringReader)2 ArrayList (java.util.ArrayList)2