2 * Copyright (C) 2010 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package libcore.javax.net.ssl;
19 import java.util.Arrays;
20 import javax.net.ssl.SSLParameters;
21 import junit.framework.TestCase;
23 public class SSLParametersTest extends TestCase {
25 public void test_SSLParameters_emptyConstructor() {
26 SSLParameters p = new SSLParameters();
27 assertNull(p.getCipherSuites());
28 assertNull(p.getProtocols());
29 assertFalse(p.getWantClientAuth());
30 assertFalse(p.getNeedClientAuth());
33 public void test_SSLParameters_cipherSuitesConstructor() {
34 String[] cipherSuites = new String[] { "foo", null, "bar" };
35 SSLParameters p = new SSLParameters(cipherSuites);
36 assertNotNull(p.getCipherSuites());
37 assertNotSame(cipherSuites, p.getCipherSuites());
38 assertEquals(Arrays.asList(cipherSuites), Arrays.asList(p.getCipherSuites()));
39 assertNull(p.getProtocols());
40 assertFalse(p.getWantClientAuth());
41 assertFalse(p.getNeedClientAuth());
44 public void test_SSLParameters_cpherSuitesProtocolsConstructor() {
45 String[] cipherSuites = new String[] { "foo", null, "bar" };
46 String[] protocols = new String[] { "baz", null, "qux" };
47 SSLParameters p = new SSLParameters(cipherSuites, protocols);
48 assertNotNull(p.getCipherSuites());
49 assertNotNull(p.getProtocols());
50 assertNotSame(cipherSuites, p.getCipherSuites());
51 assertNotSame(protocols, p.getProtocols());
52 assertEquals(Arrays.asList(cipherSuites), Arrays.asList(p.getCipherSuites()));
53 assertEquals(Arrays.asList(protocols), Arrays.asList(p.getProtocols()));
54 assertFalse(p.getWantClientAuth());
55 assertFalse(p.getNeedClientAuth());
58 public void test_SSLParameters_CipherSuites() {
59 SSLParameters p = new SSLParameters();
60 assertNull(p.getCipherSuites());
62 // confirm clone on input
63 String[] cipherSuites = new String[] { "fnord" };
64 String[] copy = cipherSuites.clone();
65 p.setCipherSuites(copy);
67 assertEquals(Arrays.asList(cipherSuites), Arrays.asList(p.getCipherSuites()));
69 // confirm clone on output
70 assertNotSame(p.getCipherSuites(), p.getCipherSuites());
73 public void test_SSLParameters_Protocols() {
74 SSLParameters p = new SSLParameters();
75 assertNull(p.getProtocols());
77 // confirm clone on input
78 String[] protocols = new String[] { "fnord" };
79 String[] copy = protocols.clone();
82 assertEquals(Arrays.asList(protocols), Arrays.asList(p.getProtocols()));
84 // confirm clone on output
85 assertNotSame(p.getProtocols(), p.getProtocols());
88 public void test_SSLParameters_ClientAuth() {
89 SSLParameters p = new SSLParameters();
90 assertFalse(p.getWantClientAuth());
91 assertFalse(p.getNeedClientAuth());
93 // confirm turning one on by itself
94 p.setWantClientAuth(true);
95 assertTrue(p.getWantClientAuth());
96 assertFalse(p.getNeedClientAuth());
98 // confirm turning setting on toggles the other
99 p.setNeedClientAuth(true);
100 assertFalse(p.getWantClientAuth());
101 assertTrue(p.getNeedClientAuth());
103 // confirm toggling back
104 p.setWantClientAuth(true);
105 assertTrue(p.getWantClientAuth());
106 assertFalse(p.getNeedClientAuth());