@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);
    }
  }
 /**
  * Returns the key with the given name out of the keys in the given list of keys. Uses plain java
  * means to look for the key (so that tests may limit theirself to test single bits of
  * functionality).
  *
  * @param name
  * @param keys
  * @return
  */
 public static IOpenShiftSSHKey getKey(String name, List<IOpenShiftSSHKey> keys) {
   IOpenShiftSSHKey matchingKey = null;
   for (IOpenShiftSSHKey key : keys) {
     if (name.equals(key.getName())) {
       matchingKey = key;
       break;
     }
   }
   return matchingKey;
 }
  @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);
    }
  }
 public static void silentlyDestroyKey(IOpenShiftSSHKey key) {
   if (key == null) {
     return;
   }
   try {
     key.destroy();
   } catch (Exception e) {
     //			e.printStackTrace();
   }
 }