Skip to content

Commit

Permalink
NIFI-4916 - ConvertExcelToCSVProcessor inherit parent attributes. This
Browse files Browse the repository at this point in the history
…closes #2500.

Signed-off-by: Mark Payne <markap14@hotmail.com>
  • Loading branch information
pvillard31 authored and markap14 committed Mar 2, 2018
1 parent b4a4cc5 commit c58b025
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Expand Up @@ -292,7 +292,7 @@ public void process(InputStream inputStream) throws IOException {
private void handleExcelSheet(ProcessSession session, FlowFile originalParentFF, final InputStream sheetInputStream, ExcelSheetReadConfig readConfig,
CSVFormat csvFormat) throws IOException {

FlowFile ff = session.create();
FlowFile ff = session.create(originalParentFF);
try {
final DataFormatter formatter = new DataFormatter();
final InputSource sheetSource = new InputSource(sheetInputStream);
Expand Down
Expand Up @@ -20,7 +20,9 @@
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.nifi.csv.CSVUtils;
import org.apache.nifi.flowfile.attributes.CoreAttributes;
Expand All @@ -44,7 +46,10 @@ public void init() {
@Test
public void testMultipleSheetsGeneratesMultipleFlowFiles() throws Exception {

testRunner.enqueue(new File("src/test/resources/TwoSheets.xlsx").toPath());
Map<String, String> attributes = new HashMap<String, String>();
attributes.put("test", "attribute");

testRunner.enqueue(new File("src/test/resources/TwoSheets.xlsx").toPath(), attributes);
testRunner.run();

testRunner.assertTransferCount(ConvertExcelToCSVProcessor.SUCCESS, 2);
Expand All @@ -59,6 +64,7 @@ public void testMultipleSheetsGeneratesMultipleFlowFiles() throws Exception {

//Since TestRunner.run() will create a random filename even if the attribute is set in enqueue manually we just check that "_{SHEETNAME}.csv is present
assertTrue(ffSheetA.getAttribute(CoreAttributes.FILENAME.key()).endsWith("_TestSheetA.csv"));
assertTrue(ffSheetA.getAttribute("test").equals("attribute"));

MockFlowFile ffSheetB = testRunner.getFlowFilesForRelationship(ConvertExcelToCSVProcessor.SUCCESS).get(1);
Long rowsSheetB = new Long(ffSheetB.getAttribute(ConvertExcelToCSVProcessor.ROW_NUM));
Expand All @@ -68,6 +74,7 @@ public void testMultipleSheetsGeneratesMultipleFlowFiles() throws Exception {

//Since TestRunner.run() will create a random filename even if the attribute is set in enqueue manually we just check that "_{SHEETNAME}.csv is present
assertTrue(ffSheetB.getAttribute(CoreAttributes.FILENAME.key()).endsWith("_TestSheetB.csv"));
assertTrue(ffSheetB.getAttribute("test").equals("attribute"));

}

Expand Down

0 comments on commit c58b025

Please sign in to comment.