Home | History | Annotate | Download | only in ssl
      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 tests.api.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 SSLEngineResultStatusTest extends TestCase {
     28 
     29     /**
     30      * Test for <code> SSLEngineResult.Status.values() </code>
     31      */
     32     public void test_SSLEngineResultStatus_values() {
     33         boolean flag = false;
     34         String[] str = {"BUFFER_OVERFLOW", "BUFFER_UNDERFLOW", "CLOSED", "OK"};
     35         SSLEngineResult.Status[] enS = SSLEngineResult.Status.values();
     36         if (enS.length == str.length) {
     37             for (int i = 0; i < enS.length; i++) {
     38                 flag = false;
     39                 for (int j = 0; j < str.length; j++) {
     40                     if (enS[i].toString() == str[j]) {
     41                         flag = true;
     42                         break;
     43                     }
     44                 }
     45             }
     46             assertTrue("Incorrect Status", flag);
     47         } else {
     48             fail("Incorrect number of enum constant was returned");
     49         }
     50     }
     51 
     52     /**
     53      * Test for <code> SSLEngineResult.Status.valueOf(String name) </code>
     54      */
     55     public void test_SSLEngineResultStatus_valueOf() {
     56         String[] str = {"BUFFER_OVERFLOW", "BUFFER_UNDERFLOW", "CLOSED", "OK"};
     57         String[] str_invalid = {"", "OK1", "BUFFER_overflow", "BUFFER_UND",
     58                 "CLOSED_CLOSED", "Bad string for verification valueOf method"};
     59         SSLEngineResult.Status enS;
     60 
     61         //Correct parameter
     62         for (int i = 0; i < str.length; i++) {
     63             try {
     64                 enS = SSLEngineResult.Status.valueOf(str[i]);
     65                 assertEquals("Incorrect Status", enS.toString(), str[i]);
     66             } catch (Exception e) {
     67                 fail("Unexpected exception " + e + " was thrown for " + str[i]);
     68             }
     69         }
     70 
     71        //Incorrect parameter
     72         for (int i = 0; i < str_invalid.length; i++) {
     73             try {
     74                 enS = SSLEngineResult.Status.valueOf(str_invalid[i]);
     75                 fail("IllegalArgumentException should be thrown for " + str_invalid[i]);
     76             } catch (IllegalArgumentException iae) {
     77                 //expected
     78             }
     79         }
     80 
     81         //Null parameter
     82         try {
     83             enS = SSLEngineResult.Status.valueOf(null);
     84             fail("NullPointerException/IllegalArgumentException should be thrown for NULL parameter");
     85         } catch (NullPointerException npe) {
     86             //expected
     87         } catch (IllegalArgumentException iae) {
     88         }
     89     }
     90 }
     91