private TextFileInputField[] getInputFileFields() { return createInputFileFields( "Header1", "Header2" ); } }
@Test public void testASCII() throws Exception { doTest( ASCII, ASCII, TEST_DATA ); }
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() ); }
private CsvInputMeta createStepMeta( final String testFilePath, final String encoding ) { final CsvInputMeta meta = new CsvInputMeta(); meta.setFilename( testFilePath ); meta.setDelimiter( "\t" ); meta.setEncoding( encoding ); meta.setEnclosure( "\"" ); meta.setBufferSize( "50000" ); meta.setInputFields( getInputFileFields() ); meta.setHeaderPresent( true ); return meta; }
@Test public void testUTF8() throws Exception { doTest( UTF8, UTF8, TEST_DATA ); }
@Test public void testUTF16BE() throws Exception { doTest( UTF16BE, UTF16BE, TEST_DATA ); }
@Test public void testUTF16LE() throws Exception { doTest( UTF16LE, UTF16LE, TEST_DATA ); }