Search in sources :

Example 6 with CashFlowDetail

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

the class CashFlowValidatorTest method doNotValidateCumulativeCashIfRevenueOrExpenseNotGiven.

@Test
public void doNotValidateCumulativeCashIfRevenueOrExpenseNotGiven() {
    when(validationContext.getMessageContext()).thenReturn(messageContext);
    when(messageContext.hasErrorMessages()).thenReturn(true);
    DateTime may = new DateTime(2001, 5, 12, 0, 0, 0, 0);
    DateTime june = new DateTime(2001, 6, 12, 0, 0, 0, 0);
    DateTime july = new DateTime(2001, 7, 12, 0, 0, 0, 0);
    MonthlyCashFlowDetail cashFlowDetail1 = new MonthlyCashFlowDetail(may, new BigDecimal(12), new BigDecimal(13), "notes");
    MonthlyCashFlowDetail cashFlowDetail2 = new MonthlyCashFlowDetail(june, null, null, "notes");
    CashFlowDetail cashFlowDetail = new CashFlowDetail(asList(cashFlowDetail1, cashFlowDetail2));
    CashFlowForm cashFlowForm = new CashFlowForm(cashFlowDetail, false, new BigDecimal(1000), 10d);
    cashFlowValidator.validateCaptureCashFlow(cashFlowForm, validationContext);
    verify(messageContext, times(2)).hasErrorMessages();
    verify(validationContext).getMessageContext();
    verify(messageContext, never()).addMessage(argThat(new MessageMatcher(CashFlowConstants.CUMULATIVE_CASH_FLOW_FOR_MONTH_SHOULD_BE_GREATER_THAN_ZERO)));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) MonthlyCashFlowDetail(org.mifos.platform.cashflow.service.MonthlyCashFlowDetail) CashFlowDetail(org.mifos.platform.cashflow.service.CashFlowDetail) DateTime(org.joda.time.DateTime) MonthlyCashFlowDetail(org.mifos.platform.cashflow.service.MonthlyCashFlowDetail) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 7 with CashFlowDetail

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

the class CashFlowValidatorTest method shouldNotValidateForCalculatedIndebtednessRateLessThanIndebtednessRate.

@Test
public void shouldNotValidateForCalculatedIndebtednessRateLessThanIndebtednessRate() {
    when(validationContext.getMessageContext()).thenReturn(messageContext);
    CashFlowDetail cashFlowDetail = new CashFlowDetail(EMPTY_LIST);
    cashFlowDetail.setTotalCapital(new BigDecimal(1000d));
    cashFlowDetail.setTotalLiability(new BigDecimal(5d));
    CashFlowForm cashFlowForm = new CashFlowForm(cashFlowDetail, true, new BigDecimal(1000d), 1000d);
    cashFlowValidator.validateCaptureCashFlow(cashFlowForm, validationContext);
    verify(validationContext).getMessageContext();
    verify(messageContext, never()).addMessage(Matchers.<MessageResolver>anyObject());
}
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 8 with CashFlowDetail

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

the class CashFlowValidatorTest method doNotValidateTotalCapitalAndLiabilityIfCaptureCapitalLiabilityInfoIsNotSet.

@Test
public void doNotValidateTotalCapitalAndLiabilityIfCaptureCapitalLiabilityInfoIsNotSet() throws Exception {
    when(validationContext.getMessageContext()).thenReturn(messageContext);
    CashFlowDetail cashFlowDetail = new CashFlowDetail(EMPTY_LIST);
    cashFlowDetail.setTotalCapital(null);
    cashFlowDetail.setTotalLiability(null);
    CashFlowForm cashFlowForm = new CashFlowForm(cashFlowDetail, false, null, 0d);
    cashFlowValidator.validateCaptureCashFlow(cashFlowForm, validationContext);
    verify(validationContext).getMessageContext();
    verify(messageContext, never()).addMessage(Matchers.<MessageResolver>anyObject());
}
Also used : MonthlyCashFlowDetail(org.mifos.platform.cashflow.service.MonthlyCashFlowDetail) CashFlowDetail(org.mifos.platform.cashflow.service.CashFlowDetail) Test(org.junit.Test)

Example 9 with CashFlowDetail

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

the class CashFlowValidatorTest method validateCaptureCashFlowWhenTotalCapitalIsZero.

@Test
public void validateCaptureCashFlowWhenTotalCapitalIsZero() throws Exception {
    when(validationContext.getMessageContext()).thenReturn(messageContext);
    CashFlowDetail cashFlowDetail = new CashFlowDetail(EMPTY_LIST);
    cashFlowDetail.setTotalCapital(new BigDecimal(0));
    cashFlowDetail.setTotalLiability(new BigDecimal(0));
    CashFlowForm cashFlowForm = new CashFlowForm(cashFlowDetail, true, null, 0d);
    cashFlowValidator.validateCaptureCashFlow(cashFlowForm, validationContext);
    verify(validationContext).getMessageContext();
    verify(messageContext).addMessage(argThat(new MessageMatcher(CashFlowConstants.TOTAL_CAPITAL_SHOULD_BE_GREATER_THAN_ZERO)));
}
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)

Example 10 with CashFlowDetail

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

the class CashFlowValidatorTest method shouldComputeTotalExpenseAndTotalRevenueForAllMonthlyCashFlows.

@Test
public void shouldComputeTotalExpenseAndTotalRevenueForAllMonthlyCashFlows() {
    when(validationContext.getMessageContext()).thenReturn(messageContext);
    when(messageContext.hasErrorMessages()).thenReturn(false);
    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");
    MonthlyCashFlowDetail cashFlowDetail3 = new MonthlyCashFlowDetail(new DateTime(), new BigDecimal(20), new BigDecimal(30), "notes");
    CashFlowDetail cashFlowDetail = new CashFlowDetail(asList(cashFlowDetail1, cashFlowDetail2, cashFlowDetail3));
    CashFlowForm cashFlowForm = new CashFlowForm(cashFlowDetail, false, new BigDecimal(1000), 10d);
    cashFlowValidator.validateCaptureCashFlow(cashFlowForm, validationContext);
    assertThat(cashFlowForm.getTotalExpenses().doubleValue(), is(76d));
    assertThat(cashFlowForm.getTotalRevenues().doubleValue(), is(55d));
    verify(messageContext, times(2)).hasErrorMessages();
    verify(validationContext).getMessageContext();
}
Also used : MonthlyCashFlowDetail(org.mifos.platform.cashflow.service.MonthlyCashFlowDetail) CashFlowDetail(org.mifos.platform.cashflow.service.CashFlowDetail) MonthlyCashFlowDetail(org.mifos.platform.cashflow.service.MonthlyCashFlowDetail) DateTime(org.joda.time.DateTime) 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