Source Code Cross Referenced for ProxyTest.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » luni » tests » java » net » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » org package » org.apache.harmony.luni.tests.java.net 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Licensed to the Apache Software Foundation (ASF) under one or more
002:         * contributor license agreements.  See the NOTICE file distributed with
003:         * this work for additional information regarding copyright ownership.
004:         * The ASF licenses this file to You under the Apache License, Version 2.0
005:         * (the "License"); you may not use this file except in compliance with
006:         * the License.  You may obtain a copy of the License at
007:         * 
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.apache.harmony.luni.tests.java.net;
017:
018:        import java.net.InetSocketAddress;
019:        import java.net.Proxy;
020:        import java.net.SocketAddress;
021:
022:        import junit.framework.TestCase;
023:
024:        public class ProxyTest extends TestCase {
025:
026:            private SocketAddress address = new InetSocketAddress("127.0.0.1",
027:                    1234);
028:
029:            /**
030:             * @tests java.net.Proxy#Proxy(java.net.Proxy.Type, SocketAddress)
031:             */
032:            public void test_ConstructorLjava_net_ProxyLjava_net_SocketAddress_Normal() {
033:                // test HTTP type proxy
034:                Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
035:                assertEquals(Proxy.Type.HTTP, proxy.type());
036:                assertEquals(address, proxy.address());
037:
038:                // test SOCKS type proxy
039:                proxy = new Proxy(Proxy.Type.SOCKS, address);
040:                assertEquals(Proxy.Type.SOCKS, proxy.type());
041:                assertEquals(address, proxy.address());
042:
043:                // test DIRECT type proxy
044:                proxy = Proxy.NO_PROXY;
045:                assertEquals(Proxy.Type.DIRECT, proxy.type());
046:                assertNull(proxy.address());
047:            }
048:
049:            /**
050:             * @tests java.net.Proxy#Proxy(java.net.Proxy.Type, SocketAddress)
051:             */
052:            public void test_ConstructorLjava_net_ProxyLjava_net_SocketAddress_IllegalAddress() {
053:                Proxy proxy = null;
054:                // test HTTP type proxy
055:                try {
056:                    proxy = new Proxy(Proxy.Type.HTTP, null);
057:                    fail("should throw IllegalArgumentException");
058:                } catch (IllegalArgumentException e) {
059:                    // expected
060:                }
061:                // test SOCKS type proxy
062:                try {
063:                    proxy = new Proxy(Proxy.Type.SOCKS, null);
064:                    fail("should throw IllegalArgumentException");
065:                } catch (IllegalArgumentException e) {
066:                    // expected
067:                }
068:                // test DIRECT type proxy
069:                try {
070:                    proxy = new Proxy(Proxy.Type.DIRECT, null);
071:                    fail("should throw IllegalArgumentException");
072:                } catch (IllegalArgumentException e) {
073:                    // expected
074:                }
075:                // test DIRECT type proxy, any address is illegal
076:                try {
077:                    proxy = new Proxy(Proxy.Type.DIRECT, address);
078:                    fail("should throw IllegalArgumentException");
079:                } catch (IllegalArgumentException e) {
080:                    // expected
081:                }
082:
083:            }
084:
085:            /**
086:             * @tests java.net.Proxy#hashCode()
087:             * @see also see test_equalsLjava_lang_Object_Equals
088:             */
089:            public void test_hashCode() {
090:                // This method has been tested in test_equalsLjava_lang_Object_Equals.
091:            }
092:
093:            /**
094:             * @tests java.net.Proxy#type()
095:             */
096:            public void test_type() {
097:                // This method has been tested in test_ConstructorLjava_net_ProxyLjava_net_SocketAddress_Normal. 
098:            }
099:
100:            /**
101:             * @tests java.net.Proxy#address() This method has been tested in
102:             *        Constructor test case.
103:             */
104:            public void test_address() {
105:                // This method has been tested in test_ConstructorLjava_net_ProxyLjava_net_SocketAddress_Normal.
106:            }
107:
108:            /**
109:             * @tests java.net.Proxy#toString()
110:             */
111:            public void test_toString() {
112:                Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
113:                // include type String
114:                assertTrue(proxy.toString().indexOf(proxy.type().toString()) != -1);
115:                // include address String
116:                assertTrue(proxy.toString().indexOf(proxy.address().toString()) != -1);
117:
118:                proxy = new Proxy(Proxy.Type.SOCKS, address);
119:                // include type String
120:                assertTrue(proxy.toString().indexOf(proxy.type().toString()) != -1);
121:                // include address String
122:                assertTrue(proxy.toString().indexOf(proxy.address().toString()) != -1);
123:
124:                proxy = Proxy.NO_PROXY;
125:                // include type String
126:                assertTrue(proxy.toString().indexOf(proxy.type().toString()) != -1);
127:
128:                proxy = new Proxy(null, address);
129:                // ensure no NPE is thrown
130:                proxy.toString();
131:
132:            }
133:
134:            /**
135:             * @tests java.net.Proxy#equals(Object)
136:             */
137:            public void test_equalsLjava_lang_Object_Equals() {
138:                SocketAddress address1 = new InetSocketAddress("127.0.0.1",
139:                        1234);
140:                SocketAddress address2 = new InetSocketAddress("127.0.0.1",
141:                        1234);
142:                // HTTP type
143:                Proxy proxy1 = new Proxy(Proxy.Type.HTTP, address1);
144:                Proxy proxy2 = new Proxy(Proxy.Type.HTTP, address2);
145:                assertTrue(proxy1.equals(proxy2));
146:                // assert hashCode
147:                assertTrue(proxy1.hashCode() == proxy2.hashCode());
148:
149:                // SOCKS type
150:                Proxy proxy3 = new Proxy(Proxy.Type.SOCKS, address1);
151:                Proxy proxy4 = new Proxy(Proxy.Type.SOCKS, address2);
152:                assertTrue(proxy3.equals(proxy4));
153:                // assert hashCode
154:                assertTrue(proxy3.hashCode() == proxy4.hashCode());
155:
156:                // null type
157:                Proxy proxy5 = new Proxy(null, address1);
158:                Proxy proxy6 = new Proxy(null, address2);
159:                assertTrue(proxy5.equals(proxy6));
160:            }
161:
162:            /**
163:             * @tests java.net.Proxy#equals(Object)
164:             */
165:            public void test_equalsLjava_lang_Object_NotEquals() {
166:                SocketAddress address1 = new InetSocketAddress("127.0.0.1",
167:                        1234);
168:                SocketAddress address2 = new InetSocketAddress("127.0.0.1",
169:                        1235);
170:                Proxy proxy[] = { new Proxy(Proxy.Type.HTTP, address1),
171:                        new Proxy(Proxy.Type.HTTP, address2),
172:                        new Proxy(Proxy.Type.SOCKS, address1),
173:                        new Proxy(Proxy.Type.SOCKS, address2), Proxy.NO_PROXY,
174:                        new Proxy(null, address1), new Proxy(null, address2) };
175:                // All of them are not equals
176:                for (int i = 0; i < proxy.length; i++) {
177:                    for (int j = i + 1; j < proxy.length; j++) {
178:                        assertFalse(proxy[i].equals(proxy[j]));
179:                    }
180:                }
181:                // Not equals to an Object type instance. Ensure no exception is thrown.
182:                assertFalse(proxy[0].equals(new Object()));
183:            }
184:
185:            /**
186:             * @tests java.net.Proxy.Type#valueOf(String)
187:             */
188:            public void test_Type_valueOfLjava_lang_String_Normal() {
189:                assertEquals(Proxy.Type.DIRECT, Proxy.Type.valueOf("DIRECT"));
190:                assertEquals(Proxy.Type.HTTP, Proxy.Type.valueOf("HTTP"));
191:                assertEquals(Proxy.Type.SOCKS, Proxy.Type.valueOf("SOCKS"));
192:            }
193:
194:            /**
195:             * @tests java.net.Proxy.Type#valueOf(String)
196:             */
197:            public void test_Type_valueOfLjava_lang_String_IllegalName() {
198:                String[] illegalName = { "Direct", "direct", "http", "socks",
199:                        "illegalName", "" };
200:                for (int i = 0; i < illegalName.length; i++) {
201:                    try {
202:                        Proxy.Type.valueOf(illegalName[i]);
203:                        fail("should throw IllegalArgumentException, illegalName:"
204:                                + illegalName);
205:                    } catch (IllegalArgumentException e) {
206:                        // expected
207:                    }
208:                }
209:            }
210:
211:            /**
212:             * @tests java.net.Proxy.Type#valueOf(String)
213:             */
214:            public void test_Type_valueOfLjava_lang_String_NullPointerException() {
215:                // Some old RIs,which throw IllegalArgumentException.
216:                // Latest RIs throw NullPointerException.
217:                try {
218:                    Proxy.Type.valueOf(null);
219:                    fail("should throw an exception.");
220:                } catch (NullPointerException e) {
221:                    // May be caused by some compilers' code
222:                } catch (IllegalArgumentException e) {
223:                    // other compilers will throw this
224:                }
225:            }
226:
227:            /**
228:             * @tests java.net.Proxy.Type#values()
229:             */
230:            public void test_Type_values() {
231:                Proxy.Type types[] = Proxy.Type.values();
232:                assertEquals(3, types.length);
233:                assertEquals(Proxy.Type.DIRECT, types[0]);
234:                assertEquals(Proxy.Type.HTTP, types[1]);
235:                assertEquals(Proxy.Type.SOCKS, types[2]);
236:            }
237:
238:        }
w__w__w__.j_a__v___a__2s__.___c_o__m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.