Source Code Cross Referenced for TestNamingEntries.java in  » Sevlet-Container » jetty-modules » org » mortbay » jetty » plus » naming » 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 » Sevlet Container » jetty modules » org.mortbay.jetty.plus.naming 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // ========================================================================
002:        // $Id: TestNamingEntries.java 887 2006-09-05 13:46:42Z janb $
003:        // Copyright 2006 Mort Bay Consulting Pty. Ltd.
004:        // ------------------------------------------------------------------------
005:        // Licensed under the Apache License, Version 2.0 (the "License");
006:        // you may not use this file except in compliance with the License.
007:        // You may obtain a copy of the License at 
008:        // http://www.apache.org/licenses/LICENSE-2.0
009:        // Unless required by applicable law or agreed to in writing, software
010:        // distributed under the License is distributed on an "AS IS" BASIS,
011:        // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012:        // See the License for the specific language governing permissions and
013:        // limitations under the License.
014:        // ========================================================================
015:
016:        package org.mortbay.jetty.plus.naming;
017:
018:        import java.util.Enumeration;
019:        import java.util.Hashtable;
020:
021:        import javax.naming.Context;
022:        import javax.naming.InitialContext;
023:        import javax.naming.Name;
024:        import javax.naming.NamingException;
025:        import javax.naming.RefAddr;
026:        import javax.naming.Reference;
027:        import javax.naming.Referenceable;
028:        import javax.naming.StringRefAddr;
029:        import javax.naming.spi.ObjectFactory;
030:
031:        import junit.framework.TestCase;
032:
033:        /**
034:         * TestEnvEntry
035:         *
036:         *
037:         */
038:        public class TestNamingEntries extends TestCase {
039:            public static class SomeObject {
040:                private int value;
041:
042:                public SomeObject(int value) {
043:                    this .value = value;
044:                }
045:
046:                public int getValue() {
047:                    return this .value;
048:                }
049:            }
050:
051:            public static class SomeObjectFactory implements  ObjectFactory {
052:
053:                public SomeObjectFactory() {
054:
055:                }
056:
057:                /** 
058:                 * @see javax.naming.spi.ObjectFactory#getObjectInstance(java.lang.Object, javax.naming.Name, javax.naming.Context, java.util.Hashtable)
059:                 * @param arg0
060:                 * @param arg1
061:                 * @param arg2
062:                 * @param arg3
063:                 * @return
064:                 * @throws Exception
065:                 */
066:                public Object getObjectInstance(Object arg0, Name arg1,
067:                        Context arg2, Hashtable arg3) throws Exception {
068:                    Reference ref = (Reference) arg0;
069:
070:                    RefAddr refAddr = ref.get(0);
071:                    String valueName = refAddr.getType();
072:                    if (!valueName.equalsIgnoreCase("val"))
073:                        throw new RuntimeException(
074:                                "Unrecognized refaddr type = " + valueName);
075:
076:                    String value = (String) refAddr.getContent();
077:
078:                    return new SomeObject(Integer.parseInt(value.trim()));
079:
080:                }
081:
082:            }
083:
084:            public static class SomeOtherObject extends SomeObject implements 
085:                    Referenceable {
086:
087:                private String svalue;
088:
089:                public SomeOtherObject(String value) {
090:                    super (Integer.parseInt(value.trim()));
091:
092:                }
093:
094:                /** 
095:                 * @see javax.naming.Referenceable#getReference()
096:                 * @return
097:                 * @throws NamingException
098:                 */
099:                public Reference getReference() throws NamingException {
100:                    RefAddr refAddr = new StringRefAddr("val", String
101:                            .valueOf(getValue()));
102:                    Reference ref = new Reference(SomeOtherObject.class
103:                            .getName(), refAddr, SomeOtherObjectFactory.class
104:                            .getName(), null);
105:                    return ref;
106:                }
107:            }
108:
109:            public static class SomeOtherObjectFactory implements  ObjectFactory {
110:
111:                public SomeOtherObjectFactory() {
112:
113:                }
114:
115:                /** 
116:                 * @see javax.naming.spi.ObjectFactory#getObjectInstance(java.lang.Object, javax.naming.Name, javax.naming.Context, java.util.Hashtable)
117:                 * @param arg0
118:                 * @param arg1
119:                 * @param arg2
120:                 * @param arg3
121:                 * @return
122:                 * @throws Exception
123:                 */
124:                public Object getObjectInstance(Object arg0, Name arg1,
125:                        Context arg2, Hashtable arg3) throws Exception {
126:                    Reference ref = (Reference) arg0;
127:
128:                    RefAddr refAddr = ref.get(0);
129:                    String valueName = refAddr.getType();
130:                    if (!valueName.equalsIgnoreCase("val"))
131:                        throw new RuntimeException(
132:                                "Unrecognized refaddr type = " + valueName);
133:
134:                    String value = (String) refAddr.getContent();
135:
136:                    return new SomeOtherObject(value.trim());
137:                }
138:
139:            }
140:
141:            public SomeObject someObject;
142:
143:            public void setUp() {
144:                this .someObject = new SomeObject(4);
145:            }
146:
147:            public void testEnvEntry() throws Exception {
148:                InitialContext icontext = new InitialContext();
149:
150:                //override webxml
151:                EnvEntry ee = new EnvEntry("nameA", someObject, true);
152:                assertNotNull(EnvEntry.getEnvEntry(NamingEntry.SCOPE_GLOBAL,
153:                        "nameA"));
154:                assertTrue(EnvEntry.getEnvEntry(NamingEntry.SCOPE_GLOBAL,
155:                        "nameA") instanceof  EnvEntry);
156:                Object x = icontext.lookup("nameA");
157:                assertNotNull(x);
158:                assertEquals(x, someObject);
159:            }
160:
161:            public void testResource() throws Exception {
162:                InitialContext icontext = new InitialContext();
163:
164:                Resource resource = new Resource("resourceA", someObject);
165:                assertNotNull(Resource.getResource(NamingEntry.SCOPE_GLOBAL,
166:                        "resourceA"));
167:                assertTrue(Resource.getResource(NamingEntry.SCOPE_GLOBAL,
168:                        "resourceA") instanceof  Resource);
169:                assertEquals(icontext.lookup("resourceA"), someObject);
170:            }
171:
172:            public void testResourceReferenceable() throws Exception {
173:                SomeOtherObject someOtherObj = new SomeOtherObject("100");
174:                InitialContext icontext = new InitialContext();
175:                Resource res = new Resource("resourceByReferenceable",
176:                        someOtherObj);
177:                Object o = icontext.lookup("resourceByReferenceable");
178:                assertNotNull(o);
179:                System.err.println(o);
180:                assertTrue(o instanceof  SomeOtherObject);
181:                assertEquals(((SomeOtherObject) o).getValue(), 100);
182:
183:            }
184:
185:            public void testResourceReference() throws Exception {
186:                RefAddr refAddr = new StringRefAddr("val", "10");
187:                Reference ref = new Reference(SomeObject.class.getName(),
188:                        refAddr, SomeObjectFactory.class.getName(), null);
189:
190:                InitialContext icontext = new InitialContext();
191:                Resource resource = new Resource("resourceByRef", ref);
192:                assertNotNull(Resource.getResource(NamingEntry.SCOPE_GLOBAL,
193:                        "resourceByRef"));
194:                assertTrue(Resource.getResource(NamingEntry.SCOPE_GLOBAL,
195:                        "resourceByRef") instanceof  Resource);
196:                Object o = icontext.lookup("resourceByRef");
197:                assertNotNull(o);
198:                assertTrue(o instanceof  SomeObject);
199:
200:                assertEquals(((SomeObject) o).getValue(), 10);
201:            }
202:
203:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.