hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rola...@apache.org
Subject svn commit: r548038 - in /jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http: conn/TestAllConn.java conn/TestScheme.java mockup/SecureSocketFactoryMockup.java mockup/SocketFactoryMockup.java
Date Sun, 17 Jun 2007 13:08:16 GMT
Author: rolandw
Date: Sun Jun 17 06:08:14 2007
New Revision: 548038

URL: http://svn.apache.org/viewvc?view=rev&rev=548038
Log:
socket factory mockups, include TestScheme in unit tests

Added:
    jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/mockup/SecureSocketFactoryMockup.java
  (with props)
    jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/mockup/SocketFactoryMockup.java
  (with props)
Modified:
    jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/conn/TestAllConn.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/conn/TestScheme.java

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/conn/TestAllConn.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/conn/TestAllConn.java?view=diff&rev=548038&r1=548037&r2=548038
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/conn/TestAllConn.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/conn/TestAllConn.java
Sun Jun 17 06:08:14 2007
@@ -44,7 +44,7 @@
         TestSuite suite = new TestSuite();
 
         suite.addTest(TestHttpRoute.suite());
-        //suite.addTest(TestScheme.suite()); @@@ this one has a problem
+        suite.addTest(TestScheme.suite());
 
         return suite;
     }

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/conn/TestScheme.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/conn/TestScheme.java?view=diff&rev=548038&r1=548037&r2=548038
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/conn/TestScheme.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/conn/TestScheme.java
Sun Jun 17 06:08:14 2007
@@ -38,7 +38,9 @@
 import junit.framework.TestSuite;
 
 import org.apache.http.HttpHost;
-import org.apache.http.conn.ssl.SSLSocketFactory;
+//import org.apache.http.conn.ssl.SSLSocketFactory;
+import org.apache.http.mockup.SecureSocketFactoryMockup;
+
 
 /**
  * Unit tests for {@link Scheme} and {@link SchemeRegistry}.
@@ -70,10 +72,12 @@
                    http.getSocketFactory()); 
         assertFalse(http.isLayered()); 
         Scheme https = new Scheme
-            ("https", SSLSocketFactory.getSocketFactory(), 443);
+            ("https", SecureSocketFactoryMockup.INSTANCE, 443);
+        //  ("https", SSLSocketFactory.getSocketFactory(), 443);
         assertEquals("https", https.getName()); 
         assertEquals(443, https.getDefaultPort()); 
-        assertSame(SSLSocketFactory.getSocketFactory(),
+        assertSame(//SSLSocketFactory.getSocketFactory()
+                   SecureSocketFactoryMockup.INSTANCE,
                    https.getSocketFactory()); 
         assertTrue(https.isLayered());
 
@@ -114,7 +118,8 @@
         Scheme http = new Scheme
             ("http", PlainSocketFactory.getSocketFactory(), 80);
         Scheme https = new Scheme
-            ("https", SSLSocketFactory.getSocketFactory(), 443);
+            ("https", SecureSocketFactoryMockup.INSTANCE, 443);
+        //  ("https", SSLSocketFactory.getSocketFactory(), 443);
         Scheme myhttp = new Scheme
             ("http", PlainSocketFactory.getSocketFactory(), 80);
 
@@ -147,7 +152,8 @@
         Scheme http = new Scheme
             ("http", PlainSocketFactory.getSocketFactory(), 80);
         Scheme https = new Scheme
-            ("https", SSLSocketFactory.getSocketFactory(), 443);
+            ("https", SecureSocketFactoryMockup.INSTANCE, 443);
+        //  ("https", SSLSocketFactory.getSocketFactory(), 443);
 
     	schmreg.register(http);
     	schmreg.register(https);
@@ -232,9 +238,10 @@
         Scheme myhttp = new Scheme
             ("http", PlainSocketFactory.getSocketFactory(), 80);
         Scheme https = new Scheme
-            ("http", SSLSocketFactory.getSocketFactory(), 443);
+            ("https", SecureSocketFactoryMockup.INSTANCE, 443);
+        //  ("https", SSLSocketFactory.getSocketFactory(), 443);
 
-        assertTrue(http.hashCode() != https.hashCode());
+        assertTrue(http.hashCode() != https.hashCode()); // not guaranteed
         assertTrue(http.hashCode() == myhttp.hashCode());
     }
     
@@ -244,7 +251,8 @@
         Scheme myhttp = new Scheme
             ("http", PlainSocketFactory.getSocketFactory(), 80);
         Scheme https = new Scheme
-            ("http", SSLSocketFactory.getSocketFactory(), 443);
+            ("https", SecureSocketFactoryMockup.INSTANCE, 443);
+        //  ("https", SSLSocketFactory.getSocketFactory(), 443);
 
         assertFalse(http.equals(https));
         assertFalse(http.equals(null));

Added: jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/mockup/SecureSocketFactoryMockup.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/mockup/SecureSocketFactoryMockup.java?view=auto&rev=548038
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/mockup/SecureSocketFactoryMockup.java
(added)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/mockup/SecureSocketFactoryMockup.java
Sun Jun 17 06:08:14 2007
@@ -0,0 +1,67 @@
+/*
+ * $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.mockup;
+
+import java.net.Socket;
+import java.net.InetAddress;
+
+import org.apache.http.conn.SecureSocketFactory;
+import org.apache.http.params.HttpParams;
+
+
+
+/**
+ * {@link SecureSocketFactory} mockup implementation.
+ */
+public class SecureSocketFactoryMockup extends SocketFactoryMockup
+    implements SecureSocketFactory {
+
+    /* A default instance of this mockup. */
+    public final static SecureSocketFactory INSTANCE =
+        new SecureSocketFactoryMockup("INSTANCE");
+
+
+    public SecureSocketFactoryMockup(String name) {
+        super(name);
+    }
+
+    // don't implement equals and hashcode, all instances are different!
+
+    public String toString() {
+        return "SecureSocketFactoryMockup." + mockup_name;
+    }
+
+
+    public Socket createSocket(Socket socket, String host, int port,
+                                      boolean autoClose) {
+        throw new UnsupportedOperationException("I'm a mockup!");
+    }
+}

