CertStore2Testpublic class CertStore2Test extends TestCase
Fields Summary |
---|
private static final String | CERT_STORE_PROVIDER_NAME | private static final String | CERT_STORE_NAME | Provider | provider |
Methods Summary |
---|
protected void | setUp()
super.setUp();
provider = new MyCertStoreProvider();
Security.addProvider(provider);
| protected void | tearDown()
super.tearDown();
Security.removeProvider(CERT_STORE_PROVIDER_NAME);
| public void | testGetCRLs()
CertStore certStore = null;
try {
certStore = CertStore.getInstance(CERT_STORE_NAME, new MyCertStoreParameters());
} catch (InvalidAlgorithmParameterException e) {
fail("unexpected exception: " + e);
} catch (NoSuchAlgorithmException e) {
fail("unexpected exception: " + e);
}
assertNotNull(certStore);
try {
Collection<? extends CRL> ls = certStore.getCRLs(null);
assertNull(ls);
} catch (CertStoreException e) {
fail("unexpected exception: " + e);
}
try {
Collection<? extends CRL> ls = certStore.getCRLs(new MyCRLSelector());
assertNotNull(ls);
assertTrue(ls.isEmpty());
} catch (CertStoreException e) {
fail("unexpected exception: " + e);
}
try {
certStore.getCRLs(new MyOtherCRLSelector());
fail("expected CertStoreException");
} catch (CertStoreException e) {
// ok
}
| public void | testGetCertificates()
CertStore certStore = null;
try {
certStore = CertStore.getInstance(CERT_STORE_NAME, null);
} catch (InvalidAlgorithmParameterException e) {
fail("unexpected exception: " + e);
} catch (NoSuchAlgorithmException e) {
fail("unexpected exception: " + e);
}
assertNotNull(certStore);
try {
Collection<? extends Certificate> certificates = certStore.getCertificates(null);
assertNull(certificates);
} catch (CertStoreException e) {
fail("unexpected exception: " + e);
}
try {
Collection<? extends Certificate> certificates = certStore.getCertificates(new MyCertSelector());
assertNotNull(certificates);
assertTrue(certificates.isEmpty());
} catch (CertStoreException e) {
fail("unexpected exception: " + e);
}
try {
certStore.getCertificates(new MyOtherCertSelector());
fail("expected CertStoreException");
} catch (CertStoreException e) {
// ok
}
| public void | testGetInstanceStringCertStoreParameters()
try {
CertStoreParameters parameters = new MyCertStoreParameters();
CertStore certStore = CertStore.getInstance(CERT_STORE_NAME,
parameters);
assertNotNull(certStore);
assertNotNull(certStore.getCertStoreParameters());
assertNotSame(parameters, certStore.getCertStoreParameters());
} catch (NoSuchAlgorithmException e) {
fail("unexpected exception: " + e);
} catch (InvalidAlgorithmParameterException e) {
fail("unexpected exception: " + e);
}
try {
CertStore certStore = CertStore.getInstance(CERT_STORE_NAME, null);
assertNotNull(certStore);
assertNull(certStore.getCertStoreParameters());
} catch (InvalidAlgorithmParameterException e) {
fail("unexpected exception: " + e);
} catch (NoSuchAlgorithmException e) {
fail("unexpected exception: " + e);
}
try {
CertStore.getInstance("UnknownCertStore", null);
fail("expected NoSuchAlgorithmException");
} catch (InvalidAlgorithmParameterException e) {
fail("unexpected exception: " + e);
} catch (NoSuchAlgorithmException e) {
// ok
}
try {
CertStore.getInstance(CERT_STORE_NAME,
new MyOtherCertStoreParameters());
fail("expected InvalidAlgorithmParameterException");
} catch (InvalidAlgorithmParameterException e) {
// ok
} catch (NoSuchAlgorithmException e) {
fail("unexpected exception: " + e);
}
| public void | testGetInstanceStringCertStoreParametersProvider()
try {
CertStoreParameters parameters = new MyCertStoreParameters();
CertStore certStore = CertStore.getInstance(CERT_STORE_NAME,
parameters, provider);
assertNotNull(certStore);
assertNotNull(certStore.getCertStoreParameters());
assertNotSame(parameters, certStore.getCertStoreParameters());
assertSame(provider, certStore.getProvider());
} catch (NoSuchAlgorithmException e) {
fail("unexpected exception: " + e);
} catch (InvalidAlgorithmParameterException e) {
fail("unexpected exception: " + e);
}
try {
CertStore certStore = CertStore.getInstance(CERT_STORE_NAME, null,
provider);
assertNotNull(certStore);
assertNull(certStore.getCertStoreParameters());
assertSame(provider, certStore.getProvider());
} catch (NoSuchAlgorithmException e) {
fail("unexpected exception: " + e);
} catch (InvalidAlgorithmParameterException e) {
fail("unexpected exception: " + e);
}
try {
CertStore.getInstance("UnknownCertStore", null, provider);
fail("expected NoSuchAlgorithmException");
} catch (NoSuchAlgorithmException e) {
// ok
} catch (InvalidAlgorithmParameterException e) {
fail("unexpected exception: " + e);
}
try {
CertStore.getInstance(CERT_STORE_NAME,
new MyOtherCertStoreParameters(), provider);
fail("expected InvalidAlgorithmParameterException");
} catch (NoSuchAlgorithmException e) {
fail("unexpected exception: " + e);
} catch (InvalidAlgorithmParameterException e) {
// ok
}
| public void | testGetInstanceStringCertStoreParametersString()
try {
CertStoreParameters parameters = new MyCertStoreParameters();
CertStore certStore = CertStore.getInstance(CERT_STORE_NAME,
parameters, CERT_STORE_PROVIDER_NAME);
assertNotNull(certStore);
assertNotNull(certStore.getCertStoreParameters());
assertNotSame(parameters, certStore.getCertStoreParameters());
assertEquals(CERT_STORE_PROVIDER_NAME, certStore.getProvider()
.getName());
} catch (InvalidAlgorithmParameterException e) {
fail("unexpected exception: " + e);
} catch (NoSuchAlgorithmException e) {
fail("unexpected exception: " + e);
} catch (NoSuchProviderException e) {
fail("unexpected exception: " + e);
}
try {
CertStore certStore = CertStore.getInstance(CERT_STORE_NAME, null,
CERT_STORE_PROVIDER_NAME);
assertNotNull(certStore);
assertNull(certStore.getCertStoreParameters());
assertEquals(CERT_STORE_PROVIDER_NAME, certStore.getProvider()
.getName());
} catch (InvalidAlgorithmParameterException e) {
fail("unexpected exception: " + e);
} catch (NoSuchAlgorithmException e) {
fail("unexpected exception: " + e);
} catch (NoSuchProviderException e) {
fail("unexpected exception: " + e);
}
try {
CertStore.getInstance("UnknownCertStore",
new MyCertStoreParameters(), CERT_STORE_PROVIDER_NAME);
fail("expected NoSuchAlgorithmException");
} catch (InvalidAlgorithmParameterException e) {
fail("unexpected exception: " + e);
} catch (NoSuchAlgorithmException e) {
// ok
} catch (NoSuchProviderException e) {
fail("unexpected exception: " + e);
}
try {
CertStore.getInstance(CERT_STORE_NAME, null,
"UnknownCertStoreProvider");
fail("expected NoSuchProviderException");
} catch (InvalidAlgorithmParameterException e) {
fail("unexpected exception: " + e);
} catch (NoSuchAlgorithmException e) {
fail("unexpected exception: " + e);
} catch (NoSuchProviderException e) {
// ok
}
try {
CertStore.getInstance(CERT_STORE_NAME,
new MyOtherCertStoreParameters(), CERT_STORE_PROVIDER_NAME);
} catch (InvalidAlgorithmParameterException e) {
// ok
} catch (NoSuchAlgorithmException e) {
fail("unexpected exception: " + e);
} catch (NoSuchProviderException e) {
fail("unexpected exception: " + e);
}
|
|