UkelonnServiceProvider extends UkelonnServiceBase { @Override public Account registerPerformedJob(PerformedTransaction job) { int accountId = job.getAccount().getAccountId(); int jobtypeId = job.getTransactionTypeId(); double jobamount = job.getTransactionAmount(); Date timeofjob = job.getTransactionDate(); try(Connection connection = datasource.getConnection()) { try(PreparedStatement statement = connection.prepareStatement("insert into transactions (account_id, transaction_type_id,transaction_amount, transaction_time) values (?, ?, ?, ?)")) { statement.setInt(1, accountId); statement.setInt(2, jobtypeId); statement.setDouble(3, jobamount); statement.setTimestamp(4, new java.sql.Timestamp(timeofjob.getTime())); statement.executeUpdate(); } } catch (SQLException exception) { String message = String.format("Failed to register performed job in the database, account: %d jobtype: %d amount: %f", accountId, jobtypeId, jobamount); logError(message, exception); } return getAccount(job.getAccount().getUsername()); }  @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 testRegisterPerformedJob() throws Exception { try { UkelonnServiceProvider ukelonn = getUkelonnServiceSingleton(); String username = "jad"; UserManagementService useradmin = mock(UserManagementService.class); no.priv.bang.osgiservice.users.User user = new no.priv.bang.osgiservice.users.User(1, username, "jad@gmail.com", "Jane", "Doe"); when(useradmin.getUser(anyString())).thenReturn(user); ukelonn.setUserAdmin(useradmin); Account account = ukelonn.getAccount(username); double oldBalance = account.getBalance(); TransactionType jobtype = ukelonn.getJobTypes().get(0); PerformedTransaction performedJob = new PerformedTransaction(account, jobtype.getId(), jobtype.getTransactionAmount(), new Date()); Account updatedAccount = ukelonn.registerPerformedJob(performedJob); assertThat(updatedAccount.getBalance()).isGreaterThan(oldBalance); } finally { restoreTestDatabase(); } }