protected MockConnection createMockConnection() {
    // this query must be the same as the query in TestMapper.xml
    MockResultSet rs = new MockResultSet("SELECT 1");
    rs.addRow(new Object[] {1});

    MockConnection con = new MockConnection();
    con.getPreparedStatementResultSetHandler().prepareResultSet("SELECT 1", rs);

    return con;
  }
  private void prepareResultsetReturningMultipleKeys() {
    MockConnection connection = getJDBCMockObjectFactory().getMockConnection();
    PreparedStatementResultSetHandler statementHandler =
        connection.getPreparedStatementResultSetHandler();
    MockResultSet keysResult = statementHandler.createResultSet();
    keysResult.addColumn("id");
    keysResult.addRow(new Object[] {BigDecimal.valueOf(11L)});
    keysResult.addRow(new Object[] {BigDecimal.valueOf(12L)});
    keysResult.addRow(new Object[] {BigDecimal.valueOf(13L)});

    statementHandler.prepareGeneratedKeys("insert", keysResult);
  }
 @Test
 public void testMakeStatCumulWithoutExistingData() throws Exception {
   MockConnection connexion = factory.getMockConnection();
   StatementResultSetHandler statementHandler = connexion.getStatementResultSetHandler();
   statementHandler.setExactMatch(true);
   MockResultSet result = statementHandler.createResultSet();
   result.addColumn("dateStat", new Object[] {"2011-04-17"});
   result.addColumn("fileDir", new Object[] {"/var/data/silverpeas/kmelia36"});
   result.addColumn("sizeDir", new Object[] {543L});
   statementHandler.prepareResultSet("SELECT * FROM SB_Stat_SizeDir", result);
   MockResultSet cumulResult = statementHandler.createResultSet();
   statementHandler.prepareResultSet(
       "SELECT dateStat,fileDir,sizeDir FROM SB_Stat_SizeDirCumul "
           + "WHERE dateStat='2011-04-01' AND fileDir='/var/data/silverpeas/kmelia36'",
       cumulResult);
   SilverStatisticsManagerDAO.makeStatCumul(connexion, typeofStat, config);
   module.verifyAllStatementsClosed();
   List<?> statements = module.getExecutedSQLStatements();
   assertNotNull(statements);
   assertThat(statements.size(), is(3));
   List<?> preparedStatements = module.getPreparedStatements();
   assertNotNull(preparedStatements);
   assertThat(preparedStatements, hasSize(2));
   MockPreparedStatement pstmt = module.getPreparedStatement(0);
   assertThat(
       pstmt.getSQL(),
       is(
           "UPDATE SB_Stat_SizeDirCumul SET sizeDir=?  WHERE "
               + "dateStat='2011-04-01' AND fileDir='/var/data/silverpeas/kmelia36'"));
   Map parameters = pstmt.getParameterMap();
   assertThat(parameters.size(), is(0));
   pstmt = module.getPreparedStatement(1);
   assertThat(
       pstmt.getSQL(),
       is("INSERT INTO SB_Stat_SizeDirCumul(dateStat,fileDir,sizeDir) " + "VALUES(?,?,?)"));
   parameters = pstmt.getParameterMap();
   assertThat(parameters.size(), is(3));
   assertThat((String) parameters.get(1), is("2011-04-01"));
   assertThat((String) parameters.get(2), is("/var/data/silverpeas/kmelia36"));
   assertThat((Long) parameters.get(3), is(543L));
 }