Propchange: jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/mockup/SecureSocketFactoryMockup.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/mockup/SecureSocketFactoryMockup.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/mockup/SecureSocketFactoryMockup.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/mockup/SocketFactoryMockup.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/mockup/SocketFactoryMockup.java?view=auto&rev=548038
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/mockup/SocketFactoryMockup.java
(added)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/mockup/SocketFactoryMockup.java
Sun Jun 17 06:08:14 2007
@@ -0,0 +1,79 @@
+/*
+ * $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.mockup;
+
+import java.net.Socket;
+import java.net.InetAddress;
+
+import org.apache.http.conn.SocketFactory;
+import org.apache.http.params.HttpParams;
+
+
+
+/**
+ * {@link SocketFactory} mockup implementation.
+ */
+public class SocketFactoryMockup implements SocketFactory {
+
+    /* A default instance of this mockup. */
+    public final static SocketFactory INSTANCE =
+        new SocketFactoryMockup("INSTANCE");
+
+    /** The name of this mockup socket factory. */
+    protected final String mockup_name;
+
+
+    public SocketFactoryMockup(String name) {
+        mockup_name = (name != null) ? name : String.valueOf(hashCode());
+    }
+
+    // don't implement equals and hashcode, all instances are different!
+
+    public String toString() {
+        return "SocketFactoryMockup." + mockup_name;
+    }
+
+
+    public Socket createSocket() {
+        throw new UnsupportedOperationException("I'm a mockup!");
+    }
+
+    public Socket connectSocket(Socket sock, String host, int port,
+                                InetAddress localAddress, int localPort,
+                                HttpParams params) {
+        throw new UnsupportedOperationException("I'm a mockup!");
+    }
+
+    public boolean isSecure(Socket sock) {
+        // no way that the argument is from *this* factory...
+        throw new IllegalArgumentException("I'm a mockup!");
+    }
+}

Propchange: jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/mockup/SocketFactoryMockup.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/mockup/SocketFactoryMockup.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/mockup/SocketFactoryMockup.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message