Search in sources :

Example 1 with CashFlowDetail

use of org.mifos.platform.cashflow.service.CashFlowDetail in project head by mifos.

the class LoanServiceFacadeWebTierTest method shouldValidateForRepaymentCapacity.

@Ignore
@Test
public void shouldValidateForRepaymentCapacity() {
    CashFlowDetail cashFlowDetail = new CashFlowDetail(Collections.EMPTY_LIST);
    BigDecimal loanAmount = new BigDecimal(1000);
    CashFlowForm cashFlowForm = new CashFlowForm(cashFlowDetail, false, loanAmount, 10d);
    cashFlowForm.setTotalExpenses(BigDecimal.valueOf(76));
    cashFlowForm.setTotalRevenues(BigDecimal.valueOf(55).add(loanAmount));
    RepaymentScheduleInstallment installment1 = installmentBuilder.reset(locale).withPrincipal(new Money(rupee, "4.9")).withTotalValue("10").build();
    RepaymentScheduleInstallment installment2 = installmentBuilder.reset(locale).withPrincipal(new Money(rupee, "4.9")).withTotalValue("20").build();
    RepaymentScheduleInstallment installment3 = installmentBuilder.reset(locale).withPrincipal(new Money(rupee, "4.9")).withTotalValue("30").build();
    List<RepaymentScheduleInstallment> installments = asList(installment1, installment2, installment3);
    // calcuated repayment capacity is 3298.33
    Errors errors;
//        errors = loanServiceFacade.validateCashFlowForInstallments(installments, cashFlowForm, 1600d);
//        assertThat(errors.hasErrorEntryWithCode(AccountConstants.REPAYMENT_CAPACITY_LESS_THAN_ALLOWED), is(false));
//        errors = loanServiceFacade.validateCashFlowForInstallments(installments, cashFlowForm, 3300d);
//        assertThat(errors.hasErrorEntryWithCode(AccountConstants.REPAYMENT_CAPACITY_LESS_THAN_ALLOWED), is(true));
}
Also used : Money(org.mifos.framework.util.helpers.Money) Errors(org.mifos.platform.validations.Errors) MonthlyCashFlowDetail(org.mifos.platform.cashflow.service.MonthlyCashFlowDetail) CashFlowDetail(org.mifos.platform.cashflow.service.CashFlowDetail) RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) CashFlowForm(org.mifos.platform.cashflow.ui.model.CashFlowForm) BigDecimal(java.math.BigDecimal) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with CashFlowDetail

use of org.mifos.platform.cashflow.service.CashFlowDetail in project head by mifos.

the class CashFlowFormTest method testGetMonthlyCashFlows.

@Test
public void testGetMonthlyCashFlows() throws Exception {
    MonthlyCashFlowDetail cashFlowDetail1 = new MonthlyCashFlowDetail(new DateTime(), new BigDecimal(12), new BigDecimal(12), "notes");
    MonthlyCashFlowDetail cashFlowDetail2 = new MonthlyCashFlowDetail(new DateTime(), new BigDecimal(23), new BigDecimal(34), "notes");
    ArrayList<MonthlyCashFlowDetail> monthlyCashFlowDetails = new ArrayList<MonthlyCashFlowDetail>();
    monthlyCashFlowDetails.add(cashFlowDetail1);
    monthlyCashFlowDetails.add(cashFlowDetail2);
    CashFlowDetail cashFlowDetail = new CashFlowDetail(monthlyCashFlowDetails);
    CashFlowForm cashFlowForm = new CashFlowForm(cashFlowDetail, false, null, 0d);
    List<MonthlyCashFlowForm> actual = cashFlowForm.getMonthlyCashFlows();
    List<MonthlyCashFlowForm> expected = new ArrayList<MonthlyCashFlowForm>();
    expected.add(new MonthlyCashFlowForm(cashFlowDetail1));
    expected.add(new MonthlyCashFlowForm(cashFlowDetail2));
    assertThat(actual.get(0), new MonthlyCashFlowFormMatcher(expected.get(0)));
    assertThat(actual.get(1), new MonthlyCashFlowFormMatcher(expected.get(1)));
}
Also used : MonthlyCashFlowFormMatcher(org.mifos.platform.cashflow.matchers.MonthlyCashFlowFormMatcher) MonthlyCashFlowDetail(org.mifos.platform.cashflow.service.MonthlyCashFlowDetail) CashFlowDetail(org.mifos.platform.cashflow.service.CashFlowDetail) ArrayList(java.util.ArrayList) MonthlyCashFlowDetail(org.mifos.platform.cashflow.service.MonthlyCashFlowDetail) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 3 with CashFlowDetail

use of org.mifos.platform.cashflow.service.CashFlowDetail in project head by mifos.

the class CashFlowFormTest method shouldForValidateIndebtednessRate.

