Source Code Cross Referenced for SanityTest.java in  » Database-JDBC-Connection-Pool » jTDS » net » sourceforge » jtds » test » 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 JDBC Connection Pool » jTDS » net.sourceforge.jtds.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.jtds.test;
002:
003:        import java.sql.*;
004:
005:        /**
006:         * Some simple tests just to make sure everything is working properly.
007:         *
008:         * @created    9 August 2001
009:         * @version    1.0
010:         */
011:
012:        public class SanityTest extends TestBase {
013:            public SanityTest(String name) {
014:                super (name);
015:            }
016:
017:            /**
018:             * A simple test to make sure everything seems to be OK
019:             */
020:            public void testSanity() throws Exception {
021:                Statement stmt = con.createStatement();
022:                makeTestTables(stmt);
023:                makeObjects(stmt, 5);
024:                stmt.close();
025:            }
026:
027:            /**
028:             * Basic test of cursor mechanisms.
029:             */
030:            public void testCursorStatements() throws Exception {
031:                Statement stmt = con.createStatement();
032:                makeTestTables(stmt);
033:                makeObjects(stmt, 5);
034:
035:                ResultSet rs;
036:
037:                assertEquals("Expected an update count", false, stmt
038:                        .execute("DECLARE cursor1 SCROLL CURSOR FOR"
039:                                + "\nSELECT * FROM #test"));
040:
041:                assertEquals("Expected an update count", false, stmt
042:                        .execute("OPEN cursor1"));
043:
044:                rs = stmt.executeQuery("FETCH LAST FROM cursor1");
045:                dump(rs);
046:                rs.close();
047:
048:                rs = stmt.executeQuery("FETCH FIRST FROM cursor1");
049:                dump(rs);
050:                rs.close();
051:
052:                stmt.execute("CLOSE cursor1");
053:                stmt.execute("DEALLOCATE cursor1");
054:                stmt.close();
055:            }
056:
057:            public void testCursorRSCreate() throws Exception {
058:                Statement stmt = con.createStatement(
059:                        ResultSet.TYPE_SCROLL_INSENSITIVE,
060:                        ResultSet.CONCUR_READ_ONLY);
061:
062:                makeTestTables(stmt);
063:                makeObjects(stmt, 5);
064:
065:                ResultSet rs = stmt
066:                        .executeQuery("Select * from #test order by 1");
067:
068:                // Move to last row (5)
069:                rs.last();
070:                assertEquals(5, rs.getRow());
071:                assertEquals(4, rs.getInt(1));
072:                assertEquals(false, rs.isBeforeFirst());
073:                assertEquals(false, rs.isFirst());
074:                assertEquals(true, rs.isLast());
075:                assertEquals(false, rs.isAfterLast());
076:
077:                // Move before first row
078:                rs.beforeFirst();
079:                assertEquals(0, rs.getRow());
080:
081:                try {
082:                    rs.getInt(1);
083:                    fail("There should be no current row.");
084:                } catch (SQLException ex) {
085:                    // This is ok, there's no row
086:                }
087:
088:                assertEquals(true, rs.isBeforeFirst());
089:                assertEquals(false, rs.isFirst());
090:                assertEquals(false, rs.isLast());
091:                assertEquals(false, rs.isAfterLast());
092:
093:                // Try to move 3 rows ahead (should end up on row 3 -- the spec,
094:                // says that relative(1) is identical to next() and relative(-1) is
095:                // identical to previous(), but the Javadoc says that they are
096:                // different). Weird stuff...
097:                rs.relative(3);
098:                assertEquals(3, rs.getRow());
099:                assertEquals(2, rs.getInt(1));
100:                assertEquals(false, rs.isBeforeFirst());
101:                assertEquals(false, rs.isFirst());
102:                assertEquals(false, rs.isLast());
103:                assertEquals(false, rs.isAfterLast());
104:
105:                // Move after last row
106:                rs.afterLast();
107:                assertEquals(0, rs.getRow());
108:
109:                try {
110:                    rs.getInt(1);
111:                    fail("There should be no current row.");
112:                } catch (SQLException ex) {
113:                    // This is ok, there's no row
114:                }
115:
116:                assertEquals(false, rs.isBeforeFirst());
117:                assertEquals(false, rs.isFirst());
118:                assertEquals(false, rs.isLast());
119:                assertEquals(true, rs.isAfterLast());
120:
121:                // Move to first row
122:                rs.first();
123:                assertEquals(1, rs.getRow());
124:                assertEquals(0, rs.getInt(1));
125:                assertEquals(false, rs.isBeforeFirst());
126:                assertEquals(true, rs.isFirst());
127:                assertEquals(false, rs.isLast());
128:                assertEquals(false, rs.isAfterLast());
129:
130:                // Move to row 4
131:                rs.absolute(4);
132:                assertEquals(4, rs.getRow());
133:                assertEquals(3, rs.getInt(1));
134:                assertEquals(false, rs.isBeforeFirst());
135:                assertEquals(false, rs.isFirst());
136:                assertEquals(false, rs.isLast());
137:                assertEquals(false, rs.isAfterLast());
138:
139:                // Move 2 rows back
140:                rs.relative(-2);
141:                assertEquals(2, rs.getRow());
142:                assertEquals(1, rs.getInt(1));
143:                assertEquals(false, rs.isBeforeFirst());
144:                assertEquals(false, rs.isFirst());
145:                assertEquals(false, rs.isLast());
146:                assertEquals(false, rs.isAfterLast());
147:
148:                rs.close();
149:                stmt.close();
150:            }
151:
152:            public void testCursorRSScroll() throws Exception {
153:                Statement stmt = con.createStatement(
154:                        ResultSet.TYPE_SCROLL_INSENSITIVE,
155:                        ResultSet.CONCUR_READ_ONLY);
156:
157:                makeTestTables(stmt);
158:                makeObjects(stmt, 5);
159:
160:                ResultSet rs = stmt.executeQuery("Select * from #test");
161:
162:                while (rs.next())
163:                    ;
164:
165:                rs.close();
166:                stmt.close();
167:            }
168:
169:            /*
170:             * Check that image fields that have once been set to a non
171:             * null value return null when updated to null.
172:             * Fix bug [1774322] Sybase nulled text fields return not null.
173:             */
174:            public void testNullImage() throws Exception {
175:                Statement stmt = con.createStatement();
176:                stmt
177:                        .execute("CREATE TABLE #TEST (id int primary key not null, img image null)");
178:                stmt.executeUpdate("INSERT INTO #TEST VALUES (1, null)");
179:                ResultSet rs = stmt.executeQuery("SELECT * FROM #TEST");
180:                rs.next();
181:                assertTrue(rs.getBytes(2) == null);
182:                stmt
183:                        .executeUpdate("UPDATE #TEST SET img = '0x0123' WHERE id = 1");
184:                rs = stmt.executeQuery("SELECT * FROM #TEST");
185:                rs.next();
186:                assertTrue(rs.getBytes(2) != null);
187:                stmt.executeUpdate("UPDATE #TEST SET img = null WHERE id = 1");
188:                rs = stmt.executeQuery("SELECT * FROM #TEST");
189:                rs.next();
190:                assertTrue(rs.getBytes(2) == null);
191:                stmt.close();
192:            }
193:
194:            /*
195:             * Check that text fields that have once been set to a non
196:             * null value return null when updated to null.
197:             * Fix bug [1774322] Sybase nulled text fields return not null.
198:             */
199:            public void testNullText() throws Exception {
200:                Statement stmt = con.createStatement();
201:                stmt
202:                        .execute("CREATE TABLE #TEST (id int primary key not null, txt text null)");
203:                stmt.executeUpdate("INSERT INTO #TEST VALUES (1, null)");
204:                ResultSet rs = stmt.executeQuery("SELECT * FROM #TEST");
205:                rs.next();
206:                assertTrue(rs.getString(2) == null);
207:                stmt.executeUpdate("UPDATE #TEST SET txt = ' ' WHERE id = 1");
208:                rs = stmt.executeQuery("SELECT * FROM #TEST");
209:                rs.next();
210:                assertTrue(rs.getString(2) != null);
211:                stmt.executeUpdate("UPDATE #TEST SET txt = null WHERE id = 1");
212:                rs = stmt.executeQuery("SELECT * FROM #TEST");
213:                rs.next();
214:                assertTrue(rs.getString(2) == null);
215:                stmt.close();
216:            }
217:
218:            public static void main(String[] args) {
219:                junit.textui.TestRunner.run(SanityTest.class);
220:            }
221:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.