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* @version $Revision$
21*/
22
23package tests.security.cert;
24
25
26import dalvik.annotation.TestTargets;
27import dalvik.annotation.TestLevel;
28import dalvik.annotation.TestTargetNew;
29import dalvik.annotation.TestTargetClass;
30
31import junit.framework.Test;
32import junit.framework.TestCase;
33import junit.framework.TestSuite;
34
35import java.security.InvalidAlgorithmParameterException;
36import java.security.cert.CRL;
37import java.security.cert.CRLSelector;
38import java.security.cert.CertSelector;
39import java.security.cert.CertStoreException;
40import java.security.cert.CertStoreSpi;
41import java.security.cert.Certificate;
42
43import org.apache.harmony.security.tests.support.cert.MyCertStoreParameters;
44import org.apache.harmony.security.tests.support.cert.MyCertStoreSpi;
45
46/**
47 * Tests for <code>CertStoreSpi</code> class constructors and methods.
48 *
49 */
50@TestTargetClass(CertStoreSpi.class)
51public class CertStoreSpiTest extends TestCase {
52
53
54    /**
55     * Test for <code>CertStoreSpi</code> constructor Assertion: constructs
56     * CertStoreSpi
57     */
58    @TestTargets({
59        @TestTargetNew(
60            level = TestLevel.COMPLETE,
61            notes = "",
62            method = "CertStoreSpi",
63            args = {java.security.cert.CertStoreParameters.class}
64        ),
65        @TestTargetNew(
66            level = TestLevel.COMPLETE,
67            notes = "",
68            method = "engineGetCertificates",
69            args = {java.security.cert.CertSelector.class}
70        ),
71        @TestTargetNew(
72            level = TestLevel.COMPLETE,
73            notes = "",
74            method = "engineGetCRLs",
75            args = {java.security.cert.CRLSelector.class}
76        )
77    })
78    public void testCertStoreSpi01() throws InvalidAlgorithmParameterException,
79            CertStoreException {
80        CertStoreSpi certStoreSpi = null;
81        CertSelector certSelector = new tmpCertSelector();//new
82                                                          // X509CertSelector();
83        CRLSelector crlSelector = new tmpCRLSelector();//new X509CRLSelector();
84        try {
85            certStoreSpi = new MyCertStoreSpi(null);
86            fail("InvalidAlgorithmParameterException must be thrown");
87        } catch (InvalidAlgorithmParameterException e) {
88        }
89        certStoreSpi = new MyCertStoreSpi(new MyCertStoreParameters());
90        assertNull("Not null collection", certStoreSpi
91                .engineGetCertificates(certSelector));
92        assertNull("Not null collection", certStoreSpi
93                .engineGetCRLs(crlSelector));
94    }
95
96    public static Test suite() {
97        return new TestSuite(CertStoreSpiTest.class);
98    }
99
100    public static void main(String args[]) {
101        junit.textui.TestRunner.run(suite());
102    }
103
104    /**
105     * Additional classes for verification CertStoreSpi class
106     */
107    public static class tmpCRLSelector implements CRLSelector {
108        public Object clone() {
109            return null;
110        }
111        public boolean match (CRL crl) {
112            return false;
113        }
114    }
115    public static class tmpCertSelector implements CertSelector {
116        public Object clone() {
117            return null;
118        }
119        public boolean match (Certificate crl) {
120            return true;
121        }
122    }
123
124}
125