@Test
public void shouldForValidateIndebtednessRate() {
    CashFlowDetail cashFlowDetail = new CashFlowDetail(Collections.EMPTY_LIST);
    cashFlowDetail.setTotalCapital(BigDecimal.TEN);
    cashFlowDetail.setTotalLiability(BigDecimal.TEN);
    CashFlowForm cashFlowForm;
    cashFlowForm = new CashFlowForm(cashFlowDetail, true, new BigDecimal(123), null);
    assertThat(cashFlowForm.shouldForValidateIndebtednessRate(), is(false));
    cashFlowForm = new CashFlowForm(cashFlowDetail, true, new BigDecimal(123), 0d);
    assertThat(cashFlowForm.shouldForValidateIndebtednessRate(), is(false));
    cashFlowForm = new CashFlowForm(cashFlowDetail, true, null, 123d);
    assertThat(cashFlowForm.shouldForValidateIndebtednessRate(), is(false));
    cashFlowForm = new CashFlowForm(null, true, new BigDecimal(123), 123d);
    assertThat(cashFlowForm.shouldForValidateIndebtednessRate(), is(false));
    cashFlowForm = new CashFlowForm(cashFlowDetail, false, new BigDecimal(123), 123d);
    assertThat(cashFlowForm.shouldForValidateIndebtednessRate(), is(false));
    cashFlowForm = new CashFlowForm(cashFlowDetail, true, new BigDecimal(123), 123d);
    assertThat(cashFlowForm.shouldForValidateIndebtednessRate(), is(true));
}
Also used : MonthlyCashFlowDetail(org.mifos.platform.cashflow.service.MonthlyCashFlowDetail) CashFlowDetail(org.mifos.platform.cashflow.service.CashFlowDetail) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 4 with CashFlowDetail

use of org.mifos.platform.cashflow.service.CashFlowDetail in project head by mifos.

the class CashFlowFormTest method shouldComputeRepaymentCapacity.

@Test
public void shouldComputeRepaymentCapacity() {
    CashFlowDetail cashFlowDetail = new CashFlowDetail(Collections.EMPTY_LIST);
    CashFlowForm cashFlowForm = new CashFlowForm(cashFlowDetail, false, new BigDecimal(1000), 10d);
    cashFlowForm.setTotalExpenses(BigDecimal.valueOf(76));
    cashFlowForm.setTotalRevenues(BigDecimal.valueOf(55));
    BigDecimal repaymentCapacity = cashFlowForm.computeRepaymentCapacity(BigDecimal.valueOf(60));
    assertThat(repaymentCapacity, is(notNullValue()));
    assertThat(repaymentCapacity.doubleValue(), is(1631.67));
}
Also used : MonthlyCashFlowDetail(org.mifos.platform.cashflow.service.MonthlyCashFlowDetail) CashFlowDetail(org.mifos.platform.cashflow.service.CashFlowDetail) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 5 with CashFlowDetail

use of org.mifos.platform.cashflow.service.CashFlowDetail in project head by mifos.

the class CashFlowValidatorTest method validateForCalculatedIndebtednessRateGreaterThanOrEqualToIndebtednessRate.

@Test
public void validateForCalculatedIndebtednessRateGreaterThanOrEqualToIndebtednessRate() {
    when(validationContext.getMessageContext()).thenReturn(messageContext);
    CashFlowDetail cashFlowDetail = new CashFlowDetail(EMPTY_LIST);
    cashFlowDetail.setTotalCapital(new BigDecimal(100d));
    cashFlowDetail.setTotalLiability(new BigDecimal(5d));
    CashFlowForm cashFlowForm = new CashFlowForm(cashFlowDetail, true, new BigDecimal(1000d), 1000d);
    cashFlowValidator.validateCaptureCashFlow(cashFlowForm, validationContext);
    verify(validationContext).getMessageContext();
    verify(messageContext).addMessage(argThat(new MessageMatcher(CashFlowConstants.INDEBTEDNESS_RATIO_MORE_THAN_ALLOWED)));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) MonthlyCashFlowDetail(org.mifos.platform.cashflow.service.MonthlyCashFlowDetail) CashFlowDetail(org.mifos.platform.cashflow.service.CashFlowDetail) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

CashFlowDetail (org.mifos.platform.cashflow.service.CashFlowDetail)18 Test (org.junit.Test)17 MonthlyCashFlowDetail (org.mifos.platform.cashflow.service.MonthlyCashFlowDetail)17 BigDecimal (java.math.BigDecimal)15 MessageMatcher (org.mifos.platform.matchers.MessageMatcher)7 DateTime (org.joda.time.DateTime)5 CashFlowForm (org.mifos.platform.cashflow.ui.model.CashFlowForm)4 ArrayList (java.util.ArrayList)2 Ignore (org.junit.Ignore)2 RepaymentScheduleInstallment (org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment)2 Money (org.mifos.framework.util.helpers.Money)2 Errors (org.mifos.platform.validations.Errors)2 CashFlowFormMatcher (org.mifos.platform.cashflow.matchers.CashFlowFormMatcher)1 MonthlyCashFlowFormMatcher (org.mifos.platform.cashflow.matchers.MonthlyCashFlowFormMatcher)1 CashFlowBoundary (org.mifos.platform.cashflow.service.CashFlowBoundary)1 MonthlyCashFlowForm (org.mifos.platform.cashflow.ui.model.MonthlyCashFlowForm)1