use of dalvik.annotation.AndroidOnly 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 dalvik.annotation.AndroidOnly in project robovm by robovm.
the class SSLEngineTest method test_UseClientMode.
/**
* @throws NoSuchAlgorithmException
* javax.net.ssl.SSLEngine#setUseClientMode(boolean mode)
* javax.net.ssl.SSLEngine#getUseClientMode()
*/
@AndroidOnly("The RI doesn't throw the expected IllegalStateException.")
public void test_UseClientMode() throws NoSuchAlgorithmException {
SSLEngine sse = getEngine();
try {
sse.setUseClientMode(false);
assertFalse(sse.getUseClientMode());
sse.setUseClientMode(true);
assertTrue(sse.getUseClientMode());
} catch (Exception ex) {
fail("Unexpected exception " + ex);
}
try {
sse = getEngine(null, 1080);
sse.setUseClientMode(true);
sse.beginHandshake();
try {
sse.setUseClientMode(false);
fail("IllegalArgumentException was not thrown");
} catch (IllegalArgumentException iae) {
//expected
}
} catch (Exception ex) {
fail("Unexpected exception " + ex);
}
}
use of dalvik.annotation.AndroidOnly in project robovm by robovm.
the class SSLEngineTest method test_wrap_ByteBuffer_ByteBuffer_04.
/**
* javax.net.ssl.SSLEngine#wrap(ByteBuffer src, ByteBuffer dst)
* IllegalStateException should be thrown.
*/
@AndroidOnly("The RI doesn't throw the IllegalStateException.")
public void test_wrap_ByteBuffer_ByteBuffer_04() {
String host = "new host";
int port = 8080;
ByteBuffer bbs = ByteBuffer.allocate(10);
ByteBuffer bbd = ByteBuffer.allocate(10);
SSLEngine sse = getEngine(host, port);
try {
sse.wrap(bbs, bbd);
fail("IllegalStateException wasn't thrown");
} catch (IllegalStateException iobe) {
//expected
} catch (Exception e) {
fail(e + " was thrown instead of IllegalStateException");
}
}
use of dalvik.annotation.AndroidOnly in project robovm by robovm.
the class SSLEngineTest method test_unwrap_ByteBuffer$ByteBuffer_04.
/**
* javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer[] dsts)
* IllegalStateException should be thrown.
*/
@AndroidOnly("The RI doesn't throw the IllegalStateException.")
public void test_unwrap_ByteBuffer$ByteBuffer_04() {
String host = "new host";
int port = 8080;
ByteBuffer bbs = ByteBuffer.allocate(10);
ByteBuffer[] bbd = { ByteBuffer.allocate(100), ByteBuffer.allocate(10), ByteBuffer.allocate(100) };
SSLEngine sse = getEngine(host, port);
try {
sse.unwrap(bbs, bbd);
fail("IllegalStateException wasn't thrown");
} catch (IllegalStateException iobe) {
//expected
} catch (Exception e) {
fail(e + " was thrown instead of IllegalStateException");
}
}
use of dalvik.annotation.AndroidOnly in project robovm by robovm.
the class X509CRLSelector2Test method testSetMinCRLNumberLjava_math_BigInteger.
/**
* setMinCRLNumber(BigInteger minCRL) method testing. Tests if CRLs with any
* crl number value match the selector in the case of null crlNumber
* criteria, if specified minCRL value matches the selector, and if CRL with
* inappropriate crlNumber value does not match the selector.
*/
@AndroidOnly("Uses specific class: " + "org.apache.harmony.security.asn1.ASN1OctetString.")
public void testSetMinCRLNumberLjava_math_BigInteger() {
X509CRLSelector selector = new X509CRLSelector();
BigInteger minCRL = new BigInteger("10000");
CRL crl = new TestCRL(minCRL);
selector.setMinCRLNumber(null);
assertTrue("Any CRL should match in the case of null minCRLNumber.", selector.match(crl));
selector.setMinCRLNumber(minCRL);
assertTrue("The CRL should match the selection criteria.", selector.match(crl));
selector.setMinCRLNumber(new BigInteger("10001"));
assertFalse("The CRL should not match the selection criteria.", selector.match(crl));
}
Aggregations