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