Search in sources :

Example 16 with MessageMatcher

use of org.mifos.platform.matchers.MessageMatcher in project head by mifos.

the class UploadQuestionGroupControllerTest method testUploadQuestionGroup_UploadFailureDuringValidation.

@Test
public void testUploadQuestionGroup_UploadFailureDuringValidation() {
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    ValidationException validationException = new ValidationException(GENERIC_VALIDATION);
    validationException.addChildException(new ValidationException(QUESTION_GROUP_TITLE_NOT_PROVIDED));
    validationException.addChildException(new ValidationException(DUPLICATE_QUESTION_FOUND_IN_SECTION));
    doThrow(validationException).when(questionnaireServiceFacade).uploadPPIQuestionGroup("INDIA");
    UploadQuestionGroupForm form = new UploadQuestionGroupForm();
    form.setSelectedCountry("INDIA");
    String result = controller.upload(form, requestContext);
    assertThat(result, is("failure"));
    verify(requestContext).getMessageContext();
    verify(messageContext).addMessage(argThat(new MessageMatcher(QUESTION_GROUP_TITLE_NOT_PROVIDED)));
    verify(messageContext).addMessage(argThat(new MessageMatcher(DUPLICATE_QUESTION_FOUND_IN_SECTION)));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) ValidationException(org.mifos.platform.validations.ValidationException) UploadQuestionGroupForm(org.mifos.platform.questionnaire.ui.model.UploadQuestionGroupForm) Test(org.junit.Test)

Example 17 with MessageMatcher

use of org.mifos.platform.matchers.MessageMatcher in project head by mifos.

the class UploadQuestionGroupControllerTest method testUploadQuestionGroup_UploadFailureDuringPPIProcessing.

@Test
public void testUploadQuestionGroup_UploadFailureDuringPPIProcessing() {
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    doThrow(new SystemException(FETCH_PPI_COUNTRY_XML_FAILED)).when(questionnaireServiceFacade).uploadPPIQuestionGroup("INDIA");
    UploadQuestionGroupForm form = new UploadQuestionGroupForm();
    form.setSelectedCountry("INDIA");
    String result = controller.upload(form, requestContext);
    assertThat(result, is("failure"));
    verify(requestContext).getMessageContext();
    verify(messageContext).addMessage(argThat(new MessageMatcher(FETCH_PPI_COUNTRY_XML_FAILED)));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) UploadQuestionGroupForm(org.mifos.platform.questionnaire.ui.model.UploadQuestionGroupForm) SystemException(org.mifos.framework.exceptions.SystemException) Test(org.junit.Test)

Example 18 with MessageMatcher

use of org.mifos.platform.matchers.MessageMatcher in project head by mifos.

the class CashFlowValidatorTest method indebtednessRateCalculationShouldNotThrowAnyExceptionsOnUnterminatedDecimalPlaceCalculation.

@Test
public void indebtednessRateCalculationShouldNotThrowAnyExceptionsOnUnterminatedDecimalPlaceCalculation() {
    when(validationContext.getMessageContext()).thenReturn(messageContext);
    CashFlowDetail cashFlowDetail = new CashFlowDetail(EMPTY_LIST);
    cashFlowDetail.setTotalCapital(new BigDecimal(33d));
    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)

Example 19 with MessageMatcher

use of org.mifos.platform.matchers.MessageMatcher in project head by mifos.

the class CashFlowValidatorTest method validateCaptureCashFlowWhenTotalCapitalAndTotalLiabilityIsNegative.

@Test
public void validateCaptureCashFlowWhenTotalCapitalAndTotalLiabilityIsNegative() throws Exception {
    when(validationContext.getMessageContext()).thenReturn(messageContext);
    CashFlowDetail cashFlowDetail = new CashFlowDetail(EMPTY_LIST);
    cashFlowDetail.setTotalCapital(new BigDecimal(-23));
    cashFlowDetail.setTotalLiability(new BigDecimal(-1));
    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)));
    verify(messageContext).addMessage(argThat(new MessageMatcher(CashFlowConstants.TOTAL_LIABILITY_SHOULD_BE_NON_NEGATIVE)));
}
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 20 with MessageMatcher

use of org.mifos.platform.matchers.MessageMatcher in project head by mifos.

the class CashFlowValidatorTest method cumulativeCashFlowShouldBeGreaterThanZero.

@Test
public void cumulativeCashFlowShouldBeGreaterThanZero() {
    when(validationContext.getMessageContext()).thenReturn(messageContext);
    when(messageContext.hasErrorMessages()).thenReturn(false);
    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, new BigDecimal(120), new BigDecimal(12), "notes");
    MonthlyCashFlowDetail cashFlowDetail3 = new MonthlyCashFlowDetail(july, new BigDecimal(1), new BigDecimal(108), "notes");
    CashFlowDetail cashFlowDetail = new CashFlowDetail(asList(cashFlowDetail1, cashFlowDetail2, cashFlowDetail3));
    CashFlowForm cashFlowForm = new CashFlowForm(cashFlowDetail, false, new BigDecimal(1000), 10d);
    assertEquals(new BigDecimal("-1"), cashFlowForm.getMonthlyCashFlows().get(0).getCumulativeCashFlow());
    assertEquals(new BigDecimal("107"), cashFlowForm.getMonthlyCashFlows().get(1).getCumulativeCashFlow());
    assertEquals(new BigDecimal("0"), cashFlowForm.getMonthlyCashFlows().get(2).getCumulativeCashFlow());
    cashFlowValidator.validateCaptureCashFlow(cashFlowForm, validationContext);
    verify(messageContext, times(2)).hasErrorMessages();
    verify(validationContext).getMessageContext();
    verify(messageContext, times(2)).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)

Aggregations

Test (org.junit.Test)33 MessageMatcher (org.mifos.platform.matchers.MessageMatcher)33 QuestionGroupForm (org.mifos.platform.questionnaire.ui.model.QuestionGroupForm)10 CashFlowDetail (org.mifos.platform.cashflow.service.CashFlowDetail)7 MonthlyCashFlowDetail (org.mifos.platform.cashflow.service.MonthlyCashFlowDetail)7 QuestionForm (org.mifos.platform.questionnaire.ui.model.QuestionForm)7 BigDecimal (java.math.BigDecimal)6 ValidationException (org.mifos.platform.validations.ValidationException)6 BadNumericResponseException (org.mifos.platform.questionnaire.exceptions.BadNumericResponseException)4 UploadQuestionGroupForm (org.mifos.platform.questionnaire.ui.model.UploadQuestionGroupForm)4 SystemException (org.mifos.framework.exceptions.SystemException)3 DateTime (org.joda.time.DateTime)2 MandatoryAnswerNotFoundException (org.mifos.platform.questionnaire.exceptions.MandatoryAnswerNotFoundException)1 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)1