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 package org.apache.harmony.tests.javax.net.ssl; 18 19 import javax.net.ssl.SSLEngineResult; 20 21 import junit.framework.TestCase; 22 23 /** 24 * Tests for SSLEngineResult.Status class 25 * 26 */ 27 public class SSLEngineResultHandshakeStatusTest extends TestCase { 28 29 /** 30 * Test for <code> SSLEngineResult.HandshakeStatus.values() </code> 31 */ 32 public void test_SSLEngineResultHandshakeStatus_values() { 33 String[] str = {"NOT_HANDSHAKING", "FINISHED", "NEED_TASK", "NEED_WRAP", "NEED_UNWRAP"}; 34 SSLEngineResult.HandshakeStatus[] enS = SSLEngineResult.HandshakeStatus.values(); 35 if (enS.length == str.length) { 36 for (int i = 0; i < enS.length; i++) { 37 //System.out.println("enS[" + i + "] = " + enS[i]); 38 assertEquals("Incorrect Status", enS[i].toString(), str[i]); 39 } 40 } else { 41 fail("Incorrect number of enum constant was returned"); 42 } 43 } 44 45 /** 46 * Test for <code> SSLEngineResult.HandshakeStatus.valueOf(String name) </code> 47 */ 48 public void test_SSLEngineResultStatus_valueOf() { 49 String[] str = {"FINISHED", "NEED_TASK", "NEED_UNWRAP", "NEED_WRAP", "NOT_HANDSHAKING"}; 50 String[] str_invalid = {"", "FINISHED1", "NEED_task", "NEED_UN", 51 "NEED_WRAP_WRAP", "not_HANDSHAKING", "Bad string for verification valueOf method"}; 52 SSLEngineResult.HandshakeStatus enS; 53 54 //Correct parameter 55 for (int i = 0; i < str.length; i++) { 56 try { 57 enS = SSLEngineResult.HandshakeStatus.valueOf(str[i]); 58 assertEquals("Incorrect Status", enS.toString(), str[i]); 59 } catch (Exception e) { 60 fail("Unexpected exception " + e + " was thrown for " + str[i]); 61 } 62 } 63 64 //Incorrect parameter 65 for (int i = 0; i < str_invalid.length; i++) { 66 try { 67 enS = SSLEngineResult.HandshakeStatus.valueOf(str_invalid[i]); 68 fail("IllegalArgumentException should be thrown for " + str_invalid[i]); 69 } catch (IllegalArgumentException iae) { 70 //expected 71 } 72 } 73 74 //Null parameter 75 try { 76 enS = SSLEngineResult.HandshakeStatus.valueOf(null); 77 fail("NullPointerException/IllegalArgumentException should be thrown for NULL parameter"); 78 } catch (NullPointerException npe) { 79 //expected 80 } catch (IllegalArgumentException iae) { 81 } 82 } 83 } 84