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.security;
17
18import java.security.cert.CertPath;
19import java.security.cert.CertPathBuilder;
20import java.security.cert.CertPathBuilderResult;
21import java.security.cert.CertPathParameters;
22import junit.framework.TestCase;
23public abstract class CertPathBuilderTest extends TestCase {
24
25    private final String algorithmName;
26    private CertPathParameters params;
27
28    public CertPathBuilderTest(String algorithmName) {
29        this.algorithmName = algorithmName;
30    }
31
32    @Override
33    protected void setUp() throws Exception {
34        super.setUp();
35
36        params = getCertPathParameters();
37    }
38
39    public abstract CertPathParameters getCertPathParameters() throws Exception;
40    public abstract void validateCertPath(CertPath path);
41
42    public void testCertPathBuilder() throws Exception {
43        CertPathBuilder pathBuilder = CertPathBuilder.getInstance(
44                algorithmName);
45
46        CertPathBuilderResult builderResult = pathBuilder.build(params);
47
48        CertPath path = builderResult.getCertPath();
49
50        assertNotNull("built path is null", path);
51
52        validateCertPath(path);
53    }
54}
55