1   /*
2    * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/TestEquals.java,v 1.2 2004/02/22 18:08:49 olegk Exp $
3    * $Revision: 429852 $
4    * $Date: 2006-08-08 22:14:36 +0000 (Tue, 08 Aug 2006) $
5    *
6    * ====================================================================
7    *
8    *  Copyright 2002-2004 The Apache Software Foundation
9    *
10   *  Licensed under the Apache License, Version 2.0 (the "License");
11   *  you may not use this file except in compliance with the License.
12   *  You may obtain a copy of the License at
13   *
14   *      http://www.apache.org/licenses/LICENSE-2.0
15   *
16   *  Unless required by applicable law or agreed to in writing, software
17   *  distributed under the License is distributed on an "AS IS" BASIS,
18   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19   *  See the License for the specific language governing permissions and
20   *  limitations under the License.
21   * ====================================================================
22   *
23   * This software consists of voluntary contributions made by many
24   * individuals on behalf of the Apache Software Foundation.  For more
25   * information on the Apache Software Foundation, please see
26   * <http://www.apache.org/>.
27   *
28   * [Additional notices, if required by prior licensing conditions]
29   *
30   */
31   package> org.apache.commons.httpclient;
32  
33  import org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory;
34  import org.apache.commons.httpclient.protocol.Protocol;
35  import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
36  import org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory;
37  
38  import junit.framework.Test;
39  import junit.framework.TestCase;
40  import junit.framework.TestSuite;
41  
42  /***
43   */
44  public class TestEquals extends TestCase {
45      
46      public static Test suite() {
47          return new TestSuite(TestEquals.class);
48      }
49      
50      /***
51       * 
52       */
53      public TestEquals() {
54          super();
55      }
56  
57      /***
58       * @param arg0
59       */
60      public TestEquals(String arg0) {
61          super(arg0);
62      }
63  
64      public void testProtocol() {
65          
66          Protocol p1 = new Protocol("test", new DefaultProtocolSocketFactory(), 123);
67          Protocol p2 = new Protocol("test", new DefaultProtocolSocketFactory(), 123);
68          
69          assertTrue(p1.equals(p2));
70          assertTrue(p2.equals(p1));
71      }
72      
73      public void testProtocolSocketFactory() {
74          
75          ProtocolSocketFactory p1 = new DefaultProtocolSocketFactory();
76          ProtocolSocketFactory p2 = new DefaultProtocolSocketFactory();
77  
78          assertTrue(p1.equals(p2));
79          assertTrue(p2.equals(p1));
80  
81          p1 = new SSLProtocolSocketFactory();
82          p2 = new SSLProtocolSocketFactory();
83  
84          assertTrue(p1.equals(p2));
85          assertTrue(p2.equals(p1));
86          
87      }
88      
89      public void testProtocolSocketFactorySublass() {
90          ProtocolSocketFactory factory1 = new DefaultProtocolSocketFactory();
91          ProtocolSocketFactory factory2 = new DefaultProtocolSocketFactory() {};
92  
93          Protocol protocolA = new Protocol("http", factory1, 80);
94          Protocol protocolB = new Protocol("http", factory2, 80);
95          Protocol protocolC = new Protocol("http", factory2, 80);
96  
97          assertTrue(protocolB.equals(protocolC));
98          assertFalse(protocolA.equals(protocolB));
99          assertFalse(protocolB.equals(protocolA));
100         assertFalse(protocolA.equals(protocolB) != protocolB.equals(protocolA));
101         assertTrue(protocolB.equals(protocolB));
102     }
103     
104     public void testHostConfiguration() {
105         
106         HostConfiguration hc1 = new HostConfiguration();
107         hc1.setHost("http", 80, "http");
108 
109         HostConfiguration hc2 = new HostConfiguration();
110         hc2.setHost("http", 80, "http");
111 
112         assertTrue(hc1.equals(hc2));
113         assertTrue(hc2.equals(hc1));
114     }
115     
116 }