public void createConnection() {
    try {
      DatabaseMeta databaseMeta = new DatabaseMeta();
      databaseMeta.initializeVariablesFrom( null );
      getDatabaseDialog().setDatabaseMeta( databaseMeta );

      String dbName = getDatabaseDialog().open();
      if ( dbName != null ) {
        dbName = dbName.trim();
        databaseMeta.setName( dbName );
        databaseMeta.setDisplayName( dbName );
        getDatabaseDialog().setDatabaseMeta( databaseMeta );

        if ( !dbName.isEmpty() ) {
          // See if this user connection exists...
          ObjectId idDatabase = repository.getDatabaseID( dbName );
          if ( idDatabase == null ) {
            repository.insertLogEntry( BaseMessages.getString(
              PKG, "ConnectionsController.Message.CreatingDatabase", getDatabaseDialog()
                .getDatabaseMeta().getName() ) );
            repository.save( getDatabaseDialog().getDatabaseMeta(), Const.VERSION_COMMENT_INITIAL_VERSION, null );
            reloadLoadedJobsAndTransformations();
          } else {
            showAlreadyExistsMessage();
          }
        }
      }
      // We should be able to tell the difference between a cancel and an empty database name
      //
      // else {
      // MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
      // mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Connection.Edit.MissingName.Message"));
      // mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Connection.Edit.MissingName.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.Create.UnexpectedError.Message" ), e );
      }
    } finally {
      refreshConnectionList();
    }
  }
@Test
  public void createConnection_NameExists() throws Exception {
    final String dbName = "name";

    when( databaseDialog.open() ).thenReturn( dbName );
    when( databaseMeta.getDatabaseName() ).thenReturn( dbName );
    when( repository.getDatabaseID( dbName ) ).thenReturn( new StringObjectId( "existing" ) );

    controller.createConnection();
    assertShowedAlreadyExistsMessage();
  }