Path: blob/master/test/jdk/java/security/Exceptions/ChainingConstructors.java
41149 views
/*1* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 449609526* @summary Add constructors for exception chaining to java.security Exceptions27*/2829import java.security.*;30import java.security.cert.*;31import java.security.spec.*;32import javax.net.ssl.*;3334public class ChainingConstructors {3536private static final String MSG = "msg";37private static Exception cause = new Exception("cause");3839public static void main(String[] args) throws Exception {40SecurityException se = new SecurityException(cause);41if (!se.getCause().equals(cause)) {42throw new SecurityException("Test 1 failed");43}44se = new SecurityException(MSG, cause);45if (!se.getMessage().equals(MSG) || !se.getCause().equals(cause)) {46throw new SecurityException("Test 1 failed");47}4849DigestException de = new DigestException(cause);50if (!de.getCause().equals(cause)) {51throw new SecurityException("Test 2 failed");52}53de = new DigestException(MSG, cause);54if (!de.getMessage().equals(MSG) || !de.getCause().equals(cause)) {55throw new SecurityException("Test 2 failed");56}5758GeneralSecurityException gse = new GeneralSecurityException(cause);59if (!gse.getCause().equals(cause)) {60throw new SecurityException("Test 3 failed");61}62gse = new GeneralSecurityException(MSG, cause);63if (!gse.getMessage().equals(MSG) || !gse.getCause().equals(cause)) {64throw new SecurityException("Test 3 failed");65}6667InvalidAlgorithmParameterException iape =68new InvalidAlgorithmParameterException(cause);69if (!iape.getCause().equals(cause)) {70throw new SecurityException("Test 4 failed");71}72iape = new InvalidAlgorithmParameterException(MSG, cause);73if (!iape.getMessage().equals(MSG) || !iape.getCause().equals(cause)) {74throw new SecurityException("Test 4 failed");75}7677InvalidKeyException ike = new InvalidKeyException(cause);78if (!ike.getCause().equals(cause)) {79throw new SecurityException("Test 5 failed");80}81ike = new InvalidKeyException(MSG, cause);82if (!ike.getMessage().equals(MSG) || !ike.getCause().equals(cause)) {83throw new SecurityException("Test 5 failed");84}8586InvalidKeySpecException ikse = new InvalidKeySpecException(cause);87if (!ikse.getCause().equals(cause)) {88throw new SecurityException("Test 6 failed");89}90ikse = new InvalidKeySpecException(MSG, cause);91if (!ikse.getMessage().equals(MSG) || !ikse.getCause().equals(cause)) {92throw new SecurityException("Test 6 failed");93}9495KeyException ke = new KeyException(cause);96if (!ke.getCause().equals(cause)) {97throw new SecurityException("Test 7 failed");98}99ke = new KeyException(MSG, cause);100if (!ke.getMessage().equals(MSG) || !ke.getCause().equals(cause)) {101throw new SecurityException("Test 7 failed");102}103104KeyManagementException kme = new KeyManagementException(cause);105if (!kme.getCause().equals(cause)) {106throw new SecurityException("Test 8 failed");107}108kme = new KeyManagementException(MSG, cause);109if (!kme.getMessage().equals(MSG) || !kme.getCause().equals(cause)) {110throw new SecurityException("Test 8 failed");111}112113KeyStoreException kse = new KeyStoreException(cause);114if (!kse.getCause().equals(cause)) {115throw new SecurityException("Test 9 failed");116}117kse = new KeyStoreException(MSG, cause);118if (!kse.getMessage().equals(MSG) || !kse.getCause().equals(cause)) {119throw new SecurityException("Test 9 failed");120}121122NoSuchAlgorithmException nsae = new NoSuchAlgorithmException(cause);123if (!nsae.getCause().equals(cause)) {124throw new SecurityException("Test 10 failed");125}126nsae = new NoSuchAlgorithmException(MSG, cause);127if (!nsae.getMessage().equals(MSG) || !nsae.getCause().equals(cause)) {128throw new SecurityException("Test 10 failed");129}130131ProviderException pe = new ProviderException(cause);132if (!pe.getCause().equals(cause)) {133throw new SecurityException("Test 11 failed");134}135pe = new ProviderException(MSG, cause);136if (!pe.getMessage().equals(MSG) || !pe.getCause().equals(cause)) {137throw new SecurityException("Test 11 failed");138}139140SignatureException sige = new SignatureException(cause);141if (!sige.getCause().equals(cause)) {142throw new SecurityException("Test 12 failed");143}144sige = new SignatureException(MSG, cause);145if (!sige.getMessage().equals(MSG) || !sige.getCause().equals(cause)) {146throw new SecurityException("Test 12 failed");147}148149CRLException crle = new CRLException(cause);150if (!crle.getCause().equals(cause)) {151throw new SecurityException("Test 13 failed");152}153crle = new CRLException(MSG, cause);154if (!crle.getMessage().equals(MSG) || !crle.getCause().equals(cause)) {155throw new SecurityException("Test 13 failed");156}157158CertificateException ce = new CertificateException(cause);159if (!ce.getCause().equals(cause)) {160throw new SecurityException("Test 14 failed");161}162ce = new CertificateException(MSG, cause);163if (!ce.getMessage().equals(MSG) || !ce.getCause().equals(cause)) {164throw new SecurityException("Test 14 failed");165}166167CertificateParsingException cpe =168new CertificateParsingException(cause);169if (!cpe.getCause().equals(cause)) {170throw new SecurityException("Test 15 failed");171}172cpe = new CertificateParsingException(MSG, cause);173if (!cpe.getMessage().equals(MSG) || !cpe.getCause().equals(cause)) {174throw new SecurityException("Test 15 failed");175}176177CertificateEncodingException cee =178new CertificateEncodingException(cause);179if (!cee.getCause().equals(cause)) {180throw new SecurityException("Test 16 failed");181}182cee = new CertificateEncodingException(MSG, cause);183if (!cee.getMessage().equals(MSG) || !cee.getCause().equals(cause)) {184throw new SecurityException("Test 16 failed");185}186187/*188SSLException ssle =189new SSLException(cause);190if (!ssle.getCause().equals(cause)) {191throw new SecurityException("Test 17 failed");192}193ssle =new SSLException(MSG, cause);194if (!ssle.getMessage().equals(MSG) || !ssle.getCause().equals(cause)) {195throw new SecurityException("Test 17 failed");196}197*/198}199}200201202