SecurityUtils.authenticate(authenticationManager, "jose", "jose");
}
@Test
public void testAddInvestment() {
Investment investment = new Investment();
Account account = Account.findAccount(1L);
investment.setSymbol("INV");
investment.setName("investment");
investment.setProductType("type");
investment.setOwner(account.getOwner());
investment.persist();
InvestmentTransaction transaction = new InvestmentTransaction();
transaction.setQuantity(5D);
transaction.setInvestment(new Investment());
transaction.getInvestment().setId(investment.getId());
transaction.setPrice(new InvestmentPrice());
transaction.getPrice().setPrice(2D);
transaction.setAccountTransaction(new AccountTransaction());
transaction.getAccountTransaction().setAccount(new Account());
transaction.getAccountTransaction().getAccount().setId(1L);
transaction.getAccountTransaction().setAmount(BigDecimal.TEN);
transaction.getAccountTransaction().setOperationDate(DateUtils.getMidnight(new Date()));
transaction.getAccountTransaction().setSubcategory(new Subcategory());
transaction.getAccountTransaction().getSubcategory().setCategory("category.investment.buy");
double balance = account.calculateBalance().doubleValue();
investmentService.addInvestment(account.getOwner(), account, transaction, 11D);
assertNotNull("Transaction persisted", transaction.getId());
assertNotNull("Investment price persisted", transaction.getPrice().getId());
assertNotNull("Account transaction persisted", transaction.getAccountTransaction().getId());
assertEquals("One price available for the investment", new Double(2D), investment.getCurrentPrice());
assertEquals("Balance was updated accordingly", new Double(balance - 21D), new Double(account.calculateBalance().doubleValue()));
}