@Test public void testGetUpdateCount() { statementHandler.prepareUpdateCount(".*", 3); statementHandler.prepareUpdateCount("insert xyz", 4); assertEquals(new Integer(4), statementHandler.getUpdateCount("insert xyz")); assertEquals(new Integer(3), statementHandler.getUpdateCount(".*")); statementHandler.setUseRegularExpressions(true); assertEquals(new Integer(3), statementHandler.getUpdateCount("insert xyz")); assertEquals(new Integer(3), statementHandler.getUpdateCount("insert")); statementHandler.setExactMatch(true); assertEquals(new Integer(4), statementHandler.getUpdateCount("insert Xyz")); assertNull(statementHandler.getUpdateCount("insert")); statementHandler.prepareUpdateCounts("update", new int[] {1, 2}); assertEquals(new Integer(1), statementHandler.getUpdateCount("update")); }
@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)); }