public static Connection OpenConnection( String serveur, int port, String username, String password,
      boolean useKey, String keyFilename, String passPhrase, int timeOut, VariableSpace space, String proxyhost,
      int proxyport, String proxyusername, String proxypassword ) throws KettleException {
    Connection conn = null;
    char[] content = null;
    boolean isAuthenticated = false;
    try {
      // perform some checks
      if ( useKey ) {
        if ( Utils.isEmpty( keyFilename ) ) {
          throw new KettleException( BaseMessages.getString( SSHMeta.PKG, "SSH.Error.PrivateKeyFileMissing" ) );
        }
        FileObject keyFileObject = KettleVFS.getFileObject( keyFilename );

        if ( !keyFileObject.exists() ) {
          throw new KettleException( BaseMessages.getString( SSHMeta.PKG, "SSH.Error.PrivateKeyNotExist", keyFilename ) );
        }

        FileContent keyFileContent = keyFileObject.getContent();

        CharArrayWriter charArrayWriter = new CharArrayWriter( (int) keyFileContent.getSize() );

        try ( InputStream in = keyFileContent.getInputStream() ) {
          IOUtils.copy( in, charArrayWriter );
        }

        content = charArrayWriter.toCharArray();
      }
      // Create a new connection
      conn = createConnection( serveur, port );

      /* We want to connect through a HTTP proxy */
      if ( !Utils.isEmpty( proxyhost ) ) {
        /* Now connect */
        // if the proxy requires basic authentication:
        if ( !Utils.isEmpty( proxyusername ) ) {
          conn.setProxyData( new HTTPProxyData( proxyhost, proxyport, proxyusername, proxypassword ) );
        } else {
          conn.setProxyData( new HTTPProxyData( proxyhost, proxyport ) );
        }
      }

      // and connect
      if ( timeOut == 0 ) {
        conn.connect();
      } else {
        conn.connect( null, 0, timeOut * 1000 );
      }
      // authenticate
      if ( useKey ) {
        isAuthenticated =
          conn.authenticateWithPublicKey( username, content, space.environmentSubstitute( passPhrase ) );
      } else {
        isAuthenticated = conn.authenticateWithPassword( username, password );
      }
      if ( isAuthenticated == false ) {
        throw new KettleException( BaseMessages.getString( SSHMeta.PKG, "SSH.Error.AuthenticationFailed", username ) );
      }
    } catch ( Exception e ) {
      // Something wrong happened
      // do not forget to disconnect if connected
      if ( conn != null ) {
        conn.close();
      }
      throw new KettleException( BaseMessages.getString( SSHMeta.PKG, "SSH.Error.ErrorConnecting", serveur, username ), e );
    }
    return conn;
  }
@Test( expected = KettleException.class )
  public void testOpenConnection_2() throws Exception {
    when( connection.authenticateWithPassword( username, password ) ).thenReturn( false );
    SSHData.OpenConnection( server, port, username, password, false, null,
      null, 0, null, null, 0, null, null );
    verify( connection ).connect();
    verify( connection ).authenticateWithPassword( username, password );
  }