use of org.apache.harmony.security.tests.java.security.IdentityScope2Test.IdentityScopeSubclass in project robovm by robovm.
the class Identity2Test method test_removeCertificateLjava_security_Certificate.
/**
* java.security.Identity#removeCertificate(java.security.Certificate)
*/
@AndroidOnly("Spec says: Removing unknown certificates throw an exception. " + "The RI ignores unknown certificates.")
public void test_removeCertificateLjava_security_Certificate() throws Exception {
IdentitySubclass sub = new IdentitySubclass("test", new IdentityScopeSubclass());
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate[] cert = new X509Certificate[1];
cert[0] = (X509Certificate) cf.generateCertificate(certArray);
sub.setPublicKey(cert[0].getPublicKey());
CertificateImpl certImpl = new CertificateImpl(cert[0]);
sub.addCertificate(certImpl);
try {
sub.removeCertificate(null);
fail("Test 1: KeyManagementException expected.");
} catch (KeyManagementException expected) {
}
assertEquals("Test 2: Certificate should not have been removed.", 1, sub.certificates().length);
sub.removeCertificate(certImpl);
assertEquals("Test 3: Certificate has not been removed.", 0, sub.certificates().length);
// Removing the same certificate a second time should fail.
try {
sub.removeCertificate(certImpl);
fail("Test 4: KeyManagementException expected.");
} catch (KeyManagementException expected) {
}
}
use of org.apache.harmony.security.tests.java.security.IdentityScope2Test.IdentityScopeSubclass in project robovm by robovm.
the class Identity2Test method test_equalsLjava_lang_Object.
/**
* java.security.Identity#equals(java.lang.Object)
*/
public void test_equalsLjava_lang_Object() throws Exception {
IdentitySubclass sub = new IdentitySubclass("test", new IdentityScopeSubclass());
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate[] cert = new X509Certificate[1];
cert[0] = (X509Certificate) cf.generateCertificate(certArray);
sub.setPublicKey(cert[0].getPublicKey());
CertificateImpl certImpl = new CertificateImpl(cert[0]);
sub.addCertificate(certImpl);
IdentitySubclass sub2 = new IdentitySubclass("test", new IdentityScopeSubclass());
IdentitySubclass sub3 = new IdentitySubclass("identity name", new IdentityScopeSubclass());
assertEquals("the two Identity objects are not equal", sub2, sub);
assertEquals(sub, sub2);
assertFalse(sub.equals(sub3));
}
use of org.apache.harmony.security.tests.java.security.IdentityScope2Test.IdentityScopeSubclass in project robovm by robovm.
the class Identity2Test method test_getName.
/**
* java.security.Identity#getName()
*/
public void test_getName() throws Exception {
String name = "test";
IdentitySubclass sub = new IdentitySubclass(name, new IdentityScopeSubclass());
assertEquals("Wrong Name returned", name, sub.getName());
}
use of org.apache.harmony.security.tests.java.security.IdentityScope2Test.IdentityScopeSubclass in project robovm by robovm.
the class Identity2Test method test_getInfo.
/**
* java.security.Identity#getInfo()
*/
public void test_getInfo() throws Exception {
String info = "This is the general information.";
IdentitySubclass sub = new IdentitySubclass("test", new IdentityScopeSubclass());
sub.setInfo(info);
assertEquals("Wrong Info returned", info, sub.getInfo());
}
use of org.apache.harmony.security.tests.java.security.IdentityScope2Test.IdentityScopeSubclass in project robovm by robovm.
the class Identity2Test method testSetPublicKey.
/**
* java.security.Identity#setPublicKey(PublicKey key)
*/
public void testSetPublicKey() throws Exception {
IdentitySubclass sub = new IdentitySubclass("test", new IdentityScopeSubclass());
sub.setPublicKey(getPubKey());
PublicKey returnedPubKey = sub.getPublicKey();
assertEquals("Wrong PublicKey returned", getPubKey(), returnedPubKey);
sub.setPublicKey(null);
assertEquals("Wrong PublicKey returned", null, sub.getPublicKey());
}
Aggregations