Search in sources :

Example 1 with IdentitySubclass

use of org.apache.harmony.security.tests.java.security.Identity2Test.IdentitySubclass in project robovm by robovm.

the class IdentityScope2Test method test_removeIdentityLjava_security_Identity.

/**
     * java.security.IdentityScope#removeIdentity(java.security.Identity)
     */
public void test_removeIdentityLjava_security_Identity() throws Exception {
    IdentityScopeSubclass sub = new IdentityScopeSubclass("test", new IdentityScopeSubclass());
    Identity id = new IdentitySubclass();
    id.setPublicKey(getPubKey());
    sub.addIdentity(id);
    sub.removeIdentity(id);
    try {
        sub.removeIdentity(id);
        fail("KeyManagementException should have been thrown");
    } catch (KeyManagementException expected) {
    }
}
Also used : IdentitySubclass(org.apache.harmony.security.tests.java.security.Identity2Test.IdentitySubclass) Identity(java.security.Identity) KeyManagementException(java.security.KeyManagementException)

Example 2 with IdentitySubclass

use of org.apache.harmony.security.tests.java.security.Identity2Test.IdentitySubclass in project robovm by robovm.

the class IdentityScope2Test method test_toString.

/**
     * java.security.IdentityScope#toString()
     */
public void test_toString() throws Exception {
    IdentityScopeSubclass sub = new IdentityScopeSubclass("test", new IdentityScopeSubclass());
    Identity id = new IdentitySubclass();
    id.setPublicKey(getPubKey());
    sub.addIdentity(id);
    assertNotNull("toString returned a null", sub.toString());
    assertTrue("Not a valid String ", sub.toString().length() > 0);
}
Also used : IdentitySubclass(org.apache.harmony.security.tests.java.security.Identity2Test.IdentitySubclass) Identity(java.security.Identity)

Example 3 with IdentitySubclass

use of org.apache.harmony.security.tests.java.security.Identity2Test.IdentitySubclass in project robovm by robovm.

the class IdentityScope2Test method test_identities.

/**
     * java.security.IdentityScope#identities()
     */
public void test_identities() throws Exception {
    IdentityScopeSubclass sub = new IdentityScopeSubclass("test", new IdentityScopeSubclass());
    Identity id = new IdentitySubclass();
    id.setPublicKey(getPubKey());
    sub.addIdentity(id);
    Enumeration<Identity> en = sub.identities();
    assertEquals("Wrong object contained in identities", en.nextElement(), id);
    assertFalse("Contains too many elements", en.hasMoreElements());
}
Also used : IdentitySubclass(org.apache.harmony.security.tests.java.security.Identity2Test.IdentitySubclass) Identity(java.security.Identity)

Example 4 with IdentitySubclass

use of org.apache.harmony.security.tests.java.security.Identity2Test.IdentitySubclass in project robovm by robovm.

the class IdentityScope2Test method test_getIdentityLjava_security_PublicKey.

/**
     * java.security.IdentityScope#getIdentity(java.security.PublicKey)
     */
public void test_getIdentityLjava_security_PublicKey() throws Exception {
    IdentityScopeSubclass sub = new IdentityScopeSubclass("test", new IdentityScopeSubclass());
    Identity id = new IdentitySubclass();
    id.setPublicKey(getPubKey());
    sub.addIdentity(id);
    Identity returnedId = sub.getIdentity(getPubKey());
    assertEquals("Test 1: Returned Identity not the same as the added one;", id, returnedId);
    assertNull("Test 2: Null value expected.", sub.getIdentity((PublicKey) null));
    PublicKey anotherKey = KeyPairGenerator.getInstance("DSA").genKeyPair().getPublic();
    assertNull("Test 3: Null value expected.", sub.getIdentity(anotherKey));
}
Also used : IdentitySubclass(org.apache.harmony.security.tests.java.security.Identity2Test.IdentitySubclass) PublicKey(java.security.PublicKey) Identity(java.security.Identity)

Example 5 with IdentitySubclass

use of org.apache.harmony.security.tests.java.security.Identity2Test.IdentitySubclass in project robovm by robovm.

the class IdentityScope2Test method test_addIdentityLjava_security_Identity.

/**
     * java.security.IdentityScope#addIdentity(java.security.Identity)
     */
public void test_addIdentityLjava_security_Identity() throws Exception {
    IdentityScopeSubclass sub = new IdentityScopeSubclass("test", new IdentityScopeSubclass());
    Identity id = new IdentitySubclass("id1");
    id.setPublicKey(getPubKey());
    sub.addIdentity(id);
    try {
        Identity id2 = new IdentitySubclass("id2");
        id2.setPublicKey(getPubKey());
        sub.addIdentity(id2);
        fail("KeyManagementException should have been thrown");
    } catch (KeyManagementException e) {
    // Expected
    }
}
Also used : IdentitySubclass(org.apache.harmony.security.tests.java.security.Identity2Test.IdentitySubclass) Identity(java.security.Identity) KeyManagementException(java.security.KeyManagementException)

Aggregations

Identity (java.security.Identity)8 IdentitySubclass (org.apache.harmony.security.tests.java.security.Identity2Test.IdentitySubclass)8 KeyManagementException (java.security.KeyManagementException)2 PublicKey (java.security.PublicKey)1