Search in sources :

Example 1 with AccountPaymentEntityBuilder

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());
}
Also used : AccountPaymentEntityBuilder(org.mifos.accounts.business.AccountPaymentEntityBuilder) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountActionEntity(org.mifos.accounts.business.AccountActionEntity) AccountActionTypes(org.mifos.accounts.util.helpers.AccountActionTypes) Money(org.mifos.framework.util.helpers.Money) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) CustomerBO(org.mifos.customers.business.CustomerBO) LegacyLoanDao(org.mifos.accounts.loan.persistance.LegacyLoanDao) Test(org.junit.Test)

Example 2 with AccountPaymentEntityBuilder

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")));
}
Also used : PersonnelBuilder(org.mifos.domain.builders.PersonnelBuilder) Money(org.mifos.framework.util.helpers.Money) AccountNotesEntityBuilder(org.mifos.accounts.business.AccountNotesEntityBuilder) AccountPaymentEntityBuilder(org.mifos.accounts.business.AccountPaymentEntityBuilder) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountNotesEntity(org.mifos.accounts.business.AccountNotesEntity) CustomerBO(org.mifos.customers.business.CustomerBO) SavingsAccountBuilder(org.mifos.domain.builders.SavingsAccountBuilder) ClientBuilder(org.mifos.domain.builders.ClientBuilder) Test(org.junit.Test)

Example 3 with AccountPaymentEntityBuilder

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()));
}
Also used : PersonnelBuilder(org.mifos.domain.builders.PersonnelBuilder) Money(org.mifos.framework.util.helpers.Money) AccountNotesEntityBuilder(org.mifos.accounts.business.AccountNotesEntityBuilder) AccountPaymentEntityBuilder(org.mifos.accounts.business.AccountPaymentEntityBuilder) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountNotesEntity(org.mifos.accounts.business.AccountNotesEntity) CustomerBO(org.mifos.customers.business.CustomerBO) SavingsAccountBuilder(org.mifos.domain.builders.SavingsAccountBuilder) LocalDate(org.joda.time.LocalDate) ClientBuilder(org.mifos.domain.builders.ClientBuilder) Test(org.junit.Test)

Example 4 with AccountPaymentEntityBuilder

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")));
}
Also used : PersonnelBuilder(org.mifos.domain.builders.PersonnelBuilder) Money(org.mifos.framework.util.helpers.Money) AccountNotesEntityBuilder(org.mifos.accounts.business.AccountNotesEntityBuilder) AccountPaymentEntityBuilder(org.mifos.accounts.business.AccountPaymentEntityBuilder) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountNotesEntity(org.mifos.accounts.business.AccountNotesEntity) CustomerBO(org.mifos.customers.business.CustomerBO) SavingsAccountBuilder(org.mifos.domain.builders.SavingsAccountBuilder) ClientBuilder(org.mifos.domain.builders.ClientBuilder) Test(org.junit.Test)

Example 5 with AccountPaymentEntityBuilder

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));
}
Also used : PersonnelBuilder(org.mifos.domain.builders.PersonnelBuilder) Money(org.mifos.framework.util.helpers.Money) AccountBO(org.mifos.accounts.business.AccountBO) AccountNotesEntityBuilder(org.mifos.accounts.business.AccountNotesEntityBuilder) AccountPaymentEntityBuilder(org.mifos.accounts.business.AccountPaymentEntityBuilder) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountNotesEntity(org.mifos.accounts.business.AccountNotesEntity) CustomerBO(org.mifos.customers.business.CustomerBO) SavingsAccountBuilder(org.mifos.domain.builders.SavingsAccountBuilder) AccountStatusChangeHistoryEntity(org.mifos.accounts.business.AccountStatusChangeHistoryEntity) ClientBuilder(org.mifos.domain.builders.ClientBuilder) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)7 AccountPaymentEntityBuilder (org.mifos.accounts.business.AccountPaymentEntityBuilder)7 CustomerBO (org.mifos.customers.business.CustomerBO)7 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)7 Money (org.mifos.framework.util.helpers.Money)7 AccountNotesEntity (org.mifos.accounts.business.AccountNotesEntity)5 AccountNotesEntityBuilder (org.mifos.accounts.business.AccountNotesEntityBuilder)5 ClientBuilder (org.mifos.domain.builders.ClientBuilder)5 PersonnelBuilder (org.mifos.domain.builders.PersonnelBuilder)5 SavingsAccountBuilder (org.mifos.domain.builders.SavingsAccountBuilder)5 AccountActionEntity (org.mifos.accounts.business.AccountActionEntity)2 AccountTrxnEntity (org.mifos.accounts.business.AccountTrxnEntity)2 LegacyLoanDao (org.mifos.accounts.loan.persistance.LegacyLoanDao)2 AccountActionTypes (org.mifos.accounts.util.helpers.AccountActionTypes)2 LocalDate (org.joda.time.LocalDate)1 AccountBO (org.mifos.accounts.business.AccountBO)1 AccountStatusChangeHistoryEntity (org.mifos.accounts.business.AccountStatusChangeHistoryEntity)1