/** * So as not to heap up list of taken parameters, we are passing combi, but we expect to see CsvInput class instances * in it's content. */ private int processRows( StepMetaDataCombi combi ) throws Exception { CsvInput csvInput = (CsvInput) combi.step; CsvInputData stepData = (CsvInputData) combi.data; CsvInputMeta stepMeta = (CsvInputMeta) combi.meta; final int[] writtenRows = { 0 }; csvInput.addRowListener( new RowAdapter() { @Override public void rowWrittenEvent( RowMetaInterface rowMeta, Object[] row ) throws KettleStepException { writtenRows[ 0 ]++; } } ); boolean haveRowsToRead; do { haveRowsToRead = !csvInput.processRow( stepMeta, stepData ); } while ( !haveRowsToRead ); csvInput.dispose( stepMeta, stepData ); return writtenRows[ 0 ]; }
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() ); }