use of java.security.cert.CertificateFactory in project robovm by robovm.
the class CertificateFactory2Test method GetInstance01.
/**
* Test for <code>getInstance(String type)</code> method
* Assertions:
* throws NullPointerException when type is null
* throws CertificateException when type is not available
* returns CertificateFactory object
*/
public void GetInstance01(boolean mode) throws CertificateException, CRLException {
try {
CertificateFactory.getInstance(null);
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]);
fail("CertificateException must be thrown (type: ".concat(invalidValues[i]).concat(")"));
} catch (CertificateException e) {
}
}
CertificateFactory cerF;
for (int i = 0; i < validValues.length; i++) {
cerF = CertificateFactory.getInstance(validValues[i]);
assertEquals("Incorrect type", cerF.getType(), validValues[i]);
assertEquals("Incorrect provider", cerF.getProvider(), mProv);
checkResult(cerF, mode);
}
}
use of java.security.cert.CertificateFactory 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.CertificateFactory in project robovm by robovm.
the class CertificateFactory3Test method testGenerateCertPath01.
/**
* Test for <code>generateCertPath(List certificates)</code> method
* Assertion: returns CertPath with 1 Certificate
*/
public void testGenerateCertPath01() throws Exception {
CertificateFactory[] certFs = initCertFs();
assertNotNull("CertificateFactory objects were not created", certFs);
// create list of certificates with one certificate
Certificate cert = certFs[0].generateCertificate(new ByteArrayInputStream(TestUtils.getEncodedX509Certificate()));
List<Certificate> list = new Vector<Certificate>();
list.add(cert);
for (int i = 0; i < certFs.length; i++) {
CertPath certPath = null;
certPath = certFs[i].generateCertPath(list);
assertEquals(cert.getType(), certPath.getType());
List<? extends Certificate> list1 = certPath.getCertificates();
assertFalse("Result list is empty", list1.isEmpty());
Iterator<? extends Certificate> it = list1.iterator();
assertEquals("Incorrect Certificate in CertPath", cert, it.next());
}
}
use of java.security.cert.CertificateFactory in project robovm by robovm.
the class CertificateFactory3Test method testGenerateCertificates.
/**
* Test for <code>generateCertificates(InputStream inStream)</code> method
* Assertion: returns Collection which consists of 1 Certificate
*/
public void testGenerateCertificates() throws Exception {
CertificateFactory[] certFs = initCertFs();
assertNotNull("CertificateFactory objects were not created", certFs);
Certificate cert = certFs[0].generateCertificate(new ByteArrayInputStream(TestUtils.getEncodedX509Certificate()));
for (int i = 0; i < certFs.length; i++) {
Collection<? extends Certificate> col = null;
col = certFs[i].generateCertificates(new ByteArrayInputStream(TestUtils.getEncodedX509Certificate()));
Iterator<? extends Certificate> it = col.iterator();
assertEquals("Incorrect Collection size", col.size(), 1);
assertEquals("Incorrect Certificate in Collection", cert, it.next());
}
}
use of java.security.cert.CertificateFactory in project robovm by robovm.
the class CertificateFactory4Test method test_getInstanceLjava_lang_String.
/**
* java.security.cert.CertificateFactory#getInstance(java.lang.String)
*/
public void test_getInstanceLjava_lang_String() throws Exception {
// Test for method java.security.cert.CertificateFactory
// java.security.cert.CertificateFactory.getInstance(java.lang.String)
CertificateFactory fact = CertificateFactory.getInstance("X.509");
assertTrue("factory is null", fact != null);
}
Aggregations