use of java.security.cert.CertificateException in project robovm by robovm.
the class CertificateFactory2Test method GetInstance03.
/**
* Test for <code>getInstance(String type, Provider provider)</code>
* method
* Assertions:
* throws NullPointerException when type is null
* throws CertificateException when type is not available
* throws IllegalArgumentException when provider is null;
* returns CertificateFactory object
*/
public void GetInstance03(boolean mode) throws CertificateException, IllegalArgumentException, CRLException {
try {
CertificateFactory.getInstance(null, mProv);
fail("NullPointerException or CertificateException must be thrown when type is null");
} catch (CertificateException e) {
} catch (NullPointerException e) {
}
for (int i = 0; i < invalidValues.length; i++) {
try {
CertificateFactory.getInstance(invalidValues[i], mProv);
fail("CertificateException must be thrown (type: ".concat(invalidValues[i]).concat(")"));
} catch (CertificateException e) {
}
}
Provider prov = null;
for (int i = 0; i < validValues.length; i++) {
try {
CertificateFactory.getInstance(validValues[i], prov);
fail("IllegalArgumentException must be thrown when provider is null (type: ".concat(validValues[i]).concat(")"));
} catch (IllegalArgumentException e) {
}
}
CertificateFactory cerF;
for (int i = 0; i < validValues.length; i++) {
cerF = CertificateFactory.getInstance(validValues[i], mProv);
assertEquals("Incorrect type", cerF.getType(), validValues[i]);
assertEquals("Incorrect provider", cerF.getProvider(), mProv);
checkResult(cerF, mode);
}
}
use of java.security.cert.CertificateException in project robovm by robovm.
the class CertificateFactory4Test method test_generateCertificatesLjava_io_InputStream.
/**
* java.security.cert.CertificateFactory#generateCertificates(java.io.InputStream)
*/
public void test_generateCertificatesLjava_io_InputStream() throws Exception {
CertificateFactory fact = CertificateFactory.getInstance("X.509");
for (int i = 0; i < CERTIFICATE_URLS.length; i++) {
URL certUrl = new URL(BASE_URL + CERTIFICATE_URLS[i]);
try {
InputStream is = certUrl.openStream();
Collection<? extends Certificate> certs = fact.generateCertificates(is);
assertNotNull("The certificates in \"" + certUrl.toExternalForm() + "\" were not parsed correctly", certs);
} catch (IOException e) {
// the certificate could not be found, skip it
} catch (CertificateException e) {
fail("An exception was thrown while parsing \"" + certUrl.toExternalForm() + "\": " + e.getMessage());
}
}
}
use of java.security.cert.CertificateException in project robovm by robovm.
the class CertificateFactorySpiTest method testEngineGenerateCertPathLjava_io_InputStream02.
/**
* Test for <code>engineGenerateCertPath(InputStream)</code> method.
* Assertion: Generates a <code>CertPath</code> object and initializes it
* with the data read from the <code>InputStream</code>
*/
public void testEngineGenerateCertPathLjava_io_InputStream02() {
CertificateFactorySpi certFactorySpi = new extCertificateFactorySpi();
ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]);
DataInputStream dis = new DataInputStream(bais);
try {
certFactorySpi.engineGenerateCertPath(dis);
fail("UnsupportedOperationException expected");
} catch (UnsupportedOperationException e) {
// expected
} catch (CertificateException e) {
fail("Unexpected CertificateException " + e.getMessage());
}
}
use of java.security.cert.CertificateException in project robovm by robovm.
the class CertificateFactorySpiTest method testEngineGenerateCertPathLJava_util_List01.
/**
* Test for <code>engineGenerateCertPath(List<? extends Certificate>)</code>
* method Assertion: generates a <code>CertPath</code> object and
* initializes it with a <code>List</code> of <code>Certificates</code>
*/
public void testEngineGenerateCertPathLJava_util_List01() {
CertificateFactorySpi certFactorySpi = new MyCertificateFactorySpi();
MyCertificateFactorySpi.putMode(true);
List<Certificate> list = new ArrayList<Certificate>();
try {
assertNull(certFactorySpi.engineGenerateCertPath(list));
} catch (CertificateException e) {
fail("Unexpected CertificateException " + e.getMessage());
}
try {
certFactorySpi.engineGenerateCertPath((List<? extends Certificate>) null);
fail("expected NullPointerException");
} catch (NullPointerException e) {
// ok
} catch (CertificateException e) {
fail("Unexpected CertificateException " + e.getMessage());
}
}
use of java.security.cert.CertificateException in project robovm by robovm.
the class myCertificateFactory method testCertificateFactory12.
/**
* Test for <code>generateCertPath(InputStream inStream)</code>
* <code>generateCertPath(InputStream inStream, String encoding)</code>
* methods
* Assertion: throws CertificateException when inStream is null or
* when isStream contains invalid datas
*/
public void testCertificateFactory12() {
if (!X509Support) {
fail(NotSupportMsg);
return;
}
CertificateFactory[] certFs = initCertFs();
assertNotNull("CertificateFactory objects were not created", certFs);
InputStream is1 = null;
InputStream is2 = new ByteArrayInputStream(new byte[10]);
for (int i = 0; i < certFs.length; i++) {
try {
certFs[i].generateCertPath(is1);
fail("generateCertificate must thrown CertificateException or NullPointerException when input stream is null");
} catch (CertificateException e) {
} catch (NullPointerException e) {
}
try {
certFs[i].generateCertPath(is2);
fail("generateCertificate must thrown CertificateException when input stream contains invalid datas");
} catch (CertificateException e) {
}
Iterator<String> it = certFs[i].getCertPathEncodings();
while (it.hasNext()) {
String enc = it.next();
try {
certFs[i].generateCertPath(is1, enc);
fail("generateCertificate must thrown CertificateException or NullPointerException when input stream is null and encodings ".concat(enc));
} catch (CertificateException e) {
} catch (NullPointerException e) {
}
try {
certFs[i].generateCertPath(is2, enc);
fail("generateCertificate must thrown CertificateException when input stream contains invalid datas and encodings ".concat(enc));
} catch (CertificateException e) {
}
}
}
}
Aggregations