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