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 dalvik.annotation.TestTargets; 26 import dalvik.annotation.TestLevel; 27 import dalvik.annotation.TestTargetNew; 28 import dalvik.annotation.TestTargetClass; 29 30 import junit.framework.TestCase; 31 32 import java.security.cert.CertPathValidatorException; 33 import java.security.cert.Certificate; 34 import java.security.cert.PKIXCertPathChecker; 35 import java.util.Collection; 36 import java.util.HashSet; 37 import java.util.Set; 38 39 import org.apache.harmony.security.tests.support.cert.MyCertificate; 40 import org.apache.harmony.security.tests.support.cert.TestUtils; 41 42 /** 43 * Tests for <code>PKIXCertPathChecker</code> 44 * 45 */ 46 @TestTargetClass(PKIXCertPathChecker.class) 47 public class PKIXCertPathCheckerTest extends TestCase { 48 49 // 50 // Tests 51 // 52 @TestTargetNew( 53 level = TestLevel.COMPLETE, 54 notes = "", 55 method = "PKIXCertPathChecker", 56 args = {} 57 ) 58 public final void testConstructor() { 59 try { 60 new MyPKIXCertPathChecker(); 61 } catch(Exception e) { 62 fail("Unexpected exception " + e.getMessage()); 63 } 64 } 65 @TestTargetNew( 66 level = TestLevel.COMPLETE, 67 notes = "", 68 method = "clone", 69 args = {} 70 ) 71 public final void testClone() { 72 PKIXCertPathChecker pc1 = TestUtils.getTestCertPathChecker(); 73 PKIXCertPathChecker pc2 = (PKIXCertPathChecker) pc1.clone(); 74 assertNotSame("notSame", pc1, pc2); 75 } 76 77 // 78 // the following tests just call methods 79 // that are abstract in <code>PKIXCertPathChecker</code> 80 // (So they just like signature tests) 81 // 82 @TestTargetNew( 83 level = TestLevel.COMPLETE, 84 notes = "", 85 method = "isForwardCheckingSupported", 86 args = {} 87 ) 88 public final void testIsForwardCheckingSupported() { 89 PKIXCertPathChecker pc = TestUtils.getTestCertPathChecker(); 90 pc.isForwardCheckingSupported(); 91 } 92 @TestTargetNew( 93 level = TestLevel.COMPLETE, 94 notes = "", 95 method = "init", 96 args = {boolean.class} 97 ) 98 public final void testInit() 99 throws CertPathValidatorException { 100 PKIXCertPathChecker pc = TestUtils.getTestCertPathChecker(); 101 pc.init(true); 102 } 103 @TestTargetNew( 104 level = TestLevel.COMPLETE, 105 notes = "", 106 method = "getSupportedExtensions", 107 args = {} 108 ) 109 public final void testGetSupportedExtensions() { 110 PKIXCertPathChecker pc = TestUtils.getTestCertPathChecker(); 111 pc.getSupportedExtensions(); 112 } 113 @TestTargetNew( 114 level = TestLevel.COMPLETE, 115 notes = "", 116 method = "check", 117 args = {java.security.cert.Certificate.class, java.util.Collection.class} 118 ) 119 public final void testCheck() throws CertPathValidatorException { 120 PKIXCertPathChecker pc = TestUtils.getTestCertPathChecker(); 121 pc.check(new MyCertificate("", null), new HashSet<String>()); 122 } 123 124 class MyPKIXCertPathChecker extends PKIXCertPathChecker { 125 126 public MyPKIXCertPathChecker() { 127 super(); 128 } 129 130 @Override 131 public void check(Certificate cert, 132 Collection<String> unresolvedCritExts) 133 throws CertPathValidatorException { 134 } 135 136 @Override 137 public Set<String> getSupportedExtensions() { 138 return null; 139 } 140 141 @Override 142 public void init(boolean forward) throws CertPathValidatorException { 143 } 144 145 @Override 146 public boolean isForwardCheckingSupported() { 147 return false; 148 } 149 150 } 151 152 } 153