summaryrefslogtreecommitdiffstats
path: root/x-net/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'x-net/src/test/java')
-rw-r--r--x-net/src/test/java/org/apache/harmony/xnet/provider/jsse/ClientSessionContextTest.java86
-rw-r--r--x-net/src/test/java/org/apache/harmony/xnet/provider/jsse/FakeSession.java114
-rw-r--r--x-net/src/test/java/org/apache/harmony/xnet/provider/jsse/FileClientSessionCacheTest.java57
3 files changed, 0 insertions, 257 deletions
diff --git a/x-net/src/test/java/org/apache/harmony/xnet/provider/jsse/ClientSessionContextTest.java b/x-net/src/test/java/org/apache/harmony/xnet/provider/jsse/ClientSessionContextTest.java
deleted file mode 100644
index af4490b..0000000
--- a/x-net/src/test/java/org/apache/harmony/xnet/provider/jsse/ClientSessionContextTest.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.xnet.provider.jsse;
-
-import junit.framework.TestCase;
-
-import javax.net.ssl.SSLSession;
-import java.util.Enumeration;
-import java.util.Set;
-import java.util.HashSet;
-
-public class ClientSessionContextTest extends TestCase {
-
- public void testGetSessionById() {
- ClientSessionContext context = new ClientSessionContext(null, null);
-
- SSLSession a = new FakeSession("a");
- SSLSession b = new FakeSession("b");
-
- context.putSession(a);
- context.putSession(b);
-
- assertSame(a, context.getSession("a".getBytes()));
- assertSame(b, context.getSession("b".getBytes()));
-
- assertSame(a, context.getSession("a", 443));
- assertSame(b, context.getSession("b", 443));
-
- assertEquals(2, context.sessions.size());
-
- Set<SSLSession> sessions = new HashSet<SSLSession>();
- Enumeration ids = context.getIds();
- while (ids.hasMoreElements()) {
- sessions.add(context.getSession((byte[]) ids.nextElement()));
- }
-
- Set<SSLSession> expected = new HashSet<SSLSession>();
- expected.add(a);
- expected.add(b);
-
- assertEquals(expected, sessions);
- }
-
- public void testTrimToSize() {
- ClientSessionContext context = new ClientSessionContext(null, null);
-
- FakeSession a = new FakeSession("a");
- FakeSession b = new FakeSession("b");
- FakeSession c = new FakeSession("c");
- FakeSession d = new FakeSession("d");
-
- context.putSession(a);
- context.putSession(b);
- context.putSession(c);
- context.putSession(d);
-
- context.setSessionCacheSize(2);
-
- Set<SSLSession> sessions = new HashSet<SSLSession>();
- Enumeration ids = context.getIds();
- while (ids.hasMoreElements()) {
- sessions.add(context.getSession((byte[]) ids.nextElement()));
- }
-
- Set<SSLSession> expected = new HashSet<SSLSession>();
- expected.add(c);
- expected.add(d);
-
- assertEquals(expected, sessions);
- }
-
-}
diff --git a/x-net/src/test/java/org/apache/harmony/xnet/provider/jsse/FakeSession.java b/x-net/src/test/java/org/apache/harmony/xnet/provider/jsse/FakeSession.java
deleted file mode 100644
index 4a793dd..0000000
--- a/x-net/src/test/java/org/apache/harmony/xnet/provider/jsse/FakeSession.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.xnet.provider.jsse;
-
-import javax.net.ssl.SSLSession;
-import javax.net.ssl.SSLSessionContext;
-import java.security.cert.Certificate;
-import java.security.Principal;
-
-class FakeSession implements SSLSession {
- final String host;
-
- FakeSession(String host) {
- this.host = host;
- }
-
- public int getApplicationBufferSize() {
- throw new UnsupportedOperationException();
- }
-
- public String getCipherSuite() {
- throw new UnsupportedOperationException();
- }
-
- public long getCreationTime() {
- throw new UnsupportedOperationException();
- }
-
- public byte[] getId() {
- return host.getBytes();
- }
-
- public long getLastAccessedTime() {
- throw new UnsupportedOperationException();
- }
-
- public Certificate[] getLocalCertificates() {
- throw new UnsupportedOperationException();
- }
-
- public Principal getLocalPrincipal() {
- throw new UnsupportedOperationException();
- }
-
- public int getPacketBufferSize() {
- throw new UnsupportedOperationException();
- }
-
- public javax.security.cert.X509Certificate[] getPeerCertificateChain() {
- throw new UnsupportedOperationException();
- }
-
- public Certificate[] getPeerCertificates() {
- throw new UnsupportedOperationException();
- }
-
- public String getPeerHost() {
- return host;
- }
-
- public int getPeerPort() {
- return 443;
- }
-
- public Principal getPeerPrincipal() {
- throw new UnsupportedOperationException();
- }
-
- public String getProtocol() {
- throw new UnsupportedOperationException();
- }
-
- public SSLSessionContext getSessionContext() {
- throw new UnsupportedOperationException();
- }
-
- public Object getValue(String name) {
- throw new UnsupportedOperationException();
- }
-
- public String[] getValueNames() {
- throw new UnsupportedOperationException();
- }
-
- public void invalidate() {
- throw new UnsupportedOperationException();
- }
-
- public boolean isValid() {
- throw new UnsupportedOperationException();
- }
-
- public void putValue(String name, Object value) {
- throw new UnsupportedOperationException();
- }
-
- public void removeValue(String name) {
- throw new UnsupportedOperationException();
- }
-}
diff --git a/x-net/src/test/java/org/apache/harmony/xnet/provider/jsse/FileClientSessionCacheTest.java b/x-net/src/test/java/org/apache/harmony/xnet/provider/jsse/FileClientSessionCacheTest.java
deleted file mode 100644
index ee50863..0000000
--- a/x-net/src/test/java/org/apache/harmony/xnet/provider/jsse/FileClientSessionCacheTest.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.xnet.provider.jsse;
-
-import junit.framework.TestCase;
-
-import java.io.File;
-import java.io.IOException;
-
-public class FileClientSessionCacheTest extends TestCase {
-
- public void testMaxSize() throws IOException, InterruptedException {
- String tmpDir = System.getProperty("java.io.tmpdir");
- if (tmpDir == null) {
- fail("Please set 'java.io.tmpdir' system property.");
- }
- File cacheDir = new File(tmpDir
- + "/" + FileClientSessionCacheTest.class.getName() + "/cache");
- final SSLClientSessionCache cache
- = FileClientSessionCache.usingDirectory(cacheDir);
- Thread[] threads = new Thread[10];
- final int iterations = FileClientSessionCache.MAX_SIZE * 10;
- for (int i = 0; i < threads.length; i++) {
- final int id = i;
- threads[i] = new Thread() {
- @Override
- public void run() {
- for (int i = 0; i < iterations; i++) {
- cache.putSessionData(new FakeSession(id + "." + i),
- new byte[10]);
- }
- }
- };
- }
- for (int i = 0; i < threads.length; i++) {
- threads[i].start();
- }
- for (int i = 0; i < threads.length; i++) {
- threads[i].join();
- }
- assertEquals(FileClientSessionCache.MAX_SIZE, cacheDir.list().length);
- }
-}