@Test public void editConnection_NameDoesNotExist() throws Exception { final String dbName = "name"; List<UIDatabaseConnection> selectedConnection = createSelectedConnectionList( dbName ); when( connectionsTable.<UIDatabaseConnection>getSelectedItems() ).thenReturn( selectedConnection ); when( repository.getDatabaseID( dbName ) ).thenReturn( new StringObjectId( "existing" ) ); when( databaseDialog.open() ).thenReturn( "non-existing-name" ); controller.editConnection(); assertRepositorySavedDb(); }
public void editConnection() { try { Collection<UIDatabaseConnection> connections = connectionsTable.getSelectedItems(); if ( connections != null && !connections.isEmpty() ) { DatabaseMeta databaseMeta = ( (UIDatabaseConnection) connections.toArray()[0] ).getDatabaseMeta(); ObjectId idDatabase = repository.getDatabaseID( databaseMeta.getName() ); if ( idDatabase == null ) { MessageBox mb = new MessageBox( shell, SWT.ICON_ERROR | SWT.OK ); mb.setMessage( BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Edit.DoesNotExists.Message" ) ); mb.setText( BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Edit.DoesNotExists.Title" ) ); mb.open(); } else { getDatabaseDialog().setDatabaseMeta( databaseMeta ); String dbName = getDatabaseDialog().open(); if ( dbName != null ) { dbName = dbName.trim(); if ( !dbName.isEmpty() ) { ObjectId idRenamed = repository.getDatabaseID( dbName ); if ( idRenamed == null || idRenamed.equals( idDatabase ) ) { repository.insertLogEntry( BaseMessages.getString( PKG, "ConnectionsController.Message.UpdatingDatabase", databaseMeta.getName() ) ); repository.save( databaseMeta, Const.VERSION_COMMENT_EDIT_VERSION, null ); } else { showAlreadyExistsMessage(); } } } } } else { MessageBox mb = new MessageBox( shell, SWT.ICON_ERROR | SWT.OK ); mb.setMessage( BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Edit.NoItemSelected.Message" ) ); mb .setText( BaseMessages .getString( PKG, "RepositoryExplorerDialog.Connection.Edit.NoItemSelected.Title" ) ); mb.open(); } } catch ( KettleException e ) { if ( mainController == null || !mainController.handleLostRepository( e ) ) { new ErrorDialog( shell, BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Create.UnexpectedError.Title" ), BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Edit.UnexpectedError.Message" ), e ); } } finally { refreshConnectionList(); } }
ConnectionsController extends LazilyInitializedController implements IUISupportController { public void editConnection() { try { Collection<UIDatabaseConnection> connections = connectionsTable.getSelectedItems(); if ( connections != null && !connections.isEmpty() ) { DatabaseMeta databaseMeta = ( (UIDatabaseConnection) connections.toArray()[0] ).getDatabaseMeta(); ObjectId idDatabase = repository.getDatabaseID( databaseMeta.getName() ); if ( idDatabase == null ) { MessageBox mb = new MessageBox( shell, SWT.ICON_ERROR | SWT.OK ); mb.setMessage( BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Edit.DoesNotExists.Message" ) ); mb.setText( BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Edit.DoesNotExists.Title" ) ); mb.open(); } else { getDatabaseDialog().setDatabaseMeta( databaseMeta ); String dbName = getDatabaseDialog().open(); if ( dbName != null ) { dbName = dbName.trim(); if ( !dbName.isEmpty() ) { ObjectId idRenamed = repository.getDatabaseID( dbName ); if ( idRenamed == null || idRenamed.equals( idDatabase ) ) { repository.insertLogEntry( BaseMessages.getString( PKG, "ConnectionsController.Message.UpdatingDatabase", databaseMeta.getName() ) ); repository.save( databaseMeta, Const.VERSION_COMMENT_EDIT_VERSION, null ); } else { showAlreadyExistsMessage(); } } } } } else { MessageBox mb = new MessageBox( shell, SWT.ICON_ERROR | SWT.OK ); mb.setMessage( BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Edit.NoItemSelected.Message" ) ); mb .setText( BaseMessages .getString( PKG, "RepositoryExplorerDialog.Connection.Edit.NoItemSelected.Title" ) ); mb.open(); } } catch ( KettleException e ) { if ( mainController == null || !mainController.handleLostRepository( e ) ) { new ErrorDialog( shell, BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Create.UnexpectedError.Title" ), BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Edit.UnexpectedError.Message" ), e ); } } finally { refreshConnectionList(); } } }
ConnectionsController extends LazilyInitializedController implements IUISupportController { public void editConnection() { try { Collection<UIDatabaseConnection> connections = connectionsTable.getSelectedItems(); if ( connections != null && !connections.isEmpty() ) { DatabaseMeta databaseMeta = ( (UIDatabaseConnection) connections.toArray()[0] ).getDatabaseMeta(); ObjectId idDatabase = repository.getDatabaseID( databaseMeta.getName() ); if ( idDatabase == null ) { MessageBox mb = new MessageBox( shell, SWT.ICON_ERROR | SWT.OK ); mb.setMessage( BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Edit.DoesNotExists.Message" ) ); mb.setText( BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Edit.DoesNotExists.Title" ) ); mb.open(); } else { getDatabaseDialog().setDatabaseMeta( databaseMeta ); String dbName = getDatabaseDialog().open(); if ( dbName != null ) { dbName = dbName.trim(); if ( !dbName.isEmpty() ) { ObjectId idRenamed = repository.getDatabaseID( dbName ); if ( idRenamed == null || idRenamed.equals( idDatabase ) ) { repository.insertLogEntry( BaseMessages.getString( PKG, "ConnectionsController.Message.UpdatingDatabase", databaseMeta.getName() ) ); repository.save( databaseMeta, Const.VERSION_COMMENT_EDIT_VERSION, null ); } else { showAlreadyExistsMessage(); } } } } } else { MessageBox mb = new MessageBox( shell, SWT.ICON_ERROR | SWT.OK ); mb.setMessage( BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Edit.NoItemSelected.Message" ) ); mb .setText( BaseMessages .getString( PKG, "RepositoryExplorerDialog.Connection.Edit.NoItemSelected.Title" ) ); mb.open(); } } catch ( KettleException e ) { if ( mainController == null || !mainController.handleLostRepository( e ) ) { new ErrorDialog( shell, BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Create.UnexpectedError.Title" ), BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Edit.UnexpectedError.Message" ), e ); } } finally { refreshConnectionList(); } } ConnectionsController(); }
ConnectionsController extends LazilyInitializedController implements IUISupportController { public void editConnection() { try { Collection<UIDatabaseConnection> connections = connectionsTable.getSelectedItems(); if ( connections != null && !connections.isEmpty() ) { DatabaseMeta databaseMeta = ( (UIDatabaseConnection) connections.toArray()[0] ).getDatabaseMeta(); ObjectId idDatabase = repository.getDatabaseID( databaseMeta.getName() ); if ( idDatabase == null ) { MessageBox mb = new MessageBox( shell, SWT.ICON_ERROR | SWT.OK ); mb.setMessage( BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Edit.DoesNotExists.Message" ) ); mb.setText( BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Edit.DoesNotExists.Title" ) ); mb.open(); } else { getDatabaseDialog().setDatabaseMeta( databaseMeta ); String dbName = getDatabaseDialog().open(); if ( dbName != null ) { dbName = dbName.trim(); if ( !dbName.isEmpty() ) { ObjectId idRenamed = repository.getDatabaseID( dbName ); if ( idRenamed == null || idRenamed.equals( idDatabase ) ) { repository.insertLogEntry( BaseMessages.getString( PKG, "ConnectionsController.Message.UpdatingDatabase", databaseMeta.getName() ) ); repository.save( databaseMeta, Const.VERSION_COMMENT_EDIT_VERSION, null ); } else { showAlreadyExistsMessage(); } } } } } else { MessageBox mb = new MessageBox( shell, SWT.ICON_ERROR | SWT.OK ); mb.setMessage( BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Edit.NoItemSelected.Message" ) ); mb .setText( BaseMessages .getString( PKG, "RepositoryExplorerDialog.Connection.Edit.NoItemSelected.Title" ) ); mb.open(); } } catch ( KettleException e ) { if ( mainController == null || !mainController.handleLostRepository( e ) ) { new ErrorDialog( shell, BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Create.UnexpectedError.Title" ), BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Edit.UnexpectedError.Message" ), e ); } } finally { refreshConnectionList(); } } ConnectionsController(); @Override String getName(); @Override void init( Repository repository ); Repository getRepository(); void setRepReadOnly( boolean isRepReadOnly ); boolean isRepReadOnly(); void createConnection(); void addContextChangeVetoer( ContextChangeVetoer listener ); void removeContextChangeVetoer( ContextChangeVetoer listener ); void editConnection(); void removeConnection(); void setSelectedConnections( List<UIDatabaseConnection> connections ); List<UIDatabaseConnection> getRepositoryConnections(); void setRepositoryConnections( List<UIDatabaseConnection> connections ); void enableButtons( boolean enableNew, boolean enableEdit, boolean enableRemove ); void tabClicked(); }
ConnectionsController extends LazilyInitializedController implements IUISupportController { public void editConnection() { try { Collection<UIDatabaseConnection> connections = connectionsTable.getSelectedItems(); if ( connections != null && !connections.isEmpty() ) { DatabaseMeta databaseMeta = ( (UIDatabaseConnection) connections.toArray()[0] ).getDatabaseMeta(); ObjectId idDatabase = repository.getDatabaseID( databaseMeta.getName() ); if ( idDatabase == null ) { MessageBox mb = new MessageBox( shell, SWT.ICON_ERROR | SWT.OK ); mb.setMessage( BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Edit.DoesNotExists.Message" ) ); mb.setText( BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Edit.DoesNotExists.Title" ) ); mb.open(); } else { getDatabaseDialog().setDatabaseMeta( databaseMeta ); String dbName = getDatabaseDialog().open(); if ( dbName != null ) { dbName = dbName.trim(); if ( !dbName.isEmpty() ) { ObjectId idRenamed = repository.getDatabaseID( dbName ); if ( idRenamed == null || idRenamed.equals( idDatabase ) ) { repository.insertLogEntry( BaseMessages.getString( PKG, "ConnectionsController.Message.UpdatingDatabase", databaseMeta.getName() ) ); repository.save( databaseMeta, Const.VERSION_COMMENT_EDIT_VERSION, null ); } else { showAlreadyExistsMessage(); } } } } } else { MessageBox mb = new MessageBox( shell, SWT.ICON_ERROR | SWT.OK ); mb.setMessage( BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Edit.NoItemSelected.Message" ) ); mb .setText( BaseMessages .getString( PKG, "RepositoryExplorerDialog.Connection.Edit.NoItemSelected.Title" ) ); mb.open(); } } catch ( KettleException e ) { if ( mainController == null || !mainController.handleLostRepository( e ) ) { new ErrorDialog( shell, BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Create.UnexpectedError.Title" ), BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Edit.UnexpectedError.Message" ), e ); } } finally { refreshConnectionList(); } } ConnectionsController(); @Override String getName(); @Override void init( Repository repository ); Repository getRepository(); void setRepReadOnly( boolean isRepReadOnly ); boolean isRepReadOnly(); void createConnection(); void addContextChangeVetoer( ContextChangeVetoer listener ); void removeContextChangeVetoer( ContextChangeVetoer listener ); void editConnection(); void removeConnection(); void setSelectedConnections( List<UIDatabaseConnection> connections ); List<UIDatabaseConnection> getRepositoryConnections(); void setRepositoryConnections( List<UIDatabaseConnection> connections ); void enableButtons( boolean enableNew, boolean enableEdit, boolean enableRemove ); void tabClicked();  }