Search in sources :

Example 21 with MockRecordWriter

use of org.apache.nifi.serialization.record.MockRecordWriter in project nifi by apache.

the class TestConvertRecord method testSuccessfulConversion.

@Test
public void testSuccessfulConversion() throws InitializationException {
    final MockRecordParser readerService = new MockRecordParser();
    final MockRecordWriter writerService = new MockRecordWriter("header", false);
    final TestRunner runner = TestRunners.newTestRunner(ConvertRecord.class);
    runner.addControllerService("reader", readerService);
    runner.enableControllerService(readerService);
    runner.addControllerService("writer", writerService);
    runner.enableControllerService(writerService);
    runner.setProperty(ConvertRecord.RECORD_READER, "reader");
    runner.setProperty(ConvertRecord.RECORD_WRITER, "writer");
    readerService.addSchemaField("name", RecordFieldType.STRING);
    readerService.addSchemaField("age", RecordFieldType.INT);
    readerService.addRecord("John Doe", 48);
    readerService.addRecord("Jane Doe", 47);
    readerService.addRecord("Jimmy Doe", 14);
    runner.enqueue("");
    runner.run();
    runner.assertAllFlowFilesTransferred(ConvertRecord.REL_SUCCESS, 1);
    final MockFlowFile out = runner.getFlowFilesForRelationship(ConvertRecord.REL_SUCCESS).get(0);
    out.assertAttributeEquals("record.count", "3");
    out.assertAttributeEquals("mime.type", "text/plain");
    out.assertContentEquals("header\nJohn Doe,48\nJane Doe,47\nJimmy Doe,14\n");
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) TestRunner(org.apache.nifi.util.TestRunner) MockRecordWriter(org.apache.nifi.serialization.record.MockRecordWriter) MockRecordParser(org.apache.nifi.serialization.record.MockRecordParser) Test(org.junit.Test)

Aggregations

MockRecordWriter (org.apache.nifi.serialization.record.MockRecordWriter)21 MockRecordParser (org.apache.nifi.serialization.record.MockRecordParser)16 Test (org.junit.Test)13 TestRunner (org.apache.nifi.util.TestRunner)12 MockFlowFile (org.apache.nifi.util.MockFlowFile)11 Before (org.junit.Before)7 JsonTreeReader (org.apache.nifi.json.JsonTreeReader)2 RecordReaderFactory (org.apache.nifi.serialization.RecordReaderFactory)2 RecordSetWriterFactory (org.apache.nifi.serialization.RecordSetWriterFactory)2 List (java.util.List)1 MockDruidTranquilityController (org.apache.nifi.controller.druid.MockDruidTranquilityController)1 StandardEvent (org.apache.nifi.processor.util.listen.event.StandardEvent)1 InitializationException (org.apache.nifi.reporting.InitializationException)1 CommaSeparatedRecordReader (org.apache.nifi.serialization.record.CommaSeparatedRecordReader)1 RecordFieldType (org.apache.nifi.serialization.record.RecordFieldType)1 TestRunners (org.apache.nifi.util.TestRunners)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertTrue (org.junit.Assert.assertTrue)1