You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2011/08/06 13:19:26 UTC
svn commit: r1154492 - in /httpcomponents/httpcore/trunk:
httpcore-nio/src/test/java/org/apache/http/impl/nio/
httpcore-nio/src/test/java/org/apache/http/impl/nio/pool/
httpcore/src/test/java/org/apache/http/impl/
httpcore/src/test/java/org/apache/http...
Author: olegk
Date: Sat Aug 6 11:19:25 2011
New Revision: 1154492
URL: http://svn.apache.org/viewvc?rev=1154492&view=rev
Log:
More test cases
Contributed by Bill Speirs <bill.speirs at gmail.com>
Added:
httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/TestContentChannel.java (with props)
httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/pool/
httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/pool/TestBasicNIOConnPool.java (with props)
httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestNoConnectionReuseStrategy.java (with props)
httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/pool/
httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/pool/TestBasicConnPool.java (with props)
Added: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/TestContentChannel.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/TestContentChannel.java?rev=1154492&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/TestContentChannel.java (added)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/TestContentChannel.java Sat Aug 6 11:19:25 2011
@@ -0,0 +1,83 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.http.impl.nio;
+
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.junit.Assert.*;
+
+import java.nio.ByteBuffer;
+
+import org.apache.http.nio.ContentDecoder;
+import org.apache.http.nio.ContentDecoderChannel;
+import org.apache.http.nio.ContentEncoder;
+import org.apache.http.nio.ContentEncoderChannel;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+public class TestContentChannel {
+
+ @Mock private ContentDecoder decoder;
+ @Mock private ContentEncoder encoder;
+ @Mock private ByteBuffer bb;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void testContentDecoder() throws Exception {
+ ContentDecoderChannel cdc = new ContentDecoderChannel(decoder);
+
+ cdc.read(bb);
+ verify(decoder, times(1)).read(bb);
+
+ assertTrue(cdc.isOpen());
+
+ cdc.close();
+ }
+
+ @Test
+ public void testContentEncoder() throws Exception {
+ ContentEncoderChannel cec = new ContentEncoderChannel(encoder);
+
+ cec.write(bb);
+ verify(encoder, times(1)).write(bb);
+
+ assertTrue(cec.isOpen());
+
+ cec.close();
+ }
+}
Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/TestContentChannel.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/TestContentChannel.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/TestContentChannel.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/pool/TestBasicNIOConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/pool/TestBasicNIOConnPool.java?rev=1154492&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/pool/TestBasicNIOConnPool.java (added)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/pool/TestBasicNIOConnPool.java Sat Aug 6 11:19:25 2011
@@ -0,0 +1,79 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.http.impl.nio.pool;
+
+
+import org.apache.http.HttpHost;
+import org.apache.http.nio.NHttpClientConnection;
+import org.apache.http.nio.reactor.ConnectingIOReactor;
+import org.apache.http.nio.reactor.IOSession;
+import org.apache.http.params.HttpParams;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+public class TestBasicNIOConnPool {
+
+ private BasicNIOConnPool pool;
+ @Mock private ConnectingIOReactor reactor;
+ @Mock private HttpParams params;
+ private HttpHost route;
+ @Mock private IOSession session;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+
+ route = new HttpHost("localhost", 80, "http");
+
+ pool = new BasicNIOConnPool(reactor, params);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testNullConstructor() throws Exception {
+ pool = new BasicNIOConnPool(null, null);
+ }
+
+ @Test
+ public void testCreateConnection() throws Exception {
+ pool.createConnection(route, session);
+ }
+
+ @Test
+ public void testCreateEntry() throws Exception {
+ NHttpClientConnection conn = pool.createConnection(route, session);
+ BasicNIOPoolEntry entry = pool.createEntry(route, conn);
+
+ pool.closeEntry(entry);
+ }
+}
Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/pool/TestBasicNIOConnPool.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/pool/TestBasicNIOConnPool.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/pool/TestBasicNIOConnPool.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestNoConnectionReuseStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestNoConnectionReuseStrategy.java?rev=1154492&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestNoConnectionReuseStrategy.java (added)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestNoConnectionReuseStrategy.java Sat Aug 6 11:19:25 2011
@@ -0,0 +1,39 @@
+package org.apache.http.impl;
+
+import junit.framework.Assert;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.protocol.HttpContext;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+
+public class TestNoConnectionReuseStrategy {
+
+ private NoConnectionReuseStrategy strat = new NoConnectionReuseStrategy();
+ @Mock private HttpResponse response;
+ @Mock private HttpContext context;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testNullResponse() throws Exception {
+ strat.keepAlive(null, context);
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testNullContext() throws Exception {
+ strat.keepAlive(response, null);
+ }
+
+ @Test
+ public void testGoodcall() throws Exception {
+ Assert.assertFalse(strat.keepAlive(response, context));
+ }
+
+}
Propchange: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestNoConnectionReuseStrategy.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestNoConnectionReuseStrategy.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestNoConnectionReuseStrategy.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/pool/TestBasicConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/pool/TestBasicConnPool.java?rev=1154492&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/pool/TestBasicConnPool.java (added)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/pool/TestBasicConnPool.java Sat Aug 6 11:19:25 2011
@@ -0,0 +1,126 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.http.impl.pool;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
+
+import java.net.ServerSocket;
+
+import javax.net.ssl.SSLServerSocket;
+import javax.net.ssl.SSLServerSocketFactory;
+import javax.net.ssl.SSLSocketFactory;
+
+import org.apache.http.HttpClientConnection;
+import org.apache.http.HttpHost;
+import org.apache.http.params.CoreConnectionPNames;
+import org.apache.http.params.HttpParams;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+public class TestBasicConnPool {
+
+ private BasicConnPool pool;
+ private HttpHost host;
+ @Mock private HttpParams params;
+ private HttpClientConnection conn = null;
+
+ private ServerSocket server;
+ private int serverPort;
+
+ private SSLServerSocket sslServer;
+ private int sslServerPort;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+
+ // setup an "http" server
+ server = new ServerSocket(0);
+ serverPort = server.getLocalPort();
+
+ // setup an "https" server
+ sslServer = (SSLServerSocket) SSLServerSocketFactory.getDefault().createServerSocket(0);
+ sslServerPort = sslServer.getLocalPort();
+
+ pool = new BasicConnPool(params);
+
+ when(params.getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 0)).thenReturn(100);
+ when(params.getIntParameter(CoreConnectionPNames.SO_TIMEOUT, 0)).thenReturn(100);
+
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ server.close();
+ if(conn != null) {
+ conn.close();
+ conn.shutdown();
+ }
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testNullConstructor() throws Exception {
+ pool = new BasicConnPool(null, null);
+ }
+
+ @Test
+ public void testHttpCreateConnection() throws Exception {
+ host = new HttpHost("localhost", serverPort, "http");
+ conn = pool.createConnection(host);
+
+ assertEquals(true, conn.isOpen());
+ assertEquals(100, conn.getSocketTimeout());
+ }
+
+ @Test
+ public void testHttpsCreateConnection() throws Exception {
+ pool = new BasicConnPool((SSLSocketFactory)SSLSocketFactory.getDefault(), params);
+ host = new HttpHost("localhost", sslServerPort, "https");
+ conn = pool.createConnection(host);
+
+ assertEquals(true, conn.isOpen());
+ assertEquals(100, conn.getSocketTimeout());
+ }
+
+ @Test
+ public void testHttpCreateEntry() throws Exception {
+ host = new HttpHost("localhost", serverPort, "http");
+ conn = pool.createConnection(host);
+
+ BasicPoolEntry entry = pool.createEntry(host, conn);
+
+ assertEquals(conn, entry.getConnection());
+ assertEquals("localhost", entry.getRoute().getHostName());
+
+ pool.closeEntry(entry);
+ }
+
+}
Propchange: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/pool/TestBasicConnPool.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/pool/TestBasicConnPool.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/pool/TestBasicConnPool.java
------------------------------------------------------------------------------
svn:mime-type = text/plain