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