LogEntryDAOMysqlImpl extends AbstractTableCreatingDAOImpl implements LogEntryDAO { public void endEntry(LogEntry entry) { Preconditions.checkNotNull(entry); Preconditions.checkNotNull(entry.getPluginId()); Preconditions.checkNotNull(entry.getPluginId().getUri()); Preconditions.checkNotNull(entry.getPluginId().getVersion()); Preconditions.checkNotNull(entry.getStartDate()); Preconditions.checkNotNull(entry.getConfiguration()); Preconditions.checkNotNull(entry.getStatistics()); Preconditions.checkArgument(entry.getStartDate().before(entry.getEndDate()) || entry.getStartDate().equals(entry.getEndDate()), "startDate must be before endDate, or startDate = endDate"); String serializedConfiguration = entry.getConfiguration().marshal(); String serializedStatistics = entry.getStatistics().marshal(); endEntry.update(entry.getTenantId(), entry.getPluginId().getUri().toASCIIString(), entry.getPluginId().getVersion().toString(), entry.getStartDate(), entry.getAssocTypeId(), serializedConfiguration, entry.getEndDate(), serializedStatistics, entry.getEndDate(), serializedStatistics); } 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 @ExpectedDataSet("/dbunit/pluginContainer/plugin_log+1new_ended.xml") public void endEntry_shouldInsertNewEntryOnNonExistingEntry() { LogEntry newEntry = new LogEntry(2, waitingGenerator.getId().getUri(), waitingGenerator.getId().getVersion(), date("2011-02-23 16:00:00"), 1, waitingGenerator.newConfiguration()); newEntry.setEndDate(date("2011-02-23 16:10:00")); newEntry.setStatistics(new WaitingGeneratorStats()); logEntryDAO.endEntry(newEntry); }
@Test(expected = NullPointerException.class) public void endEntry_shouldThrowOnNullArgument() { logEntryDAO.endEntry(null); }
@Test(expected = NullPointerException.class) public void endEntry_shouldThrowOnNullPluginId() { LogEntry newEntry = new LogEntry(1, null, waitingGenerator.getId().getVersion(), date("2011-02-23 15:00:00"), 1, waitingGenerator.newConfiguration()); newEntry.setEndDate(date("2011-02-23 15:10:00")); newEntry.setStatistics(new WaitingGeneratorStats()); logEntryDAO.endEntry(newEntry); }
@Test(expected = NullPointerException.class) public void endEntry_shouldThrowOnNullPluginVersion() { LogEntry newEntry = new LogEntry(1, waitingGenerator.getId().getUri(), null, date("2011-02-23 15:00:00"), 1, waitingGenerator.newConfiguration()); newEntry.setEndDate(date("2011-02-23 15:10:00")); newEntry.setStatistics(new WaitingGeneratorStats()); logEntryDAO.endEntry(newEntry); }
@Test(expected = NullPointerException.class) public void endEntry_shouldThrowOnNullStartDate() { LogEntry newEntry = new LogEntry(1, waitingGenerator.getId().getUri(), waitingGenerator.getId().getVersion(), null, 1, waitingGenerator.newConfiguration()); newEntry.setEndDate(date("2011-02-23 15:10:00")); newEntry.setStatistics(new WaitingGeneratorStats()); logEntryDAO.endEntry(newEntry); }
@Test(expected = NullPointerException.class) public void endEntry_shouldThrowOnNullEndDate() { LogEntry newEntry = new LogEntry(1, waitingGenerator.getId().getUri(), waitingGenerator.getId().getVersion(), date("2011-02-23 15:00:00"), 1, waitingGenerator.newConfiguration()); newEntry.setEndDate(null); newEntry.setStatistics(new WaitingGeneratorStats()); logEntryDAO.endEntry(newEntry); }
@Test(expected = NullPointerException.class) public void endEntry_shouldThrowOnNullConfiguration() { LogEntry newEntry = new LogEntry(1, waitingGenerator.getId().getUri(), waitingGenerator.getId().getVersion(), date("2011-02-23 15:00:00"), 1, null); newEntry.setEndDate(date("2011-02-23 15:10:00")); newEntry.setStatistics(new WaitingGeneratorStats()); logEntryDAO.endEntry(newEntry); }
@Test(expected = NullPointerException.class) public void endEntry_shouldThrowOnNullStatistics() { LogEntry newEntry = new LogEntry(1, waitingGenerator.getId().getUri(), waitingGenerator.getId().getVersion(), null, 1, waitingGenerator.newConfiguration()); newEntry.setEndDate(date("2011-02-23 15:10:00")); newEntry.setStatistics(null); logEntryDAO.endEntry(newEntry); }
@Test @ExpectedDataSet("/dbunit/pluginContainer/plugin_log+1existing_ended.xml") public void endEntry_shouldEndExistingEntry() { LogEntry newEntry = new LogEntry(1, waitingGenerator.getId().getUri(), waitingGenerator.getId().getVersion(), date("2011-02-23 15:20:00"), 1, waitingGenerator.newConfiguration()); newEntry.setEndDate(date("2011-02-23 15:30:00")); newEntry.setStatistics(new WaitingGeneratorStats()); logEntryDAO.endEntry(newEntry); }