Source Code Cross Referenced for AbstractParameterResultSetHandlerTest.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.Date;
005:        import java.sql.SQLException;
006:        import java.util.ArrayList;
007:        import java.util.Arrays;
008:        import java.util.HashMap;
009:        import java.util.List;
010:        import java.util.Map;
011:
012:        import com.mockrunner.base.BaseTestCase;
013:        import com.mockrunner.jdbc.CallableStatementResultSetHandler;
014:        import com.mockrunner.jdbc.ParameterSets;
015:        import com.mockrunner.jdbc.PreparedStatementResultSetHandler;
016:        import com.mockrunner.mock.jdbc.MockCallableStatement;
017:        import com.mockrunner.mock.jdbc.MockConnection;
018:        import com.mockrunner.mock.jdbc.MockPreparedStatement;
019:        import com.mockrunner.mock.jdbc.MockResultSet;
020:
021:        public class AbstractParameterResultSetHandlerTest extends BaseTestCase {
022:            private MockConnection connection;
023:            private PreparedStatementResultSetHandler preparedStatementHandler;
024:            private CallableStatementResultSetHandler callableStatementHandler;
025:
026:            protected void setUp() throws Exception {
027:                super .setUp();
028:                connection = getJDBCMockObjectFactory().getMockConnection();
029:                preparedStatementHandler = connection
030:                        .getPreparedStatementResultSetHandler();
031:                callableStatementHandler = connection
032:                        .getCallableStatementResultSetHandler();
033:            }
034:
035:            public void testGetResultSet() throws Exception {
036:                MockResultSet result = new MockResultSet("id");
037:                preparedStatementHandler.prepareResultSet("select [x]", result,
038:                        new String[] { "a", "b" });
039:                assertNull(preparedStatementHandler.getResultSet("select x"));
040:                preparedStatementHandler.setUseRegularExpressions(true);
041:                assertNull(preparedStatementHandler.getResultSet("select x"));
042:                Map parameter = new HashMap();
043:                parameter.put(new Integer(1), "a");
044:                parameter.put(new Integer(2), "b");
045:                assertSame(result, preparedStatementHandler.getResultSet(
046:                        "select x", parameter));
047:                preparedStatementHandler.setUseRegularExpressions(false);
048:                preparedStatementHandler.setExactMatchParameter(true);
049:                MockResultSet result1 = new MockResultSet("id1");
050:                MockResultSet result2 = new MockResultSet("id2");
051:                preparedStatementHandler.prepareResultSets("xyz",
052:                        new MockResultSet[] { result1, result2 },
053:                        new String[] { "a" });
054:                parameter = new HashMap();
055:                assertNull(preparedStatementHandler.getResultSet("xyz",
056:                        parameter));
057:                parameter = new HashMap();
058:                parameter.put(new Integer(1), "a");
059:                assertSame(result1, preparedStatementHandler.getResultSet(
060:                        "xyz", parameter));
061:            }
062:
063:            public void testGetResultSets() throws Exception {
064:                MockResultSet result1 = new MockResultSet("id1");
065:                MockResultSet result2 = new MockResultSet("id2");
066:                MockResultSet[] results = new MockResultSet[] { result1,
067:                        result2 };
068:                List parameterList = new ArrayList();
069:                parameterList.add(new Integer(5));
070:                parameterList.add("6");
071:                parameterList.add("7");
072:                callableStatementHandler.prepareResultSets("select from",
073:                        results, parameterList);
074:                assertNull(callableStatementHandler
075:                        .getResultSets("select from"));
076:                Map parameter = new HashMap();
077:                parameter.put(new Integer(1), new Integer(5));
078:                parameter.put(new Integer(2), "6");
079:                assertNull(callableStatementHandler.getResultSets(
080:                        "select from", parameter));
081:                parameter.put(new Integer(3), "7");
082:                MockResultSet[] returnedResults = callableStatementHandler
083:                        .getResultSets("select from", parameter);
084:                assertNotSame(results, returnedResults);
085:                assertEquals(2, returnedResults.length);
086:                assertSame(result1, returnedResults[0]);
087:                assertSame(result2, returnedResults[1]);
088:                callableStatementHandler.prepareResultSets("select abc",
089:                        new MockResultSet[] { result2 }, new String[0]);
090:                returnedResults = callableStatementHandler.getResultSets(
091:                        "select abc", new HashMap());
092:                assertEquals(1, returnedResults.length);
093:                assertSame(result2, returnedResults[0]);
094:                parameter = new HashMap();
095:                parameter.put("abc", "1");
096:                parameter.put("def", "2");
097:                callableStatementHandler.prepareResultSets("select 123",
098:                        new MockResultSet[] { result1 }, parameter);
099:                returnedResults = callableStatementHandler.getResultSets(
100:                        "select 123", parameter);
101:                assertEquals(1, returnedResults.length);
102:                assertSame(result1, returnedResults[0]);
103:            }
104:
105:            public void testHasMultipleResultSets() throws Exception {
106:                MockResultSet result1 = new MockResultSet("id1");
107:                MockResultSet result2 = new MockResultSet("id2");
108:                List parameterList = new ArrayList();
109:                parameterList.add(new Integer(5));
110:                Map parameterMap = new HashMap();
111:                parameterMap.put(new Integer(1), new Integer(5));
112:                callableStatementHandler.prepareResultSet("select from",
113:                        result1, parameterList);
114:                assertFalse(callableStatementHandler.hasMultipleResultSets(
115:                        "select from", new HashMap()));
116:                assertFalse(callableStatementHandler.hasMultipleResultSets(
117:                        "select from", parameterMap));
118:                callableStatementHandler.prepareResultSets("select 123",
119:                        new MockResultSet[] { result1 }, parameterList);
120:                assertFalse(callableStatementHandler.hasMultipleResultSets(
121:                        "select 123", new HashMap()));
122:                assertTrue(callableStatementHandler.hasMultipleResultSets(
123:                        "select 123", parameterMap));
124:                callableStatementHandler
125:                        .prepareResultSets("select 123", new MockResultSet[] {
126:                                result1, result2 }, parameterList);
127:                assertFalse(callableStatementHandler.hasMultipleResultSets(
128:                        "select 123", new HashMap()));
129:                assertTrue(callableStatementHandler.hasMultipleResultSets(
130:                        "select 123", parameterMap));
131:                parameterMap.put(new Integer(2), new Integer(5));
132:                assertTrue(callableStatementHandler.hasMultipleResultSets(
133:                        "select 123", parameterMap));
134:                callableStatementHandler.setExactMatchParameter(true);
135:                assertFalse(callableStatementHandler.hasMultipleResultSets(
136:                        "select 123", parameterMap));
137:            }
138:
139:            public void testGetUpdateCount() throws Exception {
140:                callableStatementHandler.prepareUpdateCount("insert.*", 2,
141:                        new HashMap());
142:                assertNull(callableStatementHandler.getUpdateCount("insert.*"));
143:                assertEquals(new Integer(2), callableStatementHandler
144:                        .getUpdateCount("insert.*", new HashMap()));
145:                callableStatementHandler.setUseRegularExpressions(true);
146:                assertEquals(new Integer(2), callableStatementHandler
147:                        .getUpdateCount("INSERT INTO", new HashMap()));
148:                Map parameter = new HashMap();
149:                parameter.put(new Integer(1), "a");
150:                parameter.put("2", "b");
151:                assertEquals(new Integer(2), callableStatementHandler
152:                        .getUpdateCount("INSERT INTO", parameter));
153:                callableStatementHandler.setExactMatchParameter(true);
154:                assertNull(callableStatementHandler.getUpdateCount(
155:                        "INSERT INTO", parameter));
156:                callableStatementHandler.prepareUpdateCounts("update",
157:                        new int[] { 1, 3 }, new HashMap());
158:                assertEquals(new Integer(1), callableStatementHandler
159:                        .getUpdateCount("update", new HashMap()));
160:            }
161:
162:            public void testGetUpdateCounts() throws Exception {
163:                Map parameter = new HashMap();
164:                parameter.put(new Integer(1), "1");
165:                preparedStatementHandler.prepareUpdateCounts("insert into",
166:                        new int[] { 3 }, parameter);
167:                assertNull(preparedStatementHandler.getUpdateCounts(
168:                        "insert into", new HashMap()));
169:                Integer[] returnedUpdateCounts = preparedStatementHandler
170:                        .getUpdateCounts("insert into", parameter);
171:                assertEquals(1, returnedUpdateCounts.length);
172:                assertEquals(new Integer(3), returnedUpdateCounts[0]);
173:                preparedStatementHandler.prepareUpdateCounts("insert abc",
174:                        new int[] { 5, 6, 7 }, new ArrayList());
175:                returnedUpdateCounts = preparedStatementHandler
176:                        .getUpdateCounts("insert abc", parameter);
177:                assertEquals(3, returnedUpdateCounts.length);
178:                assertEquals(new Integer(5), returnedUpdateCounts[0]);
179:                assertEquals(new Integer(6), returnedUpdateCounts[1]);
180:                assertEquals(new Integer(7), returnedUpdateCounts[2]);
181:                preparedStatementHandler.setExactMatchParameter(true);
182:                assertNull(preparedStatementHandler.getUpdateCounts(
183:                        "insert abc", parameter));
184:            }
185:
186:            public void testHasMultipleUpdateCounts() throws Exception {
187:                Map parameter = new HashMap();
188:                parameter.put(new Integer(1), "1");
189:                preparedStatementHandler.prepareUpdateCount("insert into", 3,
190:                        new Object[] { "1" });
191:                assertFalse(preparedStatementHandler.hasMultipleUpdateCounts(
192:                        "insert into", new HashMap()));
193:                assertFalse(preparedStatementHandler.hasMultipleUpdateCounts(
194:                        "insert into", parameter));
195:                preparedStatementHandler.prepareUpdateCounts("insert 123",
196:                        new int[] { 3 }, new Object[] { "1" });
197:                assertFalse(preparedStatementHandler.hasMultipleUpdateCounts(
198:                        "insert 123", new HashMap()));
199:                assertTrue(preparedStatementHandler.hasMultipleUpdateCounts(
200:                        "insert 123", parameter));
201:                preparedStatementHandler.prepareUpdateCounts("insert 123",
202:                        new int[] { 3, 5 }, new Object[] { "1" });
203:                assertFalse(preparedStatementHandler.hasMultipleUpdateCounts(
204:                        "insert 123", new HashMap()));
205:                assertTrue(preparedStatementHandler.hasMultipleUpdateCounts(
206:                        "insert 123", parameter));
207:                preparedStatementHandler.setExactMatchParameter(true);
208:                assertTrue(preparedStatementHandler.hasMultipleUpdateCounts(
209:                        "insert 123", parameter));
210:                parameter.put(new Integer(2), "1");
211:                assertFalse(preparedStatementHandler.hasMultipleUpdateCounts(
212:                        "insert 123", parameter));
213:            }
214:
215:            public void testGetThrowsSQLException() {
216:                SQLException exc = new BatchUpdateException();
217:                preparedStatementHandler.prepareThrowsSQLException(".*", exc,
218:                        new HashMap());
219:                preparedStatementHandler.prepareThrowsSQLException(".*",
220:                        new Object[] { "1" });
221:                assertFalse(preparedStatementHandler.getThrowsSQLException(
222:                        "select * from", new HashMap()));
223:                assertNull(preparedStatementHandler.getSQLException(
224:                        "select * from", new HashMap()));
225:                preparedStatementHandler.setUseRegularExpressions(true);
226:                assertTrue(preparedStatementHandler.getThrowsSQLException(
227:                        "select * from", new HashMap()));
228:                assertSame(exc, preparedStatementHandler.getSQLException(
229:                        "select * from", new HashMap()));
230:                assertFalse(preparedStatementHandler
231:                        .getThrowsSQLException("select * from"));
232:                assertNull(preparedStatementHandler
233:                        .getSQLException("select * from"));
234:                Map parameters = new HashMap();
235:                parameters.put(new Integer(1), "1");
236:                assertTrue(preparedStatementHandler.getThrowsSQLException(
237:                        "select * from", parameters));
238:                assertSame(exc, preparedStatementHandler.getSQLException(
239:                        "select * from", parameters));
240:                preparedStatementHandler.setExactMatchParameter(true);
241:                assertNotSame(exc, preparedStatementHandler.getSQLException(
242:                        "select * from", parameters));
243:                String message = preparedStatementHandler.getSQLException(
244:                        "select * from", parameters).getMessage();
245:                assertTrue(message.indexOf(".*") != -1);
246:                preparedStatementHandler.prepareThrowsSQLException("abc", exc,
247:                        new Object[] { "1" });
248:                preparedStatementHandler.setUseRegularExpressions(false);
249:                preparedStatementHandler.setExactMatchParameter(false);
250:                preparedStatementHandler.setExactMatch(true);
251:                parameters.put(new Integer(2), "2");
252:                assertSame(exc, preparedStatementHandler.getSQLException("abc",
253:                        parameters));
254:                assertNull(preparedStatementHandler.getSQLException("abcxyz",
255:                        parameters));
256:            }
257:
258:            public void testGetGeneratedKeys() throws Exception {
259:                MockResultSet resultSet1 = new MockResultSet("id1");
260:                MockResultSet resultSet2 = new MockResultSet("id2");
261:                preparedStatementHandler.prepareGeneratedKeys("select * from",
262:                        resultSet1, new Object[] { "1" });
263:                Map parameters = new HashMap();
264:                parameters.put(new Integer(1), "1");
265:                parameters.put("2", "2");
266:                preparedStatementHandler.prepareGeneratedKeys("insert into",
267:                        resultSet2, parameters);
268:                Map actualParameters = new HashMap();
269:                actualParameters.put(new Integer(1), "1");
270:                actualParameters.put("2", "3");
271:                actualParameters.put("3", "3");
272:                assertNull(preparedStatementHandler.getGeneratedKeys(
273:                        "insert into", actualParameters));
274:                actualParameters.put("2", "2");
275:                assertSame(resultSet2, preparedStatementHandler
276:                        .getGeneratedKeys("insert into", actualParameters));
277:                preparedStatementHandler.setExactMatchParameter(true);
278:                assertNull(preparedStatementHandler.getGeneratedKeys(
279:                        "insert into", actualParameters));
280:                actualParameters.remove("3");
281:                assertSame(resultSet2, preparedStatementHandler
282:                        .getGeneratedKeys("insert into", actualParameters));
283:                actualParameters = new HashMap();
284:                actualParameters.put(new Integer(1), "1");
285:                assertNull(preparedStatementHandler.getGeneratedKeys(
286:                        "insert into", actualParameters));
287:                assertSame(resultSet1, preparedStatementHandler
288:                        .getGeneratedKeys("selECt * from", actualParameters));
289:                preparedStatementHandler.setCaseSensitive(true);
290:                assertNull(preparedStatementHandler.getGeneratedKeys(
291:                        "selECt * from", actualParameters));
292:                assertSame(resultSet1, preparedStatementHandler
293:                        .getGeneratedKeys("select * from", actualParameters));
294:            }
295:
296:            public void testGetParameterMapForExecutedStatementNull()
297:                    throws Exception {
298:                MockPreparedStatement preparedStatement = (MockPreparedStatement) connection
299:                        .prepareStatement("select");
300:                preparedStatement.execute();
301:                assertNull(preparedStatementHandler
302:                        .getParametersForExecutedStatement("select abc"));
303:                MockCallableStatement callableStatement = (MockCallableStatement) connection
304:                        .prepareCall("select");
305:                callableStatement.execute();
306:                assertNull(callableStatementHandler
307:                        .getParametersForExecutedStatement("select abc"));
308:            }
309:
310:            public void testGetParameterMapForExecutedStatementEmptyMapQuery()
311:                    throws Exception {
312:                MockPreparedStatement preparedStatement = (MockPreparedStatement) connection
313:                        .prepareStatement("select");
314:                preparedStatement.execute();
315:                assertTrue(preparedStatementHandler.getExecutedStatements()
316:                        .contains("select"));
317:                assertNotNull(preparedStatementHandler
318:                        .getParametersForExecutedStatement("select"));
319:                assertEquals(1, preparedStatementHandler
320:                        .getParametersForExecutedStatement("select")
321:                        .getNumberParameterSets());
322:                Map parameterMap = preparedStatementHandler
323:                        .getParametersForExecutedStatement("select")
324:                        .getParameterSet(0);
325:                assertEquals(0, parameterMap.size());
326:                preparedStatement.setByte(1, (byte) 2);
327:                assertEquals(0, parameterMap.size());
328:                MockCallableStatement callableStatement = (MockCallableStatement) connection
329:                        .prepareCall("select");
330:                callableStatement.execute();
331:                assertTrue(callableStatementHandler.getExecutedStatements()
332:                        .contains("select"));
333:                assertNotNull(callableStatementHandler
334:                        .getParametersForExecutedStatement("select"));
335:                assertEquals(1, callableStatementHandler
336:                        .getParametersForExecutedStatement("select")
337:                        .getNumberParameterSets());
338:                parameterMap = (Map) callableStatementHandler
339:                        .getParametersForExecutedStatement("select")
340:                        .getParameterSet(0);
341:                assertEquals(0, parameterMap.size());
342:            }
343:
344:            public void testGetParameterMapForExecutedStatementEmptyMapUpdate()
345:                    throws Exception {
346:                MockPreparedStatement preparedStatement = (MockPreparedStatement) connection
347:                        .prepareStatement("update");
348:                preparedStatement.execute();
349:                assertTrue(preparedStatementHandler.getExecutedStatements()
350:                        .contains("update"));
351:                assertNotNull(preparedStatementHandler
352:                        .getParametersForExecutedStatement("update"));
353:                assertEquals(1, preparedStatementHandler
354:                        .getParametersForExecutedStatement("update")
355:                        .getNumberParameterSets());
356:                Map parameterMap = (Map) preparedStatementHandler
357:                        .getParametersForExecutedStatement("update")
358:                        .getParameterSet(0);
359:                assertEquals(0, parameterMap.size());
360:                preparedStatement.setString(1, "test");
361:                assertEquals(0, parameterMap.size());
362:                MockCallableStatement callableStatement = (MockCallableStatement) connection
363:                        .prepareCall("insert");
364:                callableStatement.execute();
365:                assertTrue(callableStatementHandler.getExecutedStatements()
366:                        .contains("insert"));
367:                assertNotNull(callableStatementHandler
368:                        .getParametersForExecutedStatement("insert"));
369:                assertEquals(1, callableStatementHandler
370:                        .getParametersForExecutedStatement("insert")
371:                        .getNumberParameterSets());
372:                parameterMap = (Map) callableStatementHandler
373:                        .getParametersForExecutedStatement("insert")
374:                        .getParameterSet(0);
375:                assertEquals(0, parameterMap.size());
376:            }
377:
378:            public void testGetParameterMapForExecutedStatementQuery()
379:                    throws Exception {
380:                preparedStatementHandler.prepareResultSet("select",
381:                        new MockResultSet("id"));
382:                MockPreparedStatement preparedStatement = (MockPreparedStatement) connection
383:                        .prepareStatement("select");
384:                preparedStatement.setString(1, "test");
385:                preparedStatement.setInt(2, 3);
386:                preparedStatement.executeQuery();
387:                assertTrue(preparedStatementHandler.getExecutedStatements()
388:                        .contains("select"));
389:                Map parameterMap = (Map) preparedStatementHandler
390:                        .getParametersForExecutedStatement("select")
391:                        .getParameterSet(0);
392:                assertEquals(2, parameterMap.size());
393:                assertEquals("test", parameterMap.get(new Integer(1)));
394:                assertEquals(new Integer(3), parameterMap.get(new Integer(2)));
395:                preparedStatement.setString(1, "test");
396:                assertEquals("test", parameterMap.get(new Integer(1)));
397:                callableStatementHandler.prepareResultSet("select",
398:                        new MockResultSet("id"));
399:                MockCallableStatement callableStatement = (MockCallableStatement) connection
400:                        .prepareCall("select");
401:                callableStatement.setBoolean(1, true);
402:                callableStatement.execute();
403:                parameterMap = (Map) callableStatementHandler
404:                        .getParametersForExecutedStatement("select")
405:                        .getParameterSet(0);
406:                assertEquals(1, parameterMap.size());
407:                assertEquals(Boolean.TRUE, parameterMap.get(new Integer(1)));
408:            }
409:
410:            public void testGetParameterMapForExecutedStatementUpdate()
411:                    throws Exception {
412:                preparedStatementHandler.prepareResultSet("delete",
413:                        new MockResultSet("id"));
414:                MockPreparedStatement preparedStatement = (MockPreparedStatement) connection
415:                        .prepareStatement("delete");
416:                preparedStatement.setBytes(1, new byte[] { 1, 2, 3 });
417:                preparedStatement.execute();
418:                assertTrue(preparedStatementHandler.getExecutedStatements()
419:                        .contains("delete"));
420:                Map parameterMap = (Map) preparedStatementHandler
421:                        .getParametersForExecutedStatement("delete")
422:                        .getParameterSet(0);
423:                assertEquals(1, parameterMap.size());
424:                assertTrue(Arrays.equals(new byte[] { 1, 2, 3 },
425:                        (byte[]) parameterMap.get(new Integer(1))));
426:                callableStatementHandler.prepareResultSet("insert",
427:                        new MockResultSet("id"));
428:                MockCallableStatement callableStatement = (MockCallableStatement) connection
429:                        .prepareCall("insert");
430:                callableStatement.setDate("1", new Date(1));
431:                callableStatement.setString(2, "test");
432:                callableStatement.executeUpdate();
433:                parameterMap = (Map) callableStatementHandler
434:                        .getParametersForExecutedStatement("insert")
435:                        .getParameterSet(0);
436:                assertEquals(2, parameterMap.size());
437:                assertEquals(new Date(1), parameterMap.get("1"));
438:                assertEquals("test", parameterMap.get(new Integer(2)));
439:            }
440:
441:            public void testGetExecutedStatementParameterPreparedStatement()
442:                    throws Exception {
443:                MockPreparedStatement preparedStatement1 = (MockPreparedStatement) connection
444:                        .prepareStatement("delete");
445:                MockPreparedStatement preparedStatement2 = (MockPreparedStatement) connection
446:                        .prepareStatement("update");
447:                preparedStatement2.setString(1, "1");
448:                preparedStatement2.setString(2, "2");
449:                preparedStatement1.execute();
450:                preparedStatement2.execute();
451:                Map parameterMap = preparedStatementHandler
452:                        .getExecutedStatementParameterMap();
453:                assertEquals(2, parameterMap.size());
454:                Map deleteParameters = ((ParameterSets) parameterMap
455:                        .get("delete")).getParameterSet(0);
456:                assertEquals(0, deleteParameters.size());
457:                Map updateParameters = ((ParameterSets) parameterMap
458:                        .get("update")).getParameterSet(0);
459:                assertEquals(2, updateParameters.size());
460:                assertEquals("1", updateParameters.get(new Integer(1)));
461:                assertEquals("2", updateParameters.get(new Integer(2)));
462:            }
463:
464:            public void testGetExecutedStatementParameterCallableStatement()
465:                    throws Exception {
466:                MockCallableStatement callableStatement1 = (MockCallableStatement) connection
467:                        .prepareCall("insert");
468:                MockCallableStatement callableStatement2 = (MockCallableStatement) connection
469:                        .prepareCall("select x");
470:                MockCallableStatement callableStatement3 = (MockCallableStatement) connection
471:                        .prepareCall("select y");
472:                callableStatement1.setInt("1", 1);
473:                callableStatement2.setString("1", "1");
474:                callableStatement2.setString("2", "2");
475:                callableStatement3.setInt("1", 1);
476:                callableStatement3.setInt("2", 2);
477:                callableStatement3.setInt("3", 3);
478:                callableStatement1.execute();
479:                callableStatement2.execute();
480:                callableStatement3.execute();
481:                Map parameterMap = callableStatementHandler
482:                        .getExecutedStatementParameterMap();
483:                assertEquals(3, parameterMap.size());
484:                Map insertParameters = (Map) ((ParameterSets) parameterMap
485:                        .get("insert")).getParameterSet(0);
486:                assertEquals(1, insertParameters.size());
487:                assertEquals(new Integer(1), insertParameters.get("1"));
488:                Map selectXParameters = (Map) ((ParameterSets) parameterMap
489:                        .get("select x")).getParameterSet(0);
490:                assertEquals(2, selectXParameters.size());
491:                assertEquals("1", selectXParameters.get("1"));
492:                assertEquals("2", selectXParameters.get("2"));
493:                Map selectYParameters = (Map) ((ParameterSets) parameterMap
494:                        .get("select y")).getParameterSet(0);
495:                assertEquals(3, selectYParameters.size());
496:                assertEquals(new Integer(1), selectYParameters.get("1"));
497:                assertEquals(new Integer(2), selectYParameters.get("2"));
498:                assertEquals(new Integer(3), selectYParameters.get("3"));
499:            }
500:
501:            public void testGetExecutedStatementParameterMultipleMaps()
502:                    throws Exception {
503:                MockPreparedStatement preparedStatement1 = (MockPreparedStatement) connection
504:                        .prepareStatement("select");
505:                preparedStatement1.execute();
506:                preparedStatement1.setString(1, "test");
507:                preparedStatement1.setInt(2, 3);
508:                preparedStatement1.execute();
509:                preparedStatement1.clearParameters();
510:                preparedStatement1.setString(1, "xyz");
511:                preparedStatement1.execute();
512:                MockPreparedStatement preparedStatement2 = (MockPreparedStatement) connection
513:                        .prepareStatement("insert");
514:                preparedStatement2.execute();
515:                preparedStatement2.setString(1, "anothertest");
516:                preparedStatement2.execute();
517:                Map parameterMap = preparedStatementHandler
518:                        .getExecutedStatementParameterMap();
519:                assertEquals(2, parameterMap.size());
520:                ParameterSets setsFor1 = (ParameterSets) parameterMap
521:                        .get("select");
522:                assertEquals(3, setsFor1.getNumberParameterSets());
523:                Map mapFor1 = (Map) setsFor1.getParameterSet(0);
524:                assertEquals(0, mapFor1.size());
525:                mapFor1 = (Map) setsFor1.getParameterSet(1);
526:                assertEquals(2, mapFor1.size());
527:                assertEquals("test", mapFor1.get(new Integer(1)));
528:                assertEquals(new Integer(3), mapFor1.get(new Integer(2)));
529:                mapFor1 = (Map) setsFor1.getParameterSet(2);
530:                assertEquals(1, mapFor1.size());
531:                assertEquals("xyz", mapFor1.get(new Integer(1)));
532:                ParameterSets setsFor2 = (ParameterSets) parameterMap
533:                        .get("insert");
534:                assertEquals(2, setsFor2.getNumberParameterSets());
535:                Map mapFor2 = (Map) setsFor2.getParameterSet(0);
536:                assertEquals(0, mapFor2.size());
537:                mapFor2 = (Map) setsFor2.getParameterSet(1);
538:                assertEquals("anothertest", mapFor2.get(new Integer(1)));
539:            }
540:
541:            public void testPreparedSQLOrdered() {
542:                MockResultSet result1 = new MockResultSet("id1");
543:                MockResultSet result2 = new MockResultSet("id2");
544:                preparedStatementHandler.prepareResultSet("select", result1,
545:                        new HashMap());
546:                preparedStatementHandler.prepareResultSet("SelecT", result2,
547:                        new HashMap());
548:                preparedStatementHandler.prepareUpdateCount("SelecT", 3,
549:                        new HashMap());
550:                preparedStatementHandler.prepareUpdateCount("select2", 2,
551:                        new HashMap());
552:                preparedStatementHandler.prepareGeneratedKeys("seLECT",
553:                        result1, new HashMap());
554:                preparedStatementHandler.prepareGeneratedKeys("select",
555:                        result2, new HashMap());
556:                assertSame(result2, preparedStatementHandler.getResultSet(
557:                        "select", new HashMap()));
558:                assertSame(result2, preparedStatementHandler.getResultSets(
559:                        "select", new HashMap())[0]);
560:                assertEquals(new Integer(3), preparedStatementHandler
561:                        .getUpdateCount("SELECT", new HashMap()));
562:                assertEquals(new Integer(3), preparedStatementHandler
563:                        .getUpdateCounts("selecT", new HashMap())[0]);
564:                assertSame(result1, preparedStatementHandler.getGeneratedKeys(
565:                        "select", new HashMap()));
566:            }
567:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.