Search in sources :

Example 11 with MessageMatcher

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

the class QuestionControllerTest method testAddQuestionForFailureWhenInvalidNumericBoundsGiven.

@Test
public void testAddQuestionForFailureWhenInvalidNumericBoundsGiven() throws Exception {
    QuestionForm questionForm = getQuestionForm(TITLE, "number");
    questionForm.getCurrentQuestion().setNumericMin(100);
    questionForm.getCurrentQuestion().setNumericMax(10);
    questionForm.setValidator(validator);
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    when(messageContext.hasErrorMessages()).thenReturn(false);
    String result = questionController.addQuestion(questionForm, requestContext, true);
    Assert.assertThat(questionForm.getQuestions().size(), is(0));
    Assert.assertThat(result, is("failure"));
    Mockito.verify(requestContext).getMessageContext();
    Mockito.verify(messageContext).addMessage(argThat(new MessageMatcher(QuestionnaireConstants.INVALID_NUMERIC_BOUNDS)));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) QuestionForm(org.mifos.platform.questionnaire.ui.model.QuestionForm) Test(org.junit.Test)

Example 12 with MessageMatcher

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

the class QuestionGroupControllerTest method testCreateQuestionGroupForFailureWhenQuestionGroupAppliesToNotProvided.

@Test
public void testCreateQuestionGroupForFailureWhenQuestionGroupAppliesToNotProvided() throws Exception {
    QuestionGroupForm questionGroupForm = getQuestionGroupForm(TITLE, QuestionnaireConstants.DEFAULT_APPLIES_TO_OPTION, "Section");
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    String result = questionGroupController.defineQuestionGroup(questionGroupForm, requestContext, true);
    assertThat(result, Is.is(notNullValue()));
    assertThat(result, Is.is("failure"));
    verify(requestContext).getMessageContext();
    verify(messageContext).addMessage(argThat(new MessageMatcher("questionnaire.error.appliesTo.mandatory")));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) QuestionGroupForm(org.mifos.platform.questionnaire.ui.model.QuestionGroupForm) Test(org.junit.Test)

Example 13 with MessageMatcher

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

the class QuestionGroupControllerTest method testAddQuestionForEmptyTitle.

@Test
public void testAddQuestionForEmptyTitle() {
    QuestionGroupForm questionGroupForm = getQuestionGroupForm(TITLE, "Create.Client", "Default");
    questionGroupForm.setValidator(validator);
    questionGroupForm.getCurrentQuestion().setText(null);
    questionGroupForm.getCurrentQuestion().setType("freeText");
    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.text")));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) QuestionGroupForm(org.mifos.platform.questionnaire.ui.model.QuestionGroupForm) Test(org.junit.Test)

Example 14 with MessageMatcher

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

the class QuestionGroupControllerTest method testCreateQuestionGroupFailure.

@SuppressWarnings({ "ThrowableInstanceNeverThrown" })
@Test
public void testCreateQuestionGroupFailure() throws Exception {
    QuestionGroupForm questionGroupForm = getQuestionGroupForm(TITLE, "Create.Client", "S1", "S2");
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    doThrow(new SystemException("questionnaire.error.duplicate.question.found.in.section")).when(questionnaireServiceFacade).createActiveQuestionGroup(Matchers.<QuestionGroupDetail>anyObject());
    String result = questionGroupController.defineQuestionGroup(questionGroupForm, requestContext, true);
    assertThat(result, Is.is("failure"));
    verify(questionnaireServiceFacade).createActiveQuestionGroup(Matchers.<QuestionGroupDetail>anyObject());
    verify(requestContext).getMessageContext();
    verify(messageContext).addMessage(argThat(new MessageMatcher("questionnaire.error.duplicate.question.found.in.section")));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) SystemException(org.mifos.framework.exceptions.SystemException) QuestionGroupForm(org.mifos.platform.questionnaire.ui.model.QuestionGroupForm) Test(org.junit.Test)

Example 15 with MessageMatcher

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

the class QuestionGroupControllerTest method testAddQuestionForInvalidAnswerChoices.

@Test
public void testAddQuestionForInvalidAnswerChoices() {
    QuestionGroupForm questionGroupForm = getQuestionGroupForm(TITLE, "Create.Client", "Default");
    questionGroupForm.setValidator(validator);
    questionGroupForm.getCurrentQuestion().setText(TITLE);
    questionGroupForm.getCurrentQuestion().setType("singleSelect");
    questionGroupForm.getCurrentQuestion().setCurrentChoice("Choice1");
    questionGroupForm.getCurrentQuestion().addAnswerChoice();
    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("questionnaire.error.question.choices")));
}
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