FileDocCategorySizeDatePackage
CertStore2Test.javaAPI DocAndroid 1.5 API13982Wed May 06 22:41:06 BST 2009tests.security.cert

CertStore2Test

public class CertStore2Test extends TestCase

Fields Summary
private static final String
CERT_STORE_PROVIDER_NAME
private static final String
CERT_STORE_NAME
Provider
provider
Constructors Summary
Methods Summary
protected voidsetUp()

    
         
        super.setUp();
        provider = new MyCertStoreProvider();        
        Security.addProvider(provider);
    
protected voidtearDown()

        super.tearDown();
        Security.removeProvider(CERT_STORE_PROVIDER_NAME);
    
public voidtestGetCRLs()

        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 voidtestGetCertificates()

        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 voidtestGetInstanceStringCertStoreParameters()

        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 voidtestGetInstanceStringCertStoreParametersProvider()

        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 voidtestGetInstanceStringCertStoreParametersString()

        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);
        }