UkelonnServiceProvider extends UkelonnServiceBase { @Override public List<SumYearMonth> earningsSumOverMonth(String username) { List<SumYearMonth> statistics = new ArrayList<>(); try(Connection connection = datasource.getConnection()) { try(PreparedStatement statement = connection.prepareStatement("select aggregate_amount, aggregate_year, aggregate_month from sum_over_year_and_month_view where username=?")) { statement.setString(1, username); try(ResultSet resultSet = statement.executeQuery()) { while (resultSet.next()) { double sum = resultSet.getDouble(1); int year = resultSet.getInt(2); int month = resultSet.getInt(3); statistics.add(new SumYearMonth(sum, year, month)); } } } } catch (SQLException e) { logWarning(String.format("Failed to get sum of earnings per month for account \"%s\" from the database", username), e); } return statistics; }  @Activate void activate(); @Reference(target = "(osgi.jndi.service.name=jdbc/ukelonn)") void setDataSource(DataSource datasource); @Override DataSource getDataSource(); @Reference void setUserAdmin(UserManagementService useradmin); @Reference void setLogservice(LogService logservice); @Override LogService getLogservice(); @Override List<Account> getAccounts(); @Override Account getAccount(String username); @Override Account registerPerformedJob(PerformedTransaction job); @Override List<TransactionType> getJobTypes(); @Override List<Transaction> getJobs(int accountId); @Override List<Transaction> getPayments(int accountId); @Override List<Transaction> deleteJobsFromAccount(int accountId, List<Integer> idsOfJobsToDelete); @Override List<Transaction> updateJob(UpdatedTransaction editedJob); @Override List<TransactionType> getPaymenttypes(); @Override Account registerPayment(PerformedTransaction payment); @Override List<TransactionType> modifyJobtype(TransactionType jobtype); @Override List<TransactionType> createJobtype(TransactionType jobtype); @Override List<TransactionType> modifyPaymenttype(TransactionType paymenttype); @Override List<TransactionType> createPaymenttype(TransactionType paymenttype); @Override Account addAccount(User user); @Override List<SumYear> earningsSumOverYear(String username); @Override List<SumYearMonth> earningsSumOverMonth(String username); @Override List<Notification> notificationsTo(String username); @Override void notificationTo(String username, Notification notification); Account mapAccount(ResultSet results);  }
@Test public void testEarningsSumOverMonth() { UkelonnServiceProvider ukelonn = getUkelonnServiceSingleton(); List<SumYearMonth> statistics = ukelonn.earningsSumOverMonth("jad"); assertThat(statistics.size()).isPositive(); SumYearMonth firstYear = statistics.get(0); assertEquals(125.0, firstYear.getSum(), 0.0); assertEquals(2016, firstYear.getYear()); assertEquals(7, firstYear.getMonth()); }