Thursday 12 October 2017

How to Test a Processor Using MyProcessorTest in NiFi (Intellij/Windows)

This guide explains how to test a processor in Apache NiRi using the provided test class generated for MyProcessor. This guide is done by providing a typical problem and giving the solution, like a Q&A and will be updated as I figure out how to do things.

How to queue a file to test input?
public void testProcessor() {
    try {
        testRunner.enqueue(new FileInputStream(new File("src/test/data/your_data.txt")));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    testRunner.run();
}

How to set properties?
public void testProcessor() {

    testRunner.setProperty(MyProcessor.MY_PROPERTY , "value");
    testRunner.run();

}
How to set Flowfile attributes
public void testProcessor() {

    Map< String, String > attributes = new HashMap<>();
    attributes.put( "datasource_id", "2" );
    try {
        testRunner.enqueue(new FileInputStream(new File("src/test/data/108124118589781")), attributes);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    testRunner.run();
}

No comments:

Post a Comment