socket factory mockups, include TestScheme in unit tests

git-svn-id: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk@548038 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Roland Weber 2007-06-17 13:08:14 +00:00
parent d34ee9f954
commit cca8a23380
4 changed files with 163 additions and 9 deletions

View File

@ -44,7 +44,7 @@ public class TestAllConn extends TestCase {
TestSuite suite = new TestSuite();
suite.addTest(TestHttpRoute.suite());
//suite.addTest(TestScheme.suite()); @@@ this one has a problem
suite.addTest(TestScheme.suite());
return suite;
}

View File

@ -38,7 +38,9 @@ import junit.framework.TestCase;
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 @@ public class TestScheme extends TestCase {
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 @@ public class TestScheme extends TestCase {
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 @@ public class TestScheme extends TestCase {
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 @@ public class TestScheme extends TestCase {
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 @@ public class TestScheme extends TestCase {
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));

View File

@ -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!");
}
}

View File

@ -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!");
}
}