LogEntryDAOMysqlImpl extends AbstractTableCreatingDAOImpl implements LogEntryDAO { public List<LogEntry> getLogEntries(int offset, int limit) { Preconditions.checkArgument(offset >= 0, "offset must be greater than or equal to 0"); Preconditions.checkArgument(limit >= 0, "limit must be greater than or equal to 0"); return getLogEntries.execute(offset, limit); } protected  LogEntryDAOMysqlImpl(DataSource dataSource, SqlScriptService sqlScriptService,
                                   PluginRegistry pluginRegistry); @Override String getDefaultTableName(); @Override String getTableCreatingSQLScriptName(); void startEntry(LogEntry entry); void endEntry(LogEntry entry); void endAllEntries(Date endDate); void endAllEntries(); void deleteEntry(LogEntry entry); List<Integer> getRunningTenants(); List<LogEntry> getLogEntries(int offset, int limit); List<LogEntry> getLogEntriesForTenant(int tenantId, int offset, int limit); List<LogEntry> getLogEntries(int assocTypeId, int offset, int limit); List<LogEntry> getLogEntriesForTenant(int tenantId, int assocTypeId, int offset, int limit); int getNumberOfLogEntries(); int getNumberOfLogEntriesForTenant(int tenantId); void deleteLogEntries(); int getComputationDurationForDate(Date date); int getComputationDurationForDate();  }
@Test @DataSet("/dbunit/pluginContainer/plugin_log+1new_ended.xml") public void getLogEntries_shouldReturnAllStartedAndEndedLogEntries() { List<LogEntry> logEntries = logEntryDAO.getLogEntries(0, Integer.MAX_VALUE); assertThat(logEntries, is(not(nullValue()))); assertThat(logEntries, hasItem(matchesLogEntryWithoutId( new LogEntry(1, waitingGenerator.getId().getUri(), waitingGenerator.getId().getVersion(), date("2011-02-23 15:00:00"), date("2011-02-23 15:10:00"), 1, waitingGenerator.newConfiguration(), new WaitingGeneratorStats())))); assertThat(logEntries, hasItem(matchesLogEntryWithoutId( new LogEntry(1, waitingGenerator.getId().getUri(), waitingGenerator.getId().getVersion(), date("2011-02-23 15:20:00"), null, 1, waitingGenerator.newConfiguration(), null)))); assertThat(logEntries, hasItem(matchesLogEntryWithoutId( new LogEntry(2, waitingGenerator.getId().getUri(), waitingGenerator.getId().getVersion(), date("2011-02-23 16:00:00"), date("2011-02-23 16:10:00"), 1, waitingGenerator.newConfiguration(), new WaitingGeneratorStats())))); }
@Test public void getLogEntries_shouldReturnEmptyListIfLimitIsZero() { List<LogEntry> logEntries = logEntryDAO.getLogEntries(0, 0); assertThat(logEntries, is(not(nullValue()))); assertThat(logEntries.size(), is(0)); }
@Test @DataSet("/dbunit/pluginContainer/plugin_log+1new_ended.xml") public void getLogEntries_shouldReturnAtMostLimitEntries() { List<LogEntry> logEntries = logEntryDAO.getLogEntries(0, 2); assertThat(logEntries, is(not(nullValue()))); assertThat(logEntries.size(), is(lessThanOrEqualTo(2))); }
@Test @DataSet("/dbunit/pluginContainer/plugin_log+1new_ended.xml") public void getLogEntries_shouldStartAtOffset() { List<LogEntry> logEntries = logEntryDAO.getLogEntries(1, Integer.MAX_VALUE); LogEntry expected1 = new LogEntry(1, waitingGenerator.getId().getUri(), waitingGenerator.getId().getVersion(), date("2011-02-23 15:20:00"), null, 1, waitingGenerator.newConfiguration(), null); LogEntry expected2 = new LogEntry(1, waitingGenerator.getId().getUri(), waitingGenerator.getId().getVersion(), date("2011-02-23 15:00:00"), date("2011-02-23 15:10:00"), 1, waitingGenerator.newConfiguration(), new WaitingGeneratorStats()); assertThat(logEntries, is(not(nullValue()))); assertThat(logEntries, hasItem(matchesLogEntryWithoutId(expected1))); assertThat(logEntries, hasItem(matchesLogEntryWithoutId(expected2))); Iterator<LogEntry> iteratorAhead = logEntries.iterator(); Iterator<LogEntry> iterator = logEntries.iterator(); iteratorAhead.next(); while (iterator.hasNext() && iteratorAhead.hasNext()) { LogEntry entry1 = iteratorAhead.next(); LogEntry entry2 = iterator.next(); assertThat("entry 1 must be before entry 2", entry1.getStartDate(), lessThanOrEqualTo(entry2.getStartDate())); } }
@Test(expected = IllegalArgumentException.class) public void getLogEntries_shouldThrowOnNegativeOffset() { logEntryDAO.getLogEntries(-1, Integer.MAX_VALUE); }
@Test(expected = IllegalArgumentException.class) public void getLogEntries_shouldThrowOnNegativeLimit() { logEntryDAO.getLogEntries(0, -1); }