OSDN Git Service

a10ef4129b2b95f957927790edaeee560516ab8d
[android-x86/dalvik.git] / libcore / security / src / test / java / tests / targets / security / cert / CertPathValidatorTest.java
1 /*
2  * Copyright (C) 2009 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package tests.targets.security.cert;
17
18 import dalvik.annotation.TestLevel;
19 import dalvik.annotation.TestTargetNew;
20 import dalvik.annotation.TestTargets;
21
22 import junit.framework.TestCase;
23
24 import java.security.InvalidAlgorithmParameterException;
25 import java.security.NoSuchAlgorithmException;
26 import java.security.cert.CertPath;
27 import java.security.cert.CertPathParameters;
28 import java.security.cert.CertPathValidator;
29 import java.security.cert.CertPathValidatorException;
30 import java.security.cert.CertPathValidatorResult;
31
32 public abstract class CertPathValidatorTest extends TestCase {
33
34     private final String algorithmName;
35
36
37     public CertPathValidatorTest(String algorithmName) {
38         this.algorithmName = algorithmName;
39     }
40
41     abstract CertPathParameters getParams();
42     abstract CertPath getCertPath();
43     abstract void validateResult(CertPathValidatorResult validatorResult);
44
45     @TestTargets({
46         @TestTargetNew(
47                 level=TestLevel.ADDITIONAL,
48                 method="getInstance",
49                 args={String.class}
50         ),
51         @TestTargetNew(
52                 level=TestLevel.ADDITIONAL,
53                 method="validate",
54                 args={CertPath.class, CertPathParameters.class}
55         ),
56         @TestTargetNew(
57                 level=TestLevel.COMPLETE,
58                 method="method",
59                 args={}
60         )
61     })
62     public void testCertPathValidator() {
63         CertPathValidator certPathValidator = null;
64         try {
65             certPathValidator = CertPathValidator.getInstance(algorithmName);
66         } catch (NoSuchAlgorithmException e) {
67             fail(e.getMessage());
68         }
69
70         CertPathValidatorResult validatorResult = null;
71         try {
72             validatorResult = certPathValidator.validate(getCertPath(),
73                     getParams());
74         } catch (CertPathValidatorException e) {
75             fail(e.getMessage());
76         } catch (InvalidAlgorithmParameterException e) {
77             fail(e.getMessage());
78         }
79
80         validateResult(validatorResult);
81     }
82
83
84 }