Source Code Cross Referenced for TestServlet.java in  » Database-DBMS » h2database » org » h2 » test » unit » 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 » Database DBMS » h2database » org.h2.test.unit 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
003:         * (license2)
004:         * Initial Developer: H2 Group
005:         */
006:        package org.h2.test.unit;
007:
008:        import java.io.InputStream;
009:        import java.net.MalformedURLException;
010:        import java.net.URL;
011:        import java.sql.Connection;
012:        import java.sql.DriverManager;
013:        import java.sql.SQLException;
014:        import java.sql.Statement;
015:        import java.util.Enumeration;
016:        import java.util.HashMap;
017:        import java.util.Properties;
018:        import java.util.Set;
019:
020:        import javax.servlet.RequestDispatcher;
021:        import javax.servlet.Servlet;
022:        import javax.servlet.ServletContext;
023:        import javax.servlet.ServletContextEvent;
024:        import javax.servlet.ServletException;
025:
026:        import org.h2.server.web.DbStarter;
027:        import org.h2.test.TestBase;
028:
029:        /**
030:         * Tests the DbStarter servlet.
031:         * This test simulates a minimum servlet container environment.
032:         */
033:        public class TestServlet extends TestBase {
034:
035:            /**
036:             * Minimum ServletContext implementation.
037:             * Most methods are not implemented.
038:             */
039:            private static class TestServletContext implements  ServletContext {
040:
041:                private Properties initParams = new Properties();
042:                private HashMap attributes = new HashMap();
043:
044:                public void setAttribute(String key, Object value) {
045:                    attributes.put(key, value);
046:                }
047:
048:                public Object getAttribute(String key) {
049:                    return attributes.get(key);
050:                }
051:
052:                private void setInitParameter(String key, String value) {
053:                    initParams.setProperty(key, value);
054:                }
055:
056:                public String getInitParameter(String key) {
057:                    return initParams.getProperty(key);
058:                }
059:
060:                public Enumeration getAttributeNames() {
061:                    throw new UnsupportedOperationException();
062:                }
063:
064:                public ServletContext getContext(String string) {
065:                    throw new UnsupportedOperationException();
066:                }
067:
068:                public Enumeration getInitParameterNames() {
069:                    throw new UnsupportedOperationException();
070:                }
071:
072:                public int getMajorVersion() {
073:                    throw new UnsupportedOperationException();
074:                }
075:
076:                public String getMimeType(String string) {
077:                    throw new UnsupportedOperationException();
078:                }
079:
080:                public int getMinorVersion() {
081:                    throw new UnsupportedOperationException();
082:                }
083:
084:                public RequestDispatcher getNamedDispatcher(String string) {
085:                    throw new UnsupportedOperationException();
086:                }
087:
088:                public String getRealPath(String string) {
089:                    throw new UnsupportedOperationException();
090:                }
091:
092:                public RequestDispatcher getRequestDispatcher(String string) {
093:                    throw new UnsupportedOperationException();
094:                }
095:
096:                public URL getResource(String string)
097:                        throws MalformedURLException {
098:                    throw new UnsupportedOperationException();
099:                }
100:
101:                public InputStream getResourceAsStream(String string) {
102:                    throw new UnsupportedOperationException();
103:                }
104:
105:                public Set getResourcePaths(String string) {
106:                    throw new UnsupportedOperationException();
107:                }
108:
109:                public String getServerInfo() {
110:                    throw new UnsupportedOperationException();
111:                }
112:
113:                public Servlet getServlet(String string)
114:                        throws ServletException {
115:                    throw new UnsupportedOperationException();
116:                }
117:
118:                public String getServletContextName() {
119:                    throw new UnsupportedOperationException();
120:                }
121:
122:                public Enumeration getServletNames() {
123:                    throw new UnsupportedOperationException();
124:                }
125:
126:                public Enumeration getServlets() {
127:                    throw new UnsupportedOperationException();
128:                }
129:
130:                public void log(String string) {
131:                    throw new UnsupportedOperationException();
132:                }
133:
134:                public void log(Exception exception, String string) {
135:                    throw new UnsupportedOperationException();
136:                }
137:
138:                public void log(String string, Throwable throwable) {
139:                    throw new UnsupportedOperationException();
140:                }
141:
142:                public void removeAttribute(String string) {
143:                    throw new UnsupportedOperationException();
144:                }
145:
146:            }
147:
148:            public void test() throws Exception {
149:                if (config.networked || config.memory) {
150:                    return;
151:                }
152:                DbStarter listener = new DbStarter();
153:
154:                TestServletContext context = new TestServletContext();
155:                context.setInitParameter("db.url", getURL("servlet", true));
156:                context.setInitParameter("db.user", getUser());
157:                context.setInitParameter("db.password", getPassword());
158:                context.setInitParameter("db.tcpServer", "-tcpPort 8888");
159:
160:                ServletContextEvent event = new ServletContextEvent(context);
161:                listener.contextInitialized(event);
162:
163:                Connection conn1 = listener.getConnection();
164:                Connection conn1a = (Connection) context
165:                        .getAttribute("connection");
166:                check(conn1 == conn1a);
167:                Statement stat1 = conn1.createStatement();
168:                stat1.execute("CREATE TABLE T(ID INT)");
169:
170:                Connection conn2 = DriverManager.getConnection(
171:                        "jdbc:h2:tcp://localhost:8888/" + baseDir + "/servlet",
172:                        getUser(), getPassword());
173:                Statement stat2 = conn2.createStatement();
174:                stat2.execute("SELECT * FROM T");
175:                stat2.execute("DROP TABLE T");
176:
177:                try {
178:                    stat1.execute("SELECT * FROM T");
179:                    error();
180:                } catch (SQLException e) {
181:                    checkNotGeneralException(e);
182:                }
183:
184:                conn2.close();
185:
186:                listener.contextDestroyed(event);
187:
188:                // listener must be stopped
189:                try {
190:                    conn2 = DriverManager.getConnection(
191:                            "jdbc:h2:tcp://localhost:8888/" + baseDir
192:                                    + "/servlet", getUser(), getPassword());
193:                    error();
194:                } catch (SQLException e) {
195:                    checkNotGeneralException(e);
196:                }
197:
198:                // connection must be closed
199:                try {
200:                    stat1.execute("SELECT * FROM DUAL");
201:                    error();
202:                } catch (SQLException e) {
203:                    checkNotGeneralException(e);
204:                }
205:
206:            }
207:
208:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.