Source Code Cross Referenced for NamingTest.java in  » Web-Server » Winstone » winstone » testCase » 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 » Web Server » Winstone » winstone.testCase 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2003-2006 Rick Knowles <winstone-devel at lists sourceforge net>
003:         * Distributed under the terms of either:
004:         * - the common development and distribution license (CDDL), v1.0; or
005:         * - the GNU Lesser General Public License, v2.1 or later
006:         */
007:        package winstone.testCase;
008:
009:        import java.util.Hashtable;
010:
011:        import javax.naming.Context;
012:        import javax.naming.InitialContext;
013:        import javax.naming.NamingEnumeration;
014:        import javax.naming.NamingException;
015:
016:        import junit.framework.Test;
017:        import junit.framework.TestCase;
018:        import junit.framework.TestSuite;
019:
020:        /**
021:         * Automated tests for the JNDI provider component of Winstone
022:         * 
023:         * @author <a href="mailto:rick_knowles@hotmail.com">Rick Knowles</a>
024:         * @version $Id: NamingTest.java,v 1.2 2006/02/28 07:32:49 rickknowles Exp $
025:         */
026:        public class NamingTest extends TestCase {
027:            public static Test suite() {
028:                return (new TestSuite(NamingTest.class));
029:            }
030:
031:            private InitialContext ic;
032:
033:            /**
034:             * Constructor for the junit test class for the JNDI service.
035:             * 
036:             * @param name
037:             *            The name of the test case
038:             */
039:            public NamingTest(String name) {
040:                super (name);
041:            }
042:
043:            /**
044:             * Begins the setup of the test case
045:             */
046:            public void setUp() throws NamingException {
047:                Hashtable env = new Hashtable();
048:                env.put(Context.INITIAL_CONTEXT_FACTORY,
049:                        "winstone.jndi.java.javaURLContextFactory");
050:                env.put(Context.URL_PKG_PREFIXES, "winstone.jndi");
051:                this .ic = new InitialContext(env);
052:            }
053:
054:            /**
055:             * Undoes any setup work for the test case
056:             */
057:            public void tearDown() throws NamingException {
058:                this .ic.close();
059:                this .ic = null;
060:            }
061:
062:            /**
063:             * Performs an absolute context lookup
064:             */
065:            public void testAbsoluteContextLookup() throws NamingException {
066:                Object context1 = this .ic.lookup("java:/comp/env");
067:                assertNotNull("Lookup on java:/comp/env must be non-null",
068:                        context1);
069:                assertTrue("Lookup on java:/comp/env must be a Context",
070:                        context1 instanceof  Context);
071:
072:                Object context2 = this .ic.lookup("java:/comp/env/");
073:                assertNotNull("Lookup on java:/comp/env/ must be non-null",
074:                        context2);
075:                assertTrue("Lookup on java:/comp/env/ must be a Context",
076:                        context2 instanceof  Context);
077:            }
078:
079:            /**
080:             * Performs an absolute lookup on the context
081:             */
082:            public void testAbsoluteLookup() throws NamingException {
083:                Object value = this .ic.lookup("java:/comp/env");
084:                assertNotNull("Lookup on java:/comp/env must be non-null",
085:                        value);
086:            }
087:
088:            /**
089:             * Performs a relative lookup on the context
090:             */
091:            public void testRelativeLookup() throws NamingException {
092:                Object value = this .ic.lookup("");
093:                assertNotNull("Lookup on \"\" must be non-null", value);
094:            }
095:
096:            /**
097:             * Performs a relative list on the context
098:             */
099:            public void testRelativeList() throws NamingException {
100:                NamingEnumeration listing = this .ic.list("");
101:                assertNotNull("Listing of current context must be non-null",
102:                        listing);
103:                listing.close();
104:            }
105:
106:            /**
107:             * Performs an absolute list on the context
108:             */
109:            public void testAbsoluteList() throws NamingException {
110:                NamingEnumeration listing1 = this .ic.list("java:/comp/env");
111:                assertNotNull("Listing of java:/comp/env must be non-null",
112:                        listing1);
113:                listing1.close();
114:                NamingEnumeration listing2 = this .ic.list("java:/comp/env/");
115:                assertNotNull("Listing of java:/comp/env/ must be non-null",
116:                        listing2);
117:                listing2.close();
118:            }
119:
120:            /**
121:             * Performs an absolute list on the context
122:             */
123:            public void testCreateDestroyContexts() throws NamingException {
124:                Context child = this .ic.createSubcontext("TestChildContext");
125:                assertNotNull(
126:                        "Created subcontext TestChildContext must not be null",
127:                        child);
128:                NamingEnumeration listing = child.list("");
129:                assertTrue("Listing on new child context is empty", !listing
130:                        .hasMoreElements());
131:                listing.close();
132:                this .ic.destroySubcontext("java:/comp/env/TestChildContext");
133:            }
134:
135:            /**
136:             * Attempts a simple bind
137:             */
138:            public void testSimpleBind() throws NamingException {
139:                Context child = this .ic.createSubcontext("TestBindContext");
140:                assertNotNull(
141:                        "Created subcontext TestBindContext must not be null",
142:                        child);
143:                child.bind("bindInteger", new Integer(80));
144:                Object lookupInt = this .ic
145:                        .lookup("TestBindContext/bindInteger");
146:                assertNotNull(
147:                        "java:/comp/env/TestBindContext/bindInteger should be non-null",
148:                        lookupInt);
149:                assertEquals("java:/comp/env/TestBindContext/bindInteger",
150:                        lookupInt, new Integer(80));
151:                this .ic.destroySubcontext("java:/comp/env/TestBindContext");
152:            }
153:
154:            /**
155:             * Attempts a rebind
156:             */
157:            public void testSimpleRebind() throws NamingException {
158:                Context child = this .ic.createSubcontext("TestRebindContext");
159:                assertNotNull(
160:                        "Created subcontext TestRebindContext must not be null",
161:                        child);
162:                Context rebindChild = child.createSubcontext("ChildRebind");
163:                assertNotNull(
164:                        "Created subcontext rebindChild must not be null",
165:                        rebindChild);
166:                rebindChild.rebind(
167:                        "java:/comp/env/TestRebindContext/ChildRebind/integer",
168:                        new Integer(25));
169:                rebindChild.close();
170:                child.close();
171:
172:                Object lookupInt = this .ic
173:                        .lookup("java:/comp/env/TestRebindContext/ChildRebind/integer");
174:                assertNotNull(
175:                        "java:/comp/env/TestRebindContext/ChildRebind/integer should be non-null",
176:                        lookupInt);
177:                assertEquals(
178:                        "java:/comp/env/TestRebindContext/ChildRebind/integer",
179:                        lookupInt, new Integer(25));
180:
181:                this .ic.rebind("TestRebindContext/ChildRebind/integer",
182:                        new Integer(40));
183:                Object lookupInt2 = this .ic
184:                        .lookup("TestRebindContext/ChildRebind/integer");
185:                assertNotNull(
186:                        "TestRebindContext/ChildRebind/integer should be non-null",
187:                        lookupInt2);
188:                assertEquals("TestRebindContext/ChildRebind/integer",
189:                        lookupInt2, new Integer(40));
190:                Object lookupInt3 = this .ic
191:                        .lookup("java:/comp/env/TestRebindContext/ChildRebind/integer");
192:                assertNotNull(
193:                        "java:/comp/env/TestRebindContext/ChildRebind/integer should be non-null",
194:                        lookupInt3);
195:                assertEquals(
196:                        "java:/comp/env/TestRebindContext/ChildRebind/integer",
197:                        lookupInt3, new Integer(40));
198:
199:                this .ic
200:                        .destroySubcontext("java:/comp/env/TestRebindContext/ChildRebind");
201:                this .ic.destroySubcontext("java:/comp/env/TestRebindContext");
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.