use of org.mifos.accounts.business.AccountPaymentEntityBuilder in project head by mifos.
the class LoanBOTest method repayInstallmentsShouldPopulateCalculatedInterestsForDIPBLoans.
@Test
public void repayInstallmentsShouldPopulateCalculatedInterestsForDIPBLoans() throws PersistenceException {
final LegacyLoanDao legacyLoanDao = mock(LegacyLoanDao.class);
final CustomerBO customerBO = mock(CustomerBO.class);
final LoanSummaryEntity loanSummaryEntity = mock(LoanSummaryEntity.class);
LoanBO loanBO = new LoanBO() {
@Override
public boolean isDecliningBalanceInterestRecalculation() {
return true;
}
@Override
public LegacyLoanDao getlegacyLoanDao() {
return legacyLoanDao;
}
@Override
public CustomerBO getCustomer() {
return customerBO;
}
@Override
public LoanSummaryEntity getLoanSummary() {
return loanSummaryEntity;
}
};
AccountActionTypes accountActionTypes = AccountActionTypes.LOAN_REPAYMENT;
AccountActionEntity accountActionEntity = mock(AccountActionEntity.class);
AccountPaymentEntity accountPaymentEntity = new AccountPaymentEntityBuilder().with(loanBO).build();
PersonnelBO user = new PersonnelBO();
Money extraInterestDue = new Money(rupee, "0.98");
Money interest = new Money(rupee, "10");
Money interestDue = new Money(rupee, "2.07");
when(legacyLoanDao.getPersistentObject(AccountActionEntity.class, accountActionTypes.getValue())).thenReturn(accountActionEntity);
when(loanScheduleEntity.getPrincipalDue()).thenReturn(new Money(rupee, "1000"));
when(loanScheduleEntity.getTotalFeeDueWithMiscFeeDue()).thenReturn(new Money(rupee, "10"));
when(loanScheduleEntity.getPenaltyDue()).thenReturn(new Money(rupee, "10"));
when(loanScheduleEntity.getPenalty()).thenReturn(new Money(rupee, "100"));
when(loanScheduleEntity.getExtraInterestDue()).thenReturn(extraInterestDue);
when(loanScheduleEntity.getExtraInterestPaid()).thenReturn(extraInterestDue);
when(loanScheduleEntity.getInterest()).thenReturn(interest);
when(loanScheduleEntity.getInterestDue()).thenReturn(interestDue);
loanBO.repayInstallment(loanScheduleEntity, accountPaymentEntity, accountActionTypes, user, "", interestDue);
Set<AccountTrxnEntity> accountTrxns = accountPaymentEntity.getAccountTrxns();
AccountTrxnEntity accountTrxnEntity = accountTrxns.toArray(new AccountTrxnEntity[accountTrxns.size()])[0];
LoanTrxnDetailEntity loanTrxnDetailEntity = (LoanTrxnDetailEntity) accountTrxnEntity;
assertThat(loanTrxnDetailEntity.getInterestAmount().getAmount().doubleValue(), is(3.05));
CalculatedInterestOnPayment calculatedInterestOnPayment = loanTrxnDetailEntity.getCalculatedInterestOnPayment();
assertNotNull(calculatedInterestOnPayment);
assertThat(calculatedInterestOnPayment.getExtraInterestPaid(), is(extraInterestDue));
assertThat(calculatedInterestOnPayment.getInterestDueTillPaid(), is(interestDue));
assertThat(calculatedInterestOnPayment.getOriginalInterest(), is(interest));
Mockito.verify(loanScheduleEntity).makeEarlyRepaymentEntries(LoanConstants.PAY_FEES_PENALTY_INTEREST, interestDue, accountPaymentEntity.getPaymentDate());
}
use of org.mifos.accounts.business.AccountPaymentEntityBuilder in project head by mifos.
the class SavingsCloseTest method whenClosingAccountShouldWithdrawRemainingBalanceOnAccount.
@Test
public void whenClosingAccountShouldWithdrawRemainingBalanceOnAccount() {
Money remainingBalance = TestUtils.createMoney("100");
savingsAccount = new SavingsAccountBuilder().active().withSavingsProduct(savingsProduct).withCustomer(client).withBalanceOf(remainingBalance).build();
AccountPaymentEntity payment = new AccountPaymentEntityBuilder().with(savingsAccount).with(remainingBalance).build();
AccountNotesEntity notes = new AccountNotesEntityBuilder().build();
CustomerBO customer = new ClientBuilder().buildForUnitTests();
PersonnelBO loggedInUser = new PersonnelBuilder().build();
// pre verification
assertTrue(savingsAccount.getAccountPayments().isEmpty());
// exercise test
savingsAccount.closeAccount(payment, notes, customer, loggedInUser);
// verification
assertFalse(savingsAccount.getAccountPayments().isEmpty());
AccountPaymentEntity withdrawalPayment = savingsAccount.getAccountPayments().get(0);
assertThat(withdrawalPayment.getAmount(), is(TestUtils.createMoney("100")));
}
use of org.mifos.accounts.business.AccountPaymentEntityBuilder in project head by mifos.
the class SavingsCloseTest method whenClosingAccountShouldSetClosedDate.
@Test
public void whenClosingAccountShouldSetClosedDate() {
Money remainingBalance = TestUtils.createMoney("100");
savingsAccount = new SavingsAccountBuilder().active().withSavingsProduct(savingsProduct).withCustomer(client).withBalanceOf(remainingBalance).build();
AccountPaymentEntity payment = new AccountPaymentEntityBuilder().with(savingsAccount).with(remainingBalance).build();
AccountNotesEntity notes = new AccountNotesEntityBuilder().build();
CustomerBO customer = new ClientBuilder().buildForUnitTests();
PersonnelBO loggedInUser = new PersonnelBuilder().build();
// exercise test
savingsAccount.closeAccount(payment, notes, customer, loggedInUser);
// verification
assertThat(new LocalDate(savingsAccount.getClosedDate()), is(new LocalDate()));
}
use of org.mifos.accounts.business.AccountPaymentEntityBuilder in project head by mifos.
the class SavingsCloseTest method whenClosingAccountShouldPostInterestWhenRemainingSavingsBalanceIsLessThanAmountBeingWithdrawn.
@Test
public void whenClosingAccountShouldPostInterestWhenRemainingSavingsBalanceIsLessThanAmountBeingWithdrawn() {
Money remainingBalance = TestUtils.createMoney("100");
savingsAccount = new SavingsAccountBuilder().active().withSavingsProduct(savingsProduct).withCustomer(client).withBalanceOf(remainingBalance).build();
Money withdrawalAtCloseAmount = TestUtils.createMoney("105.56");
AccountPaymentEntity payment = new AccountPaymentEntityBuilder().with(savingsAccount).with(withdrawalAtCloseAmount).build();
AccountNotesEntity notes = new AccountNotesEntityBuilder().build();
CustomerBO customer = new ClientBuilder().buildForUnitTests();
PersonnelBO loggedInUser = new PersonnelBuilder().build();
// pre verification
assertTrue(savingsAccount.getAccountPayments().isEmpty());
// exercise test
savingsAccount.closeAccount(payment, notes, customer, loggedInUser);
// verification
assertFalse(savingsAccount.getAccountPayments().isEmpty());
assertThat(savingsAccount.getAccountPayments().size(), is(2));
AccountPaymentEntity interestPayment = savingsAccount.getAccountPayments().get(0);
assertThat(interestPayment.getAmount(), is(TestUtils.createMoney("5.56")));
AccountPaymentEntity withdrawalPayment = savingsAccount.getAccountPayments().get(1);
assertThat(withdrawalPayment.getAmount(), is(TestUtils.createMoney("105.56")));
}
use of org.mifos.accounts.business.AccountPaymentEntityBuilder in project head by mifos.
the class SavingsCloseTest method whenClosingAccountShouldCreateStatusChangeHistoryForClosure.
@Test
public void whenClosingAccountShouldCreateStatusChangeHistoryForClosure() {
Money remainingBalance = TestUtils.createMoney("100");
savingsAccount = new SavingsAccountBuilder().active().withSavingsProduct(savingsProduct).withCustomer(client).withBalanceOf(remainingBalance).build();
AccountPaymentEntity payment = new AccountPaymentEntityBuilder().with(savingsAccount).with(remainingBalance).build();
AccountNotesEntity notes = new AccountNotesEntityBuilder().build();
CustomerBO customer = new ClientBuilder().buildForUnitTests();
PersonnelBO loggedInUser = new PersonnelBuilder().build();
// pre verification
assertThat(savingsAccount.getAccountStatusChangeHistory().size(), is(1));
// exercise test
savingsAccount.closeAccount(payment, notes, customer, loggedInUser);
// verification
assertThat(savingsAccount.getAccountStatusChangeHistory().size(), is(2));
AccountStatusChangeHistoryEntity closure = savingsAccount.getAccountStatusChangeHistory().get(1);
assertThat(closure.getAccount(), is((AccountBO) savingsAccount));
assertTrue(closure.getOldStatus().isInState(AccountState.SAVINGS_ACTIVE));
assertTrue(closure.getNewStatus().isInState(AccountState.SAVINGS_CLOSED));
}
Aggregations