Search in sources :

Example 31 with MessageMatcher

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

the class QuestionControllerTest method testAddQuestionForFailureWhenQuestionTitleProvidedWithAllBlanks.

@Test
public void testAddQuestionForFailureWhenQuestionTitleProvidedWithAllBlanks() throws Exception {
    QuestionForm qform = new QuestionForm();
    qform.setValidator(validator);
    qform.getCurrentQuestion().setText("   ");
    qform.getCurrentQuestion().setType("freeText");
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    when(messageContext.hasErrorMessages()).thenReturn(true);
    String result = questionController.addQuestion(qform, requestContext, true);
    Assert.assertThat(qform.getQuestions().size(), is(0));
    Assert.assertThat(result, is(notNullValue()));
    Assert.assertThat(result, is("failure"));
    Mockito.verify(requestContext).getMessageContext();
    // TODO: Assert for message code content
    Mockito.verify(messageContext).addMessage(argThat(new MessageMatcher("Pattern.QuestionForm.currentQuestion.text")));
//verify(messageContext).addMessage(argThat(new MessageMatcher("NotNull.QuestionForm.currentQuestion.type")));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) QuestionForm(org.mifos.platform.questionnaire.ui.model.QuestionForm) Test(org.junit.Test)

Example 32 with MessageMatcher

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

the class QuestionControllerTest method testAddQuestionForFailureWhenQuestionTitleNotProvided.

@Test
public void testAddQuestionForFailureWhenQuestionTitleNotProvided() throws Exception {
    QuestionForm questionForm = new QuestionForm();
    questionForm.setValidator(validator);
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    when(messageContext.hasErrorMessages()).thenReturn(true);
    String result = questionController.addQuestion(questionForm, requestContext, true);
    Assert.assertThat(questionForm.getQuestions().size(), is(0));
    Assert.assertThat(result, is(notNullValue()));
    Assert.assertThat(result, is("failure"));
    Mockito.verify(requestContext).getMessageContext();
    Mockito.verify(messageContext).addMessage(argThat(new MessageMatcher("NotNull.QuestionForm.currentQuestion.text")));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) QuestionForm(org.mifos.platform.questionnaire.ui.model.QuestionForm) Test(org.junit.Test)

Example 33 with MessageMatcher

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

the class QuestionControllerTest method testAddQuestionForFailureWhenQuestionTitleIsDuplicateInForm.

@Test
public void testAddQuestionForFailureWhenQuestionTitleIsDuplicateInForm() throws Exception {
    QuestionForm questionForm = new QuestionForm();
    questionForm.getCurrentQuestion().setText("  " + TITLE + "    ");
    questionForm.setQuestions(Arrays.asList(getQuestion("0", TITLE, "number")));
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    String result = questionController.addQuestion(questionForm, requestContext, true);
    Assert.assertThat(questionForm.getQuestions().size(), is(1));
    Assert.assertThat(result, is(notNullValue()));
    Assert.assertThat(result, is("failure"));
    Mockito.verify(requestContext).getMessageContext();
    Mockito.verify(messageContext).addMessage(argThat(new MessageMatcher("questionnaire.error.question.duplicate")));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) QuestionForm(org.mifos.platform.questionnaire.ui.model.QuestionForm) 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