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 Vladimir N. Molotkov
     20 * @version $Revision$
     21 */
     22 
     23 package tests.security.cert;
     24 
     25 import junit.framework.TestCase;
     26 
     27 import java.security.cert.CertPathValidatorException;
     28 import java.security.cert.Certificate;
     29 import java.security.cert.PKIXCertPathChecker;
     30 import java.util.Collection;
     31 import java.util.HashSet;
     32 import java.util.Set;
     33 
     34 import org.apache.harmony.security.tests.support.cert.MyCertificate;
     35 import org.apache.harmony.security.tests.support.cert.TestUtils;
     36 
     37 /**
     38  * Tests for <code>PKIXCertPathChecker</code>
     39  *
     40  */
     41 public class PKIXCertPathCheckerTest extends TestCase {
     42 
     43     //
     44     // Tests
     45     //
     46     public final void testConstructor() {
     47         try {
     48             new MyPKIXCertPathChecker();
     49         } catch(Exception e) {
     50             fail("Unexpected exception " + e.getMessage());
     51         }
     52     }
     53     public final void testClone() {
     54         PKIXCertPathChecker pc1 = TestUtils.getTestCertPathChecker();
     55         PKIXCertPathChecker pc2 = (PKIXCertPathChecker) pc1.clone();
     56         assertNotSame("notSame", pc1, pc2);
     57     }
     58 
     59     //
     60     // the following tests just call methods
     61     // that are abstract in <code>PKIXCertPathChecker</code>
     62     // (So they just like signature tests)
     63     //
     64     public final void testIsForwardCheckingSupported() {
     65         PKIXCertPathChecker pc = TestUtils.getTestCertPathChecker();
     66         pc.isForwardCheckingSupported();
     67     }
     68     public final void testInit()
     69         throws CertPathValidatorException {
     70         PKIXCertPathChecker pc = TestUtils.getTestCertPathChecker();
     71         pc.init(true);
     72     }
     73     public final void testGetSupportedExtensions() {
     74         PKIXCertPathChecker pc = TestUtils.getTestCertPathChecker();
     75         pc.getSupportedExtensions();
     76     }
     77     public final void testCheck() throws CertPathValidatorException {
     78         PKIXCertPathChecker pc = TestUtils.getTestCertPathChecker();
     79         pc.check(new MyCertificate("", null), new HashSet<String>());
     80     }
     81 
     82     class MyPKIXCertPathChecker extends PKIXCertPathChecker {
     83 
     84         public MyPKIXCertPathChecker() {
     85             super();
     86         }
     87 
     88         @Override
     89         public void check(Certificate cert,
     90                 Collection<String> unresolvedCritExts)
     91         throws CertPathValidatorException {
     92         }
     93 
     94         @Override
     95         public Set<String> getSupportedExtensions() {
     96             return null;
     97         }
     98 
     99         @Override
    100         public void init(boolean forward) throws CertPathValidatorException {
    101         }
    102 
    103         @Override
    104         public boolean isForwardCheckingSupported() {
    105             return false;
    106         }
    107 
    108     }
    109 
    110 }
    111