UkelonnServiceProvider extends UkelonnServiceBase { @Override public List<TransactionType> modifyPaymenttype(TransactionType paymenttype) { try(Connection connection = datasource.getConnection()) { try(PreparedStatement statement = connection.prepareStatement("update transaction_types set transaction_type_name=?, transaction_amount=?, transaction_is_work=false, transaction_is_wage_payment=true where transaction_type_id=?")) { statement.setString(1, paymenttype.getTransactionTypeName()); statement.setDouble(2, paymenttype.getTransactionAmount()); statement.setInt(3, paymenttype.getId()); statement.executeUpdate(); } } catch (SQLException e) { String message = String.format("Failed to update payment type %d in the database", paymenttype.getId()); logError(message, e); throw new UkelonnException(message, e); } return getPaymenttypes(); }  @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 testModifyPaymenttype() { UkelonnService ukelonn = getUkelonnServiceSingleton(); List<TransactionType> paymenttypes = ukelonn.getPaymenttypes(); TransactionType paymenttype = paymenttypes.get(0); Double originalAmount = paymenttype.getTransactionAmount(); paymenttype.setTransactionAmount(originalAmount + 1); List<TransactionType> updatedPaymenttypes = ukelonn.modifyPaymenttype(paymenttype); TransactionType updatedPaymenttype = updatedPaymenttypes.get(0); assertThat(updatedPaymenttype.getTransactionAmount()).isGreaterThan(originalAmount); }