/** * Initialize for processing specified file. */ protected void init( String file ) throws Exception { meta.setFilename( getFile( file ).getURL().getFile() ); step = new CsvInput( stepMeta, null, 1, transMeta, trans ); step.init( meta, data ); step.addRowListener( rowListener ); }
private StepMetaDataCombi createBaseCombi( File sharedFile, boolean headerPresent, String delimiter ) { StepMetaDataCombi combi = new StepMetaDataCombi(); CsvInputData data = new CsvInputData(); CsvInputMeta meta = createMeta( sharedFile, createInputFileFields( "Field_000", "Field_001" ), headerPresent, delimiter ); CsvInput csvInput = createCsvInput(); csvInput.init( meta, data ); combi.step = csvInput; combi.data = data; combi.meta = meta; return combi; }
public void doTest( File file ) throws Exception { CsvInputData data = new CsvInputData(); CsvInputMeta meta = createMeta( file, createInputFileFields( "a", "b" ) ); List<Object[]> actual; try { csvInput.init( meta, data ); actual = TransTestingUtil.execute( csvInput, meta, data, 2, false ); } finally { csvInput.dispose( meta, data ); } List<Object[]> expected = Arrays.asList( new Object[] { "a", "b", 1L }, new Object[] { "a", null, 2L } ); TransTestingUtil.assertResult( expected, actual ); }
private void doTest( final String fileEncoding, final String stepEncoding, final String testData, final String delimiter, final boolean useHeader ) throws Exception { String testFilePath = createTestFile( fileEncoding, testData ).getAbsolutePath(); CsvInputMeta meta = createStepMeta( testFilePath, stepEncoding, delimiter, useHeader ); CsvInputData data = new CsvInputData(); CsvInput csvInput = new CsvInput( stepMockHelper.stepMeta, stepMockHelper.stepDataInterface, 0, stepMockHelper.transMeta, stepMockHelper.trans ); csvInput.init( meta, data ); csvInput.addRowListener( new RowAdapter() { @Override public void rowWrittenEvent( RowMetaInterface rowMeta, Object[] row ) throws KettleStepException { for ( int i = 0; i < rowMeta.size(); i++ ) { Assert.assertEquals( "Value", row[ i ] ); } } } ); boolean haveRowsToRead; do { haveRowsToRead = !csvInput.processRow( meta, data ); } while ( !haveRowsToRead ); csvInput.dispose( meta, data ); Assert.assertEquals( 2, csvInput.getLinesWritten() ); }
private void doTest( final String fileEncoding, final String stepEncoding, final String testData ) throws Exception { String testFilePath = createTestFile( fileEncoding, testData ).getAbsolutePath(); CsvInputMeta meta = createStepMeta( testFilePath, stepEncoding ); CsvInputData data = new CsvInputData(); CsvInput csvInput = new CsvInput( stepMockHelper.stepMeta, stepMockHelper.stepDataInterface, 0, stepMockHelper.transMeta, stepMockHelper.trans ); csvInput.init( meta, data ); csvInput.addRowListener( new RowAdapter() { @Override public void rowWrittenEvent( RowMetaInterface rowMeta, Object[] row ) throws KettleStepException { for ( int i = 0; i < rowMeta.size(); i++ ) { assertEquals( "Value", row[ i ] ); } } } ); boolean haveRowsToRead; do { haveRowsToRead = !csvInput.processRow( meta, data ); } while ( !haveRowsToRead ); csvInput.dispose( meta, data ); assertEquals( 2, csvInput.getLinesWritten() ); }
public void doTest( String content, String enclosure ) throws Exception { RowSet output = new QueueRowSet(); File tmp = createTestFile( "utf-8", content ); try { CsvInputMeta meta = createMeta( tmp, createInputFileFields( "f1", "f2" ), enclosure ); CsvInputData data = new CsvInputData(); csvInput.init( meta, data ); csvInput.addRowSetToOutputRowSets( output ); try { csvInput.processRow( meta, data ); } finally { csvInput.dispose( meta, data ); } } finally { tmp.delete(); } Object[] row = output.getRowImmediate(); assertNotNull( row ); assertEquals( "value1", row[ 0 ] ); assertEquals( "value2", row[ 1 ] ); assertNull( output.getRowImmediate() ); }
public void doTest( String content, String[] expected ) throws Exception { RowSet output = new QueueRowSet(); File tmp = createTestFile( encoding, content ); try { CsvInputMeta meta = createMeta( tmp, createInputFileFields( "f1", "f2", "f3" ) ); CsvInputData data = new CsvInputData(); csvInput.init( meta, data ); csvInput.addRowSetToOutputRowSets( output ); try { csvInput.processRow( meta, data ); } finally { csvInput.dispose( meta, data ); } } finally { tmp.delete(); } Object[] row = output.getRowImmediate(); assertNotNull( row ); assertEquals( expected[0], row[0] ); assertEquals( expected[1], row[1] ); assertEquals( expected[2], row[2] ); assertNull( output.getRowImmediate() ); }
private void doTest( String content ) throws Exception { RowSet output = new QueueRowSet(); File tmp = createTestFile( "utf-8", content ); try { CsvInputMeta meta = createMeta( tmp, createInputFileFields( "f1", "f2", "f3" ) ); CsvInputData data = new CsvInputData(); csvInput.init( meta, data ); csvInput.addRowSetToOutputRowSets( output ); try { csvInput.processRow( meta, data ); } finally { csvInput.dispose( meta, data ); } } finally { tmp.delete(); } Object[] row = output.getRowImmediate(); assertNotNull( row ); assertEquals( "value1", row[ 0 ] ); assertEquals( "value2", row[ 1 ] ); assertEquals( "value3", row[ 2 ] ); assertNull( output.getRowImmediate() ); }