@Test
  public void shouldAddKey() throws Exception {
    IOpenShiftSSHKey key = null;
    try {
      // pre-conditions
      String publicKeyPath = SSHKeyTestUtils.createDsaKeyPair();
      ISSHPublicKey publicKey = new SSHPublicKey(publicKeyPath);
      int numOfKeys = user.getSSHKeys().size();

      // operation
      String keyName = SSHKeyTestUtils.createRandomKeyName();
      key = user.addSSHKey(keyName, publicKey);

      // verifications
      assertThat(new SSHPublicKeyAssertion(key))
          .hasName(keyName)
          .hasPublicKey(publicKey.getPublicKey())
          .isType(publicKey.getKeyType());
      List<IOpenShiftSSHKey> keys = user.getSSHKeys();
      assertThat(keys.size()).isEqualTo(numOfKeys + 1);
      IOpenShiftSSHKey keyInList = SSHKeyTestUtils.getKey(keyName, keys);
      assertThat(key).isEqualTo(keyInList);
    } finally {
      SSHKeyTestUtils.silentlyDestroyKey(key);
    }
  }
  @Test
  public void shouldRefreshKeys() throws Exception {
    IOpenShiftSSHKey key = null;
    int originalNumOfKeys = user.getSSHKeys().size();
    try {
      // pre-conditions
      String publicKeyPath = SSHKeyTestUtils.createDsaKeyPair();
      IUser user =
          new TestConnectionBuilder()
              .defaultCredentials()
              .disableSSLCertificateChecks()
              .create()
              .getUser();

      // operation
      assertThat(user.getSSHKeys().size()).isEqualTo(originalNumOfKeys);
      String newKeyName = SSHKeyTestUtils.createRandomKeyName();
      user.addSSHKey(newKeyName, new SSHPublicKey(publicKeyPath));

      // verification
      assertThat(user.getSSHKeys().size()).isEqualTo(originalNumOfKeys + 1);
    } finally {
      SSHKeyTestUtils.silentlyDestroyKey(key);
    }
  }
 public static void addTestKeyToOpenShift(IUser user)
     throws OpenShiftException, FileNotFoundException, IOException, JSchException {
   assertThat(user).isNotNull();
   createSSHTestKeys();
   user.removeSSHKey(SSH_TEST_KEY_NAME);
   user.addSSHKey(SSH_TEST_KEY_NAME, new SSHPublicKey(SSH_TEST_PUBLICKEY));
 }
  @Test
  public void shouldUpdateKeyTypeAndPublicKey() throws Exception {
    IOpenShiftSSHKey key = null;
    try {
      // pre-conditions
      String publicKeyPath = createRandomTempFile().getAbsolutePath();
      String privateKeyPath = createRandomTempFile().getAbsolutePath();
      SSHKeyTestUtils.createDsaKeyPair(publicKeyPath, privateKeyPath);
      ISSHPublicKey publicKey = new SSHPublicKey(publicKeyPath);
      assertThat(publicKey.getKeyType()).isEqualTo(SSHKeyType.SSH_DSA);
      String keyName = SSHKeyTestUtils.createRandomKeyName();
      key = user.addSSHKey(keyName, publicKey);
      SSHKeyPair keyPair =
          SSHKeyPair.create(
              SSHKeyType.SSH_RSA,
              SSHKeyTestUtils.DEFAULT_PASSPHRASE,
              privateKeyPath,
              publicKeyPath);

      // operation
      key.setKeyType(SSHKeyType.SSH_RSA, keyPair.getPublicKey());

      // verification
      assertThat(key.getKeyType()).isEqualTo(SSHKeyType.SSH_RSA);
      assertThat(key.getPublicKey()).isEqualTo(keyPair.getPublicKey());
    } finally {
      SSHKeyTestUtils.silentlyDestroyKey(key);
    }
  }
 @Test
 public void shouldReturnThatHasntNamedDomain() throws OpenShiftException {
   // precondition
   // operation
   Boolean hasDomain = user.hasDomain(DomainTestUtils.createRandomName());
   // verification
   assertFalse(hasDomain);
 }
  @Test(expected = OpenShiftSSHKeyException.class)
  public void shouldNotAddKeyTwice() throws Exception {
    IOpenShiftSSHKey key = null;
    try {
      // pre-conditions
      String keyName = SSHKeyTestUtils.createRandomKeyName();
      ISSHPublicKey publicKey = new SSHPublicKey(SSHKeyTestUtils.createDsaKeyPair());
      key = user.addSSHKey(keyName, publicKey);

      // operation
      key = user.addSSHKey(keyName, publicKey);

      // verifications
    } finally {
      SSHKeyTestUtils.silentlyDestroyKey(key);
    }
  }
 @Test
 public void shouldReturnExistingKeys() throws HttpClientException, Throwable {
   // pre-conditions
   // operation
   List<IOpenShiftSSHKey> sshKeys = user.getSSHKeys();
   // verifications
   assertThat(sshKeys).isNotNull();
 }
 @Test
 public void shouldReturnDomains() throws OpenShiftException {
   // precondition
   DomainTestUtils.ensureHasDomain(user);
   // operation
   List<IDomain> domains = user.getDomains();
   // verification
   assertThat(domains).isNotEmpty();
 }
 @Test
 public void shouldReturnThatHasNamedDomain() throws OpenShiftException {
   // precondition
   IDomain domain = DomainTestUtils.ensureHasDomain(user);
   // operation
   Boolean hasDomain = user.hasDomain(domain.getId());
   // verification
   assertTrue(hasDomain);
 }
 @Test
 public void shouldReturnThatHasNoDomain() throws OpenShiftException {
   // precondition
   DomainTestUtils.destroyAllDomains(user);
   // operation
   Boolean hasDomain = user.hasDomain();
   // verification
   assertFalse(hasDomain);
 }
 @Test
 public void shouldReturnNoDomains() throws OpenShiftException {
   // precondition
   DomainTestUtils.destroyAllDomains(user);
   // operation
   List<IDomain> domains = user.getDomains();
   // verification
   assertThat(domains).isEmpty();
 }
 @Test
 public void shouldReturnId() throws OpenShiftException {
   // precondition
   DomainTestUtils.ensureHasDomain(user);
   // operation
   String id = user.getId();
   // verification
   assertThat(id).isNotEmpty();
 }
  @Test
  public void shouldReturnKeyForPublicKey() throws Exception {
    IOpenShiftSSHKey key = null;
    try {
      // pre-conditions
      String publicKeyPath = SSHKeyTestUtils.createDsaKeyPair();
      ISSHPublicKey publicKey = new SSHPublicKey(publicKeyPath);

      // operation
      String keyName = SSHKeyTestUtils.createRandomKeyName();
      key = user.addSSHKey(keyName, publicKey);
      IOpenShiftSSHKey keyByPublicKey = user.getSSHKeyByPublicKey(publicKey.getPublicKey());

      // verifications
      assertThat(key).isEqualTo(keyByPublicKey);
    } finally {
      SSHKeyTestUtils.silentlyDestroyKey(key);
    }
  }
  @Test
  public void shouldDestroyKey() throws Exception {
    IOpenShiftSSHKey key = null;
    try {
      // pre-conditions
      String publicKeyPath = SSHKeyTestUtils.createDsaKeyPair();
      String keyName = SSHKeyTestUtils.createRandomKeyName();
      key = user.addSSHKey(keyName, new SSHPublicKey(publicKeyPath));

      // operation
      key.destroy();
      key = null;

      // verification
      assertThat(user.getSSHKeyByName(keyName)).isNull();
    } finally {
      SSHKeyTestUtils.silentlyDestroyKey(key);
    }
  }
  @Test
  public void shouldRemoveKeyByName() throws Exception {
    IOpenShiftSSHKey key = null;
    try {
      // pre-conditions
      String publicKeyPath = SSHKeyTestUtils.createDsaKeyPair();
      String keyName = SSHKeyTestUtils.createRandomKeyName();
      key = user.addSSHKey(keyName, new SSHPublicKey(publicKeyPath));
      int numOfKeys = user.getSSHKeys().size();

      // operation
      user.deleteKey(keyName);

      // verification
      assertThat(user.getSSHKeyByName(keyName)).isNull();
      assertThat(user.getSSHKeys().size()).isEqualTo(numOfKeys - 1);
    } finally {
      SSHKeyTestUtils.silentlyDestroyKey(key);
    }
  }
  @Test
  public void shouldReturnDomainByName() throws OpenShiftException {
    // pre-condition
    IDomain domain = DomainTestUtils.ensureHasDomain(user);

    // operation
    IDomain domainByNamespace = user.getDomain(domain.getId());

    // verification
    assertThat(domainByNamespace.getId()).isEqualTo(domain.getId());
  }
 @Test
 public void shouldGetDefaultDomain() throws OpenShiftException {
   // precondition
   DomainTestUtils.ensureHasDomain(user);
   // operation
   IDomain domain = user.getDefaultDomain();
   // verification
   assertNotNull(domain);
   assertNotNull(domain.getId());
   assertTrue(domain.getId().length() > 0);
   assertNotNull(domain.getSuffix());
   assertTrue(domain.getSuffix().length() > 0);
 }
  @Test
  public void shouldCreateDomain() throws OpenShiftException {
    // pre-condition
    // cannot create domain if there's already one
    DomainTestUtils.destroyAllDomains(user);

    // operation
    String id = DomainTestUtils.createRandomName();
    IDomain domain = user.createDomain(id);

    // verification
    assertThat(domain.getId()).isEqualTo(id);
  }
  @Test
  public void shouldNoDefaultDomainAfterRefresh()
      throws OpenShiftException, FileNotFoundException, IOException {
    // precondition
    IDomain domain = DomainTestUtils.ensureHasDomain(user);
    assertNotNull(domain);

    IUser otherUser =
        new TestConnectionBuilder()
            .defaultCredentials()
            .disableSSLCertificateChecks()
            .create()
            .getUser();
    DomainTestUtils.destroyAllDomains(otherUser);
    assertNull(otherUser.getDefaultDomain());

    // operation
    user.refresh();

    // verification
    assertNull(user.getDefaultDomain());
  }