public void testCreateCommand() throws Exception {
   setupKey(new CreateCryptoKeyCommand(user.getOrg()));
   CryptoKey key = cmd.getCryptoKey();
   key = (CryptoKey) reload(key);
   assertNotNull(key.getId());
   assertNotNull(key.getKey());
 }
 public void testEdit() throws Exception {
   CryptoKey key = CryptoTest.createTestKey(user.getOrg());
   KickstartFactory.saveCryptoKey(key);
   flushAndEvict(key);
   setupKey(new EditCryptoKeyCommand(user, key.getId()));
   assertNotNull(cmd.getCryptoKey());
   assertNull(cmd.store());
 }
  public void testCreate() throws Exception {
    // Setup
    String description = "CryptoKeysHandler.testCreate-Description";
    String content = MD5Crypt.md5Hex(RandomStringUtils.random(28));

    // Test
    CryptoKeysHandler handler = new CryptoKeysHandler();
    handler.create(adminKey, description, "GPG", content);

    // Verify
    CryptoKey cryptoKey = KickstartFactory.lookupCryptoKey(description, admin.getOrg());

    assertNotNull(cryptoKey);
    assertEquals(cryptoKey.getDescription(), description);
    assertEquals(cryptoKey.getCryptoKeyType().getLabel(), "GPG");
    assertEquals(cryptoKey.getKeyString(), content);
  }
  public void testListAllKeys() throws Exception {
    // Setup
    User otherOrg = UserTestUtils.findNewUser("testUser", "cryptoOrg", true);
    CryptoKey key = CryptoTest.createTestKey(otherOrg.getOrg());
    KickstartFactory.saveCryptoKey(key);
    flushAndEvict(key);

    // Test
    CryptoKeysHandler handler = new CryptoKeysHandler();

    List allKeys = handler.listAllKeys(XmlRpcTestUtils.getSessionKey(otherOrg));

    // Verify
    assertNotNull(allKeys);
    assertEquals(allKeys.size(), 1);

    CryptoKeyDto dto = (CryptoKeyDto) allKeys.get(0);
    assertEquals(key.getDescription(), dto.getDescription());
    assertEquals(key.getOrg().getId(), dto.getOrgId());
  }
  public void testDelete() throws Exception {
    // Setup
    CryptoKey key = CryptoTest.createTestKey(admin.getOrg());
    KickstartFactory.saveCryptoKey(key);
    assertNotNull(KickstartFactory.lookupCryptoKeyById(key.getId(), key.getOrg()));
    flushAndEvict(key);

    // Test
    CryptoKeysHandler handler = new CryptoKeysHandler();
    handler.delete(adminKey, key.getDescription());

    // Verify
    CryptoKey deletedKey = KickstartFactory.lookupCryptoKeyById(key.getId(), key.getOrg());
    assertNull(deletedKey);
  }
  public void testDelete() throws Exception {
    CryptoKey key = CryptoTest.createTestKey(user.getOrg());
    KickstartFactory.saveCryptoKey(key);
    assertNotNull(KickstartFactory.lookupCryptoKeyById(key.getId(), key.getOrg()));
    flushAndEvict(key);
    KickstartFactory.removeCryptoKey(key);
    assertNull(KickstartFactory.lookupCryptoKeyById(key.getId(), key.getOrg()));

    // second method
    CryptoKey key2 = CryptoTest.createTestKey(user.getOrg());
    KickstartFactory.saveCryptoKey(key2);
    assertNotNull(KickstartFactory.lookupCryptoKeyById(key2.getId(), key2.getOrg()));
    flushAndEvict(key2);

    // CryptoKey will be deleted by the cmd.store command in setupKey
    setupKey(new DeleteCryptoKeyCommand(user, key2.getId()));
    assertNull(KickstartFactory.lookupCryptoKeyById(key2.getId(), key2.getOrg()));
  }
  public void testGetDetails() throws Exception {
    // Setup
    CryptoKey key = CryptoTest.createTestKey(admin.getOrg());
    KickstartFactory.saveCryptoKey(key);
    assertNotNull(KickstartFactory.lookupCryptoKeyById(key.getId(), key.getOrg()));
    flushAndEvict(key);

    // Test
    CryptoKeysHandler handler = new CryptoKeysHandler();
    CryptoKey cryptoKey = handler.getDetails(adminKey, key.getDescription());

    // Verify
    assertNotNull(cryptoKey);
    assertEquals(cryptoKey.getDescription(), cryptoKey.getDescription());
    assertEquals(cryptoKey.getCryptoKeyType().getLabel(), cryptoKey.getCryptoKeyType().getLabel());
    assertEquals(cryptoKey.getKeyString(), cryptoKey.getKeyString());
  }