001 package com.mockrunner.jdbc; 002 003 import java.sql.CallableStatement; 004 import java.sql.PreparedStatement; 005 import java.sql.SQLException; 006 import java.util.ArrayList; 007 import java.util.HashMap; 008 import java.util.Iterator; 009 import java.util.List; 010 import java.util.Map; 011 012 import com.mockrunner.base.NestedApplicationException; 013 import com.mockrunner.base.VerifyFailedException; 014 import com.mockrunner.mock.jdbc.JDBCMockObjectFactory; 015 import com.mockrunner.mock.jdbc.MockCallableStatement; 016 import com.mockrunner.mock.jdbc.MockPreparedStatement; 017 import com.mockrunner.mock.jdbc.MockResultSet; 018 import com.mockrunner.mock.jdbc.MockSavepoint; 019 import com.mockrunner.mock.jdbc.MockStatement; 020 import com.mockrunner.util.common.ArrayUtil; 021 import com.mockrunner.util.common.StringUtil; 022 023 /** 024 * Module for JDBC tests. 025 */ 026 public class JDBCTestModule 027 { 028 private JDBCMockObjectFactory mockFactory; 029 private boolean caseSensitive = false; 030 private boolean exactMatch = false; 031 private boolean useRegularExpressions = false; 032 033 public JDBCTestModule(JDBCMockObjectFactory mockFactory) 034 { 035 this.mockFactory = mockFactory; 036 } 037 038 /** 039 * Set if specified SQL statements should be handled case sensitive. 040 * Defaults to to <code>false</code>, i.e. <i>INSERT</i> is the same 041 * as <i>insert</i>. 042 * Please note that this method controls SQL statement 043 * matching for this class, e.g. what statements the method 044 * {@link #getPreparedStatements(String)} returns or what statements 045 * are taken into account by the method {@link #verifySQLStatementExecuted(String)}. 046 * In contrast to {@link AbstractResultSetHandler#setCaseSensitive(boolean)} it does 047 * not control the prepared results that are returned when the tested application 048 * executes a matching statement. 049 * @param caseSensitive enable or disable case sensitivity 050 */ 051 public void setCaseSensitive(boolean caseSensitive) 052 { 053 this.caseSensitive = caseSensitive; 054 } 055 056 /** 057 * Set if specified SQL statements must match exactly. 058 * Defaults to <code>false</code>, i.e. the SQL statement used 059 * to create a <code>PreparedStatement</code> must contain 060 * the specified SQL statement, but does not have to match 061 * exactly. If the original statement is <i>insert into mytable values(?, ?, ?)</i> 062 * <code>verifyPreparedStatementPresent("insert into mytable")</code> 063 * will pass. 064 * Please note that this method controls SQL statement 065 * matching for this class, e.g. what statements the method 066 * {@link #getPreparedStatements(String)} returns or what statements 067 * are taken into account by the method {@link #verifySQLStatementExecuted(String)}. 068 * In contrast to {@link AbstractResultSetHandler#setExactMatch(boolean)} it does 069 * not control the prepared results that are returned when the tested application 070 * executes a matching statement. 071 * @param exactMatch enable or disable exact matching 072 */ 073 public void setExactMatch(boolean exactMatch) 074 { 075 this.exactMatch = exactMatch; 076 } 077 078 /** 079 * Set if regular expressions should be used when matching 080 * SQL statements. Irrelevant if <code>exactMatch</code> is 081 * <code>true</code>. Default is <code>false</code>, i.e. you 082 * cannot use regular expressions and matching is based 083 * on string comparison (which is much faster). Enable 084 * this feature only if necessary. 085 * Please note that this method controls SQL statement 086 * matching for this class, e.g. what statements the method 087 * {@link #getPreparedStatements(String)} returns or what statements 088 * are taken into account by the method {@link #verifySQLStatementExecuted(String)}. 089 * In contrast to {@link AbstractResultSetHandler#setUseRegularExpressions(boolean)} it does 090 * not control the prepared results that are returned when the tested application 091 * executes a matching statement. 092 * @param useRegularExpressions should regular expressions be used 093 */ 094 public void setUseRegularExpressions(boolean useRegularExpressions) 095 { 096 this.useRegularExpressions = useRegularExpressions; 097 } 098 099 /** 100 * Returns the {@link StatementResultSetHandler}. 101 * The {@link StatementResultSetHandler} 102 * contains methods that can be used to specify the 103 * {@link com.mockrunner.mock.jdbc.MockResultSet} objects 104 * and update counts that a {@link com.mockrunner.mock.jdbc.MockStatement} 105 * should return when executing an SQL statement. 106 * @return the {@link StatementResultSetHandler} 107 */ 108 public StatementResultSetHandler getStatementResultSetHandler() 109 { 110 return mockFactory.getMockConnection().getStatementResultSetHandler(); 111 } 112 113 /** 114 * Returns the {@link PreparedStatementResultSetHandler}. 115 * The {@link PreparedStatementResultSetHandler} 116 * contains methods that can be used to specify the 117 * {@link com.mockrunner.mock.jdbc.MockResultSet} objects 118 * and update counts that a {@link com.mockrunner.mock.jdbc.MockPreparedStatement} 119 * should return when executing an SQL statement. 120 * @return the {@link PreparedStatementResultSetHandler} 121 */ 122 public PreparedStatementResultSetHandler getPreparedStatementResultSetHandler() 123 { 124 return mockFactory.getMockConnection().getPreparedStatementResultSetHandler(); 125 } 126 127 /** 128 * Returns the {@link CallableStatementResultSetHandler}. 129 * The {@link CallableStatementResultSetHandler} 130 * contains methods that can be used to specify the 131 * {@link com.mockrunner.mock.jdbc.MockResultSet} objects 132 * and update counts that a {@link com.mockrunner.mock.jdbc.MockCallableStatement} 133 * should return when executing an SQL statement. 134 * @return the {@link CallableStatementResultSetHandler} 135 */ 136 public CallableStatementResultSetHandler getCallableStatementResultSetHandler() 137 { 138 return mockFactory.getMockConnection().getCallableStatementResultSetHandler(); 139 } 140 141 /** 142 * Returns a {@link com.mockrunner.mock.jdbc.MockStatement} by its index. 143 * @param index the index of the <code>Statement</code> 144 * @return the <code>Statement</code> or <code>null</code>, if there is no such 145 * <code>Statement</code> 146 */ 147 public MockStatement getStatement(int index) 148 { 149 List statements = getStatements(); 150 if(index < statements.size()) return (MockStatement)statements.get(index); 151 return null; 152 } 153 154 /** 155 * Returns all {@link com.mockrunner.mock.jdbc.MockStatement} objects. 156 * @return the <code>List</code> of <code>Statement</code> objects 157 */ 158 public List getStatements() 159 { 160 return mockFactory.getMockConnection().getStatementResultSetHandler().getStatements(); 161 } 162 163 /** 164 * Returns a <code>List</code> of all SQL statements that were executed 165 * by calling an <code>execute</code> method of a {@link com.mockrunner.mock.jdbc.MockStatement}, 166 * {@link com.mockrunner.mock.jdbc.MockPreparedStatement} or 167 * {@link com.mockrunner.mock.jdbc.MockCallableStatement}. 168 * @return the <code>List</code> of SQL statements 169 */ 170 public List getExecutedSQLStatements() 171 { 172 ArrayList list = new ArrayList(); 173 list.addAll(mockFactory.getMockConnection().getStatementResultSetHandler().getExecutedStatements()); 174 list.addAll(mockFactory.getMockConnection().getPreparedStatementResultSetHandler().getExecutedStatements()); 175 list.addAll(mockFactory.getMockConnection().getCallableStatementResultSetHandler().getExecutedStatements()); 176 return list; 177 } 178 179 /** 180 * Returns a <code>Map</code> of all parameters that were used when 181 * executing a {@link com.mockrunner.mock.jdbc.MockPreparedStatement} or 182 * {@link com.mockrunner.mock.jdbc.MockCallableStatement}. 183 * The keys are the corresponding SQL statements. The values are the 184 * {@link ParameterSets} objects. 185 * @return the <code>Map</code> of parameters 186 */ 187 public Map getExecutedSQLStatementParameter() 188 { 189 Map map = new HashMap(); 190 map.putAll(mockFactory.getMockConnection().getPreparedStatementResultSetHandler().getExecutedStatementParameter()); 191 map.putAll(mockFactory.getMockConnection().getCallableStatementResultSetHandler().getExecutedStatementParameter()); 192 return map; 193 } 194 195 /** 196 * Returns the {@link ParameterSets} object for the specified SQL statement. 197 * If more than one {@link ParameterSets} object is found, the first one 198 * will be returned. 199 * @param sql the the SQL statement 200 * @return the {@link ParameterSets} object 201 */ 202 public ParameterSets getExecutedSQLStatementParameterSets(String sql) 203 { 204 Map map = getExecutedSQLStatementParameter(); 205 SQLStatementMatcher matcher = new SQLStatementMatcher(caseSensitive, exactMatch, useRegularExpressions); 206 List list = matcher.getMatchingObjects(map, sql, false, false); 207 if(list != null && list.size() > 0) 208 { 209 return (ParameterSets)list.get(0); 210 } 211 return null; 212 } 213 214 /** 215 * Returns the <code>ResultSet</code> objects with the specified id. 216 * If there are more than one <code>ResultSet</code> objects with the 217 * specified id, the first one is returned. If there is no 218 * <code>ResultSet</code> with the specified id, this method 219 * returns <code>null</code>. 220 * Please also see {@link #getReturnedResultSets(String)}. 221 * @return the <code>ResultSet</code> with the specified id 222 */ 223 public MockResultSet getReturnedResultSet(String id) 224 { 225 List list = getReturnedResultSets(id); 226 if(list != null && list.size() > 0) 227 { 228 return (MockResultSet)list.get(0); 229 } 230 return null; 231 } 232 233 /** 234 * Returns a <code>List</code> of the <code>ResultSet</code> objects with 235 * the specified id. Equivalent to {@link #getReturnedResultSets}, except 236 * that only <code>ResultSet</code> objects are added that have the 237 * corresponding id. 238 * Please note that <code>ResultSet</code> objects are cloned when executing 239 * statements. The <code>ResultSet</code> objects in the <code>List</code> 240 * returned by this method are really the instances the statement returned 241 * and not the instances you have used when preparing them. 242 * @return the <code>List</code> of <code>ResultSet</code> objects 243 */ 244 public List getReturnedResultSets(String id) 245 { 246 List list = getReturnedResultSets(); 247 ArrayList resultList = new ArrayList(); 248 for(int ii = 0; ii < list.size(); ii++) 249 { 250 MockResultSet resultSet = (MockResultSet)list.get(ii); 251 if(id.equals(resultSet.getId())) 252 { 253 resultList.add(resultSet); 254 } 255 } 256 return resultList; 257 } 258 259 /** 260 * Returns a <code>List</code> of all <code>ResultSet</code> objects that were returned 261 * by calling an <code>executeQuery</code> method of a {@link com.mockrunner.mock.jdbc.MockStatement}, 262 * {@link com.mockrunner.mock.jdbc.MockPreparedStatement} or 263 * {@link com.mockrunner.mock.jdbc.MockCallableStatement}. 264 * Please note that <code>ResultSet</code> objects are cloned when executing 265 * statements. The <code>ResultSet</code> objects in the <code>List</code> 266 * returned by this method are really the instances the statement returned 267 * and not the instances you have used when preparing them. 268 * @return the <code>List</code> of <code>ResultSet</code> objects 269 */ 270 public List getReturnedResultSets() 271 { 272 ArrayList list = new ArrayList(); 273 list.addAll(mockFactory.getMockConnection().getStatementResultSetHandler().getReturnedResultSets()); 274 list.addAll(mockFactory.getMockConnection().getPreparedStatementResultSetHandler().getReturnedResultSets()); 275 list.addAll(mockFactory.getMockConnection().getCallableStatementResultSetHandler().getReturnedResultSets()); 276 return list; 277 } 278 279 /** 280 * Returns a {@link com.mockrunner.mock.jdbc.MockPreparedStatement} that was 281 * created using a {@link com.mockrunner.mock.jdbc.MockConnection} by its index. 282 * @param index the index of the <code>PreparedStatement</code> 283 * @return the <code>PreparedStatement</code> or <code>null</code>, if there is no such 284 * <code>PreparedStatement</code> 285 */ 286 public MockPreparedStatement getPreparedStatement(int index) 287 { 288 List statements = getPreparedStatements(); 289 if(index < statements.size()) return (MockPreparedStatement)statements.get(index); 290 return null; 291 } 292 293 /** 294 * Returns a {@link com.mockrunner.mock.jdbc.MockPreparedStatement} that was 295 * created using a {@link com.mockrunner.mock.jdbc.MockConnection} by its SQL statement. 296 * If there are more than one {@link com.mockrunner.mock.jdbc.MockPreparedStatement} 297 * objects with the specified SQL, the first one will be returned. 298 * Please note that you can modify the search parameters with 299 * {@link #setCaseSensitive}, {@link #setExactMatch} and {@link #setUseRegularExpressions}. 300 * @param sql the SQL statement used to create the <code>PreparedStatement</code> 301 * @return the <code>PreparedStatement</code> or <code>null</code>, if there is no macth 302 */ 303 public MockPreparedStatement getPreparedStatement(String sql) 304 { 305 List list = getPreparedStatements(sql); 306 if(null != list && list.size() > 0) 307 { 308 return (MockPreparedStatement)list.get(0); 309 } 310 return null; 311 } 312 313 /** 314 * Returns all {@link com.mockrunner.mock.jdbc.MockPreparedStatement} objects. 315 * @return the <code>List</code> of <code>PreparedStatement</code> objects 316 */ 317 public List getPreparedStatements() 318 { 319 return mockFactory.getMockConnection().getPreparedStatementResultSetHandler().getPreparedStatements(); 320 } 321 322 /** 323 * Returns all {@link com.mockrunner.mock.jdbc.MockPreparedStatement} objects with 324 * the specified SQL statement as a <code>List</code>. If there are no matches, an empty 325 * <code>List</code> will be returned. 326 * Please note that you can modify the search parameters with 327 * {@link #setCaseSensitive}, {@link #setExactMatch} and {@link #setUseRegularExpressions}. 328 * @param sql the SQL statement used to create the <code>PreparedStatement</code> 329 * @return the <code>List</code> of <code>PreparedStatement</code> objects 330 */ 331 public List getPreparedStatements(String sql) 332 { 333 Map sqlStatements = mockFactory.getMockConnection().getPreparedStatementResultSetHandler().getPreparedStatementMap(); 334 SQLStatementMatcher matcher = new SQLStatementMatcher(caseSensitive, exactMatch, useRegularExpressions); 335 return matcher.getMatchingObjects(sqlStatements, sql, true, false); 336 } 337 338 /** 339 * Returns a {@link com.mockrunner.mock.jdbc.MockCallableStatement} that was 340 * created using a {@link com.mockrunner.mock.jdbc.MockConnection} by its index. 341 * @param index the index of the <code>CallableStatement</code> 342 * @return the <code>CallableStatement</code> or <code>null</code>, if there is no such 343 * <code>CallableStatement</code> 344 */ 345 public MockCallableStatement getCallableStatement(int index) 346 { 347 List statements = getCallableStatements(); 348 if(index < statements.size()) return (MockCallableStatement)statements.get(index); 349 return null; 350 } 351 352 /** 353 * Returns a {@link com.mockrunner.mock.jdbc.MockCallableStatement} that was 354 * created using a {@link com.mockrunner.mock.jdbc.MockConnection} by its SQL statement. 355 * If there are more than one {@link com.mockrunner.mock.jdbc.MockCallableStatement} 356 * objects with the specified SQL, the first one will be returned. 357 * Please note that you can modify the search parameters with 358 * {@link #setCaseSensitive}, {@link #setExactMatch} and {@link #setUseRegularExpressions}. 359 * @param sql the SQL statement used to create the <code>CallableStatement</code> 360 * @return the <code>CallableStatement</code> or <code>null</code>, if there is no macth 361 */ 362 public MockCallableStatement getCallableStatement(String sql) 363 { 364 List list = getCallableStatements(sql); 365 if(null != list && list.size() > 0) 366 { 367 return (MockCallableStatement)list.get(0); 368 } 369 return null; 370 } 371 372 /** 373 * Returns all {@link com.mockrunner.mock.jdbc.MockCallableStatement} objects. 374 * @return the <code>List</code> of <code>CallableStatement</code> objects 375 */ 376 public List getCallableStatements() 377 { 378 return mockFactory.getMockConnection().getCallableStatementResultSetHandler().getCallableStatements(); 379 } 380 381 /** 382 * Returns all {@link com.mockrunner.mock.jdbc.MockCallableStatement} objects with 383 * the specified SQL statement as a <code>List</code>. 384 * If there are no matches, an empty <code>List</code> will be returned. 385 * Please note that you can modify the search parameters with 386 * {@link #setCaseSensitive}, {@link #setExactMatch} and {@link #setUseRegularExpressions}. 387 * @param sql the SQL statement used to create the <code>CallableStatement</code> 388 * @return the <code>List</code> of <code>CallableStatement</code> objects 389 */ 390 public List getCallableStatements(String sql) 391 { 392 Map sqlStatements = mockFactory.getMockConnection().getCallableStatementResultSetHandler().getCallableStatementMap(); 393 SQLStatementMatcher matcher = new SQLStatementMatcher(caseSensitive, exactMatch, useRegularExpressions); 394 return matcher.getMatchingObjects(sqlStatements, sql, true, false); 395 } 396 397 /** 398 * Returns a parameter that was added to a <code>PreparedStatement</code> 399 * using its <code>set</code> methods. Simple data types are returned as 400 * the corresponsing wrapper type. 401 * @param statement the <code>PreparedStatement</code> 402 * @param indexOfParameter the index used to set the parameter 403 * @return the corresponding object 404 */ 405 public Object getPreparedStatementParameter(PreparedStatement statement, int indexOfParameter) 406 { 407 if(null == statement) return null; 408 return ((MockPreparedStatement)statement).getParameter(indexOfParameter); 409 } 410 411 /** 412 * Returns a parameter that was added to a <code>PreparedStatement</code> 413 * using its <code>set</code> methods. Uses the first <code>PreparedStatement</code> 414 * with the specified SQL statement. Simple data types are returned as 415 * the corresponsing wrapper type. 416 * @param sql the SQL statement 417 * @param indexOfParameter the index used to set the object 418 * @return the corresponding object 419 */ 420 public Object getPreparedStatementParameter(String sql, int indexOfParameter) 421 { 422 return getPreparedStatementParameter(getPreparedStatement(sql), indexOfParameter); 423 } 424 425 /** 426 * Returns an object that was added to a <code>PreparedStatement</code> 427 * using its <code>set</code> methods. Simple data types are returned as 428 * the corresponsing wrapper type. 429 * @param indexOfStatement the index of the statement 430 * @param indexOfParameter the index used to set the object 431 * @return the corresponding object 432 */ 433 public Object getPreparedStatementParameter(int indexOfStatement, int indexOfParameter) 434 { 435 return getPreparedStatementParameter(getPreparedStatement(indexOfStatement), indexOfParameter); 436 } 437 438 /** 439 * Returns a parameter that was added to a <code>CallableStatement</code> 440 * using its <code>set</code> methods. Simple data types are returned as 441 * the corresponsing wrapper type. 442 * @param statement the <code>CallableStatement</code> 443 * @param indexOfParameter the index used to set the parameter 444 * @return the corresponding object 445 */ 446 public Object getCallableStatementParameter(CallableStatement statement, int indexOfParameter) 447 { 448 if(null == statement) return null; 449 return ((MockCallableStatement)statement).getParameter(indexOfParameter); 450 } 451 452 /** 453 * Returns a parameter that was added to a <code>CallableStatement</code> 454 * using its <code>set</code> methods. Uses the first <code>CallableStatement</code> 455 * with the specified SQL statement. Simple data types are returned as 456 * the corresponsing wrapper type. 457 * @param sql the SQL statement 458 * @param indexOfParameter the index used to set the object 459 * @return the corresponding object 460 */ 461 public Object getCallableStatementParameter(String sql, int indexOfParameter) 462 { 463 return getCallableStatementParameter(getCallableStatement(sql), indexOfParameter); 464 } 465 466 /** 467 * Returns an object that was added to a <code>CallableStatement</code> 468 * using its <code>set</code> methods. Simple data types are returned as 469 * the corresponsing wrapper type. 470 * @param indexOfStatement the index of the statement 471 * @param indexOfParameter the index used to set the object 472 * @return the corresponding object 473 */ 474 public Object getCallableStatementParameter(int indexOfStatement, int indexOfParameter) 475 { 476 return getCallableStatementParameter(getCallableStatement(indexOfStatement), indexOfParameter); 477 } 478 479 /** 480 * Returns a parameter that was added to a <code>CallableStatement</code> 481 * using its <code>set</code> methods. 482 * @param statement the <code>CallableStatement</code> 483 * @param nameOfParameter the name of the parameter 484 * @return the corresponding object 485 */ 486 public Object getCallableStatementParameter(CallableStatement statement, String nameOfParameter) 487 { 488 if(null == statement) return null; 489 return ((MockCallableStatement)statement).getParameter(nameOfParameter); 490 } 491 492 /** 493 * Returns a parameter that was added to a <code>CallableStatement</code> 494 * using its <code>set</code> methods. Uses the first <code>CallableStatement</code> 495 * with the specified SQL statement. 496 * @param sql the SQL statement 497 * @param nameOfParameter the name of the parameter 498 * @return the corresponding object 499 */ 500 public Object getCallableStatementParameter(String sql, String nameOfParameter) 501 { 502 return getCallableStatementParameter(getCallableStatement(sql), nameOfParameter); 503 } 504 505 /** 506 * Returns an object that was added to a <code>CallableStatement</code> 507 * using its <code>set</code> methods. 508 * @param indexOfStatement the index of the statement 509 * @param nameOfParameter the name of the parameter 510 * @return the corresponding object 511 */ 512 public Object getCallableStatementParameter(int indexOfStatement, String nameOfParameter) 513 { 514 return getCallableStatementParameter(getCallableStatement(indexOfStatement), nameOfParameter); 515 } 516 517 /** 518 * Returns a list of all <code>Savepoint</code> objects. 519 * @return the <code>List</code> of {@link com.mockrunner.mock.jdbc.MockSavepoint} objects 520 */ 521 public List getSavepoints() 522 { 523 return new ArrayList(mockFactory.getMockConnection().getSavepointMap().values()); 524 } 525 526 /** 527 * Returns the <code>Savepoint</code> with the specified index. 528 * The index is the number of the created <code>Savepoint</code> 529 * starting with 0 for the first <code>Savepoint</code>. 530 * @param index the index 531 * @return the {@link com.mockrunner.mock.jdbc.MockSavepoint} 532 */ 533 public MockSavepoint getSavepoint(int index) 534 { 535 List savepoints = getSavepoints(); 536 for(int ii = 0; ii < savepoints.size(); ii++) 537 { 538 MockSavepoint currentSavepoint = (MockSavepoint)savepoints.get(ii); 539 if(currentSavepoint.getNumber() == index) return currentSavepoint; 540 } 541 return null; 542 } 543 544 /** 545 * Returns the first <code>Savepoint</code> with the specified name. 546 * Unnamed <code>Savepoint</code> objects get the name <i>""</i>. 547 * @param name the name 548 * @return the {@link com.mockrunner.mock.jdbc.MockSavepoint} 549 */ 550 public MockSavepoint getSavepoint(String name) 551 { 552 List savepoints = getSavepoints(); 553 for(int ii = 0; ii < savepoints.size(); ii++) 554 { 555 MockSavepoint currentSavepoint = (MockSavepoint)savepoints.get(ii); 556 try 557 { 558 if(currentSavepoint.getSavepointName().equals(name)) return currentSavepoint; 559 } 560 catch(SQLException exc) 561 { 562 throw new NestedApplicationException(exc); 563 } 564 } 565 return null; 566 } 567 568 /** 569 * Verifies that an SQL statement was executed. 570 * @param sql the expected SQL string 571 * @throws VerifyFailedException if verification fails 572 */ 573 public void verifySQLStatementExecuted(String sql) 574 { 575 SQLStatementMatcher matcher = new SQLStatementMatcher(caseSensitive, exactMatch, useRegularExpressions); 576 if(!matcher.contains(getExecutedSQLStatements(), sql, false)) 577 { 578 throw new VerifyFailedException("Statement " + sql + " not executed."); 579 } 580 } 581 582 /** 583 * Verifies that an SQL statement was not executed. 584 * @param sql the SQL string 585 * @throws VerifyFailedException if verification fails 586 */ 587 public void verifySQLStatementNotExecuted(String sql) 588 { 589 SQLStatementMatcher matcher = new SQLStatementMatcher(caseSensitive, exactMatch, useRegularExpressions); 590 if(matcher.contains(getExecutedSQLStatements(), sql, false)) 591 { 592 throw new VerifyFailedException("Statement " + sql + " was executed."); 593 } 594 } 595 596 /** 597 * Verifies the number of parameters for the specified SQL statement. 598 * If more than one SQL statement is found, this method uses the 599 * first one. You can specify the number of the parameter set, i.e. 600 * if a <code>PreparedStatement</code> is reused several times, the 601 * number of the parameter sets corresponds to the actual parameters 602 * at a specific <code>execute</code> call. 603 * @param sql the SQL string 604 * @param indexOfParameterSet the number of the parameter set 605 * @param number the expected number of parameters 606 * @throws VerifyFailedException if verification fails 607 */ 608 public void verifySQLStatementParameterNumber(String sql, int indexOfParameterSet, int number) 609 { 610 Map actualParameterMap = verifyAndGetParametersForSQL(sql, indexOfParameterSet); 611 if(actualParameterMap.size() != number) 612 { 613 throw new VerifyFailedException("Expected " + number + " parameter, actual " + actualParameterMap.size() + " parameter"); 614 } 615 } 616 617 /** 618 * Verifies the parameters for the specified SQL statement. 619 * If more than one SQL statement is found, this method uses the 620 * first one. The parameter map must match in size and the 621 * parameters must be equal (by comparing them with 622 * {de.lv1871.util.ParameterUtil#compareParameter}). 623 * You can specify the number of the parameter set, i.e. 624 * if a <code>PreparedStatement</code> is reused several times, the 625 * number of the parameter sets corresponds to the actual parameters 626 * at a specific <code>execute</code> call. 627 * @param sql the SQL string 628 * @param indexOfParameterSet the number of the parameter set 629 * @param parameterMap the map of expected parameters 630 * @throws VerifyFailedException if verification fails 631 */ 632 public void verifySQLStatementParameter(String sql, int indexOfParameterSet, Map parameterMap) 633 { 634 verifySQLStatementParameterNumber(sql, indexOfParameterSet, parameterMap.size()); 635 Map actualParameterMap = verifyAndGetParametersForSQL(sql, indexOfParameterSet); 636 Iterator keys = parameterMap.keySet().iterator(); 637 while(keys.hasNext()) 638 { 639 Object nextKey = keys.next(); 640 Object nextExpectedParameter = parameterMap.get(nextKey); 641 Object nextActualParameter = actualParameterMap.get(nextKey); 642 if(null == nextActualParameter) 643 { 644 throw new VerifyFailedException("No parameter " + nextKey + " found."); 645 } 646 if(!ParameterUtil.compareParameter(nextExpectedParameter, nextActualParameter)) 647 { 648 throw new VerifyFailedException("Expected " + nextExpectedParameter + " for parameter " + nextKey + ", but was " + nextActualParameter); 649 } 650 } 651 } 652 653 /** 654 * Verifies the parameter for the specified SQL statement. 655 * If more than one SQL statement is found, this method uses the 656 * first one. 657 * You can specify the number of the parameter set, i.e. 658 * if a <code>PreparedStatement</code> is reused several times, the 659 * number of the parameter sets corresponds to the actual parameters 660 * at a specific <code>execute</code> call. 661 * @param sql the SQL string 662 * @param indexOfParameterSet the number of the parameter set 663 * @param indexOfParameter the index of the parameter 664 * @param expectedParameter the expected parameter 665 * @throws VerifyFailedException if verification fails 666 */ 667 public void verifySQLStatementParameter(String sql, int indexOfParameterSet, int indexOfParameter, Object expectedParameter) 668 { 669 Map actualParameterMap = verifyAndGetParametersForSQL(sql, indexOfParameterSet); 670 Object actualParameter = actualParameterMap.get(new Integer(indexOfParameter)); 671 if(!ParameterUtil.compareParameter(expectedParameter, actualParameter)) 672 { 673 throw new VerifyFailedException("Expected " + expectedParameter + " for parameter " + indexOfParameter + ", but was " + actualParameter); 674 } 675 } 676 677 /** 678 * Verifies the parameter for the specified SQL statement. 679 * If more than one SQL statement is found, this method uses the 680 * first one. 681 * You can specify the number of the parameter set, i.e. 682 * if a <code>PreparedStatement</code> is reused several times, the 683 * number of the parameter sets corresponds to the actual parameters 684 * at a specific <code>execute</code> call. 685 * @param sql the SQL string 686 * @param indexOfParameterSet the number of the parameter set 687 * @param nameOfParameter the name of the parameter 688 * @param expectedParameter the expected parameter 689 * @throws VerifyFailedException if verification fails 690 */ 691 public void verifySQLStatementParameter(String sql, int indexOfParameterSet, String nameOfParameter, Object expectedParameter) 692 { 693 Map actualParameterMap = verifyAndGetParametersForSQL(sql, indexOfParameterSet); 694 Object actualParameter = actualParameterMap.get(nameOfParameter); 695 if(!ParameterUtil.compareParameter(expectedParameter, actualParameter)) 696 { 697 throw new VerifyFailedException("Expected " + expectedParameter + " for parameter " + nameOfParameter + ", but was " + actualParameter); 698 } 699 } 700 701 private Map verifyAndGetParametersForSQL(String sql, int indexOfParameterSet) 702 { 703 verifySQLStatementExecuted(sql); 704 SQLStatementMatcher matcher = new SQLStatementMatcher(caseSensitive, exactMatch, useRegularExpressions); 705 List matchingParameterList = matcher.getMatchingObjects(getExecutedSQLStatementParameter(), sql, true, false); 706 if(null == matchingParameterList || matchingParameterList.size() == 0) 707 { 708 throw new VerifyFailedException("No parameters for SQL " + sql + " found."); 709 } 710 ParameterSets actualParameterSets = (ParameterSets)matchingParameterList.get(0); 711 if(null == actualParameterSets || indexOfParameterSet >= actualParameterSets.getNumberParameterSets()) 712 { 713 throw new VerifyFailedException("Statement " + sql + " has no parameter set with index " + indexOfParameterSet); 714 } 715 return (Map)actualParameterSets.getParameterSet(indexOfParameterSet); 716 } 717 718 /** 719 * Verifies that the connection is closed. 720 * @throws VerifyFailedException if verification fails 721 */ 722 public void verifyConnectionClosed() 723 { 724 try 725 { 726 if(!mockFactory.getMockConnection().isClosed()) 727 { 728 throw new VerifyFailedException("Connection not closed."); 729 } 730 } 731 catch(SQLException exc) 732 { 733 throw new NestedApplicationException(exc); 734 } 735 } 736 737 /** 738 * Verifies that all statements, all prepared statements and 739 * all callable statements are closed. 740 * @throws VerifyFailedException if verification fails 741 */ 742 public void verifyAllStatementsClosed() 743 { 744 List statements = getStatements(); 745 for(int ii = 0; ii < statements.size(); ii++) 746 { 747 MockStatement statement = (MockStatement)statements.get(ii); 748 if(!statement.isClosed()) 749 { 750 throw new VerifyFailedException("Statement with index " + ii + " not closed."); 751 } 752 } 753 statements = getPreparedStatements(); 754 for(int ii = 0; ii < statements.size(); ii++) 755 { 756 MockPreparedStatement statement = (MockPreparedStatement)statements.get(ii); 757 if(!statement.isClosed()) 758 { 759 throw new VerifyFailedException("Prepared statement with index " + ii + " (SQL " + statement.getSQL() + ") not closed."); 760 } 761 } 762 statements = getCallableStatements(); 763 for(int ii = 0; ii < statements.size(); ii++) 764 { 765 MockPreparedStatement statement = (MockCallableStatement)statements.get(ii); 766 if(!statement.isClosed()) 767 { 768 throw new VerifyFailedException("Callable statement with index " + ii + " (SQL " + statement.getSQL() + ") not closed."); 769 } 770 } 771 } 772 773 /** 774 * Verifies that the <code>ResultSet</code> with the 775 * specified id is closed. Only recognizes <code>ResultSet</code> 776 * objects that were actually returned when executing a statement 777 * and that were explicitly closed. Implicit closed <code>ResultSet</code> 778 * objects (when closing a statement) are not recognized. 779 * @throws VerifyFailedException if verification fails 780 */ 781 public void verifyResultSetClosed(String id) 782 { 783 MockResultSet resultSet = getReturnedResultSet(id); 784 if(null == resultSet) 785 { 786 throw new VerifyFailedException("ResultSet with id " + id + " not present."); 787 } 788 if(!resultSet.isClosed()) 789 { 790 throw new VerifyFailedException("ResultSet with id " + id + " not closed."); 791 } 792 } 793 794 /** 795 * Verifies that the specified row of a <code>ResultSet</code> was 796 * inserted. 797 * @param resultSet the <code>ResultSet</code> 798 * @param number the number of the row 799 * @throws VerifyFailedException if verification fails 800 */ 801 public void verifyResultSetRowInserted(MockResultSet resultSet, int number) 802 { 803 if(!resultSet.rowInserted(number)) 804 { 805 throw new VerifyFailedException("Row number " + number + " of ResultSet " + resultSet.getId() + " not inserted."); 806 } 807 } 808 809 /** 810 * Verifies that the specified row of a <code>ResultSet</code> was 811 * inserted. 812 * @param id the id of the <code>ResultSet</code> 813 * @param number the number of the row 814 * @throws VerifyFailedException if verification fails 815 */ 816 public void verifyResultSetRowInserted(String id, int number) 817 { 818 MockResultSet resultSet = getReturnedResultSet(id); 819 if(null == resultSet) 820 { 821 throw new VerifyFailedException("ResultSet with id " + id + " not present."); 822 } 823 verifyResultSetRowInserted(resultSet, number); 824 } 825 826 /** 827 * Verifies that the specified row of a <code>ResultSet</code> was 828 * not inserted. 829 * @param resultSet the <code>ResultSet</code> 830 * @param number the number of the row 831 * @throws VerifyFailedException if verification fails 832 */ 833 public void verifyResultSetRowNotInserted(MockResultSet resultSet, int number) 834 { 835 if(resultSet.rowInserted(number)) 836 { 837 throw new VerifyFailedException("Row number " + number + " of ResultSet " + resultSet.getId() + " was inserted."); 838 } 839 } 840 841 /** 842 * Verifies that the specified row of a <code>ResultSet</code> was 843 * not inserted. 844 * @param id the id of the <code>ResultSet</code> 845 * @param number the number of the row 846 * @throws VerifyFailedException if verification fails 847 */ 848 public void verifyResultSetRowNotInserted(String id, int number) 849 { 850 MockResultSet resultSet = getReturnedResultSet(id); 851 if(null == resultSet) 852 { 853 throw new VerifyFailedException("ResultSet with id " + id + " not present."); 854 } 855 verifyResultSetRowNotInserted(resultSet, number); 856 } 857 858 /** 859 * Verifies that the specified row of a <code>ResultSet</code> was 860 * updated. 861 * @param resultSet the <code>ResultSet</code> 862 * @param number the number of the row 863 * @throws VerifyFailedException if verification fails 864 */ 865 public void verifyResultSetRowUpdated(MockResultSet resultSet, int number) 866 { 867 if(!resultSet.rowUpdated(number)) 868 { 869 throw new VerifyFailedException("Row number " + number + " of ResultSet " + resultSet.getId() + " not updated."); 870 } 871 } 872 873 /** 874 * Verifies that the specified row of a <code>ResultSet</code> was 875 * updated. 876 * @param id the id of the <code>ResultSet</code> 877 * @param number the number of the row 878 * @throws VerifyFailedException if verification fails 879 */ 880 public void verifyResultSetRowUpdated(String id, int number) 881 { 882 MockResultSet resultSet = getReturnedResultSet(id); 883 if(null == resultSet) 884 { 885 throw new VerifyFailedException("ResultSet with id " + id + " not present."); 886 } 887 verifyResultSetRowUpdated(resultSet, number); 888 } 889 890 /** 891 * Verifies that the specified row of a <code>ResultSet</code> was 892 * not updated. 893 * @param resultSet the <code>ResultSet</code> 894 * @param number the number of the row 895 * @throws VerifyFailedException if verification fails 896 */ 897 public void verifyResultSetRowNotUpdated(MockResultSet resultSet, int number) 898 { 899 if(resultSet.rowUpdated(number)) 900 { 901 throw new VerifyFailedException("Row number " + number + " of ResultSet " + resultSet.getId() + " was updated."); 902 } 903 } 904 905 /** 906 * Verifies that the specified row of a <code>ResultSet</code> was 907 * not updated. 908 * @param id the id of the <code>ResultSet</code> 909 * @param number the number of the row 910 * @throws VerifyFailedException if verification fails 911 */ 912 public void verifyResultSetRowNotUpdated(String id, int number) 913 { 914 MockResultSet resultSet = getReturnedResultSet(id); 915 if(null == resultSet) 916 { 917 throw new VerifyFailedException("ResultSet with id " + id + " not present."); 918 } 919 verifyResultSetRowNotUpdated(resultSet, number); 920 } 921 922 /** 923 * Verifies that the specified row of a <code>ResultSet</code> was 924 * deleted. 925 * @param resultSet the <code>ResultSet</code> 926 * @param number the number of the row 927 * @throws VerifyFailedException if verification fails 928 */ 929 public void verifyResultSetRowDeleted(MockResultSet resultSet, int number) 930 { 931 if(!resultSet.rowDeleted(number)) 932 { 933 throw new VerifyFailedException("Row number " + number + " of ResultSet " + resultSet.getId() + " not deleted."); 934 } 935 } 936 937 /** 938 * Verifies that the specified row of a <code>ResultSet</code> was 939 * deleted. 940 * @param id the id of the <code>ResultSet</code> 941 * @param number the number of the row 942 * @throws VerifyFailedException if verification fails 943 */ 944 public void verifyResultSetRowDeleted(String id, int number) 945 { 946 MockResultSet resultSet = getReturnedResultSet(id); 947 if(null == resultSet) 948 { 949 throw new VerifyFailedException("ResultSet with id " + id + " not present."); 950 } 951 verifyResultSetRowDeleted(resultSet, number); 952 } 953 954 /** 955 * Verifies that the specified row of a <code>ResultSet</code> was 956 * not deleted. 957 * @param resultSet the <code>ResultSet</code> 958 * @param number the number of the row 959 * @throws VerifyFailedException if verification fails 960 */ 961 public void verifyResultSetRowNotDeleted(MockResultSet resultSet, int number) 962 { 963 if(resultSet.rowDeleted(number)) 964 { 965 throw new VerifyFailedException("Row number " + number + " of ResultSet " + resultSet.getId() + " was deleted."); 966 } 967 } 968 969 /** 970 * Verifies that the specified row of a <code>ResultSet</code> was 971 * not deleted. 972 * @param id the id of the <code>ResultSet</code> 973 * @param number the number of the row 974 * @throws VerifyFailedException if verification fails 975 */ 976 public void verifyResultSetRowNotDeleted(String id, int number) 977 { 978 MockResultSet resultSet = getReturnedResultSet(id); 979 if(null == resultSet) 980 { 981 throw new VerifyFailedException("ResultSet with id " + id + " not present."); 982 } 983 verifyResultSetRowNotDeleted(resultSet, number); 984 } 985 986 /** 987 * Verifies that all <code>ResultSet</code> objects are closed. 988 * Only recognizes <code>ResultSet</code> * objects that were actually 989 * returned when executing a statement and that were explicitly closed. 990 * Implicit closed <code>ResultSet</code> objects (when closing a statement) 991 * are not recognized. 992 * @throws VerifyFailedException if verification fails 993 */ 994 public void verifyAllResultSetsClosed() 995 { 996 List allResultSets = getReturnedResultSets(); 997 for(int ii = 0; ii < allResultSets.size(); ii++) 998 { 999 MockResultSet resultSet = (MockResultSet)allResultSets.get(ii); 1000 if(!resultSet.isClosed()) 1001 { 1002 throw new VerifyFailedException("ResultSet with id " + resultSet.getId() + " not closed."); 1003 } 1004 } 1005 } 1006 1007 /** 1008 * Verifies that the changes were commited, i.e. the <code>commit</code> 1009 * method of <code>Connection</code> was at least called once. 1010 * Makes only sense, if the <code>Connection</code> is not in 1011 * autocommit mode. Automatic commits are not recognized. 1012 * @throws VerifyFailedException if verification fails 1013 */ 1014 public void verifyCommitted() 1015 { 1016 int number = mockFactory.getMockConnection().getNumberCommits(); 1017 if(number <= 0) 1018 { 1019 throw new VerifyFailedException("Connection received no commits."); 1020 } 1021 } 1022 1023 /** 1024 * Verifies that the changes were not commited. 1025 * Makes only sense, if the <code>Connection</code> is not in 1026 * autocommit mode. Automatic commits are not recognized. 1027 * @throws VerifyFailedException if verification fails 1028 */ 1029 public void verifyNotCommitted() 1030 { 1031 int number = mockFactory.getMockConnection().getNumberCommits(); 1032 if(number > 0) 1033 { 1034 throw new VerifyFailedException("Connection was committed"); 1035 } 1036 } 1037 1038 /** 1039 * Verifies that the changes were rolled back, i.e. the <code>rollback</code> 1040 * method of <code>Connection</code> was at least called once. 1041 * Makes only sense, if the <code>Connection</code> is not in 1042 * autocommit mode. 1043 * @throws VerifyFailedException if verification fails 1044 */ 1045 public void verifyRolledBack() 1046 { 1047 int number = mockFactory.getMockConnection().getNumberRollbacks(); 1048 if(number <= 0) 1049 { 1050 throw new VerifyFailedException("Connection received no rollbacks."); 1051 } 1052 } 1053 1054 /** 1055 * Verifies that the changes were not rolled back. 1056 * Makes only sense, if the <code>Connection</code> is not in 1057 * autocommit mode. 1058 * @throws VerifyFailedException if verification fails 1059 */ 1060 public void verifyNotRolledBack() 1061 { 1062 int number = mockFactory.getMockConnection().getNumberRollbacks(); 1063 if(number > 0) 1064 { 1065 throw new VerifyFailedException("Connection was rolled back."); 1066 } 1067 } 1068 1069 /** 1070 * Verifies the number of <code>commit</code> calls. 1071 * Makes only sense, if the <code>Connection</code> is not in 1072 * autocommit mode. 1073 * @param number the expected number of commits 1074 * @throws VerifyFailedException if verification fails 1075 */ 1076 public void verifyNumberCommits(int number) 1077 { 1078 int actualNumber = mockFactory.getMockConnection().getNumberCommits(); 1079 if(actualNumber != number) 1080 { 1081 throw new VerifyFailedException("Connection received " + actualNumber + " commits, expected " + number); 1082 } 1083 } 1084 1085 /** 1086 * Verifies the number of <code>rollback</code> calls. 1087 * Makes only sense, if the <code>Connection</code> is not in 1088 * autocommit mode. 1089 * @param number the expected number of rollbacks 1090 * @throws VerifyFailedException if verification fails 1091 */ 1092 public void verifyNumberRollbacks(int number) 1093 { 1094 int actualNumber = mockFactory.getMockConnection().getNumberRollbacks(); 1095 if(actualNumber != number) 1096 { 1097 throw new VerifyFailedException("Connection received " + actualNumber + " rollbacks, expected " + number); 1098 } 1099 } 1100 1101 /** 1102 * Verifies the number of statements. 1103 * @param number the expected number 1104 * @throws VerifyFailedException if verification fails 1105 */ 1106 public void verifyNumberStatements(int number) 1107 { 1108 verifyNumberStatements(number, getStatements()); 1109 } 1110 1111 /** 1112 * Verifies the number of prepared statements. 1113 * @param number the expected number 1114 * @throws VerifyFailedException if verification fails 1115 */ 1116 public void verifyNumberPreparedStatements(int number) 1117 { 1118 verifyNumberStatements(number, getPreparedStatements()); 1119 } 1120 1121 /** 1122 * Verifies the number of prepared statements with the specified 1123 * SQL. 1124 * @param number the expected number 1125 * @param sql the SQL 1126 * @throws VerifyFailedException if verification fails 1127 */ 1128 public void verifyNumberPreparedStatements(int number, String sql) 1129 { 1130 verifyNumberStatements(number, getPreparedStatements(sql)); 1131 } 1132 1133 /** 1134 * Verifies the number of callable statements. 1135 * @param number the expected number 1136 * @throws VerifyFailedException if verification fails 1137 */ 1138 public void verifyNumberCallableStatements(int number) 1139 { 1140 verifyNumberStatements(number, getCallableStatements()); 1141 } 1142 1143 /** 1144 * Verifies the number of callable statements with the specified 1145 * SQL. 1146 * @param number the expected number 1147 * @param sql the SQL 1148 * @throws VerifyFailedException if verification fails 1149 */ 1150 public void verifyNumberCallableStatements(int number, String sql) 1151 { 1152 verifyNumberStatements(number, getCallableStatements(sql)); 1153 } 1154 1155 private void verifyNumberStatements(int number, List statements) 1156 { 1157 if(null == statements || statements.size() == 0) 1158 { 1159 if(number == 0) return; 1160 throw new VerifyFailedException("Expected " + number + " statements, received 0 statements"); 1161 } 1162 if(statements.size() != number) 1163 { 1164 throw new VerifyFailedException("Expected " + number + " statements, received " + statements.size()+ " statements"); 1165 } 1166 } 1167 1168 /** 1169 * Verifies that a statement is closed. 1170 * @param index the index of the statement 1171 * @throws VerifyFailedException if verification fails 1172 */ 1173 public void verifyStatementClosed(int index) 1174 { 1175 MockStatement statement = getStatement(index); 1176 if(null == statement) 1177 { 1178 throw new VerifyFailedException("No statement with index " + index + " present."); 1179 } 1180 if(!statement.isClosed()) 1181 { 1182 throw new VerifyFailedException("Statement with index " + index + " not closed."); 1183 } 1184 } 1185 1186 /** 1187 * Verifies that a prepared statement is closed. 1188 * @param index the index of the prepared statement 1189 * @throws VerifyFailedException if verification fails 1190 */ 1191 public void verifyPreparedStatementClosed(int index) 1192 { 1193 MockPreparedStatement statement = getPreparedStatement(index); 1194 if(null == statement) 1195 { 1196 throw new VerifyFailedException("No prepared statement with index " + index + " present."); 1197 } 1198 if(!statement.isClosed()) 1199 { 1200 throw new VerifyFailedException("Prepared statement with index " + index + " not closed."); 1201 } 1202 } 1203 1204 /** 1205 * Verifies that a prepared statement is closed. 1206 * @param sql the SQL statement 1207 * @throws VerifyFailedException if verification fails 1208 */ 1209 public void verifyPreparedStatementClosed(String sql) 1210 { 1211 MockPreparedStatement statement = getPreparedStatement(sql); 1212 if(null == statement) 1213 { 1214 throw new VerifyFailedException("No prepared statement with SQL " + sql + " present."); 1215 } 1216 if(!statement.isClosed()) 1217 { 1218 throw new VerifyFailedException("Prepared statement with SQL " + sql + " not closed."); 1219 } 1220 } 1221 1222 /** 1223 * Verifies that a callable statement is closed. 1224 * @param index the index of the callable statement 1225 * @throws VerifyFailedException if verification fails 1226 */ 1227 public void verifyCallableStatementClosed(int index) 1228 { 1229 MockCallableStatement statement = getCallableStatement(index); 1230 if(null == statement) 1231 { 1232 throw new VerifyFailedException("No callable statement with index " + index + " present."); 1233 } 1234 if(!statement.isClosed()) 1235 { 1236 throw new VerifyFailedException("Callable statement with index " + index + " not closed."); 1237 } 1238 } 1239 1240 /** 1241 * Verifies that a callable statement is closed. 1242 * @param sql the SQL statement 1243 * @throws VerifyFailedException if verification fails 1244 */ 1245 public void verifyCallableStatementClosed(String sql) 1246 { 1247 MockCallableStatement statement = getCallableStatement(sql); 1248 if(null == statement) 1249 { 1250 throw new VerifyFailedException("No callable statement with SQL " + sql + " present."); 1251 } 1252 if(!statement.isClosed()) 1253 { 1254 throw new VerifyFailedException("Callable statement with SQL " + sql + " not closed."); 1255 } 1256 } 1257 1258 /** 1259 * Verifies that a row of a <code>ResultSet</code> is equal to the 1260 * entries in the specified <code>List</code>. Uses {@link com.mockrunner.mock.jdbc.MockResultSet#isRowEqual}. 1261 * You can verify the data of returned <code>ResultSet</code> objects if 1262 * the tested JDBC code makes updates. 1263 * @param resultSet the <code>ResultSet</code> 1264 * @param number the number of the row 1265 * @param rowData the row data 1266 * @throws VerifyFailedException if verification fails 1267 */ 1268 public void verifyResultSetRow(MockResultSet resultSet, int number, List rowData) 1269 { 1270 if(null == resultSet.getRow(number)) 1271 { 1272 throw new VerifyFailedException("ResultSet " + resultSet.getId() + " has no row " + number); 1273 } 1274 if(!resultSet.isRowEqual(number, rowData)) 1275 { 1276 StringBuffer buffer = new StringBuffer("Actual row data:\n"); 1277 StringUtil.appendObjectsAsString(buffer, resultSet.getRow(number)); 1278 buffer.append("\n"); 1279 buffer.append("Expected row data:\n"); 1280 StringUtil.appendObjectsAsString(buffer, rowData); 1281 throw new VerifyFailedException("Mismatch in row data.\n" + buffer.toString()); 1282 } 1283 } 1284 1285 /** 1286 * Verifies that a row of a <code>ResultSet</code> is equal to the 1287 * entries in the specified array. Uses {@link com.mockrunner.mock.jdbc.MockResultSet#isRowEqual}. 1288 * You can verify the data of returned <code>ResultSet</code> objects if 1289 * the tested JDBC code makes updates. 1290 * @param resultSet the <code>ResultSet</code> 1291 * @param number the number of the row 1292 * @param rowData the row data 1293 * @throws VerifyFailedException if verification fails 1294 */ 1295 public void verifyResultSetRow(MockResultSet resultSet, int number, Object[] rowData) 1296 { 1297 List dataList = ArrayUtil.getListFromObjectArray(rowData); 1298 verifyResultSetRow(resultSet, number, dataList); 1299 } 1300 1301 /** 1302 * Verifies that a row of a <code>ResultSet</code> is equal to the 1303 * entries in the specified <code>List</code>. Uses {@link com.mockrunner.mock.jdbc.MockResultSet#isRowEqual}. 1304 * You can verify the data of returned <code>ResultSet</code> objects if 1305 * the tested JDBC code makes updates. 1306 * @param id the id of the <code>ResultSet</code> 1307 * @param number the number of the row 1308 * @param rowData the row data 1309 * @throws VerifyFailedException if verification fails 1310 */ 1311 public void verifyResultSetRow(String id, int number, List rowData) 1312 { 1313 MockResultSet resultSet = getReturnedResultSet(id); 1314 if(null == resultSet) 1315 { 1316 throw new VerifyFailedException("ResultSet with id " + id + " not present."); 1317 } 1318 verifyResultSetRow(resultSet, number, rowData); 1319 } 1320 1321 /** 1322 * Verifies that a row of a <code>ResultSet</code> is equal to the 1323 * entries in the specified array. Uses {@link com.mockrunner.mock.jdbc.MockResultSet#isRowEqual}. 1324 * You can verify the data of returned <code>ResultSet</code> objects if 1325 * the tested JDBC code makes updates. 1326 * @param id the id of the <code>ResultSet</code> 1327 * @param number the number of the row 1328 * @param rowData the row data 1329 * @throws VerifyFailedException if verification fails 1330 */ 1331 public void verifyResultSetRow(String id, int number, Object[] rowData) 1332 { 1333 List dataList = ArrayUtil.getListFromObjectArray(rowData); 1334 verifyResultSetRow(id, number, dataList); 1335 } 1336 1337 /** 1338 * Verifies that a column of a <code>ResultSet</code> is equal to the 1339 * entries in the specified <code>List</code>. Uses {@link com.mockrunner.mock.jdbc.MockResultSet#isColumnEqual(int, List)}. 1340 * You can verify the data of returned <code>ResultSet</code> objects if 1341 * the tested JDBC code makes updates. 1342 * @param resultSet the <code>ResultSet</code> 1343 * @param number the number of the column 1344 * @param columnData the column data 1345 * @throws VerifyFailedException if verification fails 1346 */ 1347 public void verifyResultSetColumn(MockResultSet resultSet, int number, List columnData) 1348 { 1349 if(null == resultSet.getColumn(number)) 1350 { 1351 throw new VerifyFailedException("ResultSet " + resultSet.getId() + " has no column " + number); 1352 } 1353 if(!resultSet.isColumnEqual(number, columnData)) 1354 { 1355 StringBuffer buffer = new StringBuffer("Actual column data:\n"); 1356 StringUtil.appendObjectsAsString(buffer, resultSet.getColumn(number)); 1357 buffer.append("\n"); 1358 buffer.append("Expected column data:\n"); 1359 StringUtil.appendObjectsAsString(buffer, columnData); 1360 throw new VerifyFailedException("Mismatch in column data.\n" + buffer.toString()); 1361 } 1362 } 1363 1364 /** 1365 * Verifies that a column of a <code>ResultSet</code> is equal to the 1366 * entries in the specified array. Uses {@link com.mockrunner.mock.jdbc.MockResultSet#isColumnEqual(int, List)}. 1367 * You can verify the data of returned <code>ResultSet</code> objects if 1368 * the tested JDBC code makes updates. 1369 * @param resultSet the <code>ResultSet</code> 1370 * @param number the number of the column 1371 * @param columnData the column data 1372 * @throws VerifyFailedException if verification fails 1373 */ 1374 public void verifyResultSetColumn(MockResultSet resultSet, int number, Object[] columnData) 1375 { 1376 List dataList = ArrayUtil.getListFromObjectArray(columnData); 1377 verifyResultSetColumn(resultSet, number, dataList); 1378 } 1379 1380 /** 1381 * Verifies that a column of a <code>ResultSet</code> is equal to the 1382 * entries in the specified <code>List</code>. Uses {@link com.mockrunner.mock.jdbc.MockResultSet#isColumnEqual(int, List)}. 1383 * You can verify the data of returned <code>ResultSet</code> objects if 1384 * the tested JDBC code makes updates. 1385 * @param id the id of the <code>ResultSet</code> 1386 * @param number the number of the column 1387 * @param columnData the column data 1388 * @throws VerifyFailedException if verification fails 1389 */ 1390 public void verifyResultSetColumn(String id, int number, List columnData) 1391 { 1392 MockResultSet resultSet = getReturnedResultSet(id); 1393 if(null == resultSet) 1394 { 1395 throw new VerifyFailedException("ResultSet with id " + id + " not present."); 1396 } 1397 verifyResultSetColumn(resultSet, number, columnData); 1398 } 1399 1400 /** 1401 * Verifies that a column of a <code>ResultSet</code> is equal to the 1402 * entries in the specified array. Uses {@link com.mockrunner.mock.jdbc.MockResultSet#isColumnEqual(int, List)}. 1403 * You can verify the data of returned <code>ResultSet</code> objects if 1404 * the tested JDBC code makes updates. 1405 * @param id the id of the <code>ResultSet</code> 1406 * @param number the number of the column 1407 * @param columnData the column data 1408 * @throws VerifyFailedException if verification fails 1409 */ 1410 public void verifyResultSetColumn(String id, int number, Object[] columnData) 1411 { 1412 List dataList = ArrayUtil.getListFromObjectArray(columnData); 1413 verifyResultSetColumn(id, number, dataList); 1414 } 1415 1416 /** 1417 * Verifies that a column of a <code>ResultSet</code> is equal to the 1418 * entries in the specified <code>List</code>. Uses {@link com.mockrunner.mock.jdbc.MockResultSet#isColumnEqual(String, List)}. 1419 * You can verify the data of returned <code>ResultSet</code> objects if 1420 * the tested JDBC code makes updates. 1421 * @param resultSet the <code>ResultSet</code> 1422 * @param name the name of the column 1423 * @param columnData the column data 1424 * @throws VerifyFailedException if verification fails 1425 */ 1426 public void verifyResultSetColumn(MockResultSet resultSet, String name, List columnData) 1427 { 1428 if(null == resultSet.getColumn(name)) 1429 { 1430 throw new VerifyFailedException("ResultSet " + resultSet.getId() + " has no column " + name); 1431 } 1432 if(!resultSet.isColumnEqual(name, columnData)) 1433 { 1434 StringBuffer buffer = new StringBuffer("Actual column data:\n"); 1435 StringUtil.appendObjectsAsString(buffer, resultSet.getColumn(name)); 1436 buffer.append("\n"); 1437 buffer.append("Expected column data:\n"); 1438 StringUtil.appendObjectsAsString(buffer, columnData); 1439 throw new VerifyFailedException("Mismatch in column data.\n" + buffer.toString()); 1440 } 1441 } 1442 1443 /** 1444 * Verifies that a column of a <code>ResultSet</code> is equal to the 1445 * entries in the specified array. Uses {@link com.mockrunner.mock.jdbc.MockResultSet#isColumnEqual(String, List)}. 1446 * You can verify the data of returned <code>ResultSet</code> objects if 1447 * the tested JDBC code makes updates. 1448 * @param resultSet the <code>ResultSet</code> 1449 * @param name the name of the column 1450 * @param columnData the column data 1451 * @throws VerifyFailedException if verification fails 1452 */ 1453 public void verifyResultSetColumn(MockResultSet resultSet, String name, Object[] columnData) 1454 { 1455 List dataList = ArrayUtil.getListFromObjectArray(columnData); 1456 verifyResultSetColumn(resultSet, name, dataList); 1457 } 1458 1459 /** 1460 * Verifies that a column of a <code>ResultSet</code> is equal to the 1461 * entries in the specified <code>List</code>. Uses {@link com.mockrunner.mock.jdbc.MockResultSet#isColumnEqual(String, List)}. 1462 * You can verify the data of returned <code>ResultSet</code> objects if 1463 * the tested JDBC code makes updates. 1464 * @param id the id of the <code>ResultSet</code> 1465 * @param name the name of the column 1466 * @param columnData the column data 1467 * @throws VerifyFailedException if verification fails 1468 */ 1469 public void verifyResultSetColumn(String id, String name, List columnData) 1470 { 1471 MockResultSet resultSet = getReturnedResultSet(id); 1472 if(null == resultSet) 1473 { 1474 throw new VerifyFailedException("ResultSet with id " + id + " not present."); 1475 } 1476 verifyResultSetColumn(resultSet, name, columnData); 1477 } 1478 1479 /** 1480 * Verifies that a column of a <code>ResultSet</code> is equal to the 1481 * entries in the specified array. Uses {@link com.mockrunner.mock.jdbc.MockResultSet#isColumnEqual(String, List)}. 1482 * You can verify the data of returned <code>ResultSet</code> objects if 1483 * the tested JDBC code makes updates. 1484 * @param id the id of the <code>ResultSet</code> 1485 * @param name the name of the column 1486 * @param columnData the column data 1487 * @throws VerifyFailedException if verification fails 1488 */ 1489 public void verifyResultSetColumn(String id, String name, Object[] columnData) 1490 { 1491 List dataList = ArrayUtil.getListFromObjectArray(columnData); 1492 verifyResultSetColumn(id, name, dataList); 1493 } 1494 1495 /** 1496 * Verifies that a <code>ResultSet</code> is equal to another one. 1497 * Compares all the rows with {@link com.mockrunner.mock.jdbc.MockResultSet#isEqual}. 1498 * @param source the source <code>ResultSet</code> 1499 * @param target the target <code>ResultSet</code> 1500 * @throws VerifyFailedException if verification fails 1501 */ 1502 public void verifyResultSetEquals(MockResultSet source, MockResultSet target) 1503 { 1504 if(!source.isEqual(target)) 1505 { 1506 StringBuffer buffer = new StringBuffer("Source data:\n"); 1507 buffer.append(source.toString()); 1508 buffer.append("\n"); 1509 buffer.append("Target data:\n"); 1510 buffer.append(target.toString()); 1511 throw new VerifyFailedException("Mismatch in ResultSet data.\n" + buffer.toString()); 1512 } 1513 } 1514 1515 /** 1516 * Verifies that a <code>ResultSet</code> is equal to another one. 1517 * Compares all the rows with {@link com.mockrunner.jdbc.ParameterUtil#compareParameter}. 1518 * @param id the id of the source <code>ResultSet</code> 1519 * @param target the target <code>ResultSet</code> 1520 * @throws VerifyFailedException if verification fails 1521 */ 1522 public void verifyResultSetEquals(String id, MockResultSet target) 1523 { 1524 MockResultSet resultSet = getReturnedResultSet(id); 1525 if(null == resultSet) 1526 { 1527 throw new VerifyFailedException("ResultSet with id " + id + " not present."); 1528 } 1529 verifyResultSetEquals(resultSet, target); 1530 } 1531 1532 /** 1533 * Verifies that a <code>PreparedStatement</code> with the specified 1534 * SQL statement is present. 1535 * @param sql the SQL statement 1536 * @throws VerifyFailedException if verification fails 1537 */ 1538 public void verifyPreparedStatementPresent(String sql) 1539 { 1540 if(null == getPreparedStatement(sql)) 1541 { 1542 throw new VerifyFailedException("Prepared statement with SQL " + sql + " present."); 1543 } 1544 } 1545 1546 /** 1547 * Verifies that a <code>PreparedStatement</code> with the specified 1548 * SQL statement is not present. 1549 * @param sql the SQL statement 1550 * @throws VerifyFailedException if verification fails 1551 */ 1552 public void verifyPreparedStatementNotPresent(String sql) 1553 { 1554 if(null != getPreparedStatement(sql) ) 1555 { 1556 throw new VerifyFailedException("Prepared statement with SQL " + sql + " not present."); 1557 } 1558 } 1559 1560 /** 1561 * Verifies that a <code>CallableStatement</code> with the specified 1562 * SQL statement is present. 1563 * @param sql the SQL statement 1564 * @throws VerifyFailedException if verification fails 1565 */ 1566 public void verifyCallableStatementPresent(String sql) 1567 { 1568 if(null == getCallableStatement(sql)) 1569 { 1570 throw new VerifyFailedException("Callable statement with SQL " + sql + " present."); 1571 } 1572 } 1573 1574 /** 1575 * Verifies that a <code>CallableStatement</code> with the specified 1576 * SQL statement is not present. 1577 * @param sql the SQL statement 1578 * @throws VerifyFailedException if verification fails 1579 */ 1580 public void verifyCallableStatementNotPresent(String sql) 1581 { 1582 if(null != getCallableStatement(sql)) 1583 { 1584 throw new VerifyFailedException("Callable statement with SQL " + sql + " not present."); 1585 } 1586 } 1587 1588 /** 1589 * Verifies that a parameter was added to a <code>PreparedStatement</code> with 1590 * the specified index. 1591 * @param statement the <code>PreparedStatement</code> 1592 * @param indexOfParameter the index used to set the object 1593 * @throws VerifyFailedException if verification fails 1594 */ 1595 public void verifyPreparedStatementParameterPresent(PreparedStatement statement, int indexOfParameter) 1596 { 1597 if(null == getPreparedStatementParameter(statement, indexOfParameter)) 1598 { 1599 throw new VerifyFailedException("Prepared statement parameter with index " + indexOfParameter + " not present."); 1600 } 1601 } 1602 1603 /** 1604 * Verifies that a parameter was added to a <code>PreparedStatement</code> with 1605 * the specified index. Uses the first <code>PreparedStatement</code> with 1606 * the specified SQL. 1607 * @param sql the SQL statement of the <code>PreparedStatement</code> 1608 * @param indexOfParameter the index used to set the object 1609 * @throws VerifyFailedException if verification fails 1610 */ 1611 public void verifyPreparedStatementParameterPresent(String sql, int indexOfParameter) 1612 { 1613 if(null == getPreparedStatementParameter(sql, indexOfParameter)) 1614 { 1615 throw new VerifyFailedException("Prepared statement parameter with index " + indexOfParameter + " not present."); 1616 } 1617 } 1618 1619 /** 1620 * Verifies that a parameter was added to a <code>PreparedStatement</code> with 1621 * the specified index. 1622 * @param indexOfStatement the index of the statement 1623 * @param indexOfParameter the index used to set the object 1624 * @throws VerifyFailedException if verification fails 1625 */ 1626 public void verifyPreparedStatementParameterPresent(int indexOfStatement, int indexOfParameter) 1627 { 1628 if(null == getPreparedStatementParameter(indexOfStatement, indexOfParameter)) 1629 { 1630 throw new VerifyFailedException("Prepared statement parameter with index " + indexOfParameter + " not present."); 1631 } 1632 } 1633 1634 /** 1635 * Verifies that a parameter with the specified index is not present. 1636 * @param statement the <code>PreparedStatement</code> 1637 * @param indexOfParameter the index used to set the object 1638 * @throws VerifyFailedException if verification fails 1639 */ 1640 public void verifyPreparedStatementParameterNotPresent(PreparedStatement statement, int indexOfParameter) 1641 { 1642 if(null != getPreparedStatementParameter(statement, indexOfParameter)) 1643 { 1644 throw new VerifyFailedException("Prepared statement parameter with index " + indexOfParameter + " present."); 1645 } 1646 } 1647 1648 /** 1649 * Verifies that a parameter with the specified index is not present. 1650 * Uses the first <code>PreparedStatement</code> with the specified SQL. 1651 * @param sql the SQL statement of the <code>PreparedStatement</code> 1652 * @param indexOfParameter the index used to set the object 1653 * @throws VerifyFailedException if verification fails 1654 */ 1655 public void verifyPreparedStatementParameterNotPresent(String sql, int indexOfParameter) 1656 { 1657 if(null != getPreparedStatementParameter(sql, indexOfParameter)) 1658 { 1659 throw new VerifyFailedException("Prepared statement parameter with index " + indexOfParameter + " present."); 1660 } 1661 } 1662 1663 /** 1664 * Verifies that a parameter with the specified index is not present. 1665 * @param indexOfStatement the index of the statement 1666 * @param indexOfParameter the index used to set the object 1667 * @throws VerifyFailedException if verification fails 1668 */ 1669 public void verifyPreparedStatementParameterNotPresent(int indexOfStatement, int indexOfParameter) 1670 { 1671 if(null != getPreparedStatementParameter(indexOfStatement, indexOfParameter)) 1672 { 1673 throw new VerifyFailedException("Prepared statement parameter with index " + indexOfParameter + " present."); 1674 } 1675 } 1676 1677 /** 1678 * Verifies that a parameter was added to a <code>CallableStatement</code> with 1679 * the specified index. 1680 * @param statement the <code>CallableStatement</code> 1681 * @param indexOfParameter the index used to set the object 1682 * @throws VerifyFailedException if verification fails 1683 */ 1684 public void verifyCallableStatementParameterPresent(CallableStatement statement, int indexOfParameter) 1685 { 1686 if(null == getCallableStatementParameter(statement, indexOfParameter)) 1687 { 1688 throw new VerifyFailedException("Callable statement parameter with index " + indexOfParameter + " not present."); 1689 } 1690 } 1691 1692 /** 1693 * Verifies that a parameter was added to a <code>CallableStatement</code> with 1694 * the specified index. Uses the first <code>CallableStatement</code> with 1695 * the specified SQL. 1696 * @param sql the SQL statement of the <code>CallableStatement</code> 1697 * @param indexOfParameter the index used to set the object 1698 * @throws VerifyFailedException if verification fails 1699 */ 1700 public void verifyCallableStatementParameterPresent(String sql, int indexOfParameter) 1701 { 1702 if(null == getCallableStatementParameter(sql, indexOfParameter)) 1703 { 1704 throw new VerifyFailedException("Callable statement parameter with index " + indexOfParameter + " not present."); 1705 } 1706 } 1707 1708 /** 1709 * Verifies that a parameter was added to a <code>CallableStatement</code> with 1710 * the specified index. 1711 * @param indexOfStatement the index of the statement 1712 * @param indexOfParameter the index used to set the object 1713 * @throws VerifyFailedException if verification fails 1714 */ 1715 public void verifyCallableStatementParameterPresent(int indexOfStatement, int indexOfParameter) 1716 { 1717 if(null == getCallableStatementParameter(indexOfStatement, indexOfParameter)) 1718 { 1719 throw new VerifyFailedException("Callable statement parameter with index " + indexOfParameter + " not present."); 1720 } 1721 } 1722 1723 /** 1724 * Verifies that a parameter with the specified index is not present. 1725 * @param statement the <code>CallableStatement</code> 1726 * @param indexOfParameter the index used to set the object 1727 * @throws VerifyFailedException if verification fails 1728 */ 1729 public void verifyCallableStatementParameterNotPresent(CallableStatement statement, int indexOfParameter) 1730 { 1731 if(null != getCallableStatementParameter(statement, indexOfParameter)) 1732 { 1733 throw new VerifyFailedException("Callable statement parameter with index " + indexOfParameter + " present."); 1734 } 1735 } 1736 1737 /** 1738 * Verifies that a parameter with the specified index is not present. 1739 * Uses the first <code>CallableStatement</code> with the specified SQL. 1740 * @param sql the SQL statement of the <code>CallableStatement</code> 1741 * @param indexOfParameter the index used to set the object 1742 * @throws VerifyFailedException if verification fails 1743 */ 1744 public void verifyCallableStatementParameterNotPresent(String sql, int indexOfParameter) 1745 { 1746 if(null != getCallableStatementParameter(sql, indexOfParameter)) 1747 { 1748 throw new VerifyFailedException("Callable statement parameter with index " + indexOfParameter + " present."); 1749 } 1750 } 1751 1752 /** 1753 * Verifies that a parameter with the specified index is not present. 1754 * @param indexOfStatement the index of the statement 1755 * @param indexOfParameter the index used to set the object 1756 * @throws VerifyFailedException if verification fails 1757 */ 1758 public void verifyCallableStatementParameterNotPresent(int indexOfStatement, int indexOfParameter) 1759 { 1760 if(null != getCallableStatementParameter(indexOfStatement, indexOfParameter)) 1761 { 1762 throw new VerifyFailedException("Callable statement parameter with index " + indexOfParameter + " present."); 1763 } 1764 } 1765 1766 /** 1767 * Verifies that a parameter was added to a <code>CallableStatement</code> with 1768 * the specified index. 1769 * @param statement the <code>CallableStatement</code> 1770 * @param nameOfParameter the name of the parameter 1771 * @throws VerifyFailedException if verification fails 1772 */ 1773 public void verifyCallableStatementParameterPresent(CallableStatement statement, String nameOfParameter) 1774 { 1775 if(null == getCallableStatementParameter(statement, nameOfParameter)) 1776 { 1777 throw new VerifyFailedException("Callable statement parameter with index " + nameOfParameter + " not present."); 1778 } 1779 } 1780 1781 /** 1782 * Verifies that a parameter was added to a <code>CallableStatement</code> with 1783 * the specified index. Uses the first <code>CallableStatement</code> with 1784 * the specified SQL. 1785 * @param sql the SQL statement of the <code>CallableStatement</code> 1786 * @param nameOfParameter the name of the parameter 1787 * @throws VerifyFailedException if verification fails 1788 */ 1789 public void verifyCallableStatementParameterPresent(String sql, String nameOfParameter) 1790 { 1791 if(null == getCallableStatementParameter(sql, nameOfParameter)) 1792 { 1793 throw new VerifyFailedException("Callable statement parameter with index " + nameOfParameter + " not present."); 1794 } 1795 } 1796 1797 /** 1798 * Verifies that a parameter was added to a <code>CallableStatement</code> with 1799 * the specified index. 1800 * @param indexOfStatement the index of the statement 1801 * @param nameOfParameter the name of the parameter 1802 * @throws VerifyFailedException if verification fails 1803 */ 1804 public void verifyCallableStatementParameterPresent(int indexOfStatement, String nameOfParameter) 1805 { 1806 if(null == getCallableStatementParameter(indexOfStatement, nameOfParameter)) 1807 { 1808 throw new VerifyFailedException("Callable statement parameter with index " + nameOfParameter + " not present."); 1809 } 1810 } 1811 1812 /** 1813 * Verifies that a parameter with the specified index is not present. 1814 * @param statement the <code>CallableStatement</code> 1815 * @param nameOfParameter the name of the parameter 1816 * @throws VerifyFailedException if verification fails 1817 */ 1818 public void verifyCallableStatementParameterNotPresent(CallableStatement statement, String nameOfParameter) 1819 { 1820 if(null != getCallableStatementParameter(statement, nameOfParameter)) 1821 { 1822 throw new VerifyFailedException("Callable statement parameter with index " + nameOfParameter + " present."); 1823 } 1824 } 1825 1826 /** 1827 * Verifies that a parameter with the specified index is not present. 1828 * Uses the first <code>CallableStatement</code> with the specified SQL. 1829 * @param sql the SQL statement of the <code>CallableStatement</code> 1830 * @param nameOfParameter the name of the parameter 1831 * @throws VerifyFailedException if verification fails 1832 */ 1833 public void verifyCallableStatementParameterNotPresent(String sql, String nameOfParameter) 1834 { 1835 if(null != getCallableStatementParameter(sql, nameOfParameter)) 1836 { 1837 throw new VerifyFailedException("Callable statement parameter with index " + nameOfParameter + " present."); 1838 } 1839 } 1840 1841 /** 1842 * Verifies that a parameter with the specified index is not present. 1843 * @param indexOfStatement the index of the statement 1844 * @param nameOfParameter the name of the parameter 1845 * @throws VerifyFailedException if verification fails 1846 */ 1847 public void verifyCallableStatementParameterNotPresent(int indexOfStatement, String nameOfParameter) 1848 { 1849 if(null != getCallableStatementParameter(indexOfStatement, nameOfParameter)) 1850 { 1851 throw new VerifyFailedException("Callable statement parameter with index " + nameOfParameter + " present."); 1852 } 1853 } 1854 1855 /** 1856 * Verifies that a parameter from the specified <code>PreparedStatement</code> is equal 1857 * to the specified object. Please use the corresponding wrapper type for 1858 * primitive data types. 1859 * @param statement the <code>PreparedStatement</code> 1860 * @param indexOfParameter the index used to set the object 1861 * @param object the expected object 1862 * @throws VerifyFailedException if verification fails 1863 */ 1864 public void verifyPreparedStatementParameter(PreparedStatement statement, int indexOfParameter, Object object) 1865 { 1866 verifyPreparedStatementParameterPresent(statement, indexOfParameter); 1867 Object actualObject = getPreparedStatementParameter(statement, indexOfParameter); 1868 if(!ParameterUtil.compareParameter(actualObject, object)) 1869 { 1870 throw new VerifyFailedException("Prepared statement parameter with index " + indexOfParameter + " has the value " + 1871 actualObject.toString() + ", expected " + object.toString()); 1872 } 1873 } 1874 1875 /** 1876 * Verifies that a parameter from the <code>PreparedStatement</code> with the 1877 * specified SQL statement is equal to the specified object. 1878 * Uses the first <code>PreparedStatement</code> with the specified SQL. 1879 * Please use the corresponding wrapper type for primitive data types. 1880 * @param sql the SQL statement of the <code>PreparedStatement</code> 1881 * @param indexOfParameter the index used to set the object 1882 * @param object the expected object 1883 * @throws VerifyFailedException if verification fails 1884 */ 1885 public void verifyPreparedStatementParameter(String sql, int indexOfParameter, Object object) 1886 { 1887 verifyPreparedStatementParameterPresent(sql, indexOfParameter); 1888 Object actualObject = getPreparedStatementParameter(sql, indexOfParameter); 1889 if(!ParameterUtil.compareParameter(actualObject, object)) 1890 { 1891 throw new VerifyFailedException("Prepared statement parameter with index " + indexOfParameter + " has the value " + 1892 actualObject.toString() + ", expected " + object.toString()); 1893 } 1894 } 1895 1896 /** 1897 * Verifies that a parameter from the <code>PreparedStatement</code> with the 1898 * specified SQL statement is equal to the specified object. 1899 * Please use the corresponding wrapper type for primitive data types. 1900 * @param indexOfStatement the index of the statement 1901 * @param indexOfParameter the index used to set the object 1902 * @param object the expected object 1903 * @throws VerifyFailedException if verification fails 1904 */ 1905 public void verifyPreparedStatementParameter(int indexOfStatement, int indexOfParameter, Object object) 1906 { 1907 verifyPreparedStatementParameterPresent(indexOfStatement, indexOfParameter); 1908 Object actualObject = getPreparedStatementParameter(indexOfStatement, indexOfParameter); 1909 if(!ParameterUtil.compareParameter(actualObject, object)) 1910 { 1911 throw new VerifyFailedException("Prepared statement parameter with index " + indexOfParameter + " has the value " + 1912 actualObject.toString() + ", expected " + object.toString()); 1913 } 1914 } 1915 1916 /** 1917 * Verifies that a parameter from the specified <code>CallableStatement</code> is equal 1918 * to the specified object. Please use the corresponding wrapper type 1919 * for primitive data types. 1920 * @param statement the <code>CallableStatement</code> 1921 * @param indexOfParameter the index used to set the object 1922 * @param object the expected object 1923 * @throws VerifyFailedException if verification fails 1924 */ 1925 public void verifyCallableStatementParameter(CallableStatement statement, int indexOfParameter, Object object) 1926 { 1927 verifyCallableStatementParameterPresent(statement, indexOfParameter); 1928 Object actualObject = getCallableStatementParameter(statement, indexOfParameter); 1929 if(!ParameterUtil.compareParameter(actualObject, object)) 1930 { 1931 throw new VerifyFailedException("Callable statement parameter with index " + indexOfParameter + " has the value " + 1932 actualObject.toString() + ", expected " + object.toString()); 1933 } 1934 } 1935 1936 /** 1937 * Verifies that a parameter from the <code>CallableStatement</code> with the 1938 * specified SQL statement is equal to the specified object. 1939 * Uses the first <code>CallableStatement</code> with the specified SQL. 1940 * Please use the corresponding wrapper type for primitive data types. 1941 * @param sql the SQL statement of the <code>CallableStatement</code> 1942 * @param indexOfParameter the index used to set the object 1943 * @param object the expected object 1944 * @throws VerifyFailedException if verification fails 1945 */ 1946 public void verifyCallableStatementParameter(String sql, int indexOfParameter, Object object) 1947 { 1948 verifyCallableStatementParameterPresent(sql, indexOfParameter); 1949 Object actualObject = getCallableStatementParameter(sql, indexOfParameter); 1950 if(!ParameterUtil.compareParameter(actualObject, object)) 1951 { 1952 throw new VerifyFailedException("Callable statement parameter with index " + indexOfParameter + " has the value " + 1953 actualObject.toString() + ", expected " + object.toString()); 1954 } 1955 } 1956 1957 /** 1958 * Verifies that a parameter from the <code>CallableStatement</code> with the 1959 * specified SQL statement is equal to the specified object. 1960 * Please use the corresponding wrapper type for primitive data types. 1961 * @param indexOfStatement the index of the statement 1962 * @param indexOfParameter the index used to set the object 1963 * @param object the expected object 1964 * @throws VerifyFailedException if verification fails 1965 */ 1966 public void verifyCallableStatementParameter(int indexOfStatement, int indexOfParameter, Object object) 1967 { 1968 verifyCallableStatementParameterPresent(indexOfStatement, indexOfParameter); 1969 Object actualObject = getCallableStatementParameter(indexOfStatement, indexOfParameter); 1970 if(!ParameterUtil.compareParameter(actualObject, object)) 1971 { 1972 throw new VerifyFailedException("Callable statement parameter with index " + indexOfParameter + " has the value " + 1973 actualObject.toString() + ", expected " + object.toString()); 1974 } 1975 } 1976 1977 /** 1978 * Verifies that a parameter from the specified <code>CallableStatement</code> is equal 1979 * to the specified object. Please use the corresponding wrapper type 1980 * for primitive data types. 1981 * @param statement the <code>CallableStatement</code> 1982 * @param nameOfParameter the name of the parameter 1983 * @param object the expected object 1984 * @throws VerifyFailedException if verification fails 1985 */ 1986 public void verifyCallableStatementParameter(CallableStatement statement, String nameOfParameter, Object object) 1987 { 1988 verifyCallableStatementParameterPresent(statement, nameOfParameter); 1989 Object actualObject = getCallableStatementParameter(statement, nameOfParameter); 1990 if(!ParameterUtil.compareParameter(actualObject, object)) 1991 { 1992 throw new VerifyFailedException("Callable statement parameter with name " + nameOfParameter + " has the value " + 1993 actualObject.toString() + ", expected " + object.toString()); 1994 } 1995 } 1996 1997 /** 1998 * Verifies that a parameter from the <code>CallableStatement</code> with the 1999 * specified SQL statement is equal to the specified object. 2000 * Uses the first <code>CallableStatement</code> with the specified SQL. 2001 * Please use the corresponding wrapper type for primitive data types. 2002 * @param sql the SQL statement of the <code>CallableStatement</code> 2003 * @param nameOfParameter the name of the parameter 2004 * @param object the expected object 2005 * @throws VerifyFailedException if verification fails 2006 */ 2007 public void verifyCallableStatementParameter(String sql, String nameOfParameter, Object object) 2008 { 2009 verifyCallableStatementParameterPresent(sql, nameOfParameter); 2010 Object actualObject = getCallableStatementParameter(sql, nameOfParameter); 2011 if(!ParameterUtil.compareParameter(actualObject, object)) 2012 { 2013 throw new VerifyFailedException("Callable statement parameter with name " + nameOfParameter + " has the value " + 2014 actualObject.toString() + ", expected " + object.toString()); 2015 } 2016 } 2017 2018 /** 2019 * Verifies that a parameter from the <code>CallableStatement</code> with the 2020 * specified SQL statement is equal to the specified object. 2021 * Please use the corresponding wrapper type for primitive data types. 2022 * @param indexOfStatement the index of the statement 2023 * @param nameOfParameter the name of the parameter 2024 * @param object the expected object 2025 * @throws VerifyFailedException if verification fails 2026 */ 2027 public void verifyCallableStatementParameter(int indexOfStatement, String nameOfParameter, Object object) 2028 { 2029 verifyCallableStatementParameterPresent(indexOfStatement, nameOfParameter); 2030 Object actualObject = getCallableStatementParameter(indexOfStatement, nameOfParameter); 2031 if(!ParameterUtil.compareParameter(actualObject, object)) 2032 { 2033 throw new VerifyFailedException("Callable statement parameter with name " + nameOfParameter + " has the value " + 2034 actualObject.toString() + ", expected " + object.toString()); 2035 } 2036 } 2037 2038 /** 2039 * Verifies that an out parameter was registered on the specified 2040 * <code>CallableStatement</code>. 2041 * @param statement the <code>CallableStatement</code> 2042 * @param indexOfParameter the index of the parameter 2043 * @throws VerifyFailedException if verification fails 2044 */ 2045 public void verifyCallableStatementOutParameterRegistered(CallableStatement statement, int indexOfParameter) 2046 { 2047 if(!((MockCallableStatement)statement).isOutParameterRegistered(indexOfParameter)) 2048 { 2049 throw new VerifyFailedException("Out parameter with index " + indexOfParameter + 2050 " not registered in callable statement "); 2051 } 2052 } 2053 2054 /** 2055 * Verifies that an out parameter was registered on the 2056 * <code>CallableStatement</code> with the specified SQL. 2057 * @param sql the SQL statement 2058 * @param indexOfParameter the index of the parameter 2059 * @throws VerifyFailedException if verification fails 2060 */ 2061 public void verifyCallableStatementOutParameterRegistered(String sql, int indexOfParameter) 2062 { 2063 MockCallableStatement statement = getCallableStatement(sql); 2064 if(null == statement) 2065 { 2066 throw new VerifyFailedException("No callable statement " + sql + " present"); 2067 } 2068 if(!statement.isOutParameterRegistered(indexOfParameter)) 2069 { 2070 throw new VerifyFailedException("Out parameter with index " + indexOfParameter + 2071 " not registered in callable statement " + sql); 2072 } 2073 } 2074 2075 /** 2076 * Verifies that an out parameter was registered on the 2077 * <code>CallableStatement</code> with the specified index. 2078 * @param indexOfStatement the index of the <code>CallableStatement</code> 2079 * @param indexOfParameter the index of the parameter 2080 * @throws VerifyFailedException if verification fails 2081 */ 2082 public void verifyCallableStatementOutParameterRegistered(int indexOfStatement, int indexOfParameter) 2083 { 2084 MockCallableStatement statement = getCallableStatement(indexOfStatement); 2085 if(null == statement) 2086 { 2087 throw new VerifyFailedException("No callable statement with index " + indexOfStatement + " present"); 2088 } 2089 if(!statement.isOutParameterRegistered(indexOfParameter)) 2090 { 2091 throw new VerifyFailedException("Out parameter with index " + indexOfParameter + 2092 " not registered in callable statement with index " + indexOfStatement); 2093 } 2094 } 2095 2096 /** 2097 * Verifies that an out parameter was registered on the specified 2098 * <code>CallableStatement</code>. 2099 * @param statement the <code>CallableStatement</code> 2100 * @param nameOfParameter the name of the parameter 2101 * @throws VerifyFailedException if verification fails 2102 */ 2103 public void verifyCallableStatementOutParameterRegistered(CallableStatement statement, String nameOfParameter) 2104 { 2105 if(!((MockCallableStatement)statement).isOutParameterRegistered(nameOfParameter)) 2106 { 2107 throw new VerifyFailedException("Out parameter with name " + nameOfParameter + 2108 " not registered in callable statement "); 2109 } 2110 } 2111 2112 /** 2113 * Verifies that an out parameter was registered on the 2114 * <code>CallableStatement</code> with the specified SQL. 2115 * @param sql the SQL statement 2116 * @param nameOfParameter the name of the parameter 2117 * @throws VerifyFailedException if verification fails 2118 */ 2119 public void verifyCallableStatementOutParameterRegistered(String sql, String nameOfParameter) 2120 { 2121 MockCallableStatement statement = getCallableStatement(sql); 2122 if(null == statement) 2123 { 2124 throw new VerifyFailedException("No callable statement " + sql + " present"); 2125 } 2126 if(!statement.isOutParameterRegistered(nameOfParameter)) 2127 { 2128 throw new VerifyFailedException("Out parameter with name " + nameOfParameter + 2129 " not registered in callable statement " + sql); 2130 } 2131 } 2132 2133 /** 2134 * Verifies that an out parameter was registered on the 2135 * <code>CallableStatement</code> with the specified index. 2136 * @param indexOfStatement the index of the <code>CallableStatement</code> 2137 * @param nameOfParameter the name of the parameter 2138 * @throws VerifyFailedException if verification fails 2139 */ 2140 public void verifyCallableStatementOutParameterRegistered(int indexOfStatement, String nameOfParameter) 2141 { 2142 MockCallableStatement statement = getCallableStatement(indexOfStatement); 2143 if(null == statement) 2144 { 2145 throw new VerifyFailedException("No callable statement with index " + indexOfStatement + " present"); 2146 } 2147 if(!statement.isOutParameterRegistered(nameOfParameter)) 2148 { 2149 throw new VerifyFailedException("Out parameter with name " + nameOfParameter + 2150 " not registered in callable statement with index " + indexOfStatement); 2151 } 2152 } 2153 2154 /** 2155 * Verifies that a <code>Savepoint</code> with the specified index 2156 * is present. The index is the number of the created <code>Savepoint</code> 2157 * starting with 0 for the first <code>Savepoint</code>. 2158 * @param index the index of the <code>Savepoint</code> 2159 */ 2160 public void verifySavepointPresent(int index) 2161 { 2162 MockSavepoint savepoint = getSavepoint(index); 2163 if(null == savepoint) 2164 { 2165 throw new VerifyFailedException("No savepoint with index " + index + " present."); 2166 } 2167 } 2168 2169 /** 2170 * Verifies that a <code>Savepoint</code> with the specified name 2171 * is present. 2172 * @param name the name of the <code>Savepoint</code> 2173 */ 2174 public void verifySavepointPresent(String name) 2175 { 2176 MockSavepoint savepoint = getSavepoint(name); 2177 if(null == savepoint) 2178 { 2179 throw new VerifyFailedException("No savepoint with name " + name + " present."); 2180 } 2181 } 2182 2183 /** 2184 * Verifies that the <code>Savepoint</code> with the specified index 2185 * is released. The index is the number of the created <code>Savepoint</code> 2186 * starting with 0 for the first <code>Savepoint</code>. 2187 * @param index the index of the <code>Savepoint</code> 2188 */ 2189 public void verifySavepointReleased(int index) 2190 { 2191 verifySavepointPresent(index); 2192 if(!getSavepoint(index).isReleased()) 2193 { 2194 throw new VerifyFailedException("Savepoint with index " + index + " not released."); 2195 } 2196 } 2197 2198 /** 2199 * Verifies that the <code>Savepoint</code> with the specified name 2200 * is released. 2201 * @param name the name of the <code>Savepoint</code> 2202 */ 2203 public void verifySavepointReleased(String name) 2204 { 2205 verifySavepointPresent(name); 2206 if(!getSavepoint(name).isReleased()) 2207 { 2208 throw new VerifyFailedException("Savepoint with name " + name + " not released."); 2209 } 2210 } 2211 2212 /** 2213 * Verifies that the <code>Savepoint</code> with the specified index 2214 * is not released. The index is the number of the created <code>Savepoint</code> 2215 * starting with 0 for the first <code>Savepoint</code>. 2216 * @param index the index of the <code>Savepoint</code> 2217 */ 2218 public void verifySavepointNotReleased(int index) 2219 { 2220 verifySavepointPresent(index); 2221 if(getSavepoint(index).isReleased()) 2222 { 2223 throw new VerifyFailedException("Savepoint with index " + index + " is released."); 2224 } 2225 } 2226 2227 /** 2228 * Verifies that the <code>Savepoint</code> with the specified name 2229 * is not released. 2230 * @param name the name of the <code>Savepoint</code> 2231 */ 2232 public void verifySavepointNotReleased(String name) 2233 { 2234 verifySavepointPresent(name); 2235 if(getSavepoint(name).isReleased()) 2236 { 2237 throw new VerifyFailedException("Savepoint with name " + name + " is released."); 2238 } 2239 } 2240 2241 /** 2242 * Verifies that the <code>Savepoint</code> with the specified index 2243 * is rolled back. The index is the number of the created <code>Savepoint</code> 2244 * starting with 0 for the first <code>Savepoint</code>. 2245 * @param index the index of the <code>Savepoint</code> 2246 */ 2247 public void verifySavepointRolledBack(int index) 2248 { 2249 verifySavepointPresent(index); 2250 if(!getSavepoint(index).isRolledBack()) 2251 { 2252 throw new VerifyFailedException("Savepoint with index " + index + " not rolled back."); 2253 } 2254 } 2255 2256 /** 2257 * Verifies that the <code>Savepoint</code> with the specified name 2258 * is rolled back. 2259 * @param name the name of the <code>Savepoint</code> 2260 */ 2261 public void verifySavepointRolledBack(String name) 2262 { 2263 verifySavepointPresent(name); 2264 if(!getSavepoint(name).isRolledBack()) 2265 { 2266 throw new VerifyFailedException("Savepoint with name " + name + " not rolled back."); 2267 } 2268 } 2269 2270 /** 2271 * Verifies that the <code>Savepoint</code> with the specified index 2272 * is not rolled back. The index is the number of the created <code>Savepoint</code> 2273 * starting with 0 for the first <code>Savepoint</code>. 2274 * @param index the index of the <code>Savepoint</code> 2275 */ 2276 public void verifySavepointNotRolledBack(int index) 2277 { 2278 verifySavepointPresent(index); 2279 if(getSavepoint(index).isRolledBack()) 2280 { 2281 throw new VerifyFailedException("Savepoint with index " + index + " is rolled back."); 2282 } 2283 } 2284 2285 /** 2286 * Verifies that the <code>Savepoint</code> with the specified name 2287 * is not rolled back. 2288 * @param name the name of the <code>Savepoint</code> 2289 */ 2290 public void verifySavepointNotRolledBack(String name) 2291 { 2292 verifySavepointPresent(name); 2293 if(getSavepoint(name).isRolledBack()) 2294 { 2295 throw new VerifyFailedException("Savepoint with name " + name + " is rolled back."); 2296 } 2297 } 2298 2299 /** 2300 * @deprecated use {@link #verifySavepointRolledBack(int)} 2301 */ 2302 public void verifySavepointRollbacked(int index) 2303 { 2304 verifySavepointRolledBack(index); 2305 } 2306 2307 /** 2308 * @deprecated use {@link #verifySavepointRolledBack(String)} 2309 */ 2310 public void verifySavepointRollbacked(String name) 2311 { 2312 verifySavepointRolledBack(name); 2313 } 2314 2315 /** 2316 * @deprecated use {@link #verifySavepointNotRolledBack(int)} 2317 */ 2318 public void verifySavepointNotRollbacked(int index) 2319 { 2320 verifySavepointNotRolledBack(index); 2321 } 2322 2323 /** 2324 * @deprecated use {@link #verifySavepointNotRolledBack(String)} 2325 */ 2326 public void verifySavepointNotRollbacked(String name) 2327 { 2328 verifySavepointNotRolledBack(name); 2329 } 2330 }