Source Code Cross Referenced for JavaCompContextTest.java in  » EJB-Server-geronimo » naming » org » apache » geronimo » gjndi » 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 » EJB Server geronimo » naming » org.apache.geronimo.gjndi 
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:         */package org.apache.geronimo.gjndi;
017:
018:        import junit.framework.TestCase;
019:
020:        import javax.naming.NamingException;
021:        import javax.naming.CompositeName;
022:        import javax.naming.CompoundName;
023:        import javax.naming.Context;
024:        import javax.naming.NamingEnumeration;
025:        import javax.naming.NameClassPair;
026:        import javax.naming.Binding;
027:        import javax.naming.LinkRef;
028:        import javax.naming.InitialContext;
029:        import java.util.Map;
030:        import java.util.HashMap;
031:        import java.util.Iterator;
032:        import java.util.NoSuchElementException;
033:        import java.util.Properties;
034:        import java.util.Collections;
035:
036:        import org.apache.geronimo.naming.java.RootContext;
037:        import org.apache.xbean.naming.context.ImmutableContext;
038:        import org.apache.xbean.naming.context.WritableContext;
039:        import org.apache.xbean.naming.context.ContextAccess;
040:        import org.apache.xbean.naming.global.GlobalContextManager;
041:
042:        /**
043:         * @version $Rev$ $Date$
044:         */
045:        public class JavaCompContextTest extends TestCase {
046:            protected Context readOnlyContext;
047:            protected Properties syntax;
048:            protected Map envBinding;
049:            protected Context initialContext;
050:            protected Context compContext;
051:            protected Context envContext;
052:
053:            public void testInitialContext() throws NamingException {
054:                assertEquals("Hello", initialContext
055:                        .lookup("java:comp/env/hello"));
056:                assertEquals("Hello", initialContext.lookup(new CompositeName(
057:                        "java:comp/env/hello")));
058:            }
059:
060:            public void testLookup() throws NamingException {
061:                assertEquals("Hello", envContext.lookup("hello"));
062:                assertEquals("Hello", compContext.lookup("env/hello"));
063:                try {
064:                    envContext.lookup("foo");
065:                    fail();
066:                } catch (NamingException e) {
067:                    // OK
068:                }
069:                assertEquals("Hello", envContext.lookup(new CompositeName(
070:                        "hello")));
071:                assertEquals("Hello", compContext.lookup(new CompositeName(
072:                        "env/hello")));
073:                assertEquals("Hello", envContext.lookup(new CompoundName(
074:                        "hello", syntax)));
075:                assertEquals("Hello", compContext.lookup(new CompoundName(
076:                        "env/hello", syntax)));
077:
078:                assertEquals(envContext, envContext.lookup(""));
079:            }
080:
081:            public void testSubContext() throws NamingException {
082:                assertEquals("long name", initialContext
083:                        .lookup("java:comp/env/here/there/anywhere"));
084:                Context intermediate = (Context) initialContext
085:                        .lookup("java:comp/env/here/there");
086:                assertNotNull(intermediate);
087:                assertEquals("long name", intermediate.lookup("anywhere"));
088:            }
089:
090:            //     public void testSchemeLookup() throws NamingException {
091:            // //        envContext.lookup("dns:apache.org");
092:            //         assertEquals("Hello", envContext.lookup("java:comp/env/hello"));
093:            //         assertEquals("Hello", compContext.lookup("java:comp/env/hello"));
094:            //     }
095:
096:            public void testLookupLink() throws NamingException {
097:                assertEquals("Hello", envContext.lookup("link"));
098:            }
099:
100:            public void testComposeName() throws NamingException {
101:                assertEquals("org/research/user/jane", envContext.composeName(
102:                        "user/jane", "org/research"));
103:                assertEquals("research/user/jane", envContext.composeName(
104:                        "user/jane", "research"));
105:                assertEquals(new CompositeName("org/research/user/jane"),
106:                        envContext.composeName(new CompositeName("user/jane"),
107:                                new CompositeName("org/research")));
108:                assertEquals(new CompositeName("research/user/jane"),
109:                        envContext.composeName(new CompositeName("user/jane"),
110:                                new CompositeName("research")));
111:            }
112:
113:            public void testList() throws NamingException {
114:                NamingEnumeration ne;
115:                Map expected;
116:                Map result;
117:
118:                expected = new HashMap();
119:                for (Iterator i = envBinding.entrySet().iterator(); i.hasNext();) {
120:                    Map.Entry entry = (Map.Entry) i.next();
121:                    expected.put(entry.getKey(), entry.getValue().getClass()
122:                            .getName());
123:                }
124:                ne = envContext.list("");
125:                result = new HashMap();
126:                while (ne.hasMore()) {
127:                    NameClassPair pair = (NameClassPair) ne.next();
128:                    result.put(pair.getName(), pair.getClassName());
129:                }
130:                assertEquals(expected, result);
131:
132:                try {
133:                    ne.next();
134:                    fail();
135:                } catch (NoSuchElementException e) {
136:                    // ok
137:                }
138:                try {
139:                    ne.nextElement();
140:                    fail();
141:                } catch (NoSuchElementException e) {
142:                    // ok
143:                }
144:            }
145:
146:            public void testListBindings() throws NamingException {
147:                NamingEnumeration ne;
148:                ne = envContext.listBindings("");
149:                int count = 0;
150:                while (ne.hasMore()) {
151:                    count++;
152:                    Binding pair = (Binding) ne.next();
153:                    assertTrue(envBinding.containsKey(pair.getName()));
154:                    if (!(envBinding.get(pair.getName()) instanceof  Context)) {
155:                        assertEquals(pair.getObject(), envBinding.get(pair
156:                                .getName()));
157:                    }
158:                }
159:                assertEquals(envBinding.size(), count);
160:
161:                try {
162:                    ne.next();
163:                    fail();
164:                } catch (NoSuchElementException e) {
165:                    // ok
166:                }
167:                try {
168:                    ne.nextElement();
169:                    fail();
170:                } catch (NoSuchElementException e) {
171:                    // ok
172:                }
173:            }
174:
175:            public void testSpeed() throws NamingException {
176:                Context comp = (Context) initialContext.lookup("java:comp");
177:
178:                long start = System.currentTimeMillis();
179:                for (int i = 0; i < 1000000; i++) {
180:                    // initialContext.lookup("java:comp/hello"); // this is sloooow due to scheme resolution
181:                    // envContext.lookup("hello");
182:                    comp.lookup("env/hello");
183:                }
184:
185:                long end = System.currentTimeMillis();
186:                System.out.println("lookup(String) milliseconds: "
187:                        + (end - start));
188:            }
189:
190:            protected void setUp() throws Exception {
191:                super .setUp();
192:                System.setProperty("java.naming.factory.initial",
193:                        GlobalContextManager.class.getName());
194:                System.setProperty("java.naming.factory.url.pkgs",
195:                        "org.apache.geronimo.knaming");
196:
197:                LinkRef link = new LinkRef("java:comp/env/hello");
198:
199:                Map bindings = new HashMap();
200:                bindings.put("env/hello", "Hello");
201:                bindings.put("env/world", "Hello World");
202:                bindings.put("env/here/there/anywhere", "long name");
203:                bindings.put("env/link", link);
204:
205:                readOnlyContext = new WritableContext("", bindings,
206:                        ContextAccess.UNMODIFIABLE);
207:
208:                envBinding = new HashMap();
209:                envBinding.put("hello", "Hello");
210:                envBinding.put("world", "Hello World");
211:                envBinding.put("here", readOnlyContext.lookup("env/here"));
212:                envBinding.put("link", link);
213:
214:                RootContext.setComponentContext(readOnlyContext);
215:
216:                Context javaCompContext = new JavaCompContextGBean();
217:                Context globalContext = new ImmutableContext(Collections
218:                        .singletonMap(javaCompContext.getNameInNamespace(),
219:                                javaCompContext));
220:                GlobalContextManager.setGlobalContext(globalContext);
221:
222:                initialContext = new InitialContext();
223:                compContext = (Context) initialContext.lookup("java:comp");
224:                envContext = (Context) initialContext.lookup("java:comp/env");
225:
226:                syntax = new Properties();
227:            }
228:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.