@Test public void getFieldsTest() throws Exception { ExcelInputDialog dialog = Mockito.mock( ExcelInputDialog.class ); RowMeta fields = new RowMeta(); ExcelInputMeta info = Mockito.mock( ExcelInputMeta.class ); Mockito.doReturn( true ).when( info ).readAllSheets(); int[] startColumn = {0}; Mockito.doReturn( startColumn ).when( info ).getStartColumn(); int[] startRow = {0}; Mockito.doReturn( startRow ).when( info ).getStartRow(); KWorkbook workbook = Mockito.mock( KWorkbook.class ); Mockito.doReturn( 1 ).when( workbook ).getNumberOfSheets(); KSheet sheet = Mockito.mock( KSheet.class ); Mockito.doReturn( sheet ).when( workbook ).getSheet( 0 ); KCell cell = Mockito.mock( KCell.class ); int fieldCount = 400; for ( int i = 0; i <= fieldCount - 1; i++ ) { Mockito.doReturn( cell ).when( sheet ).getCell( i, 0 ); Mockito.doReturn( cell ).when( sheet ).getCell( i, 1 ); } Mockito.doReturn( "testValue" ).when( cell ).getContents(); Mockito.doReturn( KCellType.NUMBER ).when( cell ).getType(); PluginRegistry pluginRegistry = Mockito.mock( PluginRegistry.class ); PluginInterface stringPlugin = Mockito.mock( PluginInterface.class ); Mockito.doReturn( stringPlugin ).when( pluginRegistry ).getPlugin( ValueMetaPluginType.class, "1" ); Mockito.doReturn( Mockito.mock( ValueMetaInterface.class ) ).when( pluginRegistry ). loadClass( stringPlugin, ValueMetaInterface.class ); ValueMetaFactory.pluginRegistry = pluginRegistry; Method processingWorkbookMethod = ExcelInputDialog.class.getDeclaredMethod( "processingWorkbook", RowMetaInterface.class, ExcelInputMeta.class, KWorkbook.class ); processingWorkbookMethod.setAccessible( true ); processingWorkbookMethod.invoke( dialog, fields, info, workbook ); Assert.assertEquals( fieldCount, fields.size() ); }
public void getFields() { RowMetaInterface fields = new RowMeta(); ExcelInputMeta info = new ExcelInputMeta(); getInfo( info ); int clearFields = SWT.YES; if ( wFields.nrNonEmpty() > 0 ) { MessageBox messageBox = new MessageBox( shell, SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_QUESTION ); messageBox.setMessage( BaseMessages.getString( PKG, "ExcelInputDialog.ClearFieldList.DialogMessage" ) ); messageBox.setText( BaseMessages.getString( PKG, "ExcelInputDialog.ClearFieldList.DialogTitle" ) ); clearFields = messageBox.open(); if ( clearFields == SWT.CANCEL ) { return; } } FileInputList fileList = info.getFileList( transMeta ); for ( FileObject file : fileList.getFiles() ) { try { KWorkbook workbook = WorkbookFactory.getWorkbook( info.getSpreadSheetType(), KettleVFS.getFilename( file ), info .getEncoding() ); processingWorkbook( fields, info, workbook ); workbook.close(); } catch ( Exception e ) { new ErrorDialog( shell, BaseMessages.getString( PKG, "System.Dialog.Error.Title" ), BaseMessages .getString( PKG, "ExcelInputDialog.ErrorReadingFile2.DialogMessage", KettleVFS.getFilename( file ), e .toString() ), e ); } } if ( fields.size() > 0 ) { if ( clearFields == SWT.YES ) { wFields.clearAll( false ); } for ( int j = 0; j < fields.size(); j++ ) { ValueMetaInterface field = fields.getValueMeta( j ); wFields.add( new String[] { field.getName(), field.getTypeDesc(), "", "", "none", "N" } ); } wFields.removeEmptyRows(); wFields.setRowNums(); wFields.optWidth( true ); } else { MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_WARNING ); mb.setMessage( BaseMessages.getString( PKG, "ExcelInputDialog.UnableToFindFields.DialogMessage" ) ); mb.setText( BaseMessages.getString( PKG, "ExcelInputDialog.UnableToFindFields.DialogTitle" ) ); mb.open(); } checkAlerts(); }
ExcelInputDialog extends BaseStepDialog implements StepDialogInterface { public void getFields() { RowMetaInterface fields = new RowMeta(); ExcelInputMeta info = new ExcelInputMeta(); getInfo( info ); int clearFields = SWT.YES; if ( wFields.nrNonEmpty() > 0 ) { MessageBox messageBox = new MessageBox( shell, SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_QUESTION ); messageBox.setMessage( BaseMessages.getString( PKG, "ExcelInputDialog.ClearFieldList.DialogMessage" ) ); messageBox.setText( BaseMessages.getString( PKG, "ExcelInputDialog.ClearFieldList.DialogTitle" ) ); clearFields = messageBox.open(); if ( clearFields == SWT.CANCEL ) { return; } } FileInputList fileList = info.getFileList( transMeta ); for ( FileObject file : fileList.getFiles() ) { try { KWorkbook workbook = WorkbookFactory.getWorkbook( info.getSpreadSheetType(), KettleVFS.getFilename( file ), info .getEncoding() ); processingWorkbook( fields, info, workbook ); workbook.close(); } catch ( Exception e ) { new ErrorDialog( shell, BaseMessages.getString( PKG, "System.Dialog.Error.Title" ), BaseMessages .getString( PKG, "ExcelInputDialog.ErrorReadingFile2.DialogMessage", KettleVFS.getFilename( file ), e .toString() ), e ); } } if ( fields.size() > 0 ) { if ( clearFields == SWT.YES ) { wFields.clearAll( false ); } for ( int j = 0; j < fields.size(); j++ ) { ValueMetaInterface field = fields.getValueMeta( j ); wFields.add( new String[] { field.getName(), field.getTypeDesc(), "", "", "none", "N" } ); } wFields.removeEmptyRows(); wFields.setRowNums(); wFields.optWidth( true ); } else { MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_WARNING ); mb.setMessage( BaseMessages.getString( PKG, "ExcelInputDialog.UnableToFindFields.DialogMessage" ) ); mb.setText( BaseMessages.getString( PKG, "ExcelInputDialog.UnableToFindFields.DialogTitle" ) ); mb.open(); } checkAlerts(); } }
ExcelInputDialog extends BaseStepDialog implements StepDialogInterface { public void getFields() { RowMetaInterface fields = new RowMeta(); ExcelInputMeta info = new ExcelInputMeta(); getInfo( info ); int clearFields = SWT.YES; if ( wFields.nrNonEmpty() > 0 ) { MessageBox messageBox = new MessageBox( shell, SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_QUESTION ); messageBox.setMessage( BaseMessages.getString( PKG, "ExcelInputDialog.ClearFieldList.DialogMessage" ) ); messageBox.setText( BaseMessages.getString( PKG, "ExcelInputDialog.ClearFieldList.DialogTitle" ) ); clearFields = messageBox.open(); if ( clearFields == SWT.CANCEL ) { return; } } FileInputList fileList = info.getFileList( transMeta ); for ( FileObject file : fileList.getFiles() ) { try { KWorkbook workbook = WorkbookFactory.getWorkbook( info.getSpreadSheetType(), KettleVFS.getFilename( file ), info .getEncoding() ); processingWorkbook( fields, info, workbook ); workbook.close(); } catch ( Exception e ) { new ErrorDialog( shell, BaseMessages.getString( PKG, "System.Dialog.Error.Title" ), BaseMessages .getString( PKG, "ExcelInputDialog.ErrorReadingFile2.DialogMessage", KettleVFS.getFilename( file ), e .toString() ), e ); } } if ( fields.size() > 0 ) { if ( clearFields == SWT.YES ) { wFields.clearAll( false ); } for ( int j = 0; j < fields.size(); j++ ) { ValueMetaInterface field = fields.getValueMeta( j ); wFields.add( new String[] { field.getName(), field.getTypeDesc(), "", "", "none", "N" } ); } wFields.removeEmptyRows(); wFields.setRowNums(); wFields.optWidth( true ); } else { MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_WARNING ); mb.setMessage( BaseMessages.getString( PKG, "ExcelInputDialog.UnableToFindFields.DialogMessage" ) ); mb.setText( BaseMessages.getString( PKG, "ExcelInputDialog.UnableToFindFields.DialogTitle" ) ); mb.open(); } checkAlerts(); } ExcelInputDialog( Shell parent, Object in, TransMeta transMeta, String sname ); }
ExcelInputDialog extends BaseStepDialog implements StepDialogInterface { public void getFields() { RowMetaInterface fields = new RowMeta(); ExcelInputMeta info = new ExcelInputMeta(); getInfo( info ); int clearFields = SWT.YES; if ( wFields.nrNonEmpty() > 0 ) { MessageBox messageBox = new MessageBox( shell, SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_QUESTION ); messageBox.setMessage( BaseMessages.getString( PKG, "ExcelInputDialog.ClearFieldList.DialogMessage" ) ); messageBox.setText( BaseMessages.getString( PKG, "ExcelInputDialog.ClearFieldList.DialogTitle" ) ); clearFields = messageBox.open(); if ( clearFields == SWT.CANCEL ) { return; } } FileInputList fileList = info.getFileList( transMeta ); for ( FileObject file : fileList.getFiles() ) { try { KWorkbook workbook = WorkbookFactory.getWorkbook( info.getSpreadSheetType(), KettleVFS.getFilename( file ), info .getEncoding() ); processingWorkbook( fields, info, workbook ); workbook.close(); } catch ( Exception e ) { new ErrorDialog( shell, BaseMessages.getString( PKG, "System.Dialog.Error.Title" ), BaseMessages .getString( PKG, "ExcelInputDialog.ErrorReadingFile2.DialogMessage", KettleVFS.getFilename( file ), e .toString() ), e ); } } if ( fields.size() > 0 ) { if ( clearFields == SWT.YES ) { wFields.clearAll( false ); } for ( int j = 0; j < fields.size(); j++ ) { ValueMetaInterface field = fields.getValueMeta( j ); wFields.add( new String[] { field.getName(), field.getTypeDesc(), "", "", "none", "N" } ); } wFields.removeEmptyRows(); wFields.setRowNums(); wFields.optWidth( true ); } else { MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_WARNING ); mb.setMessage( BaseMessages.getString( PKG, "ExcelInputDialog.UnableToFindFields.DialogMessage" ) ); mb.setText( BaseMessages.getString( PKG, "ExcelInputDialog.UnableToFindFields.DialogTitle" ) ); mb.open(); } checkAlerts(); } ExcelInputDialog( Shell parent, Object in, TransMeta transMeta, String sname ); @Override String open(); void setFlags(); void getData( ExcelInputMeta meta ); void getSheets(); void getFields(); }
ExcelInputDialog extends BaseStepDialog implements StepDialogInterface { public void getFields() { RowMetaInterface fields = new RowMeta(); ExcelInputMeta info = new ExcelInputMeta(); getInfo( info ); int clearFields = SWT.YES; if ( wFields.nrNonEmpty() > 0 ) { MessageBox messageBox = new MessageBox( shell, SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_QUESTION ); messageBox.setMessage( BaseMessages.getString( PKG, "ExcelInputDialog.ClearFieldList.DialogMessage" ) ); messageBox.setText( BaseMessages.getString( PKG, "ExcelInputDialog.ClearFieldList.DialogTitle" ) ); clearFields = messageBox.open(); if ( clearFields == SWT.CANCEL ) { return; } } FileInputList fileList = info.getFileList( transMeta ); for ( FileObject file : fileList.getFiles() ) { try { KWorkbook workbook = WorkbookFactory.getWorkbook( info.getSpreadSheetType(), KettleVFS.getFilename( file ), info .getEncoding() ); processingWorkbook( fields, info, workbook ); workbook.close(); } catch ( Exception e ) { new ErrorDialog( shell, BaseMessages.getString( PKG, "System.Dialog.Error.Title" ), BaseMessages .getString( PKG, "ExcelInputDialog.ErrorReadingFile2.DialogMessage", KettleVFS.getFilename( file ), e .toString() ), e ); } } if ( fields.size() > 0 ) { if ( clearFields == SWT.YES ) { wFields.clearAll( false ); } for ( int j = 0; j < fields.size(); j++ ) { ValueMetaInterface field = fields.getValueMeta( j ); wFields.add( new String[] { field.getName(), field.getTypeDesc(), "", "", "none", "N" } ); } wFields.removeEmptyRows(); wFields.setRowNums(); wFields.optWidth( true ); } else { MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_WARNING ); mb.setMessage( BaseMessages.getString( PKG, "ExcelInputDialog.UnableToFindFields.DialogMessage" ) ); mb.setText( BaseMessages.getString( PKG, "ExcelInputDialog.UnableToFindFields.DialogTitle" ) ); mb.open(); } checkAlerts(); } ExcelInputDialog( Shell parent, Object in, TransMeta transMeta, String sname ); @Override String open(); void setFlags(); void getData( ExcelInputMeta meta ); void getSheets(); void getFields();  }