• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.security;
17 
18 import dalvik.annotation.TestLevel;
19 import dalvik.annotation.TestTargetNew;
20 import dalvik.annotation.TestTargets;
21 import java.security.cert.CertPath;
22 import java.security.cert.CertPathBuilder;
23 import java.security.cert.CertPathBuilderResult;
24 import java.security.cert.CertPathParameters;
25 import junit.framework.TestCase;
26 public abstract class CertPathBuilderTest extends TestCase {
27 
28     private final String algorithmName;
29     private CertPathParameters params;
30 
CertPathBuilderTest(String algorithmName)31     public CertPathBuilderTest(String algorithmName) {
32         this.algorithmName = algorithmName;
33     }
34 
35     @Override
setUp()36     protected void setUp() throws Exception {
37         super.setUp();
38 
39         params = getCertPathParameters();
40     }
41 
getCertPathParameters()42     public abstract CertPathParameters getCertPathParameters() throws Exception;
validateCertPath(CertPath path)43     public abstract void validateCertPath(CertPath path);
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="build",
54                 args={CertPathParameters.class}
55         ),
56         @TestTargetNew(
57                 level=TestLevel.ADDITIONAL,
58                 clazz=CertPathBuilderResult.class,
59                 method="getCertPath",
60                 args={}
61         ),
62         @TestTargetNew(
63                 level=TestLevel.COMPLETE,
64                 method="method",
65                 args={}
66         )
67     })
testCertPathBuilder()68     public void testCertPathBuilder() throws Exception {
69         CertPathBuilder pathBuilder = CertPathBuilder.getInstance(
70                 algorithmName);
71 
72         CertPathBuilderResult builderResult = pathBuilder.build(params);
73 
74         CertPath path = builderResult.getCertPath();
75 
76         assertNotNull("built path is null", path);
77 
78         validateCertPath(path);
79     }
80 }
81