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.provider.jsse; 19 20 import java.util.Enumeration; 21 import java.security.SecureRandom; 22 23 import javax.net.ssl.SSLSession; 24 25 import junit.framework.TestCase; 26 27 /** 28 * Tests for <code>SSLSessionContextImp</code> constructor and methods 29 */ 30 public class SSLSessionContextImplTest extends TestCase { 31 testSSLSessionContextImpl()32 public void testSSLSessionContextImpl() { 33 SecureRandom sr = new SecureRandom(); 34 SSLSessionImpl ses1 = new SSLSessionImpl( 35 CipherSuite.TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA, sr); 36 SSLSessionImpl ses2 = new SSLSessionImpl( 37 CipherSuite.TLS_DH_anon_WITH_3DES_EDE_CBC_SHA, sr); 38 SSLSessionImpl ses3 = new SSLSessionImpl( 39 CipherSuite.TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5, sr); 40 41 SSLSessionContextImpl context = new SSLSessionContextImpl(); 42 context.putSession(ses1); 43 context.putSession(ses2); 44 context.putSession(ses3); 45 46 for (Enumeration en = context.getIds(); en.hasMoreElements(); ) { 47 byte[] id = (byte[]) en.nextElement(); 48 assertTrue(context.getSession(id) != null); 49 } 50 51 SSLSession ses = context.getSession(ses1.getId()); 52 assertSame(ses1, ses); 53 54 ses = context.getSession(ses3.getId()); 55 assertSame(ses3, ses); 56 } 57 testGetSessionCacheSize()58 public void testGetSessionCacheSize() { 59 SSLSessionContextImpl context = new SSLSessionContextImpl(); 60 assertEquals(0, context.getSessionCacheSize()); 61 62 context.setSessionCacheSize(100); 63 assertEquals(100, context.getSessionCacheSize()); 64 65 try { 66 context.setSessionCacheSize(-1); 67 fail("No expected IllegalArgumentException"); 68 } catch (IllegalArgumentException e) { 69 } 70 } 71 testGetSessionTimeout()72 public void testGetSessionTimeout() { 73 SSLSessionContextImpl context = new SSLSessionContextImpl(); 74 assertEquals(0, context.getSessionTimeout()); 75 76 context.setSessionTimeout(1000); 77 assertEquals(1000, context.getSessionTimeout()); 78 79 try { 80 context.setSessionTimeout(-1); 81 fail("No expected IllegalArgumentException"); 82 } catch (IllegalArgumentException e) { 83 } 84 } 85 86 }