Search in sources :

Example 1 with MessageMatcher

use of org.mifos.platform.matchers.MessageMatcher 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)

Example 2 with MessageMatcher

use of org.mifos.platform.matchers.MessageMatcher 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 3 with MessageMatcher

use of org.mifos.platform.matchers.MessageMatcher 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 4 with MessageMatcher

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

the class QuestionGroupControllerTest method testAddQuestionForEmptyType.

@Test
public void testAddQuestionForEmptyType() {
    QuestionGroupForm questionGroupForm = getQuestionGroupForm(TITLE, "Create.Client", "Default");
    questionGroupForm.setValidator(validator);
    questionGroupForm.getCurrentQuestion().setText(TITLE);
    questionGroupForm.getCurrentQuestion().setType(null);
    when(messageContext.hasErrorMessages()).thenReturn(true);
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    String result = questionGroupController.addQuestion(questionGroupForm, requestContext);
    assertThat(result, is("failure"));
    verify(requestContext, times(1)).getMessageContext();
    verify(messageContext).addMessage(argThat(new MessageMatcher("NotNull.QuestionGroupForm.currentQuestion.type")));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) QuestionGroupForm(org.mifos.platform.questionnaire.ui.model.QuestionGroupForm) Test(org.junit.Test)

Example 5 with MessageMatcher

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

the class QuestionGroupControllerTest method testAddSectionWithoutQuestions.

@Test
public void testAddSectionWithoutQuestions() throws Exception {
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    QuestionGroupForm questionGroup = new QuestionGroupForm();
    questionGroup.setTitle("title");
    questionGroup.setSectionName("sectionName");
    String result = questionGroupController.addSection(questionGroup, requestContext);
    verify(requestContext).getMessageContext();
    verify(messageContext).addMessage(argThat(new MessageMatcher("questionnaire.error.no.question.in.section")));
    assertThat(result, Is.is("failure"));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) QuestionGroupForm(org.mifos.platform.questionnaire.ui.model.QuestionGroupForm) 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