Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NIFI-4916 - ConvertExcelToCSVProcessor inherit parent attributes #2500

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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