1561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes/* 2561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * Licensed to the Apache Software Foundation (ASF) under one or more 3561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * contributor license agreements. See the NOTICE file distributed with 4561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * this work for additional information regarding copyright ownership. 5561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * The ASF licenses this file to You under the Apache License, Version 2.0 6561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * (the "License"); you may not use this file except in compliance with 7561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * the License. You may obtain a copy of the License at 8561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * 9561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * http://www.apache.org/licenses/LICENSE-2.0 10561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * 11561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * Unless required by applicable law or agreed to in writing, software 12561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * distributed under the License is distributed on an "AS IS" BASIS, 13561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * See the License for the specific language governing permissions and 15561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * limitations under the License. 16561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes */ 17561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes 18561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughespackage org.apache.harmony.xnet.tests.javax.net.ssl; 19561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes 20561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport javax.net.ssl.SSLException; 21561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes 22561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport junit.framework.TestCase; 23561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes 24561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes 25561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes/** 26561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * Tests for <code>SSLException</code> class constructors and methods. 27561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes */ 28561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughespublic class SSLExceptionTest extends TestCase { 29561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes 30561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes public static void main(String[] args) { 31561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes } 32561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes 33561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes /** 34561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * Constructor for SSLExceptionTests. 358d8858e39800de641b50f6e8e864af9cf68bedeaNarayan Kamath * 36561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * @param arg0 37561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes */ 38561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes public SSLExceptionTest(String arg0) { 39561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes super(arg0); 40561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes } 41561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes 42561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes static String[] msgs = { 43561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes "", 44561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes "Check new message", 45561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes "Check new message Check new message Check new message Check new message Check new message" }; 46561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes 47561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes static Throwable tCause = new Throwable("Throwable for exception"); 48561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes 49561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes /** 50561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * Test for <code>SSLException(String)</code> constructor Assertion: 51561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * constructs SSLException with detail message msg. Parameter 52561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * <code>msg</code> is not null. 53561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes */ 54561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes public void testSSLException01() { 55561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes SSLException tE; 56561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes for (int i = 0; i < msgs.length; i++) { 57561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes tE = new SSLException(msgs[i]); 58561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes assertEquals("getMessage() must return: ".concat(msgs[i]), tE 59561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes .getMessage(), msgs[i]); 60561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes assertNull("getCause() must return null", tE.getCause()); 61561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes } 62561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes } 63561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes 64561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes /** 65561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * Test for <code>SSLException(String)</code> constructor Assertion: 66561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * constructs SSLException when <code>msg</code> is null 67561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes */ 68561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes public void testSSLException02() { 69561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes String msg = null; 70561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes SSLException tE = new SSLException(msg); 71561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes assertNull("getMessage() must return null.", tE.getMessage()); 72561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes assertNull("getCause() must return null", tE.getCause()); 73561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes } 74561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes 75561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes /** 76561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * Test for <code>DigestException(Throwable)</code> constructor Assertion: 77561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * constructs DigestException when <code>cause</code> is null 78561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes */ 79561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes public void testSSLException03() { 80561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes Throwable cause = null; 81561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes SSLException tE = new SSLException(cause); 82561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes assertNull("getMessage() must return null.", tE.getMessage()); 83561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes assertNull("getCause() must return null", tE.getCause()); 84561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes } 85561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes 86561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes /** 87561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * Test for <code>SSLException(Throwable)</code> constructor Assertion: 88561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * constructs SSLException when <code>cause</code> is not null 89561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes */ 90561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes public void testSSLException04() { 91561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes SSLException tE = new SSLException(tCause); 92561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes if (tE.getMessage() != null) { 93561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes String toS = tCause.toString(); 94561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes String getM = tE.getMessage(); 95561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes assertTrue("getMessage() should contain ".concat(toS), (getM 96561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes .indexOf(toS) != -1)); 97561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes } 98561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes // SSLException is subclass of IOException, but IOException has not 99561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes // constructors with Throwable parameters 100561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes if (tE.getCause() != null) { 101561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes // assertNotNull("getCause() must not return null", tE.getCause()); 102561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes assertEquals("getCause() must return ".concat(tCause.toString()), 103561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes tE.getCause(), tCause); 104561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes } 105561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes } 106561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes 107561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes /** 108561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * Test for <code>SSLException(String, Throwable)</code> constructor 109561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * Assertion: constructs SSLException when <code>cause</code> is null 110561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * <code>msg</code> is null 111561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes */ 112561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes public void testSSLException05() { 113561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes SSLException tE = new SSLException(null, null); 114561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes assertNull("getMessage() must return null", tE.getMessage()); 115561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes assertNull("getCause() must return null", tE.getCause()); 116561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes } 117561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes 118561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes /** 119561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * Test for <code>SSLException(String, Throwable)</code> constructor 120561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * Assertion: constructs SSLException when <code>cause</code> is null 121561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * <code>msg</code> is not null 122561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes */ 123561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes public void testSSLException06() { 124561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes SSLException tE; 125561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes for (int i = 0; i < msgs.length; i++) { 126561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes tE = new SSLException(msgs[i], null); 127561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes assertEquals("getMessage() must return: ".concat(msgs[i]), tE 128561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes .getMessage(), msgs[i]); 129561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes assertNull("getCause() must return null", tE.getCause()); 130561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes } 131561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes } 132561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes 133561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes /** 134561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * Test for <code>SSLException(String, Throwable)</code> constructor 135561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * Assertion: constructs SSLException when <code>cause</code> is not null 136561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * <code>msg</code> is null 137561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes */ 138561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes public void testSSLException07() { 139561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes SSLException tE = new SSLException(null, tCause); 140561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes if (tE.getMessage() != null) { 141561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes String toS = tCause.toString(); 142561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes String getM = tE.getMessage(); 143561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes assertTrue("getMessage() must should ".concat(toS), (getM 144561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes .indexOf(toS) != -1)); 145561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes } 146561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes // SSLException is subclass of IOException, but IOException has not 147561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes // constructors with Throwable parameters 148561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes if (tE.getCause() != null) { 149561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes // assertNotNull("getCause() must not return null", tE.getCause()); 150561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes assertEquals("getCause() must return ".concat(tCause.toString()), 151561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes tE.getCause(), tCause); 152561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes } 153561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes } 154561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes 155561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes /** 156561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * Test for <code>SSLException(String, Throwable)</code> constructor 157561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * Assertion: constructs SSLException when <code>cause</code> is not null 158561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * <code>msg</code> is not null 159561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes */ 160561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes public void testSSLException08() { 161561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes SSLException tE; 162561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes for (int i = 0; i < msgs.length; i++) { 163561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes tE = new SSLException(msgs[i], tCause); 164561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes String getM = tE.getMessage(); 165561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes String toS = tCause.toString(); 166561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes if (msgs[i].length() > 0) { 167561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes assertTrue("getMessage() must contain ".concat(msgs[i]), getM 168561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes .indexOf(msgs[i]) != -1); 169561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes if (!getM.equals(msgs[i])) { 170561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes assertTrue("getMessage() should contain ".concat(toS), getM 171561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes .indexOf(toS) != -1); 172561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes } 173561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes } 174561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes // SSLException is subclass of IOException, but IOException has not 175561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes // constructors with Throwable parameters 176561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes if (tE.getCause() != null) { 177561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes // assertNotNull("getCause() must not return null", 178561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes // tE.getCause()); 179561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes assertEquals("getCause() must return " 180561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes .concat(tCause.toString()), tE.getCause(), tCause); 181561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes } 182561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes } 183561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes } 184561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes 185561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes} 186