01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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 })
35: .equals(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", ProtocolVersion.getByVersion(new byte[] {
51: 3, 0 }).name);
52: assertEquals("TLSv1", ProtocolVersion.getByVersion(new byte[] {
53: 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
75: .getLatestVersion(new String[] { "SSLv2", "TLSv1",
76: "SSLv3" });
77: assertEquals("Incorrect protocol version", "TLSv1", ver.name);
78:
79: ver = ProtocolVersion.getLatestVersion(new String[] { "SSLv3",
80: "unknown", "SSLv2" });
81: assertEquals("Incorrect protocol version", "SSLv3", ver.name);
82: }
83:
84: }
|