|
1 /* |
|
2 * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
21 * have any questions. |
|
22 */ |
|
23 |
|
24 /* |
|
25 * @test |
|
26 * @bug 4496095 |
|
27 * @summary Add constructors for exception chaining to java.security Exceptions |
|
28 */ |
|
29 |
|
30 import java.security.*; |
|
31 import java.security.cert.*; |
|
32 import java.security.spec.*; |
|
33 import javax.net.ssl.*; |
|
34 |
|
35 public class ChainingConstructors { |
|
36 |
|
37 private static final String MSG = "msg"; |
|
38 private static Exception cause = new Exception("cause"); |
|
39 |
|
40 public static void main(String[] args) throws Exception { |
|
41 SecurityException se = new SecurityException(cause); |
|
42 if (!se.getCause().equals(cause)) { |
|
43 throw new SecurityException("Test 1 failed"); |
|
44 } |
|
45 se = new SecurityException(MSG, cause); |
|
46 if (!se.getMessage().equals(MSG) || !se.getCause().equals(cause)) { |
|
47 throw new SecurityException("Test 1 failed"); |
|
48 } |
|
49 |
|
50 DigestException de = new DigestException(cause); |
|
51 if (!de.getCause().equals(cause)) { |
|
52 throw new SecurityException("Test 2 failed"); |
|
53 } |
|
54 de = new DigestException(MSG, cause); |
|
55 if (!de.getMessage().equals(MSG) || !de.getCause().equals(cause)) { |
|
56 throw new SecurityException("Test 2 failed"); |
|
57 } |
|
58 |
|
59 GeneralSecurityException gse = new GeneralSecurityException(cause); |
|
60 if (!gse.getCause().equals(cause)) { |
|
61 throw new SecurityException("Test 3 failed"); |
|
62 } |
|
63 gse = new GeneralSecurityException(MSG, cause); |
|
64 if (!gse.getMessage().equals(MSG) || !gse.getCause().equals(cause)) { |
|
65 throw new SecurityException("Test 3 failed"); |
|
66 } |
|
67 |
|
68 InvalidAlgorithmParameterException iape = |
|
69 new InvalidAlgorithmParameterException(cause); |
|
70 if (!iape.getCause().equals(cause)) { |
|
71 throw new SecurityException("Test 4 failed"); |
|
72 } |
|
73 iape = new InvalidAlgorithmParameterException(MSG, cause); |
|
74 if (!iape.getMessage().equals(MSG) || !iape.getCause().equals(cause)) { |
|
75 throw new SecurityException("Test 4 failed"); |
|
76 } |
|
77 |
|
78 InvalidKeyException ike = new InvalidKeyException(cause); |
|
79 if (!ike.getCause().equals(cause)) { |
|
80 throw new SecurityException("Test 5 failed"); |
|
81 } |
|
82 ike = new InvalidKeyException(MSG, cause); |
|
83 if (!ike.getMessage().equals(MSG) || !ike.getCause().equals(cause)) { |
|
84 throw new SecurityException("Test 5 failed"); |
|
85 } |
|
86 |
|
87 InvalidKeySpecException ikse = new InvalidKeySpecException(cause); |
|
88 if (!ikse.getCause().equals(cause)) { |
|
89 throw new SecurityException("Test 6 failed"); |
|
90 } |
|
91 ikse = new InvalidKeySpecException(MSG, cause); |
|
92 if (!ikse.getMessage().equals(MSG) || !ikse.getCause().equals(cause)) { |
|
93 throw new SecurityException("Test 6 failed"); |
|
94 } |
|
95 |
|
96 KeyException ke = new KeyException(cause); |
|
97 if (!ke.getCause().equals(cause)) { |
|
98 throw new SecurityException("Test 7 failed"); |
|
99 } |
|
100 ke = new KeyException(MSG, cause); |
|
101 if (!ke.getMessage().equals(MSG) || !ke.getCause().equals(cause)) { |
|
102 throw new SecurityException("Test 7 failed"); |
|
103 } |
|
104 |
|
105 KeyManagementException kme = new KeyManagementException(cause); |
|
106 if (!kme.getCause().equals(cause)) { |
|
107 throw new SecurityException("Test 8 failed"); |
|
108 } |
|
109 kme = new KeyManagementException(MSG, cause); |
|
110 if (!kme.getMessage().equals(MSG) || !kme.getCause().equals(cause)) { |
|
111 throw new SecurityException("Test 8 failed"); |
|
112 } |
|
113 |
|
114 KeyStoreException kse = new KeyStoreException(cause); |
|
115 if (!kse.getCause().equals(cause)) { |
|
116 throw new SecurityException("Test 9 failed"); |
|
117 } |
|
118 kse = new KeyStoreException(MSG, cause); |
|
119 if (!kse.getMessage().equals(MSG) || !kse.getCause().equals(cause)) { |
|
120 throw new SecurityException("Test 9 failed"); |
|
121 } |
|
122 |
|
123 NoSuchAlgorithmException nsae = new NoSuchAlgorithmException(cause); |
|
124 if (!nsae.getCause().equals(cause)) { |
|
125 throw new SecurityException("Test 10 failed"); |
|
126 } |
|
127 nsae = new NoSuchAlgorithmException(MSG, cause); |
|
128 if (!nsae.getMessage().equals(MSG) || !nsae.getCause().equals(cause)) { |
|
129 throw new SecurityException("Test 10 failed"); |
|
130 } |
|
131 |
|
132 ProviderException pe = new ProviderException(cause); |
|
133 if (!pe.getCause().equals(cause)) { |
|
134 throw new SecurityException("Test 11 failed"); |
|
135 } |
|
136 pe = new ProviderException(MSG, cause); |
|
137 if (!pe.getMessage().equals(MSG) || !pe.getCause().equals(cause)) { |
|
138 throw new SecurityException("Test 11 failed"); |
|
139 } |
|
140 |
|
141 SignatureException sige = new SignatureException(cause); |
|
142 if (!sige.getCause().equals(cause)) { |
|
143 throw new SecurityException("Test 12 failed"); |
|
144 } |
|
145 sige = new SignatureException(MSG, cause); |
|
146 if (!sige.getMessage().equals(MSG) || !sige.getCause().equals(cause)) { |
|
147 throw new SecurityException("Test 12 failed"); |
|
148 } |
|
149 |
|
150 CRLException crle = new CRLException(cause); |
|
151 if (!crle.getCause().equals(cause)) { |
|
152 throw new SecurityException("Test 13 failed"); |
|
153 } |
|
154 crle = new CRLException(MSG, cause); |
|
155 if (!crle.getMessage().equals(MSG) || !crle.getCause().equals(cause)) { |
|
156 throw new SecurityException("Test 13 failed"); |
|
157 } |
|
158 |
|
159 CertificateException ce = new CertificateException(cause); |
|
160 if (!ce.getCause().equals(cause)) { |
|
161 throw new SecurityException("Test 14 failed"); |
|
162 } |
|
163 ce = new CertificateException(MSG, cause); |
|
164 if (!ce.getMessage().equals(MSG) || !ce.getCause().equals(cause)) { |
|
165 throw new SecurityException("Test 14 failed"); |
|
166 } |
|
167 |
|
168 CertificateParsingException cpe = |
|
169 new CertificateParsingException(cause); |
|
170 if (!cpe.getCause().equals(cause)) { |
|
171 throw new SecurityException("Test 15 failed"); |
|
172 } |
|
173 cpe = new CertificateParsingException(MSG, cause); |
|
174 if (!cpe.getMessage().equals(MSG) || !cpe.getCause().equals(cause)) { |
|
175 throw new SecurityException("Test 15 failed"); |
|
176 } |
|
177 |
|
178 CertificateEncodingException cee = |
|
179 new CertificateEncodingException(cause); |
|
180 if (!cee.getCause().equals(cause)) { |
|
181 throw new SecurityException("Test 16 failed"); |
|
182 } |
|
183 cee = new CertificateEncodingException(MSG, cause); |
|
184 if (!cee.getMessage().equals(MSG) || !cee.getCause().equals(cause)) { |
|
185 throw new SecurityException("Test 16 failed"); |
|
186 } |
|
187 |
|
188 /* |
|
189 SSLException ssle = |
|
190 new SSLException(cause); |
|
191 if (!ssle.getCause().equals(cause)) { |
|
192 throw new SecurityException("Test 17 failed"); |
|
193 } |
|
194 ssle =new SSLException(MSG, cause); |
|
195 if (!ssle.getMessage().equals(MSG) || !ssle.getCause().equals(cause)) { |
|
196 throw new SecurityException("Test 17 failed"); |
|
197 } |
|
198 */ |
|
199 } |
|
200 } |