You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ro...@apache.org on 2007/04/28 20:46:55 UTC

svn commit: r533410 - in /jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn: TestAllConnImpl.java TestTSCCMNoServer.java

Author: rolandw
Date: Sat Apr 28 11:46:54 2007
New Revision: 533410

URL: http://svn.apache.org/viewvc?view=rev&rev=533410
Log:
first (serverless) test case for TSCCM

Added:
    jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn/TestTSCCMNoServer.java   (with props)
Modified:
    jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn/TestAllConnImpl.java

Modified: jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn/TestAllConnImpl.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn/TestAllConnImpl.java?view=diff&rev=533410&r1=533409&r2=533410
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn/TestAllConnImpl.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn/TestAllConnImpl.java Sat Apr 28 11:46:54 2007
@@ -44,6 +44,7 @@
         TestSuite suite = new TestSuite();
 
         suite.addTest(TestLocalServer.suite());
+        suite.addTest(TestTSCCMNoServer.suite());
 
         return suite;
     }

Added: jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn/TestTSCCMNoServer.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn/TestTSCCMNoServer.java?view=auto&rev=533410
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn/TestTSCCMNoServer.java (added)
+++ jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn/TestTSCCMNoServer.java Sat Apr 28 11:46:54 2007
@@ -0,0 +1,136 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ * ====================================================================
+ * 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.conn;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.http.HttpHost;
+import org.apache.http.HttpVersion;
+import org.apache.http.params.HttpParams;
+import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.HttpProtocolParams;
+import org.apache.http.conn.Scheme;
+import org.apache.http.conn.SchemeRegistry;
+import org.apache.http.conn.SocketFactory;
+import org.apache.http.conn.PlainSocketFactory;
+import org.apache.http.conn.HttpRoute;
+import org.apache.http.conn.ManagedClientConnection;
+
+
+/**
+ * Tests for <code>ThreadSafeClientConnManager</code> that do not require
+ * a server to communicate with.
+ */
+public class TestTSCCMNoServer extends TestCase {
+
+    public TestTSCCMNoServer(String testName) {
+        super(testName);
+    }
+
+    public static void main(String args[]) {
+        String[] testCaseName = { TestTSCCMNoServer.class.getName() };
+        junit.textui.TestRunner.main(testCaseName);
+    }
+
+    public static Test suite() {
+        return new TestSuite(TestTSCCMNoServer.class);
+    }
+
+
+    /**
+     * Helper to instantiate a <code>ThreadSafeClientConnManager</code>.
+     *
+     * @param params    the parameters, or
+     *                  <code>null</code> to use defaults
+     * @param schreg    the scheme registry, or
+     *                  <code>null</code> to use defaults
+     *
+     * @return  a connection manager to test
+     */
+    public ThreadSafeClientConnManager createTSCCM(HttpParams params,
+                                                   SchemeRegistry schreg) {
+        if (params == null)
+            params = createDefaultParams();
+        if (schreg == null)
+            schreg = createSchemeRegistry();
+
+        return new ThreadSafeClientConnManager(params, schreg);
+    }
+
+
+    /**
+     * Instantiates default parameters.
+     *
+     * @return  the default parameters
+     */
+    public HttpParams createDefaultParams() {
+
+        HttpParams params = new BasicHttpParams();
+        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
+        HttpProtocolParams.setUseExpectContinue(params, false);
+
+        return params;
+    }
+
+    /**
+     * Instantiates a default scheme registry.
+     *
+     * @return the default scheme registry
+     */
+    public SchemeRegistry createSchemeRegistry() {
+
+        SchemeRegistry schreg = new SchemeRegistry();
+        SocketFactory sf = PlainSocketFactory.getSocketFactory();
+        schreg.register(new Scheme("http", sf, 80));
+
+        return schreg;
+    }
+
+
+    public void testGetConnection() {
+        ThreadSafeClientConnManager mgr = createTSCCM(null, null);
+
+        HttpHost target = new HttpHost("www.test.invalid", 80, "http");
+        HttpRoute route = new HttpRoute(target, null, false);
+
+        ManagedClientConnection conn = mgr.getConnection(route);
+        assertNotNull(conn);
+        assertNull(conn.getRoute());
+        assertFalse(conn.isOpen());
+
+        mgr.releaseConnection(conn);
+        mgr.shutdown();
+    }
+
+
+} // class TestTSCCMNoServer

Propchange: jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn/TestTSCCMNoServer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn/TestTSCCMNoServer.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/conn/TestTSCCMNoServer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain