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 Vera Y. Petrashkova
20 */
21
22package org.apache.harmony.security.tests.java.security.cert;
23
24
25import java.security.InvalidAlgorithmParameterException;
26import java.security.cert.CRL;
27import java.security.cert.CRLSelector;
28import java.security.cert.CertSelector;
29import java.security.cert.CertStoreException;
30import java.security.cert.CertStoreSpi;
31import java.security.cert.Certificate;
32
33import org.apache.harmony.security.tests.support.cert.MyCertStoreSpi;
34import org.apache.harmony.security.tests.support.cert.MyCertStoreParameters;
35
36import junit.framework.TestCase;
37import junit.framework.Test;
38import junit.framework.TestSuite;
39
40/**
41 * Tests for <code>CertStoreSpi</code> class constructors and methods.
42 */
43
44public class CertStoreSpiTest extends TestCase {
45
46    /**
47     * Constructor for CertStoreSpiTest.
48     *
49     * @param arg0
50     */
51    public CertStoreSpiTest(String arg0) {
52        super(arg0);
53    }
54
55    /**
56     * Test for <code>CertStoreSpi</code> constructor Assertion: constructs
57     * CertStoreSpi
58     */
59    public void testCertStoreSpi01() throws InvalidAlgorithmParameterException,
60            CertStoreException {
61        CertStoreSpi certStoreSpi = null;
62        CertSelector certSelector = new tmpCertSelector();//new
63        // X509CertSelector();
64        CRLSelector crlSelector = new tmpCRLSelector();//new X509CRLSelector();
65        try {
66            certStoreSpi = new MyCertStoreSpi(null);
67            fail("InvalidAlgorithmParameterException must be thrown");
68        } catch (InvalidAlgorithmParameterException e) {
69        }
70        certStoreSpi = new MyCertStoreSpi(new MyCertStoreParameters());
71        assertNull("Not null collection", certStoreSpi
72                .engineGetCertificates(certSelector));
73        assertNull("Not null collection", certStoreSpi
74                .engineGetCRLs(crlSelector));
75    }
76
77    public static Test suite() {
78        return new TestSuite(CertStoreSpiTest.class);
79    }
80
81    /**
82     * Additional classes for verification CertStoreSpi class
83     */
84    public static class tmpCRLSelector implements CRLSelector {
85        public Object clone() {
86            return null;
87        }
88
89        public boolean match(CRL crl) {
90            return false;
91        }
92    }
93
94    public static class tmpCertSelector implements CertSelector {
95        public Object clone() {
96            return null;
97        }
98
99        public boolean match(Certificate crl) {
100            return true;
101        }
102    }
103
104}
105