Home | History | Annotate | Download | only in cert
      1 /*
      2  *  Licensed to the Apache Software Foundation (ASF) under one or more
      3  *  contributor license agreements.  See the NOTICE file distributed with
      4  *  this work for additional information regarding copyright ownership.
      5  *  The ASF licenses this file to You under the Apache License, Version 2.0
      6  *  (the "License"); you may not use this file except in compliance with
      7  *  the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  */
     17 
     18 /**
     19 * @author Vera Y. Petrashkova
     20 * @version $Revision$
     21 */
     22 
     23 package tests.security.cert;
     24 
     25 
     26 import dalvik.annotation.TestTargets;
     27 import dalvik.annotation.TestLevel;
     28 import dalvik.annotation.TestTargetNew;
     29 import dalvik.annotation.TestTargetClass;
     30 
     31 import junit.framework.Test;
     32 import junit.framework.TestCase;
     33 import junit.framework.TestSuite;
     34 
     35 import java.security.InvalidAlgorithmParameterException;
     36 import java.security.cert.CRL;
     37 import java.security.cert.CRLSelector;
     38 import java.security.cert.CertSelector;
     39 import java.security.cert.CertStoreException;
     40 import java.security.cert.CertStoreSpi;
     41 import java.security.cert.Certificate;
     42 
     43 import org.apache.harmony.security.tests.support.cert.MyCertStoreParameters;
     44 import org.apache.harmony.security.tests.support.cert.MyCertStoreSpi;
     45 
     46 /**
     47  * Tests for <code>CertStoreSpi</code> class constructors and methods.
     48  *
     49  */
     50 @TestTargetClass(CertStoreSpi.class)
     51 public class CertStoreSpiTest extends TestCase {
     52 
     53 
     54     /**
     55      * Test for <code>CertStoreSpi</code> constructor Assertion: constructs
     56      * CertStoreSpi
     57      */
     58     @TestTargets({
     59         @TestTargetNew(
     60             level = TestLevel.COMPLETE,
     61             notes = "",
     62             method = "CertStoreSpi",
     63             args = {java.security.cert.CertStoreParameters.class}
     64         ),
     65         @TestTargetNew(
     66             level = TestLevel.COMPLETE,
     67             notes = "",
     68             method = "engineGetCertificates",
     69             args = {java.security.cert.CertSelector.class}
     70         ),
     71         @TestTargetNew(
     72             level = TestLevel.COMPLETE,
     73             notes = "",
     74             method = "engineGetCRLs",
     75             args = {java.security.cert.CRLSelector.class}
     76         )
     77     })
     78     public void testCertStoreSpi01() throws InvalidAlgorithmParameterException,
     79             CertStoreException {
     80         CertStoreSpi certStoreSpi = null;
     81         CertSelector certSelector = new tmpCertSelector();//new
     82                                                           // X509CertSelector();
     83         CRLSelector crlSelector = new tmpCRLSelector();//new X509CRLSelector();
     84         try {
     85             certStoreSpi = new MyCertStoreSpi(null);
     86             fail("InvalidAlgorithmParameterException must be thrown");
     87         } catch (InvalidAlgorithmParameterException e) {
     88         }
     89         certStoreSpi = new MyCertStoreSpi(new MyCertStoreParameters());
     90         assertNull("Not null collection", certStoreSpi
     91                 .engineGetCertificates(certSelector));
     92         assertNull("Not null collection", certStoreSpi
     93                 .engineGetCRLs(crlSelector));
     94     }
     95 
     96     public static Test suite() {
     97         return new TestSuite(CertStoreSpiTest.class);
     98     }
     99 
    100     /**
    101      * Additional classes for verification CertStoreSpi class
    102      */
    103     public static class tmpCRLSelector implements CRLSelector {
    104         public Object clone() {
    105             return null;
    106         }
    107         public boolean match (CRL crl) {
    108             return false;
    109         }
    110     }
    111     public static class tmpCertSelector implements CertSelector {
    112         public Object clone() {
    113             return null;
    114         }
    115         public boolean match (Certificate crl) {
    116             return true;
    117         }
    118     }
    119 
    120 }
    121