@Test
  public void shouldUpdate() {
    // pre-conditions
    ConnectionFake connection = new ConnectionFake("fakeUser", null);
    connection.setRememberPassword(true);
    connection.setConnected(true);
    assertTrue(connection.isConnected());
    assertTrue(connection.isDefaultHost());

    String newUsername = "******";
    String newHost = "http://www.redhat.com";
    String newPassword = "******";
    Connection updatingConnection = new ConnectionFake(newUsername, newHost);
    updatingConnection.setPassword(newPassword);
    updatingConnection.setRememberPassword(false);

    // operations
    connection.update(updatingConnection);

    // verifications
    assertEquals(newUsername, connection.getUsername());
    assertEquals(newHost, connection.getHost());
    assertFalse(newUsername, connection.isDefaultHost());
    assertEquals(newPassword, connection.getPassword());
    assertFalse(connection.isRememberPassword());
    assertFalse(connection.isConnected());
  }
  @Test
  public void nullHostShouldBeDefaultHost() {
    // pre-conditions

    // operations
    Connection connection = new ConnectionFake("fakeUser", null);

    // verifications
    assertTrue(connection.isDefaultHost());
    assertEquals(ConnectionUtils.getDefaultHostUrl(), connection.getHost());
  }
  @Test
  public void setHostShouldResetIsDefaultHost() {
    // pre-conditions
    Connection connection = new ConnectionFake("fakeUser", null);
    assertTrue(connection.isDefaultHost());

    // operations
    connection.setHost("http://www.redhat.com");

    // verifications
    assertFalse(connection.isDefaultHost());
  }
  @Test
  public void manuallySetDefaultHostShouldNotBeDefaultHost() {
    // pre-conditions
    String host = ConnectionUtils.getDefaultHostUrl();
    assertNotNull(host);

    // operations
    Connection connection = new ConnectionFake("fakeUser", host);

    // verifications
    assertFalse(connection.isDefaultHost());
    assertEquals(ConnectionUtils.getDefaultHostUrl(), connection.getHost());
  }
  @Test
  public void shouldNotOverrideGivenScheme() {
    // pre-conditions

    // operations
    Connection connection = new ConnectionFake("fakeUser", "scheme://openshift.redhat.com");

    // verifications
    assertNotNull(connection.getHost());
    assertTrue(connection.getHost().startsWith("scheme://"));
    assertNotNull(connection.getScheme());
    assertEquals("scheme://", connection.getScheme());
  }
  @Test
  public void shouldHaveHostWithScheme() {
    // pre-conditions

    // operations
    Connection connection = new ConnectionFake("fakeUser", "openshift.redhat.com");

    // verifications
    assertNotNull(connection.getHost());
    assertTrue(connection.getHost().startsWith(UrlUtils.HTTP));
    assertNotNull(connection.getScheme());
    assertTrue(connection.getScheme().startsWith(UrlUtils.HTTP));
  }
  @Test
  public void shouldAllowPortInUrl() throws UnsupportedEncodingException, MalformedURLException {
    // pre-conditions

    // operations
    ConnectionURL connectionUrl =
        ConnectionURL.forURL("http://adietish%40redhat.com@localhost:8081");
    Connection connection =
        new ConnectionFake(
            connectionUrl.getUsername(), connectionUrl.getScheme(), connectionUrl.getHost());

    // verifications
    assertEquals("http://localhost:8081", connection.getHost());
  }
 private IWizard createDomainWizard(final Connection user) {
   IWizard domainWizard;
   try {
     if (user.getDefaultDomain() == null || user.getDefaultDomain().getId() == null) {
       domainWizard = new NewDomainDialog(user);
     } else {
       domainWizard = new EditDomainDialog(user);
     }
   } catch (OpenShiftException e) {
     Logger.warn("Failed to retrieve User domain, prompting for creation", e);
     // let's use the domain creation wizard, then.
     domainWizard = new NewDomainDialog(user);
   }
   return domainWizard;
 }
  @Override
  public void run() {
    Connection connection = UIUtils.getFirstElement(getSelection(), Connection.class);
    if (connection == null) {
      return;
    }

    // do not show the dialog if the user was not connected or did not provide valid credentials.
    if (!connection.connect()) {
      return;
    }
    WizardDialog dialog =
        new WizardDialog(Display.getCurrent().getActiveShell(), createDomainWizard(connection));
    dialog.create();
    dialog.open();
  }
  @Test
  public void shouldExtractUrlPortions()
      throws UnsupportedEncodingException, MalformedURLException {
    // pre-conditions
    String scheme = UrlUtils.SCHEME_HTTP;
    String username = "******";
    String password = "******";
    String server = "openshift.redhat.com";

    // operations
    ConnectionURL connectionUrl =
        ConnectionURL.forURL(
            scheme + URLEncoder.encode(username, "UTF-8") + ":" + password + "@" + server);
    Connection connection =
        new ConnectionFake(
            connectionUrl.getUsername(), connectionUrl.getScheme(), connectionUrl.getHost());

    // verifications
    assertEquals(scheme, connection.getScheme());
    assertEquals(username, connection.getUsername());
    assertEquals(scheme + server, connection.getHost());
  }