Source Code Cross Referenced for LdapContextFactoryTest.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » jndi » provider » ldap » 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.jndi.provider.ldap 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more 
003:         *  contributor license agreements.  See the NOTICE file distributed with 
004:         *  this work for additional information regarding copyright ownership. 
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0 
006:         *  (the "License"); you may not use this file except in compliance with 
007:         *  the License.  You may obtain a copy of the License at 
008:         * 
009:         *     http://www.apache.org/licenses/LICENSE-2.0 
010:         * 
011:         *  Unless required by applicable law or agreed to in writing, software 
012:         *  distributed under the License is distributed on an "AS IS" BASIS, 
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
014:         *  See the License for the specific language governing permissions and 
015:         *  limitations under the License. 
016:         */
017:
018:        package org.apache.harmony.jndi.provider.ldap;
019:
020:        import java.io.ByteArrayInputStream;
021:        import java.io.ByteArrayOutputStream;
022:        import java.io.IOException;
023:        import java.io.InputStream;
024:        import java.io.OutputStream;
025:        import java.net.InetAddress;
026:        import java.net.Socket;
027:        import java.net.UnknownHostException;
028:        import java.util.Hashtable;
029:
030:        import javax.naming.ConfigurationException;
031:        import javax.naming.Context;
032:        import javax.net.SocketFactory;
033:
034:        import junit.framework.TestCase;
035:
036:        public class LdapContextFactoryTest extends TestCase {
037:            private Hashtable<String, Object> env = new Hashtable<String, Object>();
038:
039:            private LdapContextFactory factory = new LdapContextFactory();
040:
041:            public void setUp() {
042:                env.clear();
043:            }
044:
045:            public void test_getInitialContext() throws Exception {
046:                env.put(Context.PROVIDER_URL, "ldap://192.168.1.1:389");
047:
048:                env.put("java.naming.ldap.factory.socket",
049:                        MockSocketFactory.class.getName());
050:                factory.getInitialContext(env);
051:                assertEquals("192.168.1.1", MockSocketFactory.host);
052:                assertEquals(389, MockSocketFactory.port);
053:                env.clear();
054:
055:                env.put(Context.PROVIDER_URL, "ldap:///");
056:
057:                env.put("java.naming.ldap.factory.socket",
058:                        MockSocketFactory.class.getName());
059:                factory.getInitialContext(env);
060:                // default address
061:                assertEquals("localhost", MockSocketFactory.host);
062:                // default port
063:                assertEquals(389, MockSocketFactory.port);
064:                env.clear();
065:
066:                env.put(Context.PROVIDER_URL, "ldap:///o=org?objectClass?one");
067:                env.put("java.naming.ldap.factory.socket",
068:                        MockSocketFactory.class.getName());
069:                try {
070:                    // only host, port and dn is allowed
071:                    factory.getInitialContext(env);
072:                    fail("Should throws ConfigurationException");
073:                } catch (ConfigurationException e) {
074:                    // expected
075:                }
076:                env.clear();
077:
078:            }
079:
080:            public static class MockSocketFactory extends SocketFactory {
081:
082:                static String host;
083:
084:                static int port;
085:
086:                private Socket socket = new MockSocket();
087:
088:                @Override
089:                public Socket createSocket(String host, int port)
090:                        throws IOException, UnknownHostException {
091:                    MockSocketFactory.host = host;
092:                    MockSocketFactory.port = port;
093:                    return socket;
094:                }
095:
096:                @Override
097:                public Socket createSocket(InetAddress host, int port)
098:                        throws IOException {
099:                    this .host = host.getHostAddress();
100:                    this .port = port;
101:                    return socket;
102:                }
103:
104:                @Override
105:                public Socket createSocket(String host, int port,
106:                        InetAddress localHost, int localPort)
107:                        throws IOException, UnknownHostException {
108:                    this .host = host;
109:                    this .port = port;
110:                    return socket;
111:                }
112:
113:                @Override
114:                public Socket createSocket(InetAddress address, int port,
115:                        InetAddress localAddress, int localPort)
116:                        throws IOException {
117:                    this .host = address.getHostAddress();
118:                    this .port = port;
119:                    return socket;
120:                }
121:
122:            }
123:
124:            public static class MockSocket extends Socket {
125:
126:                public InputStream getInputStream() {
127:                    return new ByteArrayInputStream(new byte[0]);
128:                }
129:
130:                public OutputStream getOutputStream() {
131:                    return new ByteArrayOutputStream();
132:                }
133:            }
134:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.