OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / libcore / luni / src / test / java / org / apache / harmony / security / tests / java / security / KSTrustedCertificateEntryTest.java
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
23 package org.apache.harmony.security.tests.java.security;
24
25 import dalvik.annotation.TestTargetClass;
26 import dalvik.annotation.TestTargets;
27 import dalvik.annotation.TestLevel;
28 import dalvik.annotation.TestTargetNew;
29
30 import java.security.KeyStore;
31 import java.security.cert.Certificate;
32
33 import org.apache.harmony.security.tests.support.cert.MyCertificate;
34
35
36 import junit.framework.TestCase;
37 @TestTargetClass(KeyStore.TrustedCertificateEntry.class)
38 /**
39  * Tests for <code>KeyStore.TrustedCertificateEntry</code> class constructor and methods
40  *
41  */
42
43 public class KSTrustedCertificateEntryTest extends TestCase {
44
45     /**
46      * Test for <codfe>KeyStore.TrustedCertificateEntry(Certificate trustCert)</code>
47      * constructor
48      * Assertion: throws NullPointerException when trustCert is null
49      */
50     @TestTargetNew(
51         level = TestLevel.COMPLETE,
52         notes = "",
53         method = "TrustedCertificateEntry",
54         args = {java.security.cert.Certificate.class}
55     )
56     public void testTrustedCertificateEntry() {
57         Certificate cert = null;
58         try {
59             new KeyStore.TrustedCertificateEntry(cert);
60             fail("NullPointerException must be thrown when trustCert is null");
61         } catch (NullPointerException e) {
62         }
63
64         cert = new MyCertificate("TEST", new byte[10]);
65         try {
66             KeyStore.TrustedCertificateEntry ksTCE = new KeyStore.TrustedCertificateEntry(cert);
67             assertNotNull(ksTCE);
68             assertTrue(ksTCE instanceof KeyStore.TrustedCertificateEntry);
69         } catch (Exception e) {
70             fail("Unexpected exception was thrown when trustCert is not null");
71         }
72     }
73
74     /**
75      * Test for <codfe>getTrustedCertificate()</code> method
76      * Assertion: returns trusted Certificate from goven entry
77      */
78     @TestTargetNew(
79         level = TestLevel.COMPLETE,
80         notes = "",
81         method = "getTrustedCertificate",
82         args = {}
83     )
84     public void testGetTrustedCertificate() {
85         Certificate cert = new MyCertificate("TEST", new byte[10]);
86         KeyStore.TrustedCertificateEntry ksTCE =
87                 new KeyStore.TrustedCertificateEntry(cert);
88         assertEquals("Incorrect certificate", cert, ksTCE.getTrustedCertificate());
89     }
90
91     /**
92      * Test for <codfe>toString()</code> method
93      * Assertion: returns non null string
94      */
95     @TestTargetNew(
96         level = TestLevel.COMPLETE,
97         notes = "",
98         method = "toString",
99         args = {}
100     )
101     public void testToString() {
102         Certificate cert = new MyCertificate("TEST", new byte[10]);
103         KeyStore.TrustedCertificateEntry ksTCE =
104                 new KeyStore.TrustedCertificateEntry(cert);
105         assertNotNull("toString() returns null string", ksTCE.toString());
106     }
107 }