Source Code Cross Referenced for AbstractResultSetHandlerTest.java in  » Testing » mockrunner-0.4 » com » mockrunner » test » jdbc » 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 » Testing » mockrunner 0.4 » com.mockrunner.test.jdbc 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.mockrunner.test.jdbc;
002:
003:        import java.sql.BatchUpdateException;
004:        import java.sql.SQLException;
005:
006:        import com.mockrunner.base.BaseTestCase;
007:        import com.mockrunner.jdbc.StatementResultSetHandler;
008:        import com.mockrunner.mock.jdbc.MockConnection;
009:        import com.mockrunner.mock.jdbc.MockResultSet;
010:
011:        public class AbstractResultSetHandlerTest extends BaseTestCase {
012:            private MockConnection connection;
013:            private StatementResultSetHandler statementHandler;
014:
015:            protected void setUp() throws Exception {
016:                super .setUp();
017:                connection = getJDBCMockObjectFactory().getMockConnection();
018:                statementHandler = connection.getStatementResultSetHandler();
019:            }
020:
021:            public void testGetResultSet() {
022:                MockResultSet result = new MockResultSet("id");
023:                statementHandler.prepareResultSet("select column from table",
024:                        result);
025:                statementHandler.prepareResultSet("select .*", result);
026:                assertSame(result, statementHandler
027:                        .getResultSet("select column from table"));
028:                assertNull(statementHandler
029:                        .getResultSet("select xyz from table"));
030:                statementHandler.setUseRegularExpressions(true);
031:                assertSame(result, statementHandler
032:                        .getResultSet("select column from table"));
033:                assertSame(result, statementHandler
034:                        .getResultSet("SELECT xyz from table"));
035:                statementHandler.setCaseSensitive(true);
036:                assertNull(statementHandler
037:                        .getResultSet("SELECT xyz from table"));
038:                MockResultSet result0 = new MockResultSet("id0");
039:                MockResultSet result1 = new MockResultSet("id1");
040:                MockResultSet[] results = new MockResultSet[] { result0,
041:                        result1 };
042:                statementHandler.clearResultSets();
043:                statementHandler.prepareResultSets("select abc", results);
044:                assertSame(result0, statementHandler.getResultSet("select abc"));
045:            }
046:
047:            public void testGetResultSets() {
048:                MockResultSet result0 = new MockResultSet("id0");
049:                MockResultSet result1 = new MockResultSet("id1");
050:                MockResultSet[] results = new MockResultSet[] { result0,
051:                        result1 };
052:                statementHandler.prepareResultSets("select column from table",
053:                        results);
054:                statementHandler.prepareResultSet("select .*", result0);
055:                MockResultSet[] returnedResults = statementHandler
056:                        .getResultSets("select column from table");
057:                assertNotSame(returnedResults, results);
058:                assertEquals(2, returnedResults.length);
059:                assertSame(result0, returnedResults[0]);
060:                assertSame(result1, returnedResults[1]);
061:                assertNull(statementHandler
062:                        .getResultSet("select xyz from table"));
063:                returnedResults = statementHandler.getResultSets("select .*");
064:                assertEquals(1, returnedResults.length);
065:                assertSame(result0, returnedResults[0]);
066:            }
067:
068:            public void testHasMultipleResultSets() {
069:                MockResultSet result0 = new MockResultSet("id0");
070:                MockResultSet result1 = new MockResultSet("id1");
071:                statementHandler.prepareResultSets("select column from table",
072:                        new MockResultSet[] { result0, result1 });
073:                statementHandler.prepareResultSets("select column from abc",
074:                        new MockResultSet[] { result1 });
075:                statementHandler.prepareResultSet("select .*", result0);
076:                assertTrue(statementHandler
077:                        .hasMultipleResultSets("select column from table"));
078:                assertTrue(statementHandler
079:                        .hasMultipleResultSets("select column from abc"));
080:                assertFalse(statementHandler.hasMultipleResultSets("select .*"));
081:                assertFalse(statementHandler
082:                        .hasMultipleResultSets("do nothing"));
083:            }
084:
085:            public void testGetGlobalResultSet() {
086:                MockResultSet result0 = new MockResultSet("id0");
087:                MockResultSet result1 = new MockResultSet("id1");
088:                MockResultSet[] results = new MockResultSet[] { result0,
089:                        result1 };
090:                statementHandler.prepareGlobalResultSet(result0);
091:                assertSame(result0, statementHandler.getGlobalResultSet());
092:                MockResultSet[] returnedResults = statementHandler
093:                        .getGlobalResultSets();
094:                assertEquals(1, returnedResults.length);
095:                assertSame(result0, returnedResults[0]);
096:                statementHandler.prepareGlobalResultSets(results);
097:                assertSame(result0, statementHandler.getGlobalResultSet());
098:                returnedResults = statementHandler.getGlobalResultSets();
099:                assertNotSame(results, returnedResults);
100:                assertEquals(2, returnedResults.length);
101:                assertSame(result0, returnedResults[0]);
102:                assertSame(result1, returnedResults[1]);
103:            }
104:
105:            public void testHasMutipleGlobalResultSets() {
106:                MockResultSet result0 = new MockResultSet("id0");
107:                MockResultSet result1 = new MockResultSet("id1");
108:                statementHandler.prepareGlobalResultSet(result0);
109:                assertFalse(statementHandler.hasMultipleGlobalResultSets());
110:                statementHandler
111:                        .prepareGlobalResultSets(new MockResultSet[] { result1 });
112:                assertTrue(statementHandler.hasMultipleGlobalResultSets());
113:                statementHandler.prepareGlobalResultSets(new MockResultSet[] {
114:                        result0, result1 });
115:                assertTrue(statementHandler.hasMultipleGlobalResultSets());
116:            }
117:
118:            public void testGetGeneratedKeys() {
119:                MockResultSet result = new MockResultSet("id");
120:                statementHandler.prepareGeneratedKeys("insert into table",
121:                        result);
122:                statementHandler.prepareGeneratedKeys("insert .*", result);
123:                assertSame(result, statementHandler
124:                        .getGeneratedKeys("insert into table abc"));
125:                assertSame(result, statementHandler
126:                        .getGeneratedKeys("insert .*"));
127:                assertNull(statementHandler
128:                        .getGeneratedKeys("insert into othertable"));
129:                statementHandler.setUseRegularExpressions(true);
130:                assertSame(result, statementHandler
131:                        .getGeneratedKeys("insert into table"));
132:                assertSame(result, statementHandler
133:                        .getGeneratedKeys("INSERt regular"));
134:                statementHandler.setCaseSensitive(true);
135:                assertNull(statementHandler.getGeneratedKeys("INSERt regular"));
136:            }
137:
138:            public void testGetUpdateCount() {
139:                statementHandler.prepareUpdateCount(".*", 3);
140:                statementHandler.prepareUpdateCount("insert xyz", 4);
141:                assertEquals(new Integer(4), statementHandler
142:                        .getUpdateCount("insert xyz"));
143:                assertEquals(new Integer(3), statementHandler
144:                        .getUpdateCount(".*"));
145:                statementHandler.setUseRegularExpressions(true);
146:                assertEquals(new Integer(3), statementHandler
147:                        .getUpdateCount("insert xyz"));
148:                assertEquals(new Integer(3), statementHandler
149:                        .getUpdateCount("insert"));
150:                statementHandler.setExactMatch(true);
151:                assertEquals(new Integer(4), statementHandler
152:                        .getUpdateCount("insert Xyz"));
153:                assertNull(statementHandler.getUpdateCount("insert"));
154:                statementHandler.prepareUpdateCounts("update",
155:                        new int[] { 1, 2 });
156:                assertEquals(new Integer(1), statementHandler
157:                        .getUpdateCount("update"));
158:            }
159:
160:            public void testGetUpdateCounts() {
161:                int[] updateCounts = new int[] { 1, 2 };
162:                statementHandler.prepareUpdateCounts(".*", updateCounts);
163:                statementHandler.prepareUpdateCount("insert xyz", 4);
164:                Integer[] returnedUpdateCounts = statementHandler
165:                        .getUpdateCounts(".*");
166:                assertEquals(2, returnedUpdateCounts.length);
167:                assertEquals(new Integer(1), returnedUpdateCounts[0]);
168:                assertEquals(new Integer(2), returnedUpdateCounts[1]);
169:                returnedUpdateCounts = statementHandler
170:                        .getUpdateCounts("insert xyz");
171:                assertEquals(1, returnedUpdateCounts.length);
172:                assertEquals(new Integer(4), returnedUpdateCounts[0]);
173:                assertNull(statementHandler.getUpdateCounts("do nothing"));
174:            }
175:
176:            public void testHasMultipleUpdateCounts() {
177:                statementHandler.prepareUpdateCount("update", 3);
178:                statementHandler.prepareUpdateCounts("insert into xyz",
179:                        new int[] { 4 });
180:                statementHandler.prepareUpdateCounts("insert into abc",
181:                        new int[] { 1, 2, 4 });
182:                assertFalse(statementHandler.hasMultipleUpdateCounts("update"));
183:                assertFalse(statementHandler
184:                        .hasMultipleUpdateCounts("do nothing"));
185:                assertTrue(statementHandler
186:                        .hasMultipleUpdateCounts("insert into xyz"));
187:                assertTrue(statementHandler
188:                        .hasMultipleUpdateCounts("insert into abc"));
189:            }
190:
191:            public void testGetGlobalUpdateCount() {
192:                int[] updateCounts = new int[] { 1, 2 };
193:                statementHandler.prepareGlobalUpdateCount(4);
194:                assertEquals(4, statementHandler.getGlobalUpdateCount());
195:                int[] returnedUpdateCounts = statementHandler
196:                        .getGlobalUpdateCounts();
197:                assertEquals(1, returnedUpdateCounts.length);
198:                assertEquals(4, returnedUpdateCounts[0]);
199:                statementHandler.prepareGlobalUpdateCounts(updateCounts);
200:                assertEquals(1, statementHandler.getGlobalUpdateCount());
201:                returnedUpdateCounts = statementHandler.getGlobalUpdateCounts();
202:                assertNotSame(updateCounts, returnedUpdateCounts);
203:                assertEquals(2, returnedUpdateCounts.length);
204:                assertEquals(1, returnedUpdateCounts[0]);
205:                assertEquals(2, returnedUpdateCounts[1]);
206:            }
207:
208:            public void testHasMutipleGlobalUpdateCounts() {
209:                statementHandler.prepareGlobalUpdateCount(4);
210:                assertFalse(statementHandler.hasMultipleGlobalUpdateCounts());
211:                statementHandler.prepareGlobalUpdateCounts(new int[] { 1 });
212:                assertTrue(statementHandler.hasMultipleGlobalUpdateCounts());
213:                statementHandler.prepareGlobalUpdateCounts(new int[] { 7, 8 });
214:                assertTrue(statementHandler.hasMultipleGlobalUpdateCounts());
215:            }
216:
217:            public void testGetReturnsResultSet() {
218:                statementHandler.prepareReturnsResultSet("select.*", false);
219:                assertNull(statementHandler.getReturnsResultSet("select abc"));
220:                statementHandler.setUseRegularExpressions(true);
221:                assertEquals(Boolean.FALSE, statementHandler
222:                        .getReturnsResultSet("select abc"));
223:            }
224:
225:            public void testGetThrowsSQLException() {
226:                SQLException exc = new BatchUpdateException();
227:                statementHandler.prepareThrowsSQLException("[abc] statement",
228:                        exc);
229:                statementHandler
230:                        .prepareThrowsSQLException("[abc] statementxyz");
231:                assertFalse(statementHandler
232:                        .getThrowsSQLException("a stAtement"));
233:                assertNull(statementHandler.getSQLException("a stAtement"));
234:                statementHandler.setUseRegularExpressions(true);
235:                assertTrue(statementHandler
236:                        .getThrowsSQLException("a stAtement"));
237:                assertSame(exc, statementHandler.getSQLException("a stAtement"));
238:                statementHandler.setCaseSensitive(true);
239:                assertFalse(statementHandler
240:                        .getThrowsSQLException("a stAtement"));
241:                assertNull(statementHandler.getSQLException("a stAtement"));
242:                assertTrue(statementHandler
243:                        .getThrowsSQLException("b statement"));
244:                assertSame(exc, statementHandler.getSQLException("b statement"));
245:                assertTrue(statementHandler
246:                        .getThrowsSQLException("b statementxyz"));
247:                assertNotSame(exc, statementHandler
248:                        .getSQLException("b statementxyz"));
249:                String message = statementHandler.getSQLException(
250:                        "b statementxyz").getMessage();
251:                assertTrue(message.indexOf("[abc] statementxyz") != -1);
252:            }
253:
254:            public void testClearMethods() {
255:                statementHandler.prepareResultSet("select", new MockResultSet(
256:                        "id"));
257:                statementHandler.prepareUpdateCount("select", 3);
258:                statementHandler.prepareThrowsSQLException("select");
259:                statementHandler.prepareReturnsResultSet("select", true);
260:                statementHandler.prepareGeneratedKeys("select",
261:                        new MockResultSet("id"));
262:                statementHandler.clearResultSets();
263:                statementHandler.clearUpdateCounts();
264:                statementHandler.clearThrowsSQLException();
265:                statementHandler.clearReturnsResultSet();
266:                statementHandler.clearGeneratedKeys();
267:                assertNull(statementHandler.getResultSet("select"));
268:                assertNull(statementHandler.getUpdateCount("select"));
269:                assertFalse(statementHandler.getThrowsSQLException("select"));
270:                assertNull(statementHandler.getReturnsResultSet("select"));
271:                assertNull(statementHandler.getGeneratedKeys("select"));
272:            }
273:
274:            public void testPreparedSQLOrdered() {
275:                MockResultSet result1 = new MockResultSet("id1");
276:                MockResultSet result2 = new MockResultSet("id2");
277:                statementHandler.prepareResultSet("select", result1);
278:                statementHandler.prepareResultSet("SelecT", result2);
279:                statementHandler.prepareUpdateCount("SelecT", 3);
280:                statementHandler.prepareUpdateCount("select2", 2);
281:                statementHandler.prepareReturnsResultSet("select", false);
282:                statementHandler.prepareReturnsResultSet("selecT", true);
283:                statementHandler.prepareGeneratedKeys("seLECT", result1);
284:                statementHandler.prepareGeneratedKeys("select", result2);
285:                assertSame(result2, statementHandler.getResultSet("select"));
286:                assertSame(result2, statementHandler.getResultSets("select")[0]);
287:                assertEquals(new Integer(3), statementHandler
288:                        .getUpdateCount("SELECT"));
289:                assertEquals(new Integer(3), statementHandler
290:                        .getUpdateCounts("selecT")[0]);
291:                assertTrue(statementHandler.getReturnsResultSet("select")
292:                        .booleanValue());
293:                assertSame(result1, statementHandler.getGeneratedKeys("select"));
294:            }
295:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.