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 18 package org.apache.harmony.xnet.tests.provider.jsse; 19 20 import org.apache.harmony.xnet.provider.jsse.ProtocolVersion; 21 import junit.framework.TestCase; 22 23 /** 24 * Tests for <code>ProtocolVersion</code> constructor and methods 25 * 26 */ 27 public class ProtocolVersionTest extends TestCase { 28 29 public void testEquals() { 30 assertEquals(ProtocolVersion.getByVersion(new byte[] { 3, 0 }), 31 ProtocolVersion.getByName("SSLv3")); 32 assertEquals(ProtocolVersion.getByVersion(new byte[] { 3, 1 }), 33 ProtocolVersion.getByName("TLSv1")); 34 assertFalse(ProtocolVersion.getByVersion(new byte[] { 3, 0 }).equals( 35 ProtocolVersion.getByName("TLSv1"))); 36 37 } 38 39 /* 40 * Class under test for boolean isSupported(byte[]) 41 */ 42 public void testIsSupportedbyteArray() { 43 assertTrue(ProtocolVersion.isSupported(new byte[] { 3, 0 })); 44 assertTrue(ProtocolVersion.isSupported(new byte[] { 3, 1 })); 45 assertFalse(ProtocolVersion.isSupported(new byte[] { 3, 2 })); 46 } 47 48 public void testGetByVersion() { 49 assertNull(ProtocolVersion.getByVersion(new byte[] { 2, 1 })); 50 assertEquals("SSLv3", 51 ProtocolVersion.getByVersion(new byte[] { 3, 0 }).name); 52 assertEquals("TLSv1", 53 ProtocolVersion.getByVersion(new byte[] { 3, 1 }).name); 54 } 55 56 /* 57 * Class under test for boolean isSupported(String) 58 */ 59 public void testIsSupportedString() { 60 assertTrue(ProtocolVersion.isSupported("SSLv3")); 61 assertTrue(ProtocolVersion.isSupported("SSL")); 62 assertTrue(ProtocolVersion.isSupported("TLSv1")); 63 assertTrue(ProtocolVersion.isSupported("TLS")); 64 assertFalse(ProtocolVersion.isSupported("SSLv4")); 65 } 66 67 public void testGetByName() { 68 assertNull(ProtocolVersion.getByName("SSLv2")); 69 assertEquals("SSLv3", ProtocolVersion.getByName("SSLv3").name); 70 assertEquals("TLSv1", ProtocolVersion.getByName("TLSv1").name); 71 } 72 73 public void testGetLatestVersion() { 74 ProtocolVersion ver = ProtocolVersion.getLatestVersion(new String[] { 75 "SSLv2", "TLSv1", "SSLv3" }); 76 assertEquals("Incorrect protocol version", "TLSv1", ver.name); 77 78 ver = ProtocolVersion.getLatestVersion(new String[] {"SSLv3", 79 "unknown", "SSLv2" }); 80 assertEquals("Incorrect protocol version", "SSLv3", ver.name); 81 } 82 83